コード例 #1
0
ファイル: FileClients.cs プロジェクト: zwirek2201/CRMTool
        public void DownloadFile(FileModel file)
        {
            try
            {
                IsBusy = true;
                _writer.Write(MessageDictionary.DownloadFile);
                if (_reader.ReadByte() == MessageDictionary.OK)
                {
                    _writer.Write(file.Id);

                    byte[] fileData = ReceiveFile();

                    file.Data = fileData;

                    file.Downloaded = true;

                    FileDownloaded?.Invoke(this, new FileDownloadedEventArgs()
                    {
                        File = file
                    });
                }
                IsBusy = false;
            }
            catch (Exception ex)
            {
                _parent.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
                    ErrorHelper.LogError(ex);
                    Logout();
                });
            }
        }
コード例 #2
0
ファイル: Download.cs プロジェクト: FreeReign/UOMachine
        public Download(string url, string file, FileDownloaded completionCallback, ProgressCallback progressCallback, Files f)
        {
            try
            {
                m_Url = url;
                m_CompletionCallback = completionCallback;
                try
                {
                    m_Stream = new FileStream( file, FileMode.OpenOrCreate, FileAccess.Write );
                }
                catch (IOException e)
                {
                    file = String.Concat( file, ".new" );
                    m_Stream = new FileStream( file, FileMode.OpenOrCreate, FileAccess.Write );
                }

                m_ProgressCallback = progressCallback;
                m_File = f;
                m_Thread = new Thread(new ThreadStart(DownloadFile));
                m_Thread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Downloads the settings file asynchronously.
        /// </summary>
        public async Task DownloadSettingsFileAsync()
        {
            if (m_queryPending)
            {
                return;
            }

            m_queryPending = true;

            EveMonClient.Trace("Initiated");

            SerializableAPIResult <CloudStorageServiceAPIFile> result = await DownloadFileAsync().ConfigureAwait(false);

            FileDownloaded?.ThreadSafeInvoke(this, new CloudStorageServiceProviderEventArgs(result.Error?.ErrorMessage));
            m_queryPending = false;

            string resultText = result.HasError ? "Failed" : "Completed";

            EveMonClient.Trace($"CloudStorageServiceProvider.DownloadSettingsFileAsync - {resultText}", printMethod: false);

            if (!result.HasError)
            {
                Dispatcher.Invoke(() => SaveSettingsFile(result.Result));
            }
        }
コード例 #4
0
ファイル: Megatools.cs プロジェクト: Zelfrom/Mtgdb
        private void downloadOutputReceived(object sender, DataReceivedEventArgs e)
        {
            DownloadedCount++;
            FileDownloaded?.Invoke();

            if (_silent)
            {
                return;
            }

            if (string.IsNullOrEmpty(e.Data))
            {
                return;
            }

            if (e.Data.StartsWith("F "))
            {
                return;
            }

            if (e.Data.StartsWith("D "))
            {
                return;
            }

            Console.WriteLine(e.Data);
        }
コード例 #5
0
 private UpdateDataBase()
 {
     InitializeComponent();
     _uri = "";
     _nameDownloadedFile = "file.new";
     _fileDownloaded = NothingDelegate;
 }
コード例 #6
0
ファイル: FileClients.cs プロジェクト: zwirek2201/CRMTool
 private void CheckQueue()
 {
     try
     {
         while (_isConnected)
         {
             if (DownloadQueue.Count > 0)
             {
                 FileModel downloadedFile = DownloadQueue.First();
                 if (!downloadedFile.Downloaded)
                 {
                     DownloadFile(downloadedFile);
                 }
                 else
                 {
                     FileDownloaded?.Invoke(this, new FileDownloadedEventArgs()
                     {
                         File = downloadedFile
                     });
                 }
                 DownloadQueue.Remove(downloadedFile);
             }
         }
     }
     catch (Exception ex)
     {
         _parent.Dispatcher.Invoke(() =>
         {
             MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
             ErrorHelper.LogError(ex);
             Logout();
         });
     }
 }
コード例 #7
0
        public Download(string url, string file, FileDownloaded completionCallback, ProgressCallback progressCallback, Files f)
        {
            try
            {
                m_Url = url;
                m_CompletionCallback = completionCallback;
                try
                {
                    m_Stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write);
                }
                catch (IOException e)
                {
                    file     = String.Concat(file, ".new");
                    m_Stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write);
                }

                m_ProgressCallback = progressCallback;
                m_File             = f;
                m_Thread           = new Thread(new ThreadStart(DownloadFile));
                m_Thread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #8
0
        private DownloadInfo DoDownloadFile(DownloadInfo info)
        {
            try {
                Measure(
                    () => {
                    var webClient = new WebClient();
                    webClient.DownloadFile(info.Url, info.FilePath);
                },
                    out var workTime);
                info.Error        = DownloadError.Ok;
                info.FileSize     = new FileInfo(info.FilePath).Length;
                info.DownloadTime = workTime;
                LogWriter.Log($"Downloaded {info.ShopName}, time {workTime} ");
            }
            catch (Exception e) {
                info.Error = GetError(e.Message);
                var errorMessage =
                    info.Error == DownloadError.UnknownError
                        ? e.Message
                        : info.Error.ToString();
                _context.AddMessage($"{ info.ShopName }: { errorMessage }", true);
                LogWriter.Log($"{info.ShopName} ошибка { errorMessage }", true);
            }

            if (info.HasError == false)
            {
                _context.AddMessage($"скачали { info.ShopName }");
                _context.CalculatePercent();

                FileDownloaded?.Invoke(this, new DownloadEventArgs(info));
            }

            return(info);
        }
コード例 #9
0
 private void Download_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         FileDownloaded?.BeginInvoke("", null, null);
         Close();
     }
 }
