Ejemplo n.º 1
0
        internal void Ended(DownloadInfo downloadInfo, HowEnded howEnded, bool retry)
        {
            lock (this)
            {
                this.current.Remove(downloadInfo);

                bool b1 = success.Contains(downloadInfo);
                bool b2 = failWithoutRetry.Contains(downloadInfo);
                bool b3 = failedButRetried.Contains(downloadInfo);

                if (!b1 && !b2 && !b3)
                {
                    switch (howEnded)
                    {
                    case HowEnded.SUCCESS:
                    {
                        success.Add(downloadInfo);
                        this.progressTracker.OneDownloadHasFinished();
                        break;
                    }

                    case HowEnded.FAIL:
                    {
                        this.progressTracker.OneDownloadHasFailed(retry);

                        if (retry)
                        {
                            failedButRetried.Add(downloadInfo);
                        }
                        else
                        {
                            failWithoutRetry.Add(downloadInfo);
                        }
                        break;
                    }

                    case HowEnded.NOT_ENDED_YET:
                        break;
                    }
                }

                for (int i = 0; i < 3; i++)
                {
                    if (this.current.GetCount() < this.maxCurrent && waiting.GetCount() > 0)
                    {
                        DownloadInfo p = this.waiting.GetAndRemoveFirst();
                        if (p != null)
                        {
                            Add2(p);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 internal void Remove(DownloadInfo downloadInfo)
 {
     lock (this)
     {
         try
         {
             this.list.Remove(downloadInfo);
         }
         catch
         {
             ;
         }
     }
 }
Ejemplo n.º 3
0
 internal void Add(DownloadInfo downloadInfo)
 {
     lock (this)
     {
         if (current.GetCount() == 0)
         {
             Add2(downloadInfo);
         }
         else
         {
             waiting.Add(downloadInfo);
         }
     }
 }
Ejemplo n.º 4
0
        internal void Add(DownloadInfo downloadInfo)
        {
            if (downloadInfo == null)
            {
                return;
            }

            lock (this)
            {
                bool contained = this.Contains(downloadInfo);
                if (!contained)
                {
                    this.list.Add(downloadInfo);
                }
            }
        }
Ejemplo n.º 5
0
        public bool Contains(DownloadInfo downloadInfo)
        {
            lock (this)
            {
                try
                {
                    foreach (var x in this.list)
                    {
                        if (x == downloadInfo)
                        {
                            return(true);
                        }
                    }
                }
                catch
                {
                    ;
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        private void Add2(DownloadInfo downloadInfo)
        {
            if (downloadInfo == null)
            {
                return;
            }

            lock (this)
            {
                this.current.Add(downloadInfo);
                progressTracker.UpdateFileNum();
                bool             NoOutputRedirect = false;
                ProcessStartInfo oStartInfo;
                downloadInfo.DLError = false;
                if (NoOutputRedirect)
                {
                    oStartInfo = new ProcessStartInfo(downloadInfo.Command, downloadInfo.Arguments)
                    {
                        RedirectStandardOutput = false,
                        RedirectStandardError  = false,
                        RedirectStandardInput  = false,
                        UseShellExecute        = true,
                        WindowStyle            = ProcessWindowStyle.Normal,
                        CreateNoWindow         = false,
                        WorkingDirectory       = downloadInfo.Command.Substring(0, downloadInfo.Command.LastIndexOf(@"\"))
                    };
                }
                else
                {
                    oStartInfo = new ProcessStartInfo(downloadInfo.Command, downloadInfo.Arguments)
                    {
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        RedirectStandardInput  = true,
                        UseShellExecute        = false,
                        WindowStyle            = ProcessWindowStyle.Normal,
                        CreateNoWindow         = true,
                        WorkingDirectory       = downloadInfo.Command.Substring(0, downloadInfo.Command.LastIndexOf(@"\", downloadInfo.Command.Length - 3))
                    };
                }

                downloadInfo.process.EnableRaisingEvents = true;
                downloadInfo.process.StartInfo           = oStartInfo;
                downloadInfo.currentprogress             = downloadInfo.WebexProgress;
                downloadInfo.NotDownloaded = -1;

                if (outputHandler == null)
                {
                    outputHandler = new OutputHandlerUtil(this.downloadForm);
                }

                downloadInfo.process.OutputDataReceived += outputHandler.OutputHandler;
                downloadInfo.process.ErrorDataReceived  += outputHandler.OutputHandler;
                try
                {
                    downloadInfo.process.Start();
                    if (!NoOutputRedirect)
                    {
                        downloadInfo.process.BeginOutputReadLine();
                    }
                    if (!NoOutputRedirect)
                    {
                        downloadInfo.process.BeginErrorReadLine();
                    }
                }
                catch (Exception ex)
                {
                    File.WriteAllText(StartupForm.RootFolder + @"\crashreport.txt", ex.ToString());
                    if (StartupForm.IsItalian)
                    {
                        MessageBox.Show("Errore nell'avvio del processo. Informazioni sull'errore salvate in " + StartupForm.RootFolder + @"\crashreport.txt");
                    }
                    else
                    {
                        MessageBox.Show("Error starting the process. Exception info saved in crashreport.txt");
                    }

                    if (StartupForm.IsItalian)
                    {
                        downloadInfo.CurrentSpeed = "Finito.";
                    }
                    else
                    {
                        downloadInfo.CurrentSpeed = "Finished.";
                    }
                }
            }
        }