Beispiel #1
0
 public Message(Personne Puser,string textetwit,string colormessage,string datemessage)
 {
     Texte=textetwit;
     User=Puser;
     Color=colormessage;
     Date=datemessage;
 }
 public TwitterObject(string login, string password)
 {
     User= new Personne(login,password);
     Download.DownloadFile(TwitterUrlProfil,User.Nom,User.Password,dirtwitter,"profil.xml");
     //parser le fichier xml afin de récupérer mon profil
     XmlParser Xmlprofil= new XmlParser(dirtwitter+"profil.xml");
     User.Image=Xmlprofil.GetValue("profile_image_url",0);
     User.Pseudo=Xmlprofil.GetValue("screen_name",0);
 }
        /// <summary>
        /// Téléchargement des twittes
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public Boolean GetTwitts()
        {
            try{
            Download.DownloadFile(TwitterFriendsUrl,User.Nom,User.Password,dirtwitter,"message.xml");
            LstTwitter = new List<Message>();
            //compter le nombre de twitter
            XmlParser XmlTwit= new XmlParser(dirtwitter+"message.xml");

            NbTwit = XmlTwit.CountValue("status");
            //Console.WriteLine("nb twit"+NbTwit);
            //creation d'un twit
            Personne UserTwit;
            Message UnTwit;
            XmlDocument MyXml = new XmlDocument();
            MyXml.Load(dirtwitter+"message.xml");
            foreach (XmlElement Child in MyXml.DocumentElement.GetElementsByTagName("status"))
            {
                //Collection.Add(ParseStatusNode(Child));
                //Mon May 12 15:56:07 +0000 2008
                /*Status.ID = int.Parse(Element["id"].InnerText);
                Status.Created = ParseDateString(Element["created_at"].InnerText);
                Status.Text = Element["text"].InnerText;
                Status.Source = Element["source"].InnerText;
                Status.IsTruncated = bool.Parse(Element["truncated"].InnerText);*/
                //Console.WriteLine(Child["created_at"].InnerText+" : "+Child["text"].InnerText);

                //UserTwit = new Personne("","",XmlTwit.GetValue("screen_name",cpt));
                //UserTwit.Image=XmlTwit.GetValue("profile_image_url",cpt);

                string name;
                string image;
                ParseUserNode(Child["user"],out name,out image);
                UserTwit = new Personne("","",name);
                UserTwit.Image=image;

                UnTwit=new Message(UserTwit,Child["text"].InnerText,"blue",Child["created_at"].InnerText);
                //UnMessage=new Message(UserMessage,XmlTwit.GetValue("text",cpt),"red",XmlTwit.GetValue("created_at",cpt));
                //TODO ajouter une gestion de cache pour les images
                UnTwit.User.Logo=Download.DonwloadImage(UnTwit.User.Image,User.Nom,User.Password);
                LstTwitter.Add(UnTwit);
                //cpt--;
            }
            //ajout d'un twit dans la liste
            return true;
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                return false;
            }
        }
        /// <summary>
        /// Téléchargement des twittes
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public Boolean GetMessages()
        {
            try{
            Download.DownloadFile(IdentiFriendsUrl,User.Nom,User.Password,dirtwitter,"message.xml");
            LstIdenti = new List<Message>();
            //compter le nombre de twitter
            XmlParser XmlTwit= new XmlParser(dirtwitter+"message.xml");
            NbTwit = XmlTwit.CountValue("status");
            //creation d'un twit
            Personne UserTwit;
            Message UnTwit;
            /*for (int cpt = NbTwit-1; cpt>-1;cpt--)
            {
                UserMessage = new Personne("","",XmlTwit.GetValue("screen_name",cpt));
                UserMessage.Image=XmlTwit.GetValue("profile_image_url",cpt);
                UnMessage=new Message(UserMessage,XmlTwit.GetValue("text",cpt),"red",XmlTwit.GetValue("created_at",cpt));
                //TODO ajouter une gestion de cache pour les images
                UnMessage.User.Logo=Download.DonwloadImage(UnMessage.User.Image,User.Nom,User.Password);
                LstIdenti.Add(UnMessage);
            }*/
            XmlDocument MyXml = new XmlDocument();
            MyXml.Load(dirtwitter+"message.xml");
            foreach (XmlElement Child in MyXml.DocumentElement.GetElementsByTagName("status"))
            {

                string name;
                string image;
                ParseUserNode(Child["user"],out name,out image);
                UserTwit = new Personne("","",name);
                UserTwit.Image=image;

                UnTwit=new Message(UserTwit,Child["text"].InnerText,"blue",Child["created_at"].InnerText);
                //UnMessage=new Message(UserMessage,XmlTwit.GetValue("text",cpt),"red",XmlTwit.GetValue("created_at",cpt));
                //TODO ajouter une gestion de cache pour les images
                UnTwit.User.Logo=Download.DonwloadImage(UnTwit.User.Image,User.Nom,User.Password);
                //Console.WriteLine("Le "+UnTwit.Date+" :" +UnTwit.Texte);
                LstIdenti.Add(UnTwit);

            }

            //ajout d'un twit dans la liste
            return true;
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                return false;
            }
        }