/// <summary> /// /// </summary> /// <param name="documentId"></param> /// <returns> /// [x]a new revision /// [x][0]timestamp /// [x][1]editor name /// [x][2]filecontent with metadata /// </returns> public string[][] GetAllDocumentRevisionsWithContent(int documentId) { string[][] returnArray = null; if (documentId > 0) { ServiceReference.ServiceDocumentrevision[] revisions = null; using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client()) { revisions = proxy.GetAllDocumentRevisionsByDocumentId(documentId); } //remove duplicates //here returnArray = new string[revisions.Length][]; using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client()) { for (int i = 0; i < revisions.Length; i++) { ServiceReference.ServiceDocumentrevision doc = revisions[i]; ServiceReference.ServiceDocument originalDocument = proxy.GetDocumentById(doc.documentId); String creationTime = doc.creationTime.ToString().Replace(":", "."); String filename = originalDocument.name + "_revision_" + creationTime; String content = proxy.GetDocumentContent(originalDocument.path, filename); string[] item = new string[3]; item[0] = doc.creationTime.ToString(); item[1] = proxy.GetUserById(doc.editorId).email; item[2] = Metadata.RemoveMetadataFromFileContent(content); returnArray[i] = item; } } } return(returnArray); }
/// <summary> /// Synchronizes all documents. This includes downloading of files from the server and overwritting of eventual exisiting local saves that can cause conflicts. /// Locally absent folders from documents downloaded from the server are created locally. /// </summary> public void SyncAllDocuments() { if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { if (session.UserID != -1) //Check if user is logged in { ServiceReference.ServiceUserdocument[] documents; //Connect to webservice using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client()) { //Retrieve all documents the users documents documents = proxy.GetAllUserDocumentsByUserId(session.UserID); } if (documents != null) //check if any documents is found { //For each document found foreach (ServiceReference.ServiceUserdocument currentDoc in documents) { String relativeDirPath = FetchRelativeFilePath(currentDoc); String dirPath = session.RootFolderPath + "\\" + relativeDirPath; ServiceReference.ServiceDocument documentReference = null; using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client()) { //Get the original document from the server documentReference = proxy.GetDocumentById(currentDoc.documentId); } String filePath = dirPath + "\\" + documentReference.name + ".txt"; String content; //Connect to webservice using (ServiceReference.Service1Client proxy = new ServiceReference.Service1Client()) { //Get the content of the file on the server content = proxy.GetLatestDocumentContent(documentReference.id); //add a document revision in order to be able to detect merge conflicts later proxy.AddDocumentRevision(session.UserID, documentReference.id, content); } //Create the directories needed? Directory.CreateDirectory(Path.GetDirectoryName(filePath)); //Create a document locally with the content localPersistence.SaveDocumentToFile(content, filePath); } } else //No documents found by this userId { //loop through all the users folders and add all files to the server List <String> files = new List <String>(); foreach (String file in Directory.GetFiles(session.RootFolderPath)) { AddDocumentToServer(file); } foreach (String dir in Directory.GetDirectories(session.RootFolderPath)) { foreach (String file in Directory.GetFiles(dir)) { AddDocumentToServer(file); } } } } else { //not logged in } UpdateExplorerView(); } else { MessageBox.Show("No internet connection", "Internet connection error"); } }