Beispiel #1
0
        public Task <Result> ExecuteAsync(ReloadRulesJob job)
        {
            _jobs.Start(job);

            var path = GetFolder();

            //находим версию Устава
            var version = _dbContext.GetTypiconVersion(job.TypiconId, job.TypiconVersionStatus);

            Result result = Result.Ok();

            Result.Combine(path, version)
            .OnSuccess(() =>
            {
                DoTheJob(path.Value, version.Value);
            })
            .OnSuccess(async() =>
            {
                await _dbContext.UpdateTypiconVersionAsync(version.Value);

                await _dbContext.ClearModifiedYearsAsync(version.Value.Id);

                await _dbContext.ClearOutputFormsAsync(version.Value.TypiconId, true);

                _jobs.Finish(job, string.Empty);
            })
            .OnFailure(err =>
            {
                _jobs.Fail(job, err);

                result = Result.Fail(err);
            });

            return(Task.FromResult(result));
        }
Beispiel #2
0
        protected override async Task <Result> DoTheJob(PublishTypiconJob job)
        {
            //находим черновик
            var found = _dbContext.GetTypiconVersion(job.TypiconId, TypiconVersionStatus.Draft);

            if (found.Failure)
            {
                //TODO: SendMessage to Owner and sender

                return(Fail(job, found.Error));
            }

            var version = found.Value;

            var errMsg = version.Validate();

            if (errMsg.Count() > 0)
            {
                return(Fail(job, string.Join("", "Ошибка: ", errMsg)));
            }

            var prevStatus = version.Typicon.Status;

            //TypiconEntity
            version.Typicon.Status = TypiconStatus.Publishing;
            await _dbContext.UpdateTypiconEntityAsync(version.Typicon);

            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    version.IsModified = false;
                    version.ModifiedYears.Clear();

                    //new draft
                    var clone = version.Clone();
                    //задаем доп значения
                    clone.TypiconId     = job.TypiconId;
                    clone.VersionNumber = version.VersionNumber + 1;
                    clone.BDate         = null;
                    //Сохраняем, чтобы не было конфликта цикличных зависимостей
                    await _dbContext.UpdateTypiconVersionAsync(clone);

                    //копируем вложенные коллекции
                    version.CopyChildrenTo(clone);
                    //сохраняем
                    await _dbContext.UpdateTypiconVersionAsync(clone);

                    //old publish
                    var oldPublish = _dbContext.GetTypiconVersion(job.TypiconId, TypiconVersionStatus.Published);
                    if (oldPublish.Success)
                    {
                        oldPublish.Value.EDate = DateTime.Now;
                    }

                    //new publish
                    version.BDate = DateTime.Now;

                    //outputforms
                    await _dbContext.ClearOutputFormsAsync(job.TypiconId, job.DeleteModifiedOutputDays);

                    //TODO: SendMessage to Owner and sender


                    //typiconEntity
                    version.Typicon.Status = TypiconStatus.Published;

                    _dbContext.SaveChanges();

                    transaction.Commit();

                    return(Finish(job));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();

                    //version.Typicon.Status = prevStatus;
                    //version.IsModified = true;
                    await _dbContext.UpdateTypiconEntityStatusAsync(version.TypiconId, prevStatus);

                    return(Fail(job, ex.Message));
                }
            }
        }