Ejemplo n.º 1
0
        public TResult Create <TResult>(string url, string header, string error)
            where TResult : class
        {
            var uniqueError = error + Guid.NewGuid();
            var json        = _errorableDownloadFactory.Create(url, header, uniqueError);

            return(json == uniqueError ? null : _jsonParser.Create <TResult>(json));
        }
 public TResult Create <TResult>(T input)
     where TResult : class
 {
     try {
         return(_factory.Create <TResult>(input));
     } catch (Exception e) {
         _logger.LogError($"Error occured in {nameof(GenericClassFactoryTryCatchDecorator<object, object, object>)}", e);
         _logger.LogError(LogExtraInformation(input));
         return(null);
     }
 }
Ejemplo n.º 3
0
        public IReceived <IUser, ITransmittable> Create(string input)
        {
            var index   = input.IndexOf(' ');
            var command = input.Substring(0, index);
            var json    = input.Substring(index + 1);

            switch (command)
            {
            case "NAMES": {
                var receivedNames = _jsonParser.Create <ReceivedNames.RootObject>(json);
                var mods          = receivedNames.users.Where(u => u.features.Any(_isMod)).Select(u => new Moderator(u.nick)).ToList();
                var civilians     = receivedNames.users.Where(u => !u.features.Any(_isMod)).Select(u => new Civilian(u.nick, u.features.All(_isProtected)));
                var initialUsers  = new InitialUsers(new List <IUser>().Concat(mods).Concat(civilians));
                _mods.AddRange(mods.Select(x => x.Nick));
                return(new ReceivedInitialUsers(_timeService.UtcNow, initialUsers));
            }

            case "JOIN": {
                var join = _jsonParser.Create <Models.Websockets.ReceivedJoin.RootObject>(json);
                if (join.features.Any(_isMod))
                {
                    _mods.Add(join.nick);
                    return(new Models.Received.ReceivedJoin(new Moderator(join.nick), GetTimestamp(join.timestamp)));
                }
                return(new Models.Received.ReceivedJoin(new Civilian(join.nick, join.features.All(_isProtected)), GetTimestamp(join.timestamp)));
            }

            case "QUIT": {
                var quit = _jsonParser.Create <Models.Websockets.ReceivedQuit.RootObject>(json);
                if (quit.features.Any(_isMod))
                {
                    _mods.Remove(quit.nick);
                    return(new Models.Received.ReceivedQuit(new Moderator(quit.nick), GetTimestamp(quit.timestamp)));
                }
                return(new Models.Received.ReceivedQuit(new Civilian(quit.nick, quit.features.All(_isProtected)), GetTimestamp(quit.timestamp)));
            }

            case "MSG": {
                var message = _jsonParser.Create <ReceivedMsg.RootObject>(json);
                return(message.features.Any(_isMod)
              ? (IReceived <IUser, ITransmittable>) new PublicMessageFromMod(message.nick, message.data, GetTimestamp(message.timestamp))
              : (IReceived <IUser, ITransmittable>) new PublicMessageFromCivilian(message.nick, message.data, GetTimestamp(message.timestamp), message.features.All(_isProtected)));
            }

            case "PRIVMSG": {
                var message = _jsonParser.Create <ReceivedPrivateMessage>(json);
                return(_mods.Contains(message.nick)
              ? (IReceived <IUser, ITransmittable>) new PrivateMessageFromMod(message.nick, message.data, GetTimestamp(message.timestamp))
              : (IReceived <IUser, ITransmittable>)null);
            }

            case "PRIVMSGSENT": {
                return(null);
            }

            case "ERR": {
                switch (json.Trim('"'))
                {
                case "notfound":
                case "nopermission":
                case "needbanreason":
                    return(new ReceivedError($"Server reported error: {json}", _timeService));

                //case "duplicate":
                //case "protocolerror":
                default:
                    throw new NotImplementedException($"{nameof(DestinyGgParser)}'s ERR did not have a case for {json}");
                }
            }

            case "REFRESH":
            case "MUTE":
            case "BAN":
            case "UNMUTE":
            case "UNBAN":
            case "BROADCAST": {
                /*
                 * REFRESH {"nick":"Bot","features":["protected","subscriber","bot","flair8"],"timestamp":1494299684381}
                 * MUTE {"nick":"Bot","features":["protected","subscriber","bot","flair8"],"timestamp":1494300981192,"data":"dharmatest"}
                 * BAN {"nick":"Bot","features":["protected","subscriber","bot","flair8"],"timestamp":1494301117732,"data":"dharmatest"}
                 * UNMUTE {"nick":"Bot","features":["protected","subscriber","bot","flair8"],"timestamp":1494301248941,"data":"dharmatest"}
                 * UNBAN {"nick":"Bot","features":["protected","subscriber","bot","flair8"],"timestamp":1494301339617,"data":"dharmatest"}
                 * BROADCAST {"timestamp":1494301406689,"data":"dharmatest (sorry, this should be the last)"}
                 */
                return(null);
            }
            }
            throw new NotImplementedException($"{nameof(DestinyGgParser)} did not have a case for {input}");
        }
Ejemplo n.º 4
0
 public YoutubeFeed.Feed YoutubeFeed() =>
 _urlXmlParser.Create <YoutubeFeed.Feed>("https://www.youtube.com/feeds/videos.xml?user=destiny", "", "");
Ejemplo n.º 5
0
 public TwitchStreamStatus.RootObject StreamStatus() =>
 _urlJsonParser.Create <TwitchStreamStatus.RootObject>("https://api.twitch.tv/kraken/streams/destiny", _privateConstants.TwitchClientId, "");