Ejemplo n.º 1
0
 private MobeelizerOperationError Sync(bool syncAll)
 {
     if (mode == MobeelizerMode.DEVELOPMENT || CheckSyncStatus().IsRunning())
     {
         Log.i(TAG, "Sync is already running - skipping.");
         return(null);
     }
     else if (!connectionManager.IsNetworkAvailable)
     {
         Log.i(TAG, "Sync cannot be performed - network is not available.");
         SetSyncStatus(MobeelizerSyncStatus.FINISHED_WITH_FAILURE);
         return(MobeelizerOperationError.MissingConnectionError());
     }
     else
     {
         SetSyncStatus(MobeelizerSyncStatus.STARTED);
         return(new MobeelizerSyncServicePerformer(Mobeelizer.Instance, syncAll).Sync());
     }
 }
Ejemplo n.º 2
0
        public MobeelizerLoginResponse Login(bool offline)
        {
            bool networkConnected = IsNetworkAvailable;

            if (!networkConnected || offline)
            {
                String[] roleAndInstanceGuid = GetRoleAndInstanceGuidFromDatabase(application);

                if (roleAndInstanceGuid[0] == null)
                {
                    Log.i(TAG, "Login failure. Missing connection failure.");
                    return(new MobeelizerLoginResponse(MobeelizerOperationError.MissingConnectionError()));
                }
                else
                {
                    Log.i(TAG, "Login '" + application.User + "' from database successful.");
                    return(new MobeelizerLoginResponse(null, roleAndInstanceGuid[1], roleAndInstanceGuid[0], false));
                }
            }

            try
            {
                IMobeelizerAuthenticateResponse response = null;
                if (application.NotificationChannelUri != null)
                {
                    response = connectionService.Authenticate(application.User, application.Password, application.NotificationChannelUri);
                }
                else
                {
                    response = connectionService.Authenticate(application.User, application.Password);
                }

                if (response.Error == null)
                {
                    bool initialSyncRequired = IsInitialSyncRequired(application, response.InstanceGuid);

                    SetRoleAndInstanceGuidInDatabase(application, response.Role, response.InstanceGuid);
                    Log.i(TAG, "Login '" + application.User + "' successful.");
                    return(new MobeelizerLoginResponse(null, response.InstanceGuid, response.Role, initialSyncRequired));
                }
                else
                {
                    Log.i(TAG, "Login failure. Authentication error.");
                    ClearRoleAndInstanceGuidInDatabase(application);
                    return(new MobeelizerLoginResponse(response.Error));
                }
            }
            catch (InvalidOperationException e)
            {
                Log.i(TAG, e.Message);
                String[] roleAndInstanceGuid = GetRoleAndInstanceGuidFromDatabase(application);
                if (roleAndInstanceGuid[0] == null)
                {
                    return(new MobeelizerLoginResponse(MobeelizerOperationError.ConnectionError(e.Message)));
                }
                else
                {
                    return(new MobeelizerLoginResponse(null, roleAndInstanceGuid[1], roleAndInstanceGuid[0], false));
                }
            }
        }