Exemple #1
0
     protected void Page_Load(object sender, EventArgs e)
     {
         //Get the consent URL for the specified offers.
         ConsentUrl = wll.GetConsentUrl(Offers);
         
         HttpRequest req = HttpContext.Current.Request;
         HttpCookie authCookie = req.Cookies[AuthCookie];
 
         // If the raw consent token has been cached in a site cookie, attempt to
         // process it and extract the consent token.
         if (authCookie != null)
         {
             string t = authCookie.Value;
             Token = wll.ProcessConsentToken(t);
             getContacts(Token.DelegationToken,Token.LocationID);
             if ((Token != null) && !Token.IsValid())
             {
                 Token = null;
             }
         }
     }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get the consent URL for the specified offers.
            try
            {
                ConsentUrl = wll.GetConsentUrl(Offers);

                var action = Request["action"];

                if (action == "delauth")
                {
                    //Attempt to extract the consent token from the response.
                    var token = wll.ProcessConsent(Request.Form);

                    var authCookie = new HttpCookie(AuthCookie);
                    // If a consent token is found, store it in the cookie and then
                    // redirect to the main page.
                    if (token != null)
                    {
                        authCookie.Value   = token.Token;
                        authCookie.Expires = PersistCookie;
                    }
                    else
                    {
                        authCookie.Expires = ExpireCookie;
                    }

                    Response.Cookies.Add(authCookie);
                    Response.Redirect(Request.GetUrlRewriter().OriginalString, true);
                }
                else
                {
                    var req        = HttpContext.Current.Request;
                    var authCookie = req.Cookies[AuthCookie];

                    // If the raw consent token has been cached in a site cookie, attempt to
                    // process it and extract the consent token.
                    if (authCookie != null)
                    {
                        var t = authCookie.Value;
                        Token = wll.ProcessConsentToken(t);
                        if ((Token != null) && !Token.IsValid())
                        {
                            Token = null;
                            Response.Redirect(ConsentUrl);
                        }
                        if (Token != null)
                        {
                            ProcessContacts();
                        }
                    }
                    else
                    {
                        Response.Redirect(ConsentUrl);
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                SubmitError(ex.Message);
            }
        }
Exemple #3
0
        private IList <IContact> GetContacts(int pageNumber, int pageSize, ISelection selection)
        {
            HttpWebResponse response;

            authCookie = HttpContext.Current.Request.Cookies["delauthtoken"];
            IList <IContact> result = new List <IContact>();

            if (authCookie != null)
            {
                string t = authCookie.Value;
                WindowsLiveLogin.ConsentToken Token = WindowsLiveLogin.ProcessConsentToken(t);

                if ((Token != null) && Token.IsValid())
                {
                    ServicePointManager.ServerCertificateValidationCallback +=
                        delegate(object sender, X509Certificate certificate, X509Chain chain,
                                 SslPolicyErrors sslPolicyErrors)
                    {
                        bool validationResult = true;
                        return(validationResult);
                    };

                    UriBuilder uriBuilder = new UriBuilder();
                    uriBuilder.Scheme = "HTTPS";
                    uriBuilder.Path   = "/users/@L@" + Token.LocationID + "/rest/invitationsbyemail";
                    uriBuilder.Host   = "livecontacts.services.live.com";
                    uriBuilder.Port   = 443;
                    string uriPath = uriBuilder.Uri.AbsoluteUri;

                    response = SendHttpRequest(Token, ref uriPath, "GET");

                    if (response != null && response.ContentLength != 0)
                    {
                        XmlDocument   doc    = new XmlDocument();
                        XmlTextReader reader = new XmlTextReader(response.GetResponseStream());
                        reader.Read();
                        // load reader
                        doc.Load(reader);
                        int i = 1;
                        if (pageNumber > 0)
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                if (i < (pageNumber * pageSize) - (pageSize - 1))
                                {
                                    i++;
                                    continue;
                                }
                                if (i > (pageNumber * pageSize))
                                {
                                    break;
                                }
                                GetContact(i++, node, result);
                            }
                            TotalCount = doc.SelectNodes(@"/LiveContacts/Contacts/Contact").Count;
                        }
                        else if (selection != null)
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                if (!selection.SelectedAll && !selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                                      {
                                                                                                                          return(true);
                                                                                                                      }
                                                                                                                      return(false); }))
                                {
                                    i++;
                                    continue;
                                }
                                if (selection.SelectedAll && selection.SelectedIndexs.Exists(delegate(int record) { if (record == i)
                                                                                                                    {
                                                                                                                        return(true);
                                                                                                                    }
                                                                                                                    return(false); }))
                                {
                                    i++;
                                    continue;
                                }

                                Contact contact = new Contact();
                                contact.Index = i;
                                if (node.ChildNodes.Count > 0 && node.ChildNodes[0].ChildNodes.Count > 0 &&
                                    node.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 0)
                                {
                                    contact.FirstName = node.ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText;
                                }
                                if (node.ChildNodes.Count > 0 && node.ChildNodes[0].ChildNodes.Count > 0 &&
                                    node.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 1)
                                {
                                    contact.LastName = node.ChildNodes[0].ChildNodes[0].ChildNodes[1].InnerText;
                                }
                                if (node.ChildNodes.Count > 1)
                                {
                                    contact.Email = node.ChildNodes[1].InnerText;
                                }
                                result.Add(contact);
                                i++;
                            }
                        }
                        else
                        {
                            foreach (XmlNode node in doc.SelectNodes(@"/LiveContacts/Contacts/Contact"))
                            {
                                GetContact(i++, node, result);
                            }
                            TotalCount = doc.SelectNodes(@"/LiveContacts/Contacts/Contact").Count;
                        }
                    }
                    response.Close();
                }
            }
            return(result);
        }