Exemplo n.º 1
0
 public TodoController(TodoContext todoContext,
                       ILogger <TodoController> logger,
                       IOperationTransien operationTransien,
                       IOperationScope operationScope,
                       IOperationSingleton operationSingleton,
                       IOptionsMonitor <PositionOptions> optionsMonitor,
                       IOptionsSnapshot <TopItemSettings> namedOptionsAccessor,
                       IOptions <MyConfigOptions> options,
                       IHttpClientFactory httpClientFactory,
                       IMemoryCache cache,
                       IDistributedCache distributedCache)
 {
     _todoContext        = todoContext;
     _logger             = logger;
     _operationTransien  = operationTransien;
     _operationScope     = operationScope;
     _operationSingleton = operationSingleton;
     _positionOptions    = optionsMonitor.CurrentValue;
     _monthTopItem       = namedOptionsAccessor.Get(TopItemSettings.Month);
     _yearTopItem        = namedOptionsAccessor.Get(TopItemSettings.Year);
     _myConfigOptions    = options.Value;
     _clientFactory      = httpClientFactory;
     _cache            = cache;
     _distributedCache = distributedCache;
 }
Exemplo n.º 2
0
        public LocalOperationScope(OperationScopeProvider operationScopeProvider, IOperationScope parentOperationScope, string name)
        {
            _operationScopeProvider = operationScopeProvider;

            _data[@"$operationScopeId"]     = Guid.NewGuid();
            _data[@"$operationScopeName"]   = name;
            _data[@"$parentOperationScope"] = parentOperationScope;
        }
 public CompositeTypeTask(
     IServiceFactory serviceFactory,
     IOperationScope scope
     )
 {
     this.serviceFactory = serviceFactory;
     this.scope          = scope;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Performs the current run segment run.
 /// </summary>
 public void Run()
 {
     foreach (EntityIdentifier id in this.idsOfEntitiesToDelete)
     {
         using (IOperationScope scope = this.operationExecutive.CreateOperation())
         {
             this.DeleteEntity(id);
             scope.Complete();
         }
     }
 }
Exemplo n.º 5
0
 private void SetMappingState(IMapping <TEntity> mapping, MappingState state)
 {
     using (IOperationScope scope = this.operationExecutive.CreateOperation())
     {
         mapping.SetState(state);
         this.eventDispatcher.OrphanMappingProcessed(
             new OrphanMappingProcessedArgs(
                 this.operationExecutive.CurrentOperation.TimeStamp));
         scope.Complete();
     }
 }
Exemplo n.º 6
0
 public static void Update([NotNull] this IOperationScope scope, [NotNull] IOperationProgress progress)
 {
     if (scope == null)
     {
         throw new ArgumentNullException(nameof(scope));
     }
     if (progress == null)
     {
         throw new ArgumentNullException(nameof(progress));
     }
     scope.Runner.RootTracker.UpdateOperation(scope.Operation, progress);
 }
Exemplo n.º 7
0
        public static void Error([NotNull] this IOperationScope scope, [NotNull] Exception error)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            scope.Runner.RootTracker.OperationError(scope.Operation, error);
        }
Exemplo n.º 8
0
        public async Task Invoke(HttpContext httpContext,
                                 ILogger <RequestSetOptionsMiddleware> logger,
                                 IOperationTransien operationTransien,
                                 IOperationScope operationScope,
                                 IOperationSingleton operationSingleton)
        {
            var option = httpContext.Request.Query["option"];

            logger.LogInformation($"transient id is {operationTransien.OperationId}");
            logger.LogInformation($"scope id is {operationScope.OperationId}");
            logger.LogInformation($"singleton id is {operationSingleton.OperationId}");
            if (!string.IsNullOrEmpty(option))
            {
                httpContext.Items["option"] = WebUtility.HtmlEncode(option);
            }
            await _next(httpContext);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Performs the current run segment run.
        /// </summary>
        public void Run()
        {
            IEnumerable <TEntity> entities = this.LoadEntities();
            IDictionary <EntityIdentifier, IMapping <TEntity> > mappings = this.GetMappings();

            foreach (TEntity entity in entities)
            {
                using (IOperationScope scope = this.operationExecutive.CreateOperation())
                {
                    if (entity == null)
                    {
                        throw new InvalidOperationException(
                                  Resources.FeedReturnedCollectionWithNullElement);
                    }
                    this.Process(entity);
                    this.RemoveMapping(mappings, entity);
                    scope.Complete();
                }
            }
            this.ProcessOrphanMappings(mappings.Values);
        }
 public virtual void OperationScopeDisposing(IOperationScope scope)
 {
 }
Exemplo n.º 11
0
 public EntryService(
     IOperationScope scope
     )
 {
     this.scope = scope;
 }
 public HttpClientLogger(IOperationScope scope)
 {
     this.scope = scope;
 }
 public WSLogger(
     IOperationScope scope
     )
 {
     this.scope = scope;
 }
        public void RunAsync(int OperationId, string Code, ErpType Erp, bool Forced, Action <TaskStatus> After)
        {
            var ts = new CancellationTokenSource();
            CancellationToken ct = ts.Token;

            Task newTask = Task.Run(async() =>
            {
                void setScope()
                {
                    IOperationScope scope = container.GetInstance <IOperationScope>();
                    scope.Provide(OperationId, ct);
                }

                try
                {
                    using (AsyncScopedLifestyle.BeginScope(container))
                    {
                        setScope();

                        ITaskFinder finder = container.GetInstance <ITaskFinder>();
                        (bool IsAsync, object Task)item = finder.Get(Code, Erp);

                        TaskStatus status;
                        if (item.IsAsync)
                        {
                            status = await(item.Task as ITaskAsync).Execute();
                        }
                        else
                        {
                            status = (item.Task as ITask).Execute();
                        }
                        After(status);
                    }
                }
                catch (Exception e)
                {
                    /* Use a different scope to ignore all the data inserted before */
                    using (AsyncScopedLifestyle.BeginScope(container))
                    {
                        setScope();

                        ITaskLogger logger = container.GetInstance <ITaskLogger>();

                        await logger.Insert(e, $"Task {Code}");

                        bool cancelled = IsCancelledException(e);
                        After(cancelled ? TaskStatus.Cancelled : TaskStatus.Error);
                    }
                }
            }, ct);

            JobTrack track = new JobTrack()
            {
                JobCode     = Code,
                Task        = newTask,
                TokenSource = ts,
                OperationId = OperationId
            };

            tracker.Add(track);
        }