예제 #1
0
        public IReportTaskRunContext GetCurrentContext(bool takeDefault)
        {
            var context = autofac.Resolve <IReportTaskRunContext>();

            context.OpersToExecute = takeDefault
                ? Operations.Where(oper => oper.Properties.IsDefault)
                                     .OrderBy(oper => oper.Properties.Number).ToList()
                : Operations.OrderBy(oper => oper.Properties.Number).ToList();

            if (!context.OpersToExecute.Any())
            {
                var msg = $"Task {Id} did not executed (no operations found)";
                monik.ApplicationInfo(msg);
                Console.WriteLine(msg);
                return(null);
            }

            context.DefaultExporter = autofac.Resolve <IDefaultTaskExporter>();
            context.TaskId          = Id;
            context.TaskName        = Name;
            context.DependsOn       = DependsOn;

            context.CancelSource = new CancellationTokenSource();


            var pairsTask = Task.Run(async() => await Task.WhenAll(Parameters.Select(async pair =>
                                                                                     new KeyValuePair <string, object>(pair.Key,
                                                                                                                       await repository.GetBaseQueryResult("select " + pair.Value,
                                                                                                                                                           context.CancelSource.Token)))));

            var pairs = pairsTask.Result;

            context.Parameters = pairs
                                 .ToDictionary(pair => pair.Key, pair => pair.Value);

            var dtoTaskInstance = new DtoTaskInstance
            {
                TaskId    = Id,
                StartTime = DateTime.Now,
                Duration  = 0,
                State     = (int)InstanceState.InProcess
            };

            dtoTaskInstance.Id =
                repository.CreateEntity(dtoTaskInstance);

            context.TaskInstance = dtoTaskInstance;

            return(context);
        }
예제 #2
0
        public void GetFileFromSshTest()
        {
            var sshImp          = autofac.ResolveNamed <IOperation>("CommonSshImporter");
            var taskContext     = autofac.Resolve <IRTaskRunContext>();
            var dtoTaskInstance = new DtoTaskInstance
            {
                Id        = 151256,
                StartTime = DateTime.Now,
                Duration  = 0,
                State     = (int)InstanceState.InProcess
            };

            taskContext.TaskInstance = dtoTaskInstance;
            sshImp.Execute(taskContext);
        }
예제 #3
0
        } //ctor

        public IReportTaskRunContext GetCurrentContext(bool isDefault)
        {
            var context = autofac.Resolve <IReportTaskRunContext>();

            context.OpersToExecute = isDefault
                ? Operations.Where(oper => oper.Properties.IsDefault)
                                     .OrderBy(oper => oper.Properties.Number).ToList()
                : Operations.OrderBy(oper => oper.Properties.Number).ToList();

            if (!context.OpersToExecute.Any())
            {
                var msg = $"Task {Id} did not executed (no operations found)";
                monik.ApplicationInfo(msg);
                Console.WriteLine(msg);
                return(null);
            }

            context.Exporter = autofac.Resolve <IDefaultTaskExporter>();
            context.TaskId   = Id;
            context.TaskName = Name; //can do it by NamedParameter+ctor,but..

            context.Parameters = Parameters
                                 .ToDictionary(pair => pair.Key,
                                               pair => repository.GetBaseQueryResult("select " + pair.Value.ToString()));

            context.CancelSource = new CancellationTokenSource();

            var dtoTaskInstance = new DtoTaskInstance
            {
                TaskId    = Id,
                StartTime = DateTime.Now,
                Duration  = 0,
                State     = (int)InstanceState.InProcess
            };

            dtoTaskInstance.Id =
                repository.CreateEntity(dtoTaskInstance);

            context.TaskInstance = dtoTaskInstance;

            return(context);
        }
예제 #4
0
        private void RunOperation(IReportTaskRunContext taskContext, IOperation oper,
                                  DtoTaskInstance dtoTaskInstance, List <Tuple <Exception, string> > exceptions)
        {
            {
                var dtoOperInstance = new DtoOperInstance
                {
                    TaskInstanceId = dtoTaskInstance.Id,
                    OperationId    = oper.Properties.Id,
                    StartTime      = DateTime.Now,
                    Duration       = 0,
                    State          = (int)InstanceState.InProcess
                };

                dtoOperInstance.Id =
                    repository.CreateEntity(dtoOperInstance);

                taskContext.PackageStates[oper.Properties.Number - 1] =
                    GetOperationStateFromInstance(oper.Properties.Name, dtoOperInstance);

                Stopwatch operDuration = new Stopwatch();
                operDuration.Start();

                try
                {
                    Task.Run(async() => await oper
                             .ExecuteAsync(taskContext)).Wait(taskContext.CancelSource.Token);

                    if (oper.Properties.NeedSavePackage)
                    {
                        dtoOperInstance.DataSet =
                            taskContext.GetCompressedPackage(oper.Properties.PackageName);
                    }

                    dtoOperInstance.State = (int)InstanceState.Success;
                    operDuration.Stop();
                    dtoOperInstance.Duration =
                        Convert.ToInt32(operDuration.ElapsedMilliseconds);
                    repository.UpdateEntity(dtoOperInstance);
                }

                catch (Exception e)
                {
                    if (e is OperationCanceledException)
                    {
                        dtoOperInstance.State = (int)InstanceState.Canceled;
                    }

                    else
                    {
                        if (e.InnerException == null)
                        {
                            exceptions.Add(new Tuple <Exception, string>(e, oper.Properties.Name));
                            dtoOperInstance.ErrorMessage = e.Message;
                        }

                        else
                        {
                            var allExceptions = e.FromHierarchy(ex => ex.InnerException).ToList();

                            exceptions.AddRange(allExceptions
                                                .Select(exx => new Tuple <Exception, string>(exx, oper.Properties.Name)));

                            dtoOperInstance.ErrorMessage =
                                string.Join("\n", allExceptions.Select(exx => exx.Message));
                        }

                        dtoOperInstance.State = (int)InstanceState.Failed;
                    }

                    operDuration.Stop();
                    dtoOperInstance.Duration =
                        Convert.ToInt32(operDuration.ElapsedMilliseconds);
                    repository.UpdateEntity(dtoOperInstance);
                }
                finally
                {
                    taskContext.PackageStates[oper.Properties.Number - 1] =
                        GetOperationStateFromInstance(oper.Properties.Name, dtoOperInstance);
                }
            }
        }