コード例 #1
0
        internal String AddFile(Stream stream)
        {
            String guid = Guid.NewGuid().ToString();
            String path = SavaFile(guid, stream);

            application.GetDatabase().AddFile(guid, path);
            return(guid);
        }
コード例 #2
0
        internal MobeelizerOperationError PrepareOutputFile(Others.File outputFile)
        {
            MobeelizerOutputData         outputData  = null;
            MobeelizerSyncEnumerable     enumerable  = null;
            MobeelizerSyncFileEnumerable filesToSync = null;

            try
            {
                outputData = new MobeelizerOutputData(outputFile, GetTmpOutputFile());
                enumerable = application.GetDatabase().GetEntitiesToSync();
                foreach (MobeelizerJsonEntity entity in enumerable)
                {
                    Log.i(TAG, "Add entity to sync: " + entity.ToString());
                    outputData.WriteEntity(entity);
                }

                filesToSync = application.GetDatabase().GetFilesToSync();
                foreach (var file in filesToSync)
                {
                    String guid = file.Guid;
                    using (Stream stream = file.GetStream())
                    {
                        if (stream == null)
                        {
                            continue;
                        }

                        outputData.WriteFile(guid, stream);
                        Log.i(TAG, "Add file to sync: " + guid);
                    }
                }

                return(null);
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
            finally
            {
                if (outputData != null)
                {
                    outputData.Close();
                }
            }
        }
コード例 #3
0
        internal void ClearAndUnlockSavedState()
        {
            MobeelizerTombstoningState state;

            using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!iso.DirectoryExists(DATA_DIRECTORY))
                {
                    return;
                }

                if (!iso.FileExists(System.IO.Path.Combine(DATA_DIRECTORY, DATA_FILE)))
                {
                    return;
                }

                using (IsolatedStorageFileStream stream = iso.OpenFile(System.IO.Path.Combine(DATA_DIRECTORY, DATA_FILE), System.IO.FileMode.Open))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(MobeelizerTombstoningState));
                    state = serializer.Deserialize(stream) as MobeelizerTombstoningState;
                }
            }

            if (state != null)
            {
                Log.i(TAG, "Clearing modyfication flag.");
                if (state.LoggedIn)
                {
                    if (application.OfflineLogin(state.Instance, state.User, state.Password) == null)
                    {
                        switch (state.SyncStatus)
                        {
                        case MobeelizerSyncStatus.TASK_CREATED:
                        case MobeelizerSyncStatus.TASK_PERFORMED:
                        case MobeelizerSyncStatus.FILE_RECEIVED:
                            application.GetDatabase().UnlockModifiedFlag();
                            break;
                        }

                        application.Logout();
                    }
                }
            }

            this.ClearSavedState();
        }
コード例 #4
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."));
        }