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);
        }
        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);
                        }
                    }
                }
            }
        }