private Others.File GetTmpOutputFile() { String filePath = System.IO.Path.Combine("sync", "output"); using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (!iso.DirectoryExists("sync")) { iso.CreateDirectory("sync"); } if (iso.FileExists(filePath)) { iso.DeleteFile(filePath); } } Others.File file = new Others.File(filePath); file.Create(); return(file); }
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.")); }
private Others.File GetTmpOutputFile() { String filePath = System.IO.Path.Combine("sync", "output"); using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (!iso.DirectoryExists("sync")) { iso.CreateDirectory("sync"); } if (iso.FileExists(filePath)) { iso.DeleteFile(filePath); } } Others.File file = new Others.File(filePath); file.Create(); return file; }