public void Update(string serverUrl, string loginId, string authToken, DbFileJob dbFileJob) { lock (this) { var filePath = dbFileJob.FilePath; if (!File.Exists(filePath)) { return; } var fileReader = this.BuildFileReader(filePath); if (fileReader == null) { return; } var modelId = this.GetDocumentIdByFilePathFromDataBase.Execute(filePath); if (modelId == null) { return; } DateTime fileCreatedAt = File.GetCreationTime(filePath); DateTime fileUpdatedAt = File.GetLastWriteTime(filePath); var fileContent = fileReader.Execute(); var documentFile = new DocumentFile(modelId.Value, Path.GetFileName(filePath), filePath, fileContent, string.Empty, fileCreatedAt, fileUpdatedAt); this.DocumentFileService.UpdateDocumentFile(serverUrl, loginId, authToken, documentFile); this.UpdateFileToDataBase.Execute(filePath, fileCreatedAt, fileUpdatedAt); } }
public void Add(string serverUrl, string loginId, string authToken, DbFileJob dbFileJob) { lock (this) { var filePath = dbFileJob.FilePath; if (!File.Exists(filePath)) { return; } var fileReader = this.BuildFileReader(filePath); if (fileReader == null) { return; } var fileContent = fileReader.Execute(); DateTime fileCreatedAt = File.GetCreationTime(filePath); DateTime fileUpdatedAt = File.GetLastWriteTime(filePath); System.Diagnostics.Debug.WriteLine("*** updated " + fileUpdatedAt.ToString()); var documentFile = new DocumentFile(Path.GetFileName(filePath), filePath, fileContent, string.Empty, fileCreatedAt, fileUpdatedAt); var modelId = this.DocumentFileService.AddDocumentFile(serverUrl, loginId, authToken, documentFile); this.AddFileToDataBase.Execute(filePath, modelId.Value, fileCreatedAt, fileUpdatedAt); } }
public Exception SynchronizeDocumentFile_Execute(DbFileJob fileJob) { try { switch (fileJob.Command) { case LocalDataBaseConstants.COMMAND_ADD: this.SynchronizeDocumentFile.Add(this.ServerUrl, this.LoginId, this.AuthToken, fileJob); break; case LocalDataBaseConstants.COMMAND_REMOVE: this.SynchronizeDocumentFile.Remove(this.ServerUrl, this.LoginId, this.AuthToken, fileJob); break; case LocalDataBaseConstants.COMMAND_UPDATE: this.SynchronizeDocumentFile.Update(this.ServerUrl, this.LoginId, this.AuthToken, fileJob); break; default: var message = "invalid command : " + fileJob.Command; Logger.Warn(message); throw new Exception(message); } return(null); } catch (Exception ex) { return(ex); } }
public void Remove(string serverUrl, string loginId, string authToken, DbFileJob dbFileJob) { lock (this) { var filePath = dbFileJob.FilePath; var modelId = this.GetDocumentIdByFilePathFromDataBase.Execute(filePath); if (modelId == null) { return; } this.DocumentFileService.RemoveDocumentFile(serverUrl, loginId, authToken, modelId); this.RemoveFileToDataBase.Execute(filePath); } }