Exemple #1
0
 public virtual void LogOff(bool notifyViewPlatform, bool redirect)
 {
     base.ExecuteMethod("LogOff", delegate()
     {
         this.StencilClientAnonymous     = null;
         this.StencilClientAuthenticated = null;
         this.ViewPlatform.UnRegisterForPushNotifications();
         this.CacheHost.CachedUserClear();
         this.CacheHost.CachedDataClear();
         this.CacheHost.PersistentDataSet(false, CACHE_FILENAME_APP_PREFS, new AppPreferences());
         this.AppPreferences = new AppPreferences();
         this.UserCacheClear();
         this.DataCache.Clear();
         this.DataCache.InvalidateTimedCache();
         this.CurrentAccount = null;
         if (notifyViewPlatform)
         {
             try
             {
                 this.ViewPlatform.OnLoggedOff();
             }
             catch (Exception ex)
             {
                 this.LogError(ex, "OnLoggedOff");
             }
         }
         if (redirect)
         {
             this.ViewPlatform.NavigateToFirstScreen();
         }
     });
 }
Exemple #2
0
        public virtual StencilSDK GetSDK(bool useCurrentUserInfo)
        {
            StencilSDK result = null;

            if (useCurrentUserInfo)
            {
                result = this.StencilClientAuthenticated;
            }
            else
            {
                result = this.StencilClientAnonymous;
            }


            if (result == null)
            {
                result = new StencilSDK(this.ApiBaseUrl);

                if (!string.IsNullOrEmpty(_culture))
                {
                    result.CustomHeaders.Add(new KeyValuePair <string, string>("accept-language", _culture));
                }

                result.CustomHeaders.Add(new KeyValuePair <string, string>("X-DevicePlatform", this.ViewPlatform.ShortName));
                result.CustomHeaders.Add(new KeyValuePair <string, string>("X-DeviceVersion", this.ViewPlatform.VersionNumber));
                result.CustomHeaders.Add(new KeyValuePair <string, string>("X-DeviceToken", this.DeviceToken));

                if (useCurrentUserInfo)
                {
                    if (this.CurrentAccount != null)
                    {
                        result.ApplicationKey = this.CurrentAccount.api_key;
                        if (result.ApplicationSecret != this.CurrentAccount.api_secret)
                        {
                            result.ApplicationSecret = this.CurrentAccount.api_secret;
                        }
                        this.StencilClientAuthenticated = result;
                    }
                    else
                    {
                        result.ApplicationKey           = string.Empty;
                        result.ApplicationSecret        = string.Empty;
                        this.StencilClientAuthenticated = null;
                    }
                }
                else
                {
                    result.ApplicationKey       = string.Empty;
                    result.ApplicationSecret    = string.Empty;
                    this.StencilClientAnonymous = result;
                }
            }


            return(result);
        }
Exemple #3
0
 public void PersistPushNotificationToken(string deviceToken)
 {
     this.ExecuteMethodOrSkipAsync("PersistPushNotificationToken", async delegate()
     {
         this.LogTrace("--------- PersistPushNotificationToken -----------------");
         if (string.IsNullOrEmpty(deviceToken))
         {
             deviceToken = _pendingPushToken;
         }
         _pendingPushToken = deviceToken;// in case we log off and back on
         if (!string.IsNullOrEmpty(deviceToken))
         {
             if (this.CurrentAccount != null)
             {
                 StencilSDK client = this.GetSDK(true);
                 try
                 {
                     ActionResult result = await client.Accounts.RegisterPushTokenAsync(new PushTokenInput()
                     {
                         platform = this.ViewPlatform.ShortName,
                         token    = deviceToken
                     });
                     if (result.IsSuccess())
                     {
                         this.LogTrace("saved push notification");
                     }
                 }
                 catch (Exception ex)
                 {
                     this.LogError(ex.FirstNonAggregateException(), "PersistPushNotificationToken");
                 }
             }
             else
             {
                 _pendingPushToken = deviceToken;
             }
         }
     });
 }
Exemple #4
0
 public EndpointBase(StencilSDK sdk)
 {
     this.Sdk = sdk;
 }
Exemple #5
0
 public AssetEndpoint(StencilSDK api)
     : base(api)
 {
 }
Exemple #6
0
 public ServerEndpoint(StencilSDK api)
     : base(api)
 {
 }
 public AuthEndpoint(StencilSDK api)
     : base(api)
 {
 }
 public AccountsEndpoint(StencilSDK api)
     : base(api)
 {
 }
Exemple #9
0
        /// <summary>
        /// Does Not Throw Exceptions.
        /// </summary>
        public virtual Task <ItemResult <AccountInfo> > LoginAsyncSafe(AuthLoginInput info, Action <bool> onProcessing = null)
        {
            return(base.ExecuteFunctionAsync("LoginAsyncSafe", async delegate()
            {
                ItemResult <AccountInfo> result = new ItemResult <AccountInfo>()
                {
                    success = false
                };
                bool isOutdated = false;
                try
                {
                    ItemResult <AccountInfo> loginResult = null;
                    this.LogOff(false, false);

                    loginResult = await this.PostItemUnSafeAsync(onProcessing, async delegate()
                    {
                        StencilSDK client = this.GetSDK(false);
                        return await client.Auth.LoginAsync(info);
                    });

                    if (loginResult.IsSuccess())
                    {
                        result = loginResult;
                    }
                    else
                    {
                        result.success = false;
                        result.meta = loginResult.meta;
                        result.message = loginResult.GetMessage();
                    }
                }
                catch (Exception ex)
                {
                    ex = ex.FirstNonAggregateException();

                    base.LogError(ex, "LoginAsyncSafe");

                    result.success = false;
                    isOutdated = this.IsOutdated(ex);
                    if (isOutdated)
                    {
                        this.Outdated(string.Empty);
                    }
                    result.message = ex.Message;
                    EndpointException endpointException = ex as EndpointException;
                    if (endpointException != null)
                    {
                        result.meta = ((int)endpointException.StatusCode).ToString();
                    }
                }

                if (result.IsSuccess())
                {
                    this.CacheHost.CachedUserSet(result.item);
                    this.CurrentAccount = result.item;
                    this.UserCacheClear();
                    AppPreferences prefs = new AppPreferences();
                    this.CacheHost.PersistentDataSet(false, CACHE_FILENAME_APP_PREFS, prefs);
                    this.AppPreferences = prefs;

                    this.ViewPlatform.OnLoggedOn();
                }
                else
                {
                    this.LogOff(!isOutdated, false);
                    if (string.IsNullOrEmpty(result.message))
                    {
                        result.message = "Could not log in to your account.";
                    }
                }

                return result;
            }));
        }
 public GlobalSettingEndpoint(StencilSDK api)
     : base(api)
 {
 }