Esempio n. 1
0
 /// <summary>
 /// Initialize the task parameters, call before the form is loaded
 /// </summary>
 public void InitializeParameters(string expression, string destination)
 {
     Parameters             = new TaskParameters();
     Parameters.Source      = expression;
     Parameters.Destination = destination;
     if (!string.IsNullOrEmpty(expression))
     {
         int    lastDot   = expression.LastIndexOf('.');
         int    lastSlash = expression.LastIndexOf('/');
         string f1        = expression;
         string f2        = f1.Substring(0, lastSlash + 1);
         string f3        = f1.Substring(lastDot);
         string f4        = f1.Substring(lastSlash + 1, lastDot - lastSlash - 1);
         int    d1;
         if (int.TryParse(f4, out d1))
         {
             Parameters.Parameter   = lastDot - lastSlash - 1;
             Parameters.Expression  = string.Format("{0}{1}{2}", f2, "{0}", f3);
             Parameters.BeginIndex  = 1;
             Parameters.EndIndex    = d1;
             Parameters.TotalCount  = Parameters.EndIndex - Parameters.BeginIndex + 1;
             Parameters.ThreadCount = Convert.ToInt32(Math.Floor((double)(Parameters.TotalCount) / 5.0) + 1);
             if (Parameters.ThreadCount > 5)
             {
                 Parameters.ThreadCount = 5;
             }
         }
         else
         {
             Parameters.IsSingle   = true;
             Parameters.Expression = expression;
             Parameters.TotalCount = 1;
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Initialize the task parameters, call before the form is loaded
 /// </summary>
 public void InitializeParameters(string expression, string destination)
 {
     Parameters = new TaskParameters();
     Parameters.Source = expression;
     Parameters.Destination = destination;
     if (!string.IsNullOrEmpty(expression))
     {
         int lastDot = expression.LastIndexOf('.');
         int lastSlash = expression.LastIndexOf('/');
         string f1 = expression;
         string f2 = f1.Substring(0, lastSlash + 1);
         string f3 = f1.Substring(lastDot);
         string f4 = f1.Substring(lastSlash + 1, lastDot - lastSlash - 1);
         int d1;
         if (int.TryParse(f4, out d1))
         {
             Parameters.Parameter = lastDot - lastSlash - 1;
             Parameters.Expression = string.Format("{0}{1}{2}", f2, "{0}", f3);
             Parameters.BeginIndex = 1;
             Parameters.EndIndex = d1;
             Parameters.TotalCount = Parameters.EndIndex - Parameters.BeginIndex + 1;
             Parameters.ThreadCount = Convert.ToInt32(Math.Floor((double)(Parameters.TotalCount) / 5.0) + 1);
             if (Parameters.ThreadCount > 5) Parameters.ThreadCount = 5;
         }
         else
         {
             Parameters.IsSingle = true;
             Parameters.Expression = expression;
             Parameters.TotalCount = 1;
         }
     }
 }
Esempio n. 3
0
        private void OnDispatcherDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker     = sender as BackgroundWorker;
            TaskParameters   parameters = e.Argument as TaskParameters;

            parameters.DoneEvent = new AutoResetEvent(false);

            if (parameters.IsSingle)
            {
                string locp = Program.GetLocalPath(parameters.Source, parameters.Destination);
                if (Program.Download(parameters.Source, locp))
                {
                    worker.ReportProgress(100, new ProgressMessage(parameters.Source));
                }
            }
            else
            {
                workerList    = new List <BackgroundWorker>();
                parameterList = new List <TaskRunParameters>();

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    BackgroundWorker wk = new BackgroundWorker();
                    wk.WorkerReportsProgress = true;
                    wk.ProgressChanged      += new ProgressChangedEventHandler(OnWorkerProgressChanged);
                    wk.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(OnWorkerRunWorkerCompleted);
                    wk.DoWork += new DoWorkEventHandler(OnWorkerDoWork);
                    workerList.Add(wk);

                    TaskRunParameters tp = new TaskRunParameters();
                    tp.Destination = parameters.Destination;
                    tp.Expression  = parameters.Expression;
                    tp.Parameter   = parameters.Parameter;
                    parameterList.Add(tp);
                }

                int index = 0;
                for (int i = parameters.BeginIndex; i <= parameters.EndIndex; i++)
                {
                    if (index >= parameters.ThreadCount)
                    {
                        index = 0;
                    }
                    parameterList[index].Indices.Add(i);
                }

                for (int i = 0; i < parameters.ThreadCount; i++)
                {
                    workerList[i].RunWorkerAsync(parameterList[i]);
                }

                parameters.DoneEvent.WaitOne();
                Thread.Sleep(1000);
            }
        }
Esempio n. 4
0
        private void OnLoad(object sender, EventArgs e)
        {
            if (Parameters == null)
            {
                Parameters = new TaskParameters();
            }
            SourceLabel.Text = Parameters.Expression;
            RangeLabel.Text  = string.Format("{0} - {1}, d{2}, t{3}, {4}",
                                             Parameters.BeginIndex, Parameters.EndIndex, Parameters.Parameter, Parameters.ThreadCount,
                                             Parameters.IsSingle ? "single" : "multi");
            DestinationLabel.Text = Parameters.Destination;
            ProgressBar.Maximum   = Parameters.TotalCount;

            InitializeDispatcher();
            dispatcher.RunWorkerAsync(Parameters);
        }
Esempio n. 5
0
        private void OnLoad(object sender, EventArgs e)
        {
            if (Parameters == null) Parameters = new TaskParameters();
            SourceLabel.Text = Parameters.Expression;
            RangeLabel.Text = string.Format("{0} - {1}, d{2}, t{3}, {4}",
                Parameters.BeginIndex, Parameters.EndIndex, Parameters.Parameter, Parameters.ThreadCount,
                Parameters.IsSingle ? "single" : "multi");
            DestinationLabel.Text = Parameters.Destination;
            ProgressBar.Maximum = Parameters.TotalCount;

            InitializeDispatcher();
            dispatcher.RunWorkerAsync(Parameters);
        }