Beispiel #1
0
        public void AddListInfo(ListStatuses ls)
        {
            List <ListStatuses> list = new List <ListStatuses> (_lists);

            list.Add(ls);
            _lists = list.ToArray();
        }
Beispiel #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);
            }
        }
Beispiel #3
0
 void WriteList(JsonTextWriter writer, ListStatuses list)
 {
     writer.WriteStartObject();
     writer.WriteKey("id");
     writer.WriteNumber(list.List.ID);
     writer.WriteKey("username");
     writer.WriteString(list.Account.ScreenName);
     WriteRestUsage(writer, list.RestInfo);
     writer.WriteEndObject();
 }
Beispiel #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);
                }
            }
        }
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 WriteList(JsonTextWriter writer, ListStatuses list)
 {
     writer.WriteStartObject ();
     writer.WriteKey ("id");
     writer.WriteNumber (list.List.ID);
     writer.WriteKey ("username");
     writer.WriteString (list.Account.ScreenName);
     WriteRestUsage (writer, list.RestInfo);
     writer.WriteEndObject ();
 }
Beispiel #7
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 #8
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 #9
0
 public void AddListInfo(ListStatuses ls)
 {
     List<ListStatuses> list = new List<ListStatuses> (_lists);
     list.Add (ls);
     _lists = list.ToArray ();
 }
Beispiel #10
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 ();
            }
        }
Beispiel #11
0
 public TimelineInfo(TimelineBase owner, ListStatuses list)
     : this(null, owner, list.Statuses, "List \"" + list.List.FullName + "\"")
 {
     List = list;
     RestAccount = list.Account;
     RestUsage = list.RestInfo;
 }