Пример #1
0
        public StatusBox(Status status)
            : base()
        {
            this.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.Size = new Size(200, 70);
            this.BackColor = Color.White;

            this.status = status;
            status.SetProfileImage();

            // Download the image file of the status if it doesn't exist yet
            if (!File.Exists(status.ProfileImageFile) && !ImageDownloader.Images.Contains(status.ProfileImageFile))
            {
                ImageDownloader.Images.Add(status.ProfileImageFile);

                ImageDownloader imgDownloader = new ImageDownloader();
                imgDownloader.ImageDownloadComplete += new ImageDownloadCompleteHandler(HandleImageDownloadComplete);
                imgDownloader.DownloadImage(status.ProfileImageUrl, status.ProfileImageFile);
            }
            else
            {
                profileImageDownloaded = true;
            }
        }
Пример #2
0
        private bool TabContainsStatus(TabPage tab, Status s)
        {
            if (tab.InvokeRequired)
            {
                return (bool)this.Invoke(new TabContainsStatusCallback(TabContainsStatus), new object[2] { tab, s });
            }
            else
            {
                foreach (Control childCtl in tab.Controls)
                {
                    StatusBox sbox = childCtl as StatusBox;
                    if (sbox != null)
                    {
                        if (sbox.StatusId == s.Id)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Пример #3
0
        private void ParseTimelineData(string xmlData, string requestType)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.LoadXml(xmlData);
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot parse XML result", "Request error");
            }

            switch (requestType)
            {
                case RequestInterface.FRIENDS_TIMELINE:
                    SetControlEnabled(mainStreamTab, false);
                    //SetControlEnabled(repliesTab, false);
                    break;

                case RequestInterface.REPLIES:
                    SetControlEnabled(repliesTab, false);
                    break;

                case RequestInterface.DIRECT_MESSAGES:
                    SetControlEnabled(directMessagesTab, false);
                    break;
            }

            XmlNodeList nodeList = doc.GetElementsByTagName("status");
            for (int i = 0; i < nodeList.Count; i++)
            {
                XmlNode node = nodeList.Item(i);
                Status status = new Status();

                XmlNodeList childNodes = node.ChildNodes;
                for (int j = 0; j < childNodes.Count; j++)
                {
                    XmlNode childNode = childNodes.Item(j);
                    GetStatusDataFromXmlNode(status, childNode);
                }

                // If the status doesn't exist yet, we need to create a new child for it
                switch (requestType)
                {
                    case RequestInterface.FRIENDS_TIMELINE:
                        if (!TabContainsStatus(mainStreamTab, status))
                        {
                            AddStatusToTab(status, mainStreamTab, mainStreamDone);
                        }
                        /*if (status.IsReply && !TabContainsStatus(repliesTab, status))
                        {
                            AddStatusToTab(status, repliesTab, mainStreamDone);
                        }*/
                        break;

                    case RequestInterface.REPLIES:
                        if (!TabContainsStatus(repliesTab, status))
                        {
                            AddStatusToTab(status, repliesTab, repliesDone);
                        }
                        break;

                    case RequestInterface.DIRECT_MESSAGES:
                        if (!TabContainsStatus(directMessagesTab, status))
                        {
                            AddStatusToTab(status, directMessagesTab, dmDone);
                        }
                        break;
                }
                statuses[status.Id] = status;
            }

            switch (requestType)
            {
                case RequestInterface.FRIENDS_TIMELINE:
                    SetControlEnabled(mainStreamTab, true);
                    //SetControlEnabled(repliesTab, true);
                    if (mainStreamDone == false)
                    {
                        mainStreamDone = true;
                    }
                    break;

                case RequestInterface.REPLIES:
                    SetControlEnabled(repliesTab, true);
                    // Set initial request completed if not yet completed
                    if (repliesDone == false)
                    {
                        repliesDone = true;
                    }
                    break;

                case RequestInterface.DIRECT_MESSAGES:
                    SetControlEnabled(directMessagesTab, true);
                    // Set initial request completed if not yet completed
                    if (dmDone == false)
                    {
                        dmDone = true;
                    }
                    break;
            }
        }
Пример #4
0
        private void GetStatusDataFromXmlNode(Status status, XmlNode childNode)
        {
            switch (childNode.Name)
            {
                case "created_at":
                    //status.CreatedAt = DateTime.Parse(childNode.InnerText);
                    break;

                case "id":
                    status.Id = Convert.ToInt64(childNode.InnerText);
                    break;

                case "text":
                    status.StatusText = childNode.InnerText;
                    break;

                case "user":
                    if (childNode.HasChildNodes)
                    {
                        for (int k = 0; k < childNode.ChildNodes.Count; k++)
                        {
                            XmlNode childChildNode = childNode.ChildNodes.Item(k);
                            switch (childChildNode.Name)
                            {
                                case "id": status.UserId = Convert.ToInt64(childChildNode.InnerText); break;
                                case "name": status.FullName = childChildNode.InnerText; break;
                                case "screen_name": status.ScreenName = childChildNode.InnerText; break;
                                case "profile_image_url": status.ProfileImageUrl = childChildNode.InnerText; break;
                            }
                            if (k > 5)
                            {
                                // id = node 0; name = node 1; screen_name = node 2; profile_image = 5
                                break;
                            }
                        }
                    }
                    break;
            }
        }
Пример #5
0
        private void AddStatusToTab(Status s, TabPage tab, bool addToTop)
        {
            if (tab.InvokeRequired)
            {
                this.Invoke(new AddStatusToTabCallback(AddStatusToTab), new object[3] { s, tab, addToTop });
            }
            else
            {
                // The status box to be added
                StatusBox sbox = new StatusBox(s);
                sbox.Size = new Size(tab.Width - 5, 70);
                sbox.InitializeControls();

                if (addToTop)
                {
                    // if add to top is specified, we need to shift the initial controls down
                    if (tab.Controls.Count > 0)
                    {
                        foreach (Control childCtl in tab.Controls)
                        {
                            StatusBox childbox = childCtl as StatusBox;
                            if (childbox != null)
                            {
                                childbox.Location = new Point(childbox.Location.X, childbox.Location.Y + childbox.Height);
                            }
                        }

                        // Set the status box location
                        sbox.Location = new Point(sbox.Location.X, 0);
                    }
                }
                else
                {
                    int lastCtlIdx = (tab.Controls.Count > 1) ? (tab.Controls.Count - 1) : 0;
                    int currentY = (tab.Controls.Count > 0) ?
                        (tab.Controls[lastCtlIdx].Location.Y + tab.Controls[lastCtlIdx].Height) : 0;
                    sbox.Location = new Point(sbox.Location.X, currentY + 5);
                }

                tab.Controls.Add(sbox);
            }
        }
Пример #6
0
 private void AddStatusToTab(Status s, TabPage tab)
 {
     AddStatusToTab(s, tab, false);
 }