Пример #1
0
 //Constructor
 private Truelife()
 {
     LoadLoginData();
     ProfileData = new ProfileItem();
 }
Пример #2
0
        void WebClient_GetProfile_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            TruelifeEventArgs eventArg = new TruelifeEventArgs();
            eventArg.Code = 0;
            eventArg.Description = "error";
            try
            {
                if (e.Error != null)
                {
                    throw new Exception(e.Error.Message);
                }
                //----------
                XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
                if (xdoc.Root == null)
                {
                    throw new Exception("Root is null");
                }

                if (xdoc.Root.Element("header") == null)
                {
                    throw new Exception("header is null");
                }

                if (xdoc.Root.Element("header").Element("code") == null)
                {
                    throw new Exception("header/code is null");
                }

                if (xdoc.Root.Element("header").Element("description") == null)
                {
                    throw new Exception("header/description is null");
                }
                //----------
                var code = xdoc.Root.Element("header").Element("code");
                eventArg.Code = XmlValueParser.ParseInteger(code);

                var desc = xdoc.Root.Element("header").Element("description");
                eventArg.Description = XmlValueParser.ParseString(desc);

                if (eventArg.Code == 400)
                {
                    eventArg.ErrorMessageForUser = "******";
                    eventArg.ErrorMessageForDeveloper = "error code is " + eventArg.Code + " , " + desc;
                    eventArg.IsError = true;
                    ProfileData = null;
                }
                else if (eventArg.Code != 200)
                {
                    eventArg.ErrorMessageForUser = "******" + eventArg.Code + " , " + desc;
                    eventArg.ErrorMessageForDeveloper = "error code is " + eventArg.Code + " , " + desc;
                    eventArg.IsError = true;
                    ProfileData = null;
                }
                else
                {
                    if (xdoc.Root.Element("profile") == null)
                    {
                        throw new Exception("profile is null");
                    }

                    //parse
                    ProfileData.UserID = XmlValueParser.ParseInteger(xdoc.Root.Element("profile").Element("uid"));
                    ProfileData.Email = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("email"));
                    ProfileData.FirstName = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("first_name"));
                    ProfileData.LastName = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("last_name"));
                    ProfileData.Birthday = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("birthday"));
                    ProfileData.Gender = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("gender"));
                    ProfileData.DisplayName = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("display_name"));
                    ProfileData.EmailContact = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("email_contact"));
                    ProfileData.MobileContact = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("mobile_contact"));
                    ProfileData.Mobile = XmlValueParser.ParseString(xdoc.Root.Element("profile").Element("mobile"));

                    //----------
                    eventArg.IsError = false;
                }
            }
            catch (Exception ex)
            {
                eventArg.ErrorMessageForUser = "******";
                eventArg.ErrorMessageForDeveloper = "Error : Truelife - GetProfile ; " + ex.Message;
                eventArg.IsError = true;
                ProfileData = null;
            }
            //-----
            GetProfileCompleted(eventArg);
        }