public void CreateTask(ContentItem item)
        {
            var name = TransformalizeTaskHandler.GetName(item.As <TitlePart>().Title);

            var tasks = _manager.GetTasks(name);

            if (tasks != null && tasks.Any())
            {
                return;
            }

            _manager.CreateTask(name, DateTime.UtcNow.AddSeconds(30), item);
        }
Esempio n. 2
0
        public void Run(string args)
        {
            var split = args.Split(',');
            var id    = Convert.ToInt32(split[0]);
            var mode  = split[1];

            var part    = GetConfiguration(id);
            var request = new TransformalizeRequest(part, GetQuery(), null, Logger)
            {
                Options = new Options()
                {
                    Mode = mode
                }
            };

            if (request.Root.Errors().Any())
            {
                foreach (var error in request.Root.Errors())
                {
                    Logger.Error(error);
                }
            }
            else
            {
                var response = Run(request);

                if (!response.Log.Any())
                {
                    return;
                }

                var name     = TransformalizeTaskHandler.GetName(part.Title());
                var reportId = _reportsManager.CreateReport(mode.Left(1).ToUpper() + mode.Substring(1), name);
                var report   = _reportsManager.Get(reportId);

                var status = string.Empty;
                foreach (var log in response.Log)
                {
                    var level = log[1].Left(4);
                    var utc   = Convert.ToDateTime(log[0]).ToUniversalTime();
                    var data  = log.Skip(3);
                    switch (level)
                    {
                    case "erro":
                        report.Entries.Add(new ReportEntry {
                            Message = string.Join(" | ", data), Type = ReportEntryType.Error, Utc = utc
                        });
                        status = "with Error(s)";
                        break;

                    case "warn":
                        report.Entries.Add(new ReportEntry {
                            Message = string.Join(" | ", data), Type = ReportEntryType.Warning, Utc = utc
                        });
                        if (status != "with Error(s)")
                        {
                            status = "with Warning(s)";
                        }
                        break;

                    default:
                        report.Entries.Add(new ReportEntry {
                            Message = string.Join(" | ", data), Type = ReportEntryType.Information, Utc = utc
                        });
                        break;
                    }
                }
                report.ActivityName += " " + status;
                _reportsManager.Flush();
            }
        }