public Activity Handle(CreateActivity request) { var group = _groupDataStorage.Find(request.GroupKey); var activity = new Activity(0, group.Key, request.Name); return(_activityDataStorage.Create(activity)); }
public Question Handle(CreateQuestion request) { return(_questionDataStorage.Create(new Question(0, request.Text) { Periodicity = request.Periodicity, Type = request.Type, Options = request.Options })); }
private async Task Crawl(Uri urlToCrawl, Link crawlerObjective) { try { Robots robot = await GetRobotTxt(urlToCrawl); if (robot == null || robot.IsPathAllowed(_userAgent, urlToCrawl.AbsoluteUri)) { using (HttpResponseMessage html = await _httpClient.GetAsync(urlToCrawl)) { crawlerObjective.Date = DateTime.Now; crawlerObjective.Address = urlToCrawl.AbsoluteUri; crawlerObjective.Response = html.ToString(); crawlerObjective.IsCrawled = true; if (string.IsNullOrEmpty(crawlerObjective.FoundOn)) { crawlerObjective.FoundOn = urlToCrawl.AbsoluteUri; } _storage.Create(crawlerObjective); if (html.IsSuccessStatusCode) { using (HttpContent content = html.Content) { var page = await content.ReadAsStringAsync(); HtmlDocument htmlDocument = GetHtmlDocument(); htmlDocument.LoadHtml(page); ParseHtml(urlToCrawl, htmlDocument); } } } } } catch (Exception e) { System.Console.Write("\nCrawl: "); System.Console.Write(e.Message); } }
private void EventHandler(object?sender, EncodedMessageEventArgs args) { var messageModel = args.ReceivedObject as MessageModel; if (messageModel == null) { return; } var message = _mapper.Map <ServiceBMessagesStorage.Message>(messageModel); _storage.Create(message); }
public User Handle(CreateUser request) { if (request.TelegramId.HasValue) { var user = _queryDispatcher.Fetch(new FindUserByTelegramId(request.TelegramId.Value)); if (user != null) { throw new ArgumentException("TelegramId"); } } return(_dataStorage.Create(new User(0) { TelegramId = request.TelegramId })); }
public Nothing Handle(ToggleActivityOccurrence request) { var activity = _activityDataStorage.Find(request.ActivityKey); var occurrence = _dispatcher .Fetch(new OccurrencesQuery(request.When, TimeSpan.FromDays(1))) .SingleOrDefault(n => n.ActivityKey == activity.Key && n.When == request.When.Date); if (occurrence == null) { occurrence = _occurrencesDataStorage.Create(new ActivityOccurrence(0, activity.Key, request.When)); _queueDispatcher.Enqueue(new ActivityOccurrenceSaved(activity, occurrence)); } else { _occurrencesDataStorage.Delete(occurrence); _queueDispatcher.Enqueue(new ActivityOccurrenceDeleted(activity, occurrence)); } return(Nothing.AtAll); }
public FinancialJournalEntry Handle(CreateFinancialJournalEntry request) { var taxon = _dispatcher.Fetch(new TaxonTreeQuery { TaxonKey = request.TaxonKey }); if (!taxon.IsSelectable) { throw new InvalidOperationException("Taxon is no selectable"); } var entry = _dataStorage.Create(new FinancialJournalEntry(0, request.TaxonKey) { Remarks = request.Remarks, Actual = request.Actual, Forecasted = request.Forecasted, When = GetWhenFromRequest(request) }); _queueDispatcher.Enqueue(new FinancialJournalEntrySaved(entry)); return(entry); }
public ReadingListEntry Handle(CreateReadingListEntry request) { var entry = new ReadingListEntry(0, request.Author, request.Title); return(_dataStorage.Create(entry)); }
public Nothing Handle(AnswerOnQuestion request) { _answerDataStorage.Create(new Answer(0, request.QuestionKey, DateTime.UtcNow, request.SelectedOptions)); return(Nothing.AtAll); }
public Group Handle(CreateGroup request) { return(_dataStorage.Create(new Group(0, request.Name))); }