コード例 #1
0
        private void CheckScheduleAndExecute()
        {
            List <IRTask> tasks;

            lock (this)
                tasks = _tasks.ToList();

            DateTime time = DateTime.Now;

            CultureInfo.CurrentCulture = new CultureInfo("en-US");
            var currentDay  = time.ToString("ddd").ToLower().Substring(0, 2);
            var currentTime = time.ToString("HHmm");

            foreach (var task in tasks.Where(x => x.Schedule != null))
            {
                string[] schedDays = _schedules.First(s => s.Id == task.Schedule.Id).Schedule.Split(' ');

                if (!schedDays.Any(s => s.Contains(currentDay) && s.Contains(currentTime)))
                {
                    continue;
                }

                _monik.ApplicationInfo($"Отсылка отчёта {task.Id} по расписанию");

                Task.Factory.StartNew(() => task.Execute());
            } //for
        }
コード例 #2
0
ファイル: HostHolder.cs プロジェクト: Liklainy/ReportServer
        public HostHolder()
        {
            _nancyHost = new NancyHost(
                new Uri("http://localhost:12345"),
                new Bootstrapper(),
                HostConfigs);

            _monik = Bootstrapper.Global.Resolve <IClientControl>();
            _monik.ApplicationInfo("HostHolder.ctor");
        }
コード例 #3
0
ファイル: RTask.cs プロジェクト: Liklainy/ReportServer
        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