/// <summary>
 /// 构造
 /// </summary>
 public FileSyncUserSession()
 {
     if (!settings.TryGetValue<FileSyncAuthorizeInfo>(authorizeInfoKey, out authInfo))
     {
         authInfo = new FileSyncAuthorizeInfo();
     }
 }
        /// <summary>
        /// 保存用户的授权信息
        /// </summary>
        /// <param name="info">授权信息</param>
        public void SaveUserSessionInfo(FileSyncAuthorizeInfo info)
        {
            if (info == null)
                return;
            authInfo = info;

            if (!settings.Contains(authorizeInfoKey))
            {
                settings.Add(authorizeInfoKey, authInfo);
            }
            else
            {
                settings[authorizeInfoKey] = authInfo;
            }
        }
Пример #3
0
        private void AuthorizeFinish(object obj, FileSyncRequestResultEventArgs arg)
        {
            switch (arg.Result)
            {
                case FileSyncAPIRequestResult.Success:

                    try
                    {
                        FileSyncAuthorizeInfo authInfo = new FileSyncAuthorizeInfo();

                        string xml = arg.Response;

                        XmlDocument xd = new XmlDocument();
                        xd.LoadXml(xml);

                        authInfo.AuthSid = xd.SelectSingleNode("/QDocRoot/authSid").InnerText;
                        authInfo.UserName = xd.SelectSingleNode("/QDocRoot/username").InnerText;

                        FileSync.CurrentUser.SaveUserSessionInfo(authInfo);

                        if (tempCallback != null)
                        {
                            tempCallback(this, arg);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (tempCallback != null)
                        {
                            FileSyncError error = new FileSyncError();
                            error.error_code = requestErrorDomain;
                            error.error_msg = "An error occurs when parse server response." + ex.Message;

                            tempCallback(this, new FileSyncRequestResultEventArgs(null, FileSyncAPIRequestResult.Fail, error));
                        }
                    }

                    break;
                case FileSyncAPIRequestResult.Fail:
                    if (tempCallback != null)
                    {
                        tempCallback(this, arg);
                    }
                    break;
                default:
                    break;
            }
        }