Ejemplo n.º 1
0
        private void OnCoreCallBack(SCFEventType type, int error, string status)
        {
            switch (type)
            {
            case SCFEventType.AccessTokenLoginCallback:
                SDKLogger.Instance.Debug("event type: AccessTokenLoginCallback");
                if (error == 0)
                {
                    SDKLogger.Instance.Info("Log in success");
                    isAuthorized = true;
                    AuthorizeAction?.Invoke(new SparkApiEventArgs(true, null));
                    AuthorizeAction = null;
                }
                else
                {
                    SDKLogger.Instance.Info("Log in failed");
                    isAuthorized = false;

                    AuthorizeAction?.Invoke(new SparkApiEventArgs(false, null));
                    AuthorizeAction = null;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        private void OnCoreCallBack(SCFEventType type, int error, string status)
        {
            SDKLogger.Instance.Debug("event type:{0}, error[{1}], status:{2}", type.ToString(), error, status);
            switch (type)
            {
            case SCFEventType.AccessTokenRefreshed:
                if (error == 0)
                {
                    string rspToken     = null;
                    int    rspExpiresIn = 0;
                    m_core.getAccessToken(ref rspToken, ref rspExpiresIn);

                    this.accessTokenStore = new AccessToken(rspToken, rspExpiresIn);

                    SDKLogger.Instance.Info("access token refreshed");

                    this.AccessTokenAction?.Invoke(new SparkApiEventArgs <string>(true, null, this.accessTokenStore.token));
                    this.AccessTokenAction = null;
                }
                else
                {
                    SDKLogger.Instance.Error("access token failed");
                    this.AccessTokenAction?.Invoke(new SparkApiEventArgs <string>(false, null, null));
                    this.AccessTokenAction = null;
                }
                break;

            case SCFEventType.Login:

                if (error == 0)
                {
                    this.isAuthorized = true;

                    string rspToken     = null;
                    int    rspExpiresIn = 0;
                    m_core.getAccessToken(ref rspToken, ref rspExpiresIn);

                    this.accessTokenStore = new AccessToken(rspToken, rspExpiresIn);
                    SDKLogger.Instance.Info("Log in success");

                    this.AuthorizeAction?.Invoke(new SparkApiEventArgs(true, null));
                    this.AuthorizeAction = null;
                }
                else
                {
                    this.isAuthorized = false;
                    SDKLogger.Instance.Error("Log in failed. error:{0}, status:{1}", error, status);

                    this.AuthorizeAction?.Invoke(new SparkApiEventArgs(false, null));
                    this.AuthorizeAction = null;
                }
                break;

            case SCFEventType.RefreshTokenLoginCallback:
                if (error == 0)
                {
                    this.isAuthorized = true;

                    string rspToken     = null;
                    int    rspExpiresIn = 0;
                    m_core.getAccessToken(ref rspToken, ref rspExpiresIn);

                    this.accessTokenStore = new AccessToken(rspToken, rspExpiresIn);
                    SDKLogger.Instance.Info("RefreshTokenLogin in success");

                    this.AuthorizedAction?.Invoke(new SparkApiEventArgs(true, null));
                    this.AuthorizedAction = null;
                }
                else
                {
                    this.isAuthorized = false;
                    SDKLogger.Instance.Info("RefreshTokenLogin in failed. error:{0}, status:{1}", error, status);
                    this.AuthorizedAction?.Invoke(new SparkApiEventArgs(false, null));
                    this.AuthorizedAction = null;
                }
                break;

            default:
                break;
            }
        }