示例#1
0
        public void DoAchieve(int gangId)
        {
            var achieves = GetUnCheckedAchieveList(gangId);

            foreach (var item in achieves)
            {
                item.MemberId = gangId;
                IDataExecutor <Achievement> executor = ExecutorFactory <Achievement> .Build(item.Executor);

                executor.Execute(item);
            }
        }
示例#2
0
        public void Execute(string address = null)
        {
            var dtoInstance = new DtoFullInstance()
            {
                StartTime = DateTime.Now,
                TaskId    = Id,
                State     = (int)InstanceState.InProcess
            };

            dtoInstance.Id =
                _repository.CreateEntity(_mapper.Map <DtoInstance>(dtoInstance));

            _repository.CreateEntity(_mapper.Map <DtoInstanceData>(dtoInstance));

            string[] deliveryAddrs = { };

            if (!string.IsNullOrEmpty(address))
            {
                deliveryAddrs = new[] { address }
            }
            ;
            else if (SendAddresses != null)
            {
                deliveryAddrs = SendAddresses.GetAddresses();
            }

            Stopwatch duration = new Stopwatch();

            duration.Start();
            int    i            = 1;
            bool   dataObtained = false;
            string jsonReport   = "";
            string htmlReport   = "";

            while (!dataObtained && i <= TryCount)
            {
                try
                {
                    jsonReport   = _dataEx.Execute(this);
                    htmlReport   = _viewEx.ExecuteHtml(ViewTemplate, jsonReport);
                    dataObtained = true;
                    i++;
                    break;
                }
                catch (Exception ex)
                {
                    jsonReport = ex.Message;
                    htmlReport = ex.Message;
                }

                i++;
            }

            if (dataObtained)
            {
                try
                {
                    if (deliveryAddrs?.Length > 0)
                    {
                        _postMaster.Send(ReportName, deliveryAddrs,
                                         HasHtmlBody ? htmlReport : null,
                                         HasJsonAttachment ? jsonReport : null);
                    }

                    if (ChatId != 0)
                    {
                        try
                        {
                            _bot.SendTextMessageAsync(ChatId, _viewEx.ExecuteTelegramView(jsonReport, ReportName),
                                                      ParseMode.Markdown).Wait();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }

                    _monik.ApplicationInfo($"Отчёт {Id} успешно выслан");
                }
                catch (Exception e)
                {
                    _monik.ApplicationError(e.Message);
                }
            }

            duration.Stop();

            dtoInstance.Data      = _archiver.CompressString(jsonReport);
            dtoInstance.ViewData  = _archiver.CompressString(htmlReport);
            dtoInstance.TryNumber = i - 1;
            dtoInstance.Duration  = Convert.ToInt32(duration.ElapsedMilliseconds);
            dtoInstance.State     = dataObtained ? (int)InstanceState.Success : (int)InstanceState.Failed;

            // string filename = $@"{AppDomain.CurrentDomain.BaseDirectory}\\Report{Id}-{DateTime.Now:HHmmss}";

            _repository.UpdateEntity(_mapper.Map <DtoInstance>(dtoInstance));
            _repository.UpdateEntity(_mapper.Map <DtoInstanceData>(dtoInstance));
        } //method