private void InsertFile(IDropboxFile file) { var newId = documentStore.Add(file); syncInfoRepository.Add(new SyncInfo { ExactDivisionId = documentStore.GetDivisionId(), ExactId = newId, DropboxAccountId = dropboxFileProvider.GetAccountId(), DropboxPath = file.FilePath, LastModified = file.Modified }); }
private void SyncFile(IDropboxFile file) { var fileSyncInfo = syncInfoRepository.GetByDropboxPath(dropboxFileProvider.GetAccountId(), documentStore.GetDivisionId(), file.FilePath); if (fileSyncInfo == null) { InsertFile(file); } else if (documentStore.ContainsDocument(fileSyncInfo.ExactId) == false) { syncInfoRepository.Remove(fileSyncInfo); InsertFile(file); } else if (fileSyncInfo.LastModified < file.Modified) { UpdateFile(file, fileSyncInfo); } }
public void Update(Guid guid, IDropboxFile file) { var document = documentService.Get(guid); UpdateDocumentModel(file, document); var documentUpdated = documentService.Update(document); if (!documentUpdated) { throw new Exception("Document was not updated"); } var documentAttachment = documentAttachmentService.GetByDocumentId(guid).FirstOrDefault(); if (documentAttachment == null) { documentAttachment = new DocumentAttachment { Document = document.ID }; UpdateDocumentDocumentAttachmentModel(file, documentAttachment); var insertedDocumentAttachment = documentAttachmentService.Create(documentAttachment); if (insertedDocumentAttachment == null) { throw new Exception("Attachment was not updated"); } } else { UpdateDocumentDocumentAttachmentModel(file, documentAttachment); var documentAttachmentUpdated = documentAttachmentService.Update(documentAttachment); if (!documentAttachmentUpdated) { throw new Exception("Attachment was not updated"); } } }
public Guid Add(IDropboxFile file) { var document = new Document { Type = GetDefaultTypeId(), Category = GetDefaultDocumentCategoryId() }; UpdateDocumentModel(file, document); var insertedDocument = documentService.Create(document); if (insertedDocument == null) { throw new Exception("Document was not inserted"); } try { var documentAttachment = new DocumentAttachment { Document = insertedDocument.ID }; UpdateDocumentDocumentAttachmentModel(file, documentAttachment); var insertedDocumentAttachment = documentAttachmentService.Create(documentAttachment); if (insertedDocumentAttachment == null) { throw new Exception("Attachment was not inserted"); } } catch { documentService.Delete(insertedDocument); throw; } return(insertedDocument.ID); }
private static string GetFileName(IDropboxFile file) { return(System.IO.Path.GetFileName(file.FilePath)); }
private static void UpdateDocumentModel(IDropboxFile file, Document document) { document.DocumentDate = file.Modified; document.Modified = file.Modified; document.Subject = GetFileName(file); }
private static void UpdateDocumentDocumentAttachmentModel(IDropboxFile file, DocumentAttachment documentAttachment) { documentAttachment.FileName = GetFileName(file); documentAttachment.Attachment = file.GetFileContent(); }
private void UpdateFile(IDropboxFile file, SyncInfo syncInfo) { documentStore.Update(syncInfo.ExactId, file); syncInfo.LastModified = file.Modified; syncInfoRepository.Update(syncInfo); }