/// <summary>
        /// Gets the content of a document revision from the file system.
        /// </summary>
        /// <param name="documentRevision">The documentrevision, which the method returns the content from</param>
        /// <returns>The content of the document revision</returns>
        public String GetDocumentRevisionContent(Documentrevision documentRevision)
        {
            Document originalDocument = GetDocumentById(documentRevision.documentId);
            String   creationTime     = documentRevision.creationTime.ToString().Replace(":", ".");
            String   filepath         = originalDocument.path + "\\" + originalDocument.name + "_revision_" + creationTime + ".txt";

            return(fsh.GetDocumentContent(filepath));
        }
示例#2
0
        /// <summary>
        /// Gets the pure content of a document revision
        /// </summary>
        /// <param name="documentRevisionId">The id of the document revision</param>
        /// <returns>The pure content of the document revision</returns>
        public string GetDocumentRevisionContentById(int documentRevisionId)
        {
            Documentrevision documentRevision = PersistentStorage.GetInstance().GetDocumentRevisionById(documentRevisionId);
            String           fileContent      = PersistentStorage.GetInstance().GetDocumentRevisionContent(documentRevision);
            String           xaml             = fileContent.Substring(fileContent.IndexOf("<"));
            FlowDocument     flowDocument     = (FlowDocument)System.Windows.Markup.XamlReader.Parse(xaml);
            TextRange        textRange        = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

            return(textRange.Text);
        }
示例#3
0
        /// <summary>
        /// Create a new Documentrevision object.
        /// </summary>
        /// <param name="id">Initial value of the id property.</param>
        /// <param name="documentId">Initial value of the documentId property.</param>
        /// <param name="creationTime">Initial value of the creationTime property.</param>
        /// <param name="path">Initial value of the path property.</param>
        /// <param name="editorId">Initial value of the editorId property.</param>
        public static Documentrevision CreateDocumentrevision(global::System.Int32 id, global::System.Int32 documentId, global::System.DateTime creationTime, global::System.String path, global::System.Int32 editorId)
        {
            Documentrevision documentrevision = new Documentrevision();

            documentrevision.id           = id;
            documentrevision.documentId   = documentId;
            documentrevision.creationTime = creationTime;
            documentrevision.path         = path;
            documentrevision.editorId     = editorId;
            return(documentrevision);
        }
示例#4
0
 /// <summary>
 /// Adds a documentrevision to an already existing document
 /// </summary>
 /// <param name="editorId">The id of the user who made the revision</param>
 /// <param name="documentId">The id of the original document</param>
 /// <param name="content">The xaml + metadata content of the file</param>
 public void AddDocumentRevision(DateTime creationTime, int editorId, int documentId, String filepath)
 {
     using (PieFactoryEntities context = new PieFactoryEntities())
     {
         Documentrevision documentRevision = new Documentrevision();
         documentRevision.creationTime = creationTime;
         documentRevision.editorId     = editorId;
         documentRevision.documentId   = documentId;
         documentRevision.path         = filepath;
         context.Documentrevisions.AddObject(documentRevision);
         context.SaveChanges();
     }
 }
示例#5
0
 public String[] GetContentAsStringArray(Documentrevision documentRevision)
 {
     Document originalDoc = PersistentStorage.GetInstance().GetDocumentById(documentRevision.documentId);
     DateTime timestamp = documentRevision.creationTime;
     String timestampString = timestamp.ToString().Replace(':', '.');
     String content = PersistentStorage.GetInstance().GetDocumentContent(originalDoc.path + "\\" + originalDoc.name + "_revision_" + timestampString + ".txt");
     content = content.Substring(content.IndexOf('<')); //Remove metadata
     FlowDocument flowDoc = (FlowDocument)System.Windows.Markup.XamlReader.Parse(content);
     TextRange textRange = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);
     String pureContent = textRange.Text; //The "pure" content of the flowdocument i.e. what the user has written
     String[] returnArray = pureContent.Split(new String[] { "\r\n", "\n" }, StringSplitOptions.None);
     return returnArray;
 }
示例#6
0
 /// <summary>
 /// Adds a documentrevision to an already existing document
 /// </summary>
 /// <param name="editorId">The id of the user who made the revision</param>
 /// <param name="documentId">The id of the original document</param>
 /// <param name="content">The xaml + metadata content of the file</param>
 public void AddDocumentRevision(DateTime creationTime, int editorId, int documentId, String filepath)
 {
     using (PieFactoryEntities context = new PieFactoryEntities())
     {
         Documentrevision documentRevision = new Documentrevision();
         documentRevision.creationTime = creationTime;
         documentRevision.editorId = editorId;
         documentRevision.documentId = documentId;
         documentRevision.path = filepath;
         context.Documentrevisions.AddObject(documentRevision);
         context.SaveChanges();
     }
 }
示例#7
0
        public String[] GetContentAsStringArray(Documentrevision documentRevision)
        {
            Document originalDoc     = PersistentStorage.GetInstance().GetDocumentById(documentRevision.documentId);
            DateTime timestamp       = documentRevision.creationTime;
            String   timestampString = timestamp.ToString().Replace(':', '.');
            String   content         = PersistentStorage.GetInstance().GetDocumentContent(originalDoc.path + "\\" + originalDoc.name + "_revision_" + timestampString + ".txt");

            content = content.Substring(content.IndexOf('<')); //Remove metadata
            FlowDocument flowDoc     = (FlowDocument)System.Windows.Markup.XamlReader.Parse(content);
            TextRange    textRange   = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);
            String       pureContent = textRange.Text; //The "pure" content of the flowdocument i.e. what the user has written

            String[] returnArray = pureContent.Split(new String[] { "\r\n", "\n" }, StringSplitOptions.None);
            return(returnArray);
        }
