Example #1
0
    public static void LoginAsGuestInBackground(Action <BacktoryResponse <LoginResponse> > callback)
    {
        // Simplifying this by removing "BacktoryUser" type parameter leads to error though compiler suggests, but why?!
        Backtory.RestClient.ExecuteAsync <BacktoryUser>(GuestRegisterRequest(), response =>
        {
            // **this part will be called on background thread! (Since we're using restsharp async method)**

            // if guest register failed don't proceed to login
            if (!response.IsSuccessful())
            {
                Backtory.Dispatch(() => BacktoryResponse <LoginResponse> .Unknown(response.ErrorMessage));
                return;
            }

            var guest         = response.Data;
            var loginResponse = Backtory.Execute <LoginResponse>(LoginRequest(guest.Username, guest.Password));

            if (loginResponse.Successful)
            {
                DispatchSaveCurrentUser(guest);
                DispatchSaveGuestPassword(guest.Password);
                DispatchSaveLoginInfo(loginResponse.Body);
            }

            Backtory.Dispatch(() => callback(loginResponse));
        });
    }
 // Message Processing Part ---------------------------------------------------------------------
 internal void ProcessMessage(string message)
 {
     if ((message != null) && (message.Length != 0))
     {
         try {
             JSONNode jsonNode = JSONNode.Parse(message);
             string   clazz    = (string)jsonNode ["_type"];
             if (clazz != null)
             {
                 string clientRequestId = (string)jsonNode ["clientRequestId"];
                 if (clientRequestId != null)
                 {
                     sendResponseToMainThread(message, clazz, clientRequestId);
                 }
                 else
                 {
                     Debug.Log("************");
                     Backtory.Dispatch(() => backtoryApi.NotifyMessageReceived(message, clazz));
                 }
             }
             else
             {
                 Debug.Log(TAG + "_type field not found in message");
             }
         } catch (Exception e) {
             Debug.Log(TAG + e.Data);
         }
     }
     else
     {
         // TODO
     }
 }
 internal void OnDisconnect()
 {
     if (connectorStateEngine.getConnectionState() == ConnectorStateEngine.ConnectorState.DISCONNECTING /*&& disconnectLatch.getCount() == 1*/)
     {
         disconnectLatch.Signal();
     }
     else
     {
         Backtory.Dispatch(() => sdkListener.OnDisconnect());
     }
     connectorStateEngine.ChangeState(ConnectorStateEngine.StateChangeEvent.CONNECTED);
 }
Example #4
0
 private static void DispatchSaveCurrentUser(BacktoryUser backtoryUser)
 {
     Backtory.Dispatch(() => { SaveAsCurrentUserInMemoryAndStorage(backtoryUser); });
 }
Example #5
0
 private static void DispatchSaveGuestPassword(string guestNewPassword)
 {
     Backtory.Dispatch(() => { SaveGuestPassword(guestNewPassword); });
 }
Example #6
0
 private static void DispatchSaveLoginInfo(LoginResponse loginResponse)
 {
     Backtory.Dispatch(() => { SaveLoginInfo(loginResponse); });
 }