Exemplo n.º 1
0
        void Download(string url, DownloadArgs args)
        {
            var client = new WebClient();

            client.OpenReadCompleted += HandleOpenReadCompleted;;
            client.OpenReadAsync(new Uri(url), args);
        }
Exemplo n.º 2
0
        void DownloadData_OnProcessFinish(object sender, DownloadArgs e)
        {
            if (this.InvokeRequired)
            {
                if (e.OrderType == 1)
                {
                    this.Invoke(new Action(FJMainForm.Instance.cSortingTask.ReLoad));
                    this.Invoke(new Action(FJMainForm.Instance.CBox.LoadCigBox));
                    this.Invoke(new Action(FJMainForm.Instance.SetVision));
                    this.Invoke(new Action(FJMainForm.Instance.SetOutPort));
                    this.Invoke(new Action(FJMainForm.Instance.CSortingMain.ReLoad));
                }
                else if (e.OrderType == 2)
                {
                    this.Invoke(new Action(FJMainForm.Instance.cAbnSortingTask.ReLoad));
                    this.Invoke(new Action(FJMainForm.Instance.CAbnBox.LoadCigBox));
                    this.Invoke(new Action(FJMainForm.Instance.SetVision));
                }
            }

            IsDownload = false;

            MonitorLog monitorLog = MonitorLog.NewMonitorLog();

            monitorLog.LOGNAME     = "线程完成";
            monitorLog.LOGINFO     = e.LineName + "分拣任务下载完成";
            monitorLog.LOGLOCATION = "线程操作";
            monitorLog.LOGTYPE     = 1;
            monitorLog.Save();
        }
Exemplo n.º 3
0
 void DownloadData_OnTransferFinish(object sender, DownloadArgs e)
 {
     IsDownload          = false;
     btnDownload.Enabled = true;
     btnExport.Enabled   = true;
     MessageBox.Show("打标机数据传送完成!");
 }
Exemplo n.º 4
0
        public void Execute(DownloadArgs args)
        {
            string dest = Path.ChangeExtension(args.Source, ".git");

            Console.WriteLine($"Unzipping{args.Source} to {dest} ...");
            ZipFile.ExtractToDirectory(args.Source, dest);
        }
        public void DownloadReport(string reportId)
        {
            DownloadArgs downloadArgs = new DownloadArgs
            {
                reportId       = reportId,
                configuration  = _configuration,
                tokenGenerator = _tokenGenerator,
                logger         = _logger
            };

            ThreadPool.QueueUserWorkItem(new WaitCallback(DownloadReportThread), downloadArgs);
        }
        public static async void DownloadReportThread(Object obj)
        {
            DownloadArgs download = obj as DownloadArgs;

            download.logger.LogInformation($"Starting download of report {download.reportId}");
            var accessToken = await download.tokenGenerator.GenerateADTokenWithRetries();

            if (string.IsNullOrEmpty(accessToken))
            {
                download.logger.LogError("Token generation failed");
                return;
            }

            var baseUrl               = download.configuration["ProgrammaticExport:ApiEndpointUrl"];
            var reportExecutionPath   = download.configuration["ProgrammaticExport:ReportExecutionPath"];
            var finalExecutionUriPath = String.Format(reportExecutionPath, download.reportId);

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = await client.GetAsync(finalExecutionUriPath);

            if ((int)response.StatusCode != 200)
            {
                download.logger.LogError($"Failed to get valid response; {response.StatusCode}");
                return;
            }
            var resp = await response.Content.ReadAsStringAsync();

            APIOutput <ScheduledReportExecutionObject> executionResultObject = JsonConvert.DeserializeObject <APIOutput <ScheduledReportExecutionObject> >(resp);

            if (executionResultObject.TotalCount != 1 || string.IsNullOrEmpty(executionResultObject.Value.First().ReportLocation))
            {
                download.logger.LogError($"Invalid record obtained");
                return;
            }
            try
            {
                UncompressedWebClient webClient = new UncompressedWebClient();
                var reportDir = System.IO.Directory.GetCurrentDirectory() + $"\\DownloadedReports";
                System.IO.Directory.CreateDirectory(reportDir);
                var reportFile = $"{reportDir}\\report_{DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString()}.csv";
                webClient.DownloadFile(executionResultObject.Value.First().ReportAccessSecureLink, reportFile);
            } catch (Exception e)
            {
                download.logger.LogError($"Download failed: {e.Message}");
            }
        }
Exemplo n.º 7
0
        static void Example1()
        {
            var files = new List <(Uri, string)> {
                (new Uri("https://www.html-5-tutorial.com/table-tag.htm"), null),
                (new Uri("https://www.html-5-tutorial.com/html-tag.htm"), null),
                (new Uri("https://dotnet.microsoft.com/learn/csharp"), null)
            };

            var downloadArgs = new DownloadArgs
            {
                MaintainSameDirectoryStructure = true,
                RootFolderForDownload          = "Test",
                Files           = files,
                ProgressTracker = t => Console.WriteLine($"Download complete for {t.sourceFileName}")
            };

            RemoteFiles.Instance.Download(downloadArgs);
        }
Exemplo n.º 8
0
        static void Example2()
        {
            Console.WriteLine("Change all h1 to h2 before saving the contents!");
            var files = new List <(Uri, string)> {
                (new Uri("https://www.html-5-tutorial.com/table-tag.htm"), "Downloads/table-tag.html"),
                (new Uri("https://www.html-5-tutorial.com/html-tag.htm"), "Downloads/html-tag.html"),
                (new Uri("https://dotnet.microsoft.com/learn/csharp"), "Downloads/learn-csharp.html")
            };

            var downloadArgs = new DownloadArgs
            {
                Files                    = files,
                ProgressTracker          = t => Console.WriteLine($"Download complete for {t.sourceFileName}"),
                PostFetchContentOverride = contents => contents.Replace("h1", "h2")
            };

            RemoteFiles.Instance.Download(downloadArgs);
        }
Exemplo n.º 9
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            btnDownload.Enabled = false;
            btnExport.Enabled   = false;
            thread = new Thread(new ParameterizedThreadStart(DownloadData.TransferOrderBox));

            if (IsSelectSortingLine())
            {
                DownloadArgs downloadArgs = new DownloadArgs();
                downloadArgs.OrderDate = dateTimeInput1.Value.Date.ToString("yyyy-MM-dd");
                //downloadArgs.Batch = cobbatch.SelectedValue.ToString();

                //DownloadData.TransferOrderBox(downloadArgs);
                thread.Start(downloadArgs);
            }
            else
            {
                MessageBox.Show("任务条件未选择");
            }
        }
Exemplo n.º 10
0
        private void StartDownloads()
        {
            List <DownloadArgs> downloadArgslist = new List <DownloadArgs>();

            foreach (CheckBoxItem checkBoxX in itemPanel1.Items)
            {
                if (checkBoxX.Checked)
                {
                    TaskInfo     taskInfo     = checkBoxX.Tag as TaskInfo;
                    DownloadArgs downloadArgs = new DownloadArgs();
                    downloadArgs.OrderDate = dateTimeInput1.Value.Date.ToString("yyyy-MM-dd");
                    downloadArgs.LineCode  = taskInfo.LineCode;
                    downloadArgs.LineName  = taskInfo.LineName;
                    downloadArgs.Batch     = taskInfo.TaskNo;
                    downloadArgs.OrderType = Convert.ToInt16(taskInfo.LineType);
                    downloadArgs.OutPut    = coboutport.SelectedValue.ToString();
                    downloadArgslist.Add(downloadArgs);
                }
            }
            thread.Start(downloadArgslist);
        }