Exemple #1
0
        public async Task <IHttpActionResult> Post(int limit = 10)
        {
            var tasks = await _repository.GetAllAsync(m => m.StatusId == pendingId ||
                                                      m.StatusId == resumeId ||
                                                      m.StatusId == failureId, limit : limit);

            foreach (var task in tasks)
            {
                task.StatusId = activeId;
            }
            ;

            try
            {
                await _repository.UpdateRangeAsync(tasks);
            }
            catch (DbUpdateException)
            {
                throw;
            }

            InfoTask result = new InfoTask {
                Domains = tasks.GroupBy(msg => msg.Content,
                                        (key, group) => new InfoDomain {
                    Message = key,
                    Tasks   = group.Select(msg => (Info)msg).ToList()
                }).ToList()
            };

            return(Ok(result));
        }
        private static void AnalyzeFiles(object sender, DoWorkEventArgs e)
        {
            var testDelay = 10000; //ввел доп задержку, чтобы интервал для тестирования увеличить
            var period    = DateTime.Now.Subtract(TimeSpan.FromMilliseconds(Storage.DataTaskStorage.Period + testDelay));
            var filesAfterLastTaskWorkflow = Storage.StorageBinaryFiles.Where(item => item.Key > period).Select(item => item.Value);
            var countMatches = 0;

            foreach (var word in Storage.DataTaskStorage.SetWords)
            {
                foreach (var file in filesAfterLastTaskWorkflow)
                {
                    var strFile = System.Text.Encoding.UTF8.GetString(file, 0, file.Length);
                    countMatches += Regex.Matches(strFile, word).Count;
                }
            }

            var messageResult =
                $"Дата запуска задания = {DateTime.Now}. В результате обработки задания с idTask={Storage.DataTaskStorage.Id} в период с {Storage.DataTaskStorage.DateStart}" +
                $" по {Storage.DataTaskStorage.DateFinish} для поискового списка слов {string.Join(" ",Storage.DataTaskStorage.SetWords)} получено количество совпадений = {countMatches}";
            var id   = Storage.StorageTasks.Count > 0 ? Storage.DataTaskStorage.Id : 1;
            var data = new InfoTask {
                Id = id, Info = messageResult
            };

            Storage.StorageTasks.Add(data);
        }
Exemple #3
0
        public static async Task <InfoTask> GetTasksAsync(int limit = 10)
        {
            InfoTask            task     = null;
            Uri                 baseUri  = new Uri(BaseAddress);
            HttpResponseMessage response = await _client.PostAsync(new Uri(baseUri, "api/tasks/take?limit=" + limit), null);

            if (response.IsSuccessStatusCode)
            {
                task = await response.Content.ReadAsAsync <InfoTask>();
            }
            return(task);
        }
Exemple #4
0
        public async Task <IHttpActionResult> Put(AddTask model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ICollection <Message> tasks = new List <Message>();

            foreach (var domain in model.Domains)
            {
                foreach (string phone in domain.Phones)
                {
                    Message task = new Message {
                        PhoneNumber = phone,
                        Content     = domain.Message,
                        StatusId    = pendingId
                    };
                    tasks.Add(task);
                }
            }

            try
            {
                await _repository.AddRangeAsync(tasks);
            }
            catch (DbUpdateException)
            {
                throw;
            }

            InfoTask result = new InfoTask {
                Domains = tasks.GroupBy(msg => msg.Content,
                                        (key, group) => new InfoDomain {
                    Message = key,
                    Tasks   = group.Select(msg => (Info)msg).ToList()
                }).ToList()
            };

            return(Ok(result));
        }