Esempio n. 1
0
        public void AddSearchInfo(SearchStatuses search)
        {
            List <SearchStatuses> list = new List <SearchStatuses> (_searches);

            list.Add(search);
            _searches = list.ToArray();
        }
Esempio 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);
            }
        }
Esempio n. 3
0
 void WriteSearch(JsonTextWriter writer, SearchStatuses search)
 {
     writer.WriteStartObject();
     writer.WriteKey("keywords");
     writer.WriteString(search.Keyword);
     writer.WriteKey("username");
     writer.WriteString(search.Account.ScreenName);
     WriteRestUsage(writer, search.RestInfo);
     writer.WriteEndObject();
 }
Esempio n. 4
0
        public void ReconstructAllStreaming(IStreamingHandler[] targets, bool dummy)
        {
            if (Accounts.Length != targets.Length)
            {
                throw new ArgumentException();
            }

            CloseAllStreaming();

            Dictionary <IStreamingHandler, List <TwitterAccount> > dic = new Dictionary <IStreamingHandler, List <TwitterAccount> > ();

            for (int i = 0; i < Accounts.Length; i++)
            {
                IStreamingHandler h = targets[i];
                if (h == null)
                {
                    continue;
                }
                List <TwitterAccount> list;
                if (!dic.TryGetValue(h, out list))
                {
                    list = new List <TwitterAccount> ();
                    dic.Add(h, list);
                }
                list.Add(Accounts[i]);
            }
            foreach (KeyValuePair <IStreamingHandler, List <TwitterAccount> > pair in dic)
            {
                TwitterAccount homeTarget   = pair.Key as TwitterAccount;
                SearchStatuses searchTarget = pair.Key as SearchStatuses;
                ListStatuses   listTarget   = pair.Key as ListStatuses;
                if (homeTarget != null)
                {
                    /*ulong[] ids;
                     * try {
                     *      ids = dummy ? null : homeTarget.TwitterClient.FriendIDs;
                     * } catch {
                     *      continue;
                     * }
                     * new StreamingClient (pair.Value.ToArray (), ids, homeTarget, dummy);*/
                    new StreamingClient(homeTarget, homeTarget, dummy);
                }
                else if (searchTarget != null)
                {
                    searchTarget.StreamingClient = new StreamingClient(pair.Value.ToArray(), searchTarget.Keyword, searchTarget, dummy);
                }
                else if (listTarget != null)
                {
                    listTarget.StreamingClient = new StreamingClient(pair.Value.ToArray(), listTarget.Account, listTarget.List, listTarget, dummy);
                }
            }
        }
Esempio n. 5
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();
        }
Esempio n. 6
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;
 }
Esempio n. 7
0
 void WriteSearch(JsonTextWriter writer, SearchStatuses search)
 {
     writer.WriteStartObject ();
     writer.WriteKey ("keywords");
     writer.WriteString (search.Keyword);
     writer.WriteKey ("username");
     writer.WriteString (search.Account.ScreenName);
     WriteRestUsage (writer, search.RestInfo);
     writer.WriteEndObject ();
 }
Esempio n. 8
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 ();
 }
Esempio n. 9
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;
            }
        }
Esempio n. 10
0
 public void AddSearchInfo(SearchStatuses search)
 {
     List<SearchStatuses> list = new List<SearchStatuses> (_searches);
     list.Add (search);
     _searches = list.ToArray ();
 }
Esempio n. 11
0
        private void MenuItem_AddNewTimeline_Click(object sender, RoutedEventArgs e)
        {
            NewTimelineWindow win = new NewTimelineWindow (_mgr);
            win.Owner = this;
            bool? ret = win.ShowDialog ();
            if (!ret.HasValue || !ret.Value)
                return;

            TimelineBase info = null;
            TwitterAccount account = win.SelectedAccount;
            if (win.IsCheckedAccountTimeline) {
                info = new TimelineInfo (_mgr, _rootTLs, account, win.SelectedAccountTimeline);
            } else if (win.IsCheckedNewSearch && win.SearchKeyword.Length > 0) {
                SearchStatuses search = new SearchStatuses (account, win.SearchKeyword);
                if (win.IsUseStreamingForSearch)
                    search.StreamingClient = new StreamingClient (new TwitterAccount[] {account}, search.Keyword, search, false);
                _mgr.AddSearchInfo (search);
                info = new TimelineInfo (_rootTLs, search);
            } else if (win.IsCheckedExistedSearch && win.SelectedExistedSearch != null) {
                info = new TimelineInfo (_rootTLs, win.SelectedExistedSearch);
            } else if (win.IsCheckedNewTab && win.NewTabTitle.Length > 0) {
                info = new TabInfo (_rootTLs, win.NewTabTitle);
            } else if (win.IsCheckedList) {
                ListStatuses listStatuses = new ListStatuses (win.SelectedAccount, win.SelectedList);
                if (win.IsUseStreamingForList)
                    listStatuses.StreamingClient = new StreamingClient (new TwitterAccount[] {win.SelectedListStreamingAccount}, win.SelectedAccount, win.SelectedList, listStatuses, false);
                _mgr.AddListInfo (listStatuses);
                info = new TimelineInfo (_rootTLs, listStatuses);
            }
            if (info != null) {
                _rootTLs.TimeLines.Add (info);
                SaveConfig ();
            }
        }
Esempio n. 12
0
 public TimelineInfo(TimelineBase owner, SearchStatuses search)
     : this(null, owner, search.Statuses, "Search \"" + search.Keyword + "\"")
 {
     Search = search;
     RestAccount = search.Account;
     RestUsage = search.RestInfo;
 }