Beispiel #1
0
 IStreamingHandler LoadStreamingTarget(JsonObject obj, TwitterAccount[] accounts, SearchStatuses[] searches, ListStatuses[] lists)
 {
     JsonObject root = obj.Value["streaming"] as JsonObject;
     if (root == null) return null;
     string mode = (root.Value["mode"] as JsonString).Value;
     switch (mode) {
         case "follow":
             string username = (root.Value["username"] as JsonString).Value;
             for (int i = 0; i < accounts.Length; i ++)
                 if (username.Equals (accounts[i].ScreenName))
                     return accounts[i];
             break;
         case "track":
             string keywords = (root.Value["keywords"] as JsonString).Value;
             for (int i = 0; i < searches.Length; i ++)
                 if (keywords.Equals (searches[i].Keyword))
                     return searches[i];
             break;
         case "list":
             ulong id = (ulong)(root.Value["id"] as JsonNumber).Value;
             for (int i = 0; i < lists.Length; i++)
                 if (id == lists[i].List.ID)
                     return lists[i];
             break;
     }
     return null;
 }
Beispiel #2
0
 void LoadRestUsage(JsonObject obj, TwitterAccount.RestUsage usage)
 {
     if (obj.Value.ContainsKey ("interval"))
         usage.Interval = TimeSpan.FromSeconds ((obj.Value["interval"] as JsonNumber).Value);
     if (obj.Value.ContainsKey ("count"))
         usage.Count = (int)(obj.Value["count"] as JsonNumber).Value;
 }
Beispiel #3
0
 SearchStatuses LoadSearch(JsonObject obj, TwitterAccount[] accounts)
 {
     string keywords = (obj.Value["keywords"] as JsonString).Value;
     string username = (obj.Value["username"] as JsonString).Value;
     for (int i = 0; i < accounts.Length; i ++) {
         if (accounts[i].ScreenName == username) {
             SearchStatuses ss = new SearchStatuses (accounts[i], keywords);
             LoadRestUsage (obj, ss.RestInfo);
             return ss;
         }
     }
     throw new Exception ();
 }
Beispiel #4
0
        TwitterAccount LoadAccount(JsonObject obj)
        {
            string uname = (obj.Value["username"] as JsonString).Value;
            string password = (obj.Value["password"] as JsonString).Value;
            ICredentials credential = null;
            if (obj.Value.ContainsKey ("token")) {
                string token = (obj.Value["token"] as JsonString).Value;
                string secret = (obj.Value["secret"] as JsonString).Value;
                credential = new OAuthPasswordCache (uname, password, token, secret);
            } else {
                credential = new NetworkCredential (uname, password);
            }

            TwitterAccount account = new TwitterAccount (this);
            account.Credential = credential;
            if (obj.Value.ContainsKey ("id"))
                account.SelfUserID = (ulong)(obj.Value["id"] as JsonNumber).Value;
            if (account.SelfUserID == 0) {
                // Backward compatibility (~0.0.5)
                ThreadPool.QueueUserWorkItem (delegate (object o) {
                    if (credential as OAuthCredentialCache == null)
                        return;
                    for (int i = 0; i < 5; i ++) {
                        try {
                            account.SelfUserID = account.TwitterClient.VerifyCredentials ().ID;
                            break;
                        } catch {}
                        Thread.Sleep (5 * 1000);
                    }
                });
            }
            if (obj.Value.ContainsKey ("rest")) {
                JsonObject restRoot = (obj.Value["rest"] as JsonObject);
                string[] rest_keys = new string[] {"home", "mentions", "dm"};
                TwitterAccount.RestUsage[] rests = new TwitterAccount.RestUsage[] {account.RestHome, account.RestMentions, account.RestDirectMessages};
                for (int i = 0; i < rest_keys.Length; i ++) {
                    if (!restRoot.Value.ContainsKey (rest_keys[i])) continue;
                    JsonObject restInfoRoot = (restRoot.Value[rest_keys[i]] as JsonObject);
                    rests[i].IsEnabled = (restInfoRoot.Value["enable"] as JsonBoolean).Value;
                    rests[i].Count = (int)(restInfoRoot.Value["count"] as JsonNumber).Value;
                    rests[i].Interval = TimeSpan.FromSeconds ((restInfoRoot.Value["interval"] as JsonNumber).Value);
                }
            }
            return account;
        }
Beispiel #5
0
 ListStatuses LoadList(JsonObject obj, TwitterAccount[] accounts)
 {
     ulong id = (ulong)(obj.Value["id"] as JsonNumber).Value;
     string username = (obj.Value["username"] as JsonString).Value;
     for (int i = 0; i < accounts.Length; i++) {
         if (accounts[i].ScreenName == username) {
             ListInfo[] lists = accounts[i].TwitterClient.SelfAndFollowingList;
             for (int j = 0; j < lists.Length; j ++) {
                 if (lists[j].ID == id) {
                     ListStatuses statuses = new ListStatuses (accounts[i], lists[j]);
                     LoadRestUsage (obj, statuses.RestInfo);
                     return statuses;
                 }
             }
         }
     }
     return null;
 }
Beispiel #6
0
 void LoadConfigInternalStyles(JsonObject o)
 {
     if (o.Value.ContainsKey ("colors"))
         LoadConfigInternalColors ((JsonObject)o.Value["colors"]);
     if (o.Value.ContainsKey ("fonts"))
         LoadConfigInternalFonts ((JsonObject)o.Value["fonts"]);
     if (o.Value.ContainsKey ("icon_size"))
         IconSize = (int)(o.Value["icon_size"] as JsonNumber).Value;
 }
