Exemplo n.º 1
0
        public bool Load(ConfigLoadDelegate load, out IStreamingHandler[] targets)
        {
            targets = null;
            if (!File.Exists(ConfigFilePath))
            {
                return(false);
            }
            try {
                JsonObject root = (JsonObject) new JsonValueReader(new StreamReader(ConfigFilePath, System.Text.Encoding.UTF8)).Read();
                if (root.Value.ContainsKey("accounts"))
                {
                    JsonArray        array         = (JsonArray)root.Value["accounts"];
                    JsonArray        accountsArray = array;
                    TwitterAccount[] accounts      = new TwitterAccount[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        accounts[i] = LoadAccount((JsonObject)array[i]);
                    }
                    UpdateAccounts(accounts);

                    array = (JsonArray)root.Value["searches"];
                    SearchStatuses[] searches = new SearchStatuses[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        searches[i] = LoadSearch((JsonObject)array[i], accounts);
                    }
                    _searches = searches;

                    if (root.Value.ContainsKey("lists"))
                    {
                        array = (JsonArray)root.Value["lists"];
                        List <ListStatuses> lists = new List <ListStatuses> ();
                        for (int i = 0; i < array.Length; i++)
                        {
                            ListStatuses ls = LoadList((JsonObject)array[i], accounts);
                            if (ls != null)
                            {
                                lists.Add(ls);
                            }
                        }
                        _lists = lists.ToArray();
                    }

                    targets = new IStreamingHandler[accountsArray.Length];
                    for (int i = 0; i < accountsArray.Length; i++)
                    {
                        targets[i] = LoadStreamingTarget((JsonObject)accountsArray[i], accounts, _searches, _lists);
                    }
                    ReconstructAllStreaming(targets, true);
                }
                load(root);
                return(true);
            } catch {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool Load(ConfigLoadDelegate load, out IStreamingHandler[] targets)
        {
            targets = null;
            if (!File.Exists (ConfigFilePath))
                return false;
            try {
                JsonObject root = (JsonObject)new JsonValueReader (new StreamReader (ConfigFilePath, System.Text.Encoding.UTF8)).Read ();
                if (root.Value.ContainsKey ("accounts")) {
                    JsonArray array = (JsonArray)root.Value["accounts"];
                    JsonArray accountsArray = array;
                    TwitterAccount[] accounts = new TwitterAccount[array.Length];
                    for (int i = 0; i < array.Length; i++)
                        accounts[i] = LoadAccount ((JsonObject)array[i]);
                    UpdateAccounts (accounts);

                    array = (JsonArray)root.Value["searches"];
                    SearchStatuses[] searches = new SearchStatuses[array.Length];
                    for (int i = 0; i < array.Length; i ++)
                        searches[i] = LoadSearch ((JsonObject)array[i], accounts);
                    _searches = searches;

                    if (root.Value.ContainsKey ("lists")) {
                        array = (JsonArray)root.Value["lists"];
                        List<ListStatuses> lists = new List<ListStatuses> ();
                        for (int i = 0; i < array.Length; i++) {
                            ListStatuses ls = LoadList ((JsonObject)array[i], accounts);
                            if (ls != null)
                                lists.Add (ls);
                        }
                        _lists = lists.ToArray ();
                    }

                    targets = new IStreamingHandler[accountsArray.Length];
                    for (int i = 0; i < accountsArray.Length; i ++)
                        targets[i] = LoadStreamingTarget ((JsonObject)accountsArray[i], accounts, _searches, _lists);
                    ReconstructAllStreaming (targets, true);
                }
                load (root);
                return true;
            } catch {
                return false;
            }
        }