Ejemplo n.º 1
0
        private TwitchRootObject GetOnlineStreams()
        {
            var req = new RestRequest("/kraken/streams", Method.GET);
            req.AddHeader("Client-ID", Properties.Settings.Default.TwitchclientID.ToString());
            req.AddParameter("channel", ArrayToString(_streams));
            var response = _client.Execute(req);
            try
            {
                var des = new JsonDeserializer();
                var data = des.Deserialize<TwitchRootObject>(response);

                _lastroot = data;
                return data;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return _lastroot;
            }
        }
Ejemplo n.º 2
0
        private void RemoveStoppedStreams(TwitchRootObject obj)
        {
            foreach (var pair in from pair in _streamData where StreamStopped != null select pair)
            {
                bool bFound = obj.Streams.Any(stream => pair.Key == stream.Channel.Name);
                if(!bFound)
                {
                    TwitchStreamData sd;
                    _streamStopCounter.StreamTriesToStop(pair.Key);
                    if(_streamStopCounter.StreamHasTriedStoppingEnoughTimes(pair.Key) || !_streamData.TryRemove(pair.Key,out sd))
                    {
                        continue;
                    }
                    _streamStopCounter.StreamHasStopped(pair.Key);
                    var stream = new DeathmicChatbot.StreamInfo.Stream
                    {
                        Channel = pair.Value.Stream.Channel.Name,
                        Game = pair.Value.Stream.Game,
                        Message = pair.Value.Stream.Channel.Status
                    };
                    var streamData = new StreamData
                    {
                        Started = DateTime.Now,
                        Stream = stream,
                        StreamProvider = this
                    };
                    var streamEventArgs = new StreamEventArgs(streamData);
                    StreamStopped(this, streamEventArgs);

                }
            }
        }
Ejemplo n.º 3
0
        private void AddNewlyStartedStreams(TwitchRootObject obj)
        {
            if (obj == null || obj.Streams == null || obj.Streams.Count == 0)
                return;

            foreach(var stream in obj.Streams)
            {
                bool globalancounce = false;
                if(_streamData.Keys.Contains(stream.Channel.Name))
                {
                    globalancounce = true;
                }
                bool bTryAddresult = _streamData.TryAdd(stream.Channel.Name, new TwitchStreamData { Started = DateTime.Now, Stream = stream });

                if(bTryAddresult)
                {
                    // Probably helps differentiate between different Game Titles from Response
                    string oldgame = xmlprovider.StreamInfo(stream.Channel.Name, "game");
                    string _game = "";
                    if (oldgame != stream.Channel.Game)
                    {
                        _game = stream.Channel.Game;
                    }
                    if (oldgame != stream.Game)
                    {
                        _game = stream.Game;
                    }
                    var _stream = new DeathmicChatbot.StreamInfo.Stream
                    {
                        Channel = stream.Channel.Name,
                        Game = _game,
                        Message = stream.Channel.Status
                    };
                    var _streamdata = new StreamData
                    {
                        Stream = _stream,
                        Started = DateTime.Now,
                        StreamProvider = this
                    };
                    TwitchStreamData _tstreamdata = new TwitchStreamData();
                    _tstreamdata.Started = DateTime.Now;
                    _tstreamdata.Stream = new DeathmicChatbot.StreamInfo.Twitch.Stream();
                    _tstreamdata.Stream.Channel = new DeathmicChatbot.StreamInfo.Twitch.Channel();
                    _tstreamdata.Stream.Channel.Name = stream.Channel.Name;
                    _tstreamdata.Stream.Channel.Mature = stream.Channel.Mature;
                    _tstreamdata.Stream.Channel.ID = stream.Channel.ID;
                    _tstreamdata.Stream.Channel.Delay = stream.Channel.Delay;
                    _tstreamdata.Stream.Channel.Created_At = stream.Channel.Created_At;
                    _tstreamdata.Stream.Channel.Display_Name = stream.Channel.Display_Name;
                    _tstreamdata.Stream.Channel.Links = stream.Channel.Links;
                    _tstreamdata.Stream.Channel.Profile_Banner = stream.Channel.Profile_Banner;
                    _tstreamdata.Stream.Channel.Url = stream.Channel.Url;
                    _tstreamdata.Stream.Channel.Updated_At = stream.Channel.Updated_At;
                    _tstreamdata.Stream.Game = _game;
                    _tstreamdata.Stream.Channel.Game = _game;

                    AddStreamdatatoXML(_tstreamdata);
                    StreamEventArgs streamEventArgs = new StreamEventArgs(_streamdata);
                    StreamStarted(this, streamEventArgs);
                }
                if(!bTryAddresult && globalancounce)
                {
                    string oldgame = xmlprovider.StreamInfo(stream.Channel.Name, "game");
                    string _game = "";
                    if (oldgame != stream.Channel.Game)
                    {
                        _game = stream.Channel.Game;
                    }
                    if (oldgame != stream.Game)
                    {
                        _game = stream.Game;
                    }

                    var _stream = new DeathmicChatbot.StreamInfo.Stream
                    {
                        Channel = stream.Channel.Name,
                        Game = _game,
                        Message = stream.Channel.Status
                    };
                    var _streamdata = new StreamData
                    {
                        Stream = _stream,
                        Started = DateTime.Now,
                        StreamProvider = this
                    };
                    StreamEventArgs streamEventArgs = new StreamEventArgs(_streamdata);
                    StreamGlobalNotification(this, streamEventArgs);
                }

            }
        }