コード例 #10
0
        private void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            TotalProgress = 1;
            IsRunning     = false;

            if (FileDownloaded != null)
            {
                _ = Task.Run(() => FileDownloaded.Invoke(this, new ManifestFile(
                                                             FileName,
                                                             new List <ManifestFileChunkHeader>(),
コード例 #11
0
 /// <summary>
 /// Called when download data completed.
 /// </summary>
 private void OnDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         FileDownloadFailed?.Invoke(this, new FailedDownload(_uri, e.Error));
     }
     else
     {
         FileDownloaded?.Invoke(this, new MemoryStream(e.Result));
     }
 }
コード例 #12
0
 public Download(string url, Stream stream, FileDownloaded completionCallback)
 {
     try
     {
         m_Url                = url;
         m_Stream             = stream;
         m_CompletionCallback = completionCallback;
         m_Thread             = new Thread(new ThreadStart(DownloadFile));
         m_Thread.Start();
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #13
0
ファイル: Download.cs プロジェクト: FreeReign/UOMachine
 public Download(string url, Stream stream, FileDownloaded completionCallback)
 {
     try
     {
         m_Url = url;
         m_Stream = stream;
         m_CompletionCallback = completionCallback;
         m_Thread = new Thread(new ThreadStart(DownloadFile));
         m_Thread.Start();
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #14
0
        /// <summary>
        /// Downloads the settings file.
        /// </summary>
        /// <returns></returns>
        public CloudStorageServiceAPIFile DownloadSettingsFile()
        {
            if (!CloudStorageServiceSettings.Default.DownloadAlways || !HasCredentialsStored)
            {
                return(null);
            }

            if (!IsAuthenticated && !CheckAPIAuthIsValid())
            {
                MessageBox.Show($"The {Name} API credentials could not be authenticated.",
                                $"{Name} API Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(null);
            }

            EveMonClient.Trace("Initiated");

            SerializableAPIResult <CloudStorageServiceAPIFile> result = DownloadFileAsync().Result;

            FileDownloaded?.ThreadSafeInvoke(this, new CloudStorageServiceProviderEventArgs(result.Error?.ErrorMessage));

            if (CloudStorageServiceSettings.Default.UseImmediately)
            {
                if (result.HasError)
                {
                    MessageBox.Show($"File could not be downloaded.\n\nThe error was:\n{result.Error?.ErrorMessage}",
                                    $"{Name} API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    EveMonClient.Trace("Completed");
                    return(result.Result);
                }
            }
            else
            {
                var resultText = result.HasError ? "Failed" : "Completed";
                EveMonClient.Trace(resultText);

                if (!result.HasError)
                {
                    SaveSettingsFile(result.Result);
                }
            }

            return(null);
        }
コード例 #15
0
 public void OnSingleDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     NumberDownloaded += 1;
     // update status, don't contradict MultipleDownloadsCompleted
     if (NumberDownloaded != NumberToDownload)
     {
         Status = String.Format("Downloading {0}", repo.CurrentlyDownloadingUrl);
     }
     // efficient dumping behaviour
     if (NumberDownloaded % 10 == 0)
     {
         ComicConvert.ImgsToCbz(repo.Location, OutputFileName);
     }
     if (FileDownloaded != null)
     {
         FileDownloaded.Invoke(sender, e);
     }
 }
コード例 #16
0
        public void DownloadFileToCache(string downloadUrl, string cachedFilename, TimeSpan?expirationTime = null, FileDownloaded callback = null)
        {
            if (string.IsNullOrWhiteSpace(downloadUrl) == false)
            {
                HttpRequest webRequest  = new HttpRequest();
                RestRequest restRequest = new RestRequest(Method.GET);
                restRequest.AddHeader("Accept", "image/png, text/*");

                webRequest.ExecuteAsync(downloadUrl, restRequest,
                                        delegate(HttpStatusCode statusCode, string statusDescription, byte[] model)
                {
                    bool result = false;

                    if (model != null && Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                    {
                        // write it to cache
                        MemoryStream fileBuffer = new MemoryStream(model);
                        fileBuffer.Position     = 0;
                        FileCache.Instance.SaveFile(fileBuffer, cachedFilename, expirationTime);
                        fileBuffer.Dispose( );

                        result = true;
                    }

                    if (callback != null)
                    {
                        callback(result);
                    }
                });
            }
            else
            {
                if (callback != null)
                {
                    callback(false);
                }
            }
        }
コード例 #17
0
 protected virtual void RaiseFileDownloadedEvent(DownloadCompleteEventArgs eventArgs)
 {
     FileDownloaded?.Invoke(this, eventArgs);
 }
コード例 #18
0
 protected virtual void OnFileDownloaded(object sender, FileManifestEventArgs e)
 {
     FileDownloaded?.Invoke(sender, e);
 }
コード例 #19
0
        public void Handle(FileDownloaded message)
        {
            ICommand command = _saveFileFactory(message.File);

            CommandInvoker.Invoke(command);
        }
コード例 #20
0
 private void OnFileDownloaded(object sender, FileDownloadedArgs e)
 {
     FileDownloaded?.Invoke(this, e);
 }