public Task <IEnumerable <SubscribedEvent> > GetArchiveEventsTask(ArchiveParameters archiveParameters) { var task = new Task <IEnumerable <SubscribedEvent> >(() => { var result = GetArchiveEvents(archiveParameters); return(result); }); return(task); }
private void OnGetArchiveEventsCommand() { var archiveParameters = new ArchiveParameters { ChannelId = _channelsViewModel.SelectedChannelId, DateTimeStart = SelectedDateTimeStart, DateTimeEnd = SelectedDateTimeEnd, EventId = _registeredEventsViewModel.SelectedEventInfo.Id }; var archiveEventsTask = _archiveEventsModel.GetArchiveEventsTask(archiveParameters); archiveEventsTask.Start(); archiveEventsTask.ContinueWith(t => { ArchiveEvents = t.Result; }); }
private IEnumerable <SubscribedEvent> GetArchiveEvents(ArchiveParameters archiveParameters) { var connectionParameters = _connectionParametersModel.ConnectionParameter; var url = string.Format(ArchiveEventsUrl, connectionParameters.ServerIp, connectionParameters.Port, connectionParameters.Login, Md5Helper.Md5Hash(connectionParameters.Password), archiveParameters.DateTimeStart, archiveParameters.DateTimeEnd); if (archiveParameters.ChannelId != Guid.Empty) { url += string.Concat("&channelid=", archiveParameters.ChannelId); } if (archiveParameters.EventId != Guid.Empty) { url += string.Concat("&eventid=", archiveParameters.EventId); } _urlViewer.Url = url; var responseString = _webRequestFactory.CreateAndGetResult(url); if (string.IsNullOrEmpty(responseString)) { return(new List <SubscribedEvent>()); } var resultsSubscribedEvents = new List <SubscribedEvent>(); var stringBuilder = new List <string>(); using (var reader = new StringReader(responseString)) { while (reader.Peek() > -1) { var line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { stringBuilder.Clear(); continue; } stringBuilder.Add(line); if (line != "}") { continue; } var subscribedEvent = JsonEventParser.ParseEventFromJsonPaylaod(stringBuilder); if (subscribedEvent == null) { continue; } resultsSubscribedEvents.Add(subscribedEvent); } } return(resultsSubscribedEvents); }