Esempio n. 1
0
 public ProcessProgressChangedEventArgs(ProcessData processData)
 {
     ProcessData = processData;
 }
 public ProcessProgressChangedEventArgs(ProcessData processData)
 {
     ProcessData = processData;
 }
Esempio n. 3
0
        /// <summary>
        /// This is the async working part of the process.
        /// </summary>
        /// <param name="args">The arguments passed to the parameterized thread, the ProcessInputParams</param>
        public void Work(object args)
        {
            ///Retrieve the value of the "numberOfSeconds" parameter.
            int numberOfSeconds = Int32.Parse((args as ProcessInputParams)
                                                            .GetData("numberOfSeconds", 0)
                                                            .asLiteralInput().Value);
            int percentage = 0;

            ///This ProcessData contains the response data and process progress
            ///It it passed to the Server instance via the ProgressChanged event.
            ProcessData procData = new ProcessData(this.ExecuteResponseValue,
                                                    this.ProcessDescription,
                                                    this.MainAppDomain,
                                                    AppDomain.CurrentDomain,
                                                    percentage);

            ///It is the container of the ProcessData.
            ProcessProgressChangedEventArgs eventArgs;

            ///Get the start date.
            DateTime start = DateTime.Now;

            ///Set the status of the process at Started, update the status message accordingly.
            this.ExecuteResponseValue.status = ProcessState.Started;
            this.ExecuteResponseValue.statusMessage = "In progress...";

            ///Wait n seconds where n is the number of seconds specified by the user.
            for (int s = 1; s <= numberOfSeconds; s++)
            {
                Thread.Sleep(1000);
                percentage = (int)Math.Floor(((double)s / (double)numberOfSeconds) * 100d);

                ///At each second, update the progress of the process
                this.ExecuteResponseValue.percentageCompleted = percentage;

                ///Update the data from ProcessData which will be passed to the eventhandler
                procData.Progress = percentage;
                procData.ExecuteResponseValue = this.ExecuteResponseValue;

                ///Raise the ProgressChanged event with the eventArgs data.
                eventArgs = new ProcessProgressChangedEventArgs(procData);
                this.OnProcessProgressChanged(eventArgs);

            }

            ///Get the end date
            DateTime end = DateTime.Now;

            ///Update one last time the process infos with the final values
            ///Also update the status and status message.
            this.ExecuteResponseValue.status = ProcessState.Succeeded;
            this.ExecuteResponseValue.statusMessage = "Work done.";

            ///Set the return value.
            this.ExecuteResponseValue.returnValues.Clear();
            this.ExecuteResponseValue.returnValues.Add(new LiteralOutput("AsyncClockResult", "Async Clock Result", "A string containing the start datetime and the end datetime", "string"));
            (this.ExecuteResponseValue.returnValues[0] as LiteralOutput).Value = start.ToLongTimeString() + " " + end.ToLongTimeString();

            procData.ExecuteResponseValue = this.ExecuteResponseValue;

            ///Raise the event. Process status is set to Succeeded, it will then be disposed by the server.
            eventArgs = new ProcessProgressChangedEventArgs(procData);
            this.OnProcessProgressChanged(eventArgs);
        }