Ejemplo n.º 1
0
        private Commands.GuiReportPlanProgress BuildGuiReportPlanProgress(Commands.OperationStatus status)
        {
            TransferOperationReport report = RunningOperation.GetReport() as TransferOperationReport;

            Commands.GuiReportPlanProgress data = new Commands.GuiReportPlanProgress
            {
                Completed      = report.TransferResults.Stats.Completed,
                Total          = report.TransferResults.Stats.Total,
                BytesCompleted = report.TransferResults.Stats.BytesCompleted,
                BytesTotal     = report.TransferResults.Stats.BytesTotal,
            };
            return(data);
        }
Ejemplo n.º 2
0
        private void Run()
        {
            // Load informed plan
            Models.ISchedulablePlan plan = LoadPlan(Options);
            if (plan == null)
            {
                logger.Fatal("The {0} plan with id {1} does not exist.",
                             Options.PlanType.ToString().ToLowerInvariant(), Options.PlanIdentifier);
                ExitShowingHelpText(1);
            }

            Model = plan;

            if (Options.Verbose)
            {
                logger.Info("Running {0} plan #{1}", Options.PlanType.ToString().ToLowerInvariant(), Options.PlanIdentifier);
            }

#if !DEBUG
            try
#endif
            {
                RunningOperation = CreateOperation(plan, Options);

                RunningOperation.Start();

                while (true)
                {
                    if (!IsReleaseVersion && System.Environment.UserInteractive)
                    {
                        if (ConsoleAppHelper.TerminationRequestedEvent.WaitOne(1))
                        {
                            if (RunningOperation != null && RunningOperation.IsRunning)
                            {
                                RunningOperation.Cancel();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (RunningOperationEndedEvent.WaitOne(100))
                    {
                        break;
                    }

                    RunningOperation.DoEvents();
                }

                logger.Info("Operation finished.");

                Handler.Client.WaitUntilDone();

                RunningOperation.SendReport();
            }
#if !DEBUG
            catch (Exception ex)
            {
                string message = ex.Message;

                Handler.Send(Commands.ReportError(0, message));
                logger.Error(message);

                if (RunningOperation != null)
                {
                    BaseOperationReport report = RunningOperation.GetReport() as BaseOperationReport;
                    report.OperationStatus = OperationStatus.FAILED;
                    report.AddErrorMessage(message);
                    RunningOperation.SendReport();
                }

                Environment.Exit(1);
            }
#endif

#if DEBUG
            // Wait 10 seconds before exiting, only for debugging purposes.
            Thread.Sleep(10000);
#endif
        }