Ejemplo n.º 1
0
        /// <summary>
        /// Start a process synchronously.
        /// </summary>
        public virtual void Start()
        {
            try
            {
                RecordsProcessed = 0;

                for (int idx = 0; idx < inputList.Count; idx++)
                {
                    // raise an event on every tenth of a percent (10, 20, 30, etc...)
                    //if (CanRaiseWorkStatus(idx, inputList.Count))
                    RaiseWorkStatus("Processing", idx, MathUtil.Percentage(idx, inputList.Count));

                    // apply input constraints
                    if (GetInput(idx).Equals(default(T)))
                    {
                        throw new ApplicationException("the input for index " + idx + " cannot be set to default.");
                    }

                    // mark the starting time.
                    DateTime start = DateTime.Now;

                    try
                    {
                        MultiThreadEventArgs <T, U> ev = new MultiThreadEventArgs <T, U>(GetInput(idx), idx);

                        // run the actual method for processing input and generate output.
                        ProcessInput(ev);

                        // apply output constraints
                        if (checkForDefaultValues && ev.Result.Equals(default(U)))
                        {
                            throw new ApplicationException("the output for index " + idx + " must be changed.");
                        }

                        SetOutput(idx, ev.Result);
                    }
                    catch (Exception ex)
                    {
                        LogException(idx, ex);
                        if (!ContinueOnError)
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        // save row-level statistics.
                        if (enableStatistics)
                        {
                            statList.Add(idx, new MultiThreadingStatistics(start, DateTime.Now));
                        }
                    }

                    RecordsProcessed++;
                }

                // raise last event
                RaiseWorkStatus("Processing", inputList.Count, 100);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Process the Input
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 protected abstract void ProcessInput(MultiThreadEventArgs <T, U> e);
Ejemplo n.º 3
0
 protected override void ProcessInput(MultiThreadEventArgs <TInput, TOutput> e)
 {
     callback(e);
 }