Beispiel #7
0
        public JsonValue Read()
        {
            JsonValue cur = null;
            string lastPropName = null;
            Stack<JsonValue> stack = new Stack<JsonValue> ();
            Stack<string> propNameStack = new Stack<string> ();
            JsonReader reader = _reader;

            while (reader.Read ()) {
                switch (reader.Token) {
                    case JsonToken.ArrayStart:
                    case JsonToken.ObjectStart:
                        if (cur != null) {
                            stack.Push (cur);
                            if (cur is JsonObject) {
                                propNameStack.Push (lastPropName);
                                lastPropName = null;
                            }
                        }
                        if (reader.Token == JsonToken.ArrayStart)
                            cur = new JsonArray (new List<JsonValue> ());
                        else
                            cur = new JsonObject (new Dictionary<string,JsonValue> ());
                        break;
                    case JsonToken.ObjectEnd:
                    case JsonToken.ArrayEnd:
                        if (stack.Count == 0)
                            return cur;
                        JsonValue parent = stack.Pop ();
                        if (parent is JsonArray) {
                            (parent as JsonArray).Value.Add (cur);
                        } else if (parent is JsonObject) {
                            lastPropName = propNameStack.Pop ();
                            if (lastPropName == null)
                                throw new JsonException ();
                            (parent as JsonObject).Value.Add (lastPropName, cur);
                            lastPropName = null;
                        }
                        cur = parent;
                        break;
                    case JsonToken.PropertyName:
                        if (lastPropName != null)
                            throw new JsonException ();
                        lastPropName = (string)reader.Value;
                        break;
                    case JsonToken.Boolean:
                    case JsonToken.Null:
                    case JsonToken.Number:
                    case JsonToken.String:
                        JsonValue value;
                        switch (reader.Token) {
                            case JsonToken.Boolean: value = new JsonBoolean ((bool)reader.Value); break;
                            case JsonToken.Null: value = new JsonNull (); break;
                            case JsonToken.Number:
                                value = new JsonNumber (Convert (reader.NumberType), (double)reader.Value, reader.ValueSignedInteger, reader.ValueUnsignedInteger);
                                break;
                            case JsonToken.String: value = new JsonString ((string)reader.Value); break;
                            default: throw new JsonException ();
                        }
                        if (cur == null)
                            return value;
                        if (cur is JsonArray) {
                            (cur as JsonArray).Value.Add (value);
                        } else if (cur is JsonObject) {
                            if (lastPropName == null)
                                throw new JsonException ();
                            (cur as JsonObject).Value.Add (lastPropName, value);
                            lastPropName = null;
                        }
                        break;
                }
            }

            if (cur == null)
                return null;
            throw new JsonException ();
        }
Beispiel #8
0
 void LoadConfigInternalMisc(JsonObject o)
 {
     if (o.Value.ContainsKey ("include_mentions"))
         _mgr.HomeIncludeMentions = (o.Value["include_mentions"] as JsonBoolean).Value;
 }
Beispiel #9
0
 void LoadConfigInternalFonts(JsonObject o)
 {
     try {
         FontFamily = new FontFamily ((o.Value["main-family"] as JsonString).Value);
     } catch {}
     FontSize = (o.Value["main-size"] as JsonNumber).Value;
 }
Beispiel #10
0
 Brush LoadConfigInternalColors(JsonObject o, string key, ColorCodeNameConverter conv, Brush def)
 {
     try {
         if (!o.Value.ContainsKey (key))
             return def;
         return (Brush)conv.ConvertBack ((o.Value[key] as JsonString).Value, null, null, null);
     } catch {
         return def;
     }
 }
Beispiel #11
0
 void LoadConfigInternalColors(JsonObject o)
 {
     ColorCodeNameConverter conv = new ColorCodeNameConverter ();
     Background = LoadConfigInternalColors (o, "bg", conv, Background);
     Foreground = LoadConfigInternalColors (o, "fg", conv, Foreground);
     PostTextBox.Background = LoadConfigInternalColors (o, "postTextBoxBg", conv, PostTextBox.Background);
     PostTextBox.Foreground = LoadConfigInternalColors (o, "postTextBoxFg", conv, PostTextBox.Foreground);
     PostBackground = LoadConfigInternalColors (o, "postBg", conv, PostBackground);
     PostForeground = LoadConfigInternalColors (o, "postFg", conv, PostForeground);
     NameForeground = LoadConfigInternalColors (o, "postNameFg", conv, NameForeground);
     LinkForeground = LoadConfigInternalColors (o, "postLinkFg", conv, LinkForeground);
 }
Beispiel #12
0
        void LoadConfig(JsonObject root)
        {
            if (root.Value.ContainsKey ("windows"))
                LoadConfigInternal ((JsonArray)root.Value["windows"], _rootTLs);
            if (root.Value.ContainsKey ("colors")) // compatibility 0.0.5
                LoadConfigInternalColors ((JsonObject)root.Value["colors"]);
            if (root.Value.ContainsKey ("fonts"))  // compatibility 0.0.5
                LoadConfigInternalFonts ((JsonObject)root.Value["fonts"]);
            if (root.Value.ContainsKey ("hashTags"))
                LoadConfigInternalHashTags ((JsonArray)root.Value["hashTags"]);
            if (root.Value.ContainsKey ("footer"))
                FooterText = (root.Value["footer"] as JsonString).Value;

            if (root.Value.ContainsKey ("streaming")) {
                JsonObject conf = (JsonObject)root.Value["streaming"];
                if (conf.Value.ContainsKey ("include_other"))
                    IsIncludeOtherStatus = (conf.Value["include_other"] as JsonBoolean).Value;
            }
            if (root.Value.ContainsKey ("styles"))
                LoadConfigInternalStyles ((JsonObject)root.Value["styles"]);
            if (root.Value.ContainsKey ("misc"))
                LoadConfigInternalMisc ((JsonObject)root.Value["misc"]);
        }