sweetboicz

appGetBigData

Apr 19th, 2021
553
9 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Net;
  12.  
  13. namespace appGetBigData
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         //-- C:\Users\pavel.zrubek\source\repos\appGetBigData\bin\Debug\appGetBigData.exe -CZC
  18.         //-- C:\Users\pavel.zrubek\source\repos\appGetBigData\bin\Debug\appGetBigData.exe -CZC -1 (noClose)
  19.         //-- C:\Components\appGetBigData.exe -CZCHM -1
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.            
  25.             dwl();
  26.  
  27.             if (myArgs.argNoClose == "1")
  28.             {
  29.                 Application.Exit(); Environment.Exit(0);
  30.             }
  31.         }
  32.  
  33.         private void dwl()
  34.         {
  35.            
  36.  
  37.             string sPartner = myArgs.argPartner;
  38.            
  39.             sPartner = "CZC";
  40.  
  41.             string _dl = "https://data.czc.cz/export-heureka-conviu/";
  42.             string _path = "C:\\Components\\DATA\\dwnlCZC.xml";
  43.  
  44.             switch (sPartner)
  45.             {
  46.                 case "CZC":
  47.                     _dl = "https://data.czc.cz/export-techarena";
  48.                     _path = "C:\\Components\\DATA\\dwnlCZC.xml";
  49.                     break;
  50.                 case "CZCHM":
  51.                     _dl = "https://www.techarena.cz/dwnlCZC.xml";
  52.                     _path = "C:\\Components\\DATA\\dwnlCZC.xml";
  53.                     break;
  54.                 default:
  55.                     break;
  56.             }
  57.  
  58.  
  59.             if (sPartner == "")
  60.             {
  61.                 textBox1.Text += "sPartner NEEXISTUJE!!!" + Environment.NewLine;
  62.                 return;
  63.             }
  64.  
  65.             textBox1.Text += "sPartner: " + sPartner + Environment.NewLine;
  66.             textBox1.Text += "source: " + _dl + Environment.NewLine;
  67.             textBox1.Text += "target: " + _path + Environment.NewLine;
  68.  
  69.             string sUrlToReadFileFrom = _dl;
  70.             // the path to write the file to
  71.             Uri _uri = new Uri(_dl);
  72.             string sFilePathToWriteFileTo = _path;
  73.  
  74.  
  75.             /*ServicePointManager.Expect100Continue = true;
  76.             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;// | SecurityProtocolType.Tls11;// Ssl3;// | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11;
  77.             ServicePointManager.DefaultConnectionLimit = 9999;*/
  78.  
  79.             Uri url = new Uri(sUrlToReadFileFrom);
  80.             textBox1.Text += "url: " + url + Environment.NewLine;
  81.  
  82.             System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
  83.  
  84.             /*request.MaximumAutomaticRedirections = 4;
  85.             request.MaximumResponseHeadersLength = 0x40;
  86.             request.Timeout = 0x927c0;
  87.             request.ProtocolVersion = HttpVersion.Version10;
  88.             request.UseDefaultCredentials = true;
  89.             request.Credentials = CredentialCache.DefaultCredentials;
  90.             request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36";
  91.             request.Headers.Add("IsBot", "0");*/
  92.  
  93.             System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
  94.            
  95.             Int64 iSize = 0;
  96.             // gets the size of the file in bytes    
  97.             try
  98.             {
  99.                 iSize = response.ContentLength;
  100.                 textBox1.Text += "iSize: " + iSize.ToString() + Environment.NewLine;
  101.             }
  102.             catch (Exception e)
  103.             {
  104.                 iSize = -1;
  105.                 textBox1.Text += "Exception: " + e.ToString() + Environment.NewLine;
  106.             }
  107.  
  108.             if (iSize == -1)
  109.             {
  110.                 textBox1.Text += "soubor NELZE stahnout!!!" + Environment.NewLine;
  111.                 return;
  112.             }
  113.  
  114.             response.Close();
  115.  
  116.             // keeps track of the total bytes downloaded so we can update the progress bar    
  117.             Int64 iRunningByteTotal = 0;
  118.  
  119.             // use the webclient object to download the file    
  120.             using (System.Net.WebClient client = new System.Net.WebClient())
  121.             {
  122.  
  123.                 textBox1.Text += "using webClient" + Environment.NewLine;
  124.                 // open the file at the remote URL for reading        
  125.                 using (System.IO.Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom)))
  126.                 {
  127.                     textBox1.Text += "using streamRemote" + Environment.NewLine;
  128.                     // using the FileStream object, we can write the downloaded bytes to the file system            
  129.                     using (Stream streamLocal = new FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None))
  130.                     {
  131.                         textBox1.Text += "using FileStream" + Environment.NewLine;
  132.  
  133.                         // loop the stream and get the file into the byte buffer                
  134.                         int iByteSize = 0;
  135.                         byte[] byteBuffer = new byte[iSize];
  136.                         while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
  137.                         {
  138.                             // write the bytes to the file system at the file path specified                    
  139.                             streamLocal.Write(byteBuffer, 0, iByteSize);
  140.                             iRunningByteTotal += iByteSize;
  141.  
  142.                             // calculate the progress out of a base "100"                    
  143.                             double dIndex = (double)(iRunningByteTotal);
  144.                             double dTotal = (double)byteBuffer.Length;
  145.                             double dProgressPercentage = (dIndex / dTotal);
  146.                             int iProgressPercentage = (int)(dProgressPercentage * 100);
  147.  
  148.                             // update the progress bar                    
  149.                             //backgroundWorker1.ReportProgress(iProgressPercentage);
  150.                         }
  151.  
  152.                         //textBox1.Text += iRunningByteTotal + Environment.NewLine;
  153.  
  154.                         // clean up the file stream                
  155.                         streamLocal.Close();
  156.                     }
  157.                     textBox1.Text += "HOTOVO!!!" + Environment.NewLine;
  158.                     // close the connection to the remote server            
  159.                     streamRemote.Close();
  160.                 }
  161.             }
  162.         }
  163.     }
  164. }
  165.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×