private void EventsSubscribeThread()
        {
            var connectionParameters = _connectionParametersModel.ConnectionParameter;

            var eventIdForfilter = _selectedEventforFilter != null && _selectedEventforFilter.Id != Guid.Empty ?
                                   _selectedEventforFilter.Id.ToString() :
                                   string.Empty;

            if (eventIdForfilter != string.Empty)
            {
                eventIdForfilter = string.Concat("&filter=", eventIdForfilter);
            }

            var channeldId         = _channelsViewModel.SelectedChannelId;
            var channelIdForFilter = string.Empty;

            if (channeldId != Guid.Empty)
            {
                channelIdForFilter = string.Concat("&channelid=", channeldId);
            }

            var url = String.Format(EventsUrl,
                                    connectionParameters.ServerIp,
                                    connectionParameters.Port,
                                    connectionParameters.Login,
                                    Md5Helper.Md5Hash(connectionParameters.Password),
                                    eventIdForfilter,
                                    channelIdForFilter);

            _urlViewer.Url = url;

            using (var streamToRead = _webRequestFactory.CreateInifinityWebRequest(url))
            {
                if (streamToRead == null)
                {
                    return;
                }

                var stringBuilder = new List <string>();
                using (var sr = new StreamReader(streamToRead))
                {
                    while (_isStarted)
                    {
                        try
                        {
                            string line = sr.ReadLine();
                            if (string.IsNullOrEmpty(line))
                            {
                                stringBuilder.Clear();
                                continue;
                            }

                            stringBuilder.Add(line);

                            if (line == "}")
                            {
                                var subscribedEvent = JsonEventParser.ParseEventFromJsonPaylaod(stringBuilder);

                                OnIncomingNewEvent(subscribedEvent);

                                Thread.Sleep(1000);
                            }
                            //Thread.Sleep(1000);
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }
        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);
        }
示例#3
0
        private IEnumerable <ChannelInfo> GetChannelsInfos()
        {
            var connectionParameters = _connectionParametersModel.ConnectionParameter;
            var url = string.Format(ChannelsUrl, connectionParameters.ServerIp,
                                    connectionParameters.Port,
                                    connectionParameters.Login,
                                    string.IsNullOrWhiteSpace(connectionParameters.Password) ? "" : Md5Helper.Md5Hash(connectionParameters.Password));

            var responseString = _webRequestFactory.CreateAndGetResult(url);

            _urlViewer.Url = url;

            if (string.IsNullOrEmpty(responseString))
            {
                return(new List <ChannelInfo>());
            }

            var xRoot = new XmlRootAttribute
            {
                IsNullable = true,
            };

            var ser = new XmlSerializer(typeof(Configuration), xRoot);

            int startPosToRemove = responseString.IndexOf(XmlTextToRemove, StringComparison.Ordinal);

            if (startPosToRemove == -1)
            {
                return(new List <ChannelInfo>());
            }

            responseString = responseString.Remove(startPosToRemove, XmlTextToRemove.Length);

            using (TextReader reader = new StringReader(responseString))
            {
                var config = ser.Deserialize(reader) as Configuration;

                if (config == null || config.Channels == null)
                {
                    return(new List <ChannelInfo>());
                }

                return(config.Channels);
            }
        }