示例#8
0
        /// <summary>
        /// Syncs a document with the server.
        /// </summary>
        /// <param name="editorId">The id of the user who's submitting his work</param>
        /// <param name="documentId">The id of the document</param>
        /// <param name="filepath">The path to where the file lies on the client</param>
        /// <param name="fileContent">The xaml content of the document the user is syncing</param>
        /// <param name="title">The title of the document</param>
        /// <param name="pureContent">The "pure" content of the document. One line per index in the array</param>
        /// <returns>Null if there's no mergeconflict.
        /// If there is a mergeconflict the returned is like this:
        /// Array[0] = the merged document
        /// Array[1] = insertions, same length as Array[0]
        /// Array[2] = deletions, same length as Array[3]
        /// Array[3] = the original document (server version)</returns>
        public String[][] SyncDocument(int editorId, int documentId, String filepath, String fileContent, String title, String pureContent)
        {
            String[] latestAsArray = pureContent.Split(new String[] { "\r\n", "\n" }, StringSplitOptions.None);

            PersistentStorage ps = PersistentStorage.GetInstance();

            //Document found with the given id
            if (GetDocumentById(documentId) != null)
            {
                //Check if the document has any revisions
                bool hasRevisions = ps.DocumentHasRevision(documentId);

                if (!hasRevisions)
                {
                    //No conflict
                    return(ps.SyncNoConflict(editorId, documentId, filepath, fileContent));
                }

                //Get the latest documentrevision by the user
                Documentrevision latestUserDocumentRevision = ps.GetLatestDocumentRevisionByUserId(editorId, documentId);
                //Get the latest documentrevision on the server
                Documentrevision latestServerDocumentRevision = ps.GetLatestDocumentRevisions(documentId)[0];
                //Get the content of the latest documentrevision by the user
                String latestUserDocumentContent = ps.GetDocumentRevisionContent(latestUserDocumentRevision);
                //Get the content of the latest documentrevision on the server
                String latestServerDocumentContent = ps.GetDocumentRevisionContent(latestServerDocumentRevision);

                //Check if the two contents are equal. If they are equal, there's no conflict
                if (latestUserDocumentContent == latestServerDocumentContent)
                {
                    //No conflict
                    return(ps.SyncNoConflict(editorId, documentId, filepath, fileContent));
                }
                else
                {
                    //Conflict
                    return(Model.GetInstance().SyncConflict(documentId, latestAsArray));
                }
            }
            else
            {
                //No document found with the given id.
                ps.AddDocumentWithUserDocument(title, editorId, filepath, fileContent);
                return(null);
            }
        }
        /// <summary>
        /// Gets the content of the latest document revision made from a document.
        /// </summary>
        /// <param name="documentId">The id of the document the revision is based from</param>
        /// <returns>The content of the latest document revision</returns>
        public string GetLatestDocumentContent(int documentId)
        {
            List <Documentrevision> latestDocumentRevisions = GetLatestDocumentRevisions(documentId);
            Document originalDocument = GetDocumentById(documentId);
            String   documentContent;

            if (latestDocumentRevisions.Count > 0)
            {
                Documentrevision latestDocumentRevision = latestDocumentRevisions[0];
                String           creationTime           = latestDocumentRevision.creationTime.ToString().Replace(":", ".");
                String           filepath = originalDocument.path + "\\" + originalDocument.name + "_revision_" + creationTime + ".txt";
                documentContent = GetDocumentContent(filepath);
            }
            else
            {
                String creationTime = originalDocument.creationTime.ToString().Replace(":", ".");
                String filepath     = originalDocument.path + "\\" + originalDocument.name + ".txt";
                documentContent = GetDocumentContent(filepath);
            }
            return(documentContent);
        }
示例#10
0
 /// <summary>
 /// Gets the content of a document revision from the file system.
 /// </summary>
 /// <param name="documentRevision">The documentrevision, which the method returns the content from</param>
 /// <returns>The content of the document revision</returns>
 public String GetDocumentRevisionContent(Documentrevision documentRevision)
 {
     Document originalDocument = GetDocumentById(documentRevision.documentId);
     String creationTime = documentRevision.creationTime.ToString().Replace(":", ".");
     String filepath = originalDocument.path + "\\" + originalDocument.name + "_revision_" + creationTime + ".txt";
     return fsh.GetDocumentContent(filepath);
 }
示例#11
0
 /// <summary>
 /// Create a new Documentrevision object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="documentId">Initial value of the documentId property.</param>
 /// <param name="creationTime">Initial value of the creationTime property.</param>
 /// <param name="path">Initial value of the path property.</param>
 /// <param name="editorId">Initial value of the editorId property.</param>
 public static Documentrevision CreateDocumentrevision(global::System.Int32 id, global::System.Int32 documentId, global::System.DateTime creationTime, global::System.String path, global::System.Int32 editorId)
 {
     Documentrevision documentrevision = new Documentrevision();
     documentrevision.id = id;
     documentrevision.documentId = documentId;
     documentrevision.creationTime = creationTime;
     documentrevision.path = path;
     documentrevision.editorId = editorId;
     return documentrevision;
 }
示例#12
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Documentrevisions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDocumentrevisions(Documentrevision documentrevision)
 {
     base.AddObject("Documentrevisions", documentrevision);
 }
示例#13
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Documentrevisions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDocumentrevisions(Documentrevision documentrevision)
 {
     base.AddObject("Documentrevisions", documentrevision);
 }