internal void AuthenticationComplete(AuthenticationResult authResult)
        {
            if (authResult.Error != null)
            {
                if (authResult.Error is WebException)
                {
                    var wex = authResult.Error as WebException;
                    var errorMsg = string.Format("The server returned: {0}", wex.Message);

                    //var s = new StringBuilder("Data" + Environment.NewLine);
                    //IDictionaryEnumerator ie = wex.Data.GetEnumerator();

                    //while (ie.MoveNext())
                    //{
                    //    s.Append(string.Format("{0}={1}{2}", ie.Key, ie.Value, Environment.NewLine));
                    //}

                    //s.Append(string.Format("Status:{0}{1}", wex.Status, Environment.NewLine));
                    //s.Append(wex.ToString());

                    //ApplicationEx.Instance.DisplayMessageBox(s.ToString(), "Debug info");

                    var eArgs = new AuthenticationCompletedEventArgs(authResult.ErrorMessage, false);

                    if (AuthenticationCompleted != null)
                        AuthenticationCompleted(ApplicationEx.Instance.ActiveSession, eArgs);
                }
                else
                {
                    Logging.LogException(authResult.Error);
                }
            }
            else
            {
                // This method isn't called on the right instance of the Session object.  It works first time, but then
                // logging out and logging back in, the method is called again on the original Session object.  Getting
                // the ActiveSession from the ApplicationEx is a workaround for this problem.
                Session session = ApplicationEx.Instance.ActiveSession;

                session.SessionToken = authResult.Token;
                string reference = authResult.Token;

                bool isAuthenticated = !authResult.Token.IsNullOrEmpty();

                if (!isAuthenticated)
                    reference = authResult.ErrorMessage.IsNullOrEmpty() != true ? authResult.ErrorMessage : "Unable to Authenticate";

                var eArgs = new AuthenticationCompletedEventArgs(reference, isAuthenticated);

                if (AuthenticationCompleted != null)
                    AuthenticationCompleted(session, eArgs);

                if (eArgs.IsAuthenticated)
                {
                    if (SessionCreated != null)
                        SessionCreated(session);

                    session.GetSessionInfo();
                }
            }
        }
Esempio n. 2
0
        internal void AuthenticationComplete(AuthenticationResult authResult)
        {
            if (authResult.Error != null)
            {
                if (authResult.Error is WebException)
                {
                    var wex      = authResult.Error as WebException;
                    var errorMsg = string.Format("The server returned: {0}", wex.Message);

                    //var s = new StringBuilder("Data" + Environment.NewLine);
                    //IDictionaryEnumerator ie = wex.Data.GetEnumerator();

                    //while (ie.MoveNext())
                    //{
                    //    s.Append(string.Format("{0}={1}{2}", ie.Key, ie.Value, Environment.NewLine));
                    //}

                    //s.Append(string.Format("Status:{0}{1}", wex.Status, Environment.NewLine));
                    //s.Append(wex.ToString());

                    //ApplicationEx.Instance.DisplayMessageBox(s.ToString(), "Debug info");

                    var eArgs = new AuthenticationCompletedEventArgs(authResult.ErrorMessage, false);

                    if (AuthenticationCompleted != null)
                    {
                        AuthenticationCompleted(ApplicationEx.Instance.ActiveSession, eArgs);
                    }
                }
                else
                {
                    Logging.LogException(authResult.Error);
                }
            }
            else
            {
                // This method isn't called on the right instance of the Session object.  It works first time, but then
                // logging out and logging back in, the method is called again on the original Session object.  Getting
                // the ActiveSession from the ApplicationEx is a workaround for this problem.
                Session session = ApplicationEx.Instance.ActiveSession;

                session.SessionToken = authResult.Token;
                string reference = authResult.Token;

                bool isAuthenticated = !authResult.Token.IsNullOrEmpty();

                if (!isAuthenticated)
                {
                    reference = authResult.ErrorMessage.IsNullOrEmpty() != true ? authResult.ErrorMessage : "Unable to Authenticate";
                }

                var eArgs = new AuthenticationCompletedEventArgs(reference, isAuthenticated);

                if (AuthenticationCompleted != null)
                {
                    AuthenticationCompleted(session, eArgs);
                }

                if (eArgs.IsAuthenticated)
                {
                    if (SessionCreated != null)
                    {
                        SessionCreated(session);
                    }

                    session.GetSessionInfo();
                }
            }
        }