Example #1
0
        internal void RegisterForRemoteNotifications(string chanelUri, MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                MobeelizerOperationError error = null;
                try
                {
                    NotificationChannelUri = chanelUri;
                    if (IsLoggedIn)
                    {
                        error = connectionManager.RegisterForRemoteNotifications(chanelUri);
                    }
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    error = MobeelizerOperationError.Exception(e);
                }

                callback(error);
            }));

            thread.Name = "Register for notification thread";
            thread.Start();
        }
Example #2
0
        internal void SyncAll(MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    callback(SyncAll());
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    this.SetSyncStatus(MobeelizerSyncStatus.FINISHED_WITH_FAILURE);
                    callback(MobeelizerOperationError.Exception(e));
                }
            }));

            thread.Name = "Mobeelizer full synchronization thread";
            thread.Start();
        }
Example #3
0
        internal void Sync(MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                MobeelizerOperationError error = null;
                try
                {
                    error = Sync();
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    this.SetSyncStatus(MobeelizerSyncStatus.FINISHED_WITH_FAILURE);
                    error = MobeelizerOperationError.Exception(e);
                }
                callback(error);
            }));

            thread.Name = "Mobeelizer synchronization thread";
            thread.Start();
        }
Example #4
0
        internal void Login(string instance, string user, string password, MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                MobeelizerOperationError error = null;
                try
                {
                    error = Login(instance, user, password, false);
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    error = MobeelizerOperationError.Exception(e);
                }

                callback(error);
            }));

            thread.Name = "Mobeelizer login thread";
            thread.Start();
        }
Example #5
0
        internal void SendRemoteNotification(String device, String group, IList <String> users, IDictionary <String, String> notification, MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                MobeelizerOperationError error;
                try
                {
                    CheckIfLoggedIn();
                    error = connectionManager.SendRemoteNotification(device, group, users, notification);
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    error = MobeelizerOperationError.Exception(e);
                }

                callback(error);
            }));

            thread.Name = "Send notification thread";
            thread.Start();
        }
Example #6
0
        internal void UnregisterForRemoteNotifications(MobeelizerOperationCallback callback)
        {
            Thread thread = new Thread(new ThreadStart(() =>
            {
                MobeelizerOperationError error = null;
                try
                {
                    CheckIfLoggedIn();
                    error = connectionManager.UnregisterForRemoteNotifications(NotificationChannelUri);
                }
                catch (Exception e)
                {
                    Log.i(TAG, e.Message);
                    error = MobeelizerOperationError.Exception(e);
                }

                callback(error);
            }));

            thread.Name = "Register for notification thread";
            thread.Start();
        }
Example #7
0
        internal MobeelizerOperationError Sync()
        {
            if (application.CheckSyncStatus() != MobeelizerSyncStatus.STARTED)
            {
                Log.i(TAG, "Send is already running - skipping.");
                return(null);
            }

            MobeelizerDatabase           database          = (MobeelizerDatabase)application.GetDatabase();
            IMobeelizerConnectionManager connectionManager = application.GetConnectionManager();
            String ticket  = String.Empty;
            bool   success = false;

            Others.File outputFile = null;
            Others.File inputFile  = null;
            try
            {
                database.LockModifiedFlag();
                if (isAllSynchronization)
                {
                    Log.i(TAG, "Send sync all request.");
                    MobeelizerSyncResponse response = connectionManager.SendSyncAllRequest();
                    if (response.Error == null)
                    {
                        ticket = response.Ticket;
                    }
                    else
                    {
                        return(response.Error);
                    }
                }
                else
                {
                    outputFile = GetOuptutFile();
                    outputFile.Create();
                    MobeelizerOperationError prepareFileError = dataFileService.PrepareOutputFile(outputFile);
                    if (prepareFileError != null)
                    {
                        Log.i(TAG, "Send file haven't been created.");
                        return(prepareFileError);
                    }
                    else
                    {
                        ChangeStatus(MobeelizerSyncStatus.FILE_CREATED, ticket);
                        Log.i(TAG, "Send sync request.");
                        MobeelizerSyncResponse response = connectionManager.SendSyncDiffRequest(outputFile);
                        if (response.Error == null)
                        {
                            ticket = response.Ticket;
                        }
                        else
                        {
                            return(response.Error);
                        }
                    }
                }

                Log.i(TAG, "Sync request completed: " + ticket + ".");
                ChangeStatus(MobeelizerSyncStatus.TASK_CREATED, ticket);
                MobeelizerOperationError waitError = connectionManager.WaitUntilSyncRequestComplete(ticket);
                if (waitError != null)
                {
                    return(waitError);
                }
                else
                {
                    Log.i(TAG, "Sync process complete with success.");
                    ChangeStatus(MobeelizerSyncStatus.TASK_PERFORMED, ticket);
                    MobeelizerGetSyncDataOperationResult getDataResult = connectionManager.GetSyncData(ticket);
                    if (getDataResult.Error == null)
                    {
                        inputFile = getDataResult.InputFile;
                    }
                    else
                    {
                        return(getDataResult.Error);
                    }

                    ChangeStatus(MobeelizerSyncStatus.FILE_RECEIVED, ticket);
                    MobeelizerOperationError processError = dataFileService.ProcessInputFile(inputFile, isAllSynchronization);
                    if (processError != null)
                    {
                        return(processError);
                    }
                    else
                    {
                        success = true;
                    }

                    connectionManager.ConfirmTask(ticket);
                    database.ClearModifiedFlag();
                    application.InternalDatabase.SetInitialSyncAsNotRequired(application.Instance, application.User);
                }
            }
            catch (IOException e)
            {
                Log.i(TAG, e.Message);
                return(MobeelizerOperationError.Exception(e));
            }
            catch (InvalidOperationException e)
            {
                Log.i(TAG, e.Message);
                return(MobeelizerOperationError.Exception(e));
            }
            finally
            {
                if (inputFile != null)
                {
                    inputFile.Delete();
                }

                if (outputFile != null)
                {
                    outputFile.Delete();
                }

                database.UnlockModifiedFlag();
                if (success)
                {
                    ChangeStatus(MobeelizerSyncStatus.FINISHED_WITH_SUCCESS, ticket);
                }
                else
                {
                    Log.i(TAG, "Sync process complete with failure.");
                    ChangeStatus(MobeelizerSyncStatus.FINISHED_WITH_FAILURE, ticket);
                }
            }

            return(success ? null : MobeelizerOperationError.Other("Sync process complete with failure."));
        }