コード例 #1
0
        public Task <IEnumerable <SubscribedEvent> > GetArchiveEventsTask(ArchiveParameters archiveParameters)
        {
            var task = new Task <IEnumerable <SubscribedEvent> >(() =>
            {
                var result = GetArchiveEvents(archiveParameters);
                return(result);
            });

            return(task);
        }
コード例 #2
0
        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; });
        }
コード例 #3
0
        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);
        }