Exemple #1
0
        public void UpdateDocument(
            CMISFolder folder,
            string document,
            string docName,
            Dictionary <string, object> props,
            bool major,
            string checkInComment)
        {
            IContentStream contentStream = getContentStream(document, docName);

            try
            {
                IDocument d = GetDocument(folder, docName).IDocument(session);
                d.UpdateProperties(props);
                if (d.AllowableActions == null ||
                    d.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanCheckOut))
                {
                    var      pwcId = d.CheckOut();
                    Document pwc   = (Document)session.GetObject(pwcId);
                    pwc.CheckIn(major, props, contentStream, checkInComment);
                }
                else
                {
                    d.CheckIn(major, props, contentStream, checkInComment);
                }
            }
            catch (CmisBaseException e) { throw new Exception(e.ErrorContent != null? e.ErrorContent : e.Message); }
            finally { contentStream.Stream.Dispose(); }
        }
        private void t02_Folder(CMISTestSystem con)
        {
            initializeClient(con);
            CMISFolder root = cmisClient.GetRootFolder();

            Assert.AreEqual(con.RootFolder, root.DisplayName);
            cmisClient.GetRootFolder().GetAllSubFolders().Count();

            CMISFolder sub = cmisClient.GetFolderFromPath(con.SubFolder);

            Assert.AreEqual(con.SubFolder.Split('/').Last(), sub.DisplayName);

            CMISFolder sub1 = cmisClient.GetSubfolder(sub, sieeSubPath, con.FolderType);
            CMISFolder sub3 = cmisClient.GetSubfolder(sub, sieeSubPath + "/sub2/sub3", con.FolderType);
            CMISFolder sub4 = cmisClient.GetSubfolder(sub, sieeSubPath + "/sub2/sub4", con.FolderType);
            CMISFolder sub2 = cmisClient.GetFolderFromPath(con.SubFolder + "/" + sieeSubPath + "/" + "sub2");

            Assert.AreEqual(2, sub2.GetAllSubFolders().Count());

            cmisClient.DeleteFolder(sub4);
            cmisClient.DeleteFolder(sub3);
            cmisClient.DeleteFolder(sub2);
            deleteDocument(sub1, documentName);
            cmisClient.DeleteFolder(sub1);
        }
Exemple #3
0
        public CMISFolder GetSubfolder(CMISFolder baseFolder, string pathExtension, string folderType)
        {
            IDictionary <string, object> props = new Dictionary <string, object>();

            props["cmis:objectTypeId"] = folderType;

            IFolder currFolder = baseFolder.IFolder(session);

            foreach (string element in pathExtension.Split('/'))
            {
                if (element == string.Empty)
                {
                    continue;                          // ignore leadiong "/"
                }
                List <ICmisObject> childs = currFolder.GetChildren().Where(n => n.Name == element && n is IFolder).ToList();
                if (childs.Count > 0)
                {
                    // if subfolder already exists -> use it
                    currFolder = (IFolder)childs[0];
                    continue;
                }
                // else create it
                props[PropertyIds.Name] = element;
                currFolder = currFolder.CreateFolder(props);
            }
            return(new CMISFolder(currFolder, session));
        }
        private void storeAndVerifyDocument(
            CMISFolder folder, string documentName,
            CMISType type, List <CMISTestProperty> properties)
        {
            CultureInfo ci = new CultureInfo("en-US");
            Dictionary <string, object> props = new Dictionary <string, object>();

            foreach (CMISTestProperty ctp in properties)
            {
                props[ctp.Property.Id] = ctp.Property.ConvertValue(ctp.TestValue, ci);
            }

            bool description = type.Type.PropertyDefinitions.Where(n => n.Id == "cmis:description").Count() > 0;

            if (description)
            {
                props["cmis:description"] = "Hello World";
            }
            props["cmis:objectTypeId"] = type.Id;
            cmisClient.StoreDocument(folder, sampleDocument, documentName, props, null);

            CMISDocument cmisDocument = cmisClient.GetDocument(folder, documentName);

            if (description)
            {
                Assert.AreEqual("Hello World", cmisClient.GetPropertyValue(cmisDocument, "cmis:description"));
            }
            //foreach (CMISProperty p in properties.Keys)
            foreach (CMISTestProperty ctp in properties)
            {
                object expected = ctp.TestValue;
                object result   = cmisClient.GetPropertyValue(cmisDocument, ctp.Property.Id);
                Assert.AreEqual(expected, result); break;
            }
        }
        private CMISFolder determineFolder(SIEEFieldlist fieldlist)
        {
            CMISFolder folder = cmisClient.GetFolderFromId(selectedFolderId);

            if (mySettings.UseSubFolderField)
            {
                // Get contents of subfolder field into pathExtension
                List <SIEEField> match = fieldlist.Where(n => n.Name == mySettings.SubFolderField).ToList();
                if (match.Count != 1)
                {
                    throw (new Exception("No field " + mySettings.SubFolderField + " in data"));
                }
                string pathExtension = match.First().Value;

                // Get sub folder type
                string ftype = "cmis:folder";
                if (mySettings.UseSubFolderType && mySettings.SubFolderTypeFixed)
                {
                    ftype = mySettings.SubFolderType;
                }
                if (mySettings.UseSubFolderType && mySettings.SubFolderTypeFromField)
                {
                    string newType = fieldlist.Where(n => n.ExternalId == mySettings.SubFolderTypeField).Select(n => n.Value).First();
                    if (newType != "")
                    {
                        ftype = newType;
                    }
                }
                // Get the folder
                folder = cmisClient.GetSubfolder(folder, pathExtension, ftype);
            }
            return(folder);
        }
        private void deleteDocument(CMISFolder folder, string documentName)
        {
            CMISDocument cmisDocument = cmisClient.GetDocument(folder, documentName);

            if (cmisDocument != null)
            {
                cmisClient.DeleteDocument(cmisDocument);
            }
        }
        // return the filename for addNumber collision handling
        private string getDocumentNameWithNumber(string basename, CMISFolder folder)
        {
            DocumentNameFindNumber dnfn = new DocumentNameFindNumber(DNFN_probe);

            currFolder = folder;
            int nextNumber = dnfn.GetNextFileName(basename);

            return(fileNameWithNumber(basename, nextNumber));
        }
Exemple #8
0
        public CMISDocument GetDocument(CMISFolder folder, string documentName)
        {
            List <ICmisObject> found = folder.IFolder(session).GetChildren().Where(n => n.Name == documentName && n is IDocument).ToList();

            if (found == null || found.Count == 0)
            {
                return(null);
            }
            return(new CMISDocument(found.First() as IDocument));
        }
Exemple #9
0
 public void UpdateDocument(CMISFolder folder, string document, string docName,
                            Dictionary <string, object> props, bool major, string checkInComment)
 {
     SDR.FinalFolder    = folder.DisplayName;
     SDR.Filename       = document;
     SDR.DocName        = docName;
     SDR.Properties     = props;
     SDR.Updated        = true;
     SDR.Major          = major;
     SDR.CheckInComment = checkInComment;
 }
Exemple #10
0
 public CMISDocument GetDocument(CMISFolder folder, string documentName)
 {
     if (ExistingDocument == documentName)
     {
         return(new CMISDocument("1", "Document 1"));
     }
     else
     {
         return(null);
     }
 }
Exemple #11
0
 public void StoreDocument(CMISFolder folder, string document, string docName,
                           Dictionary <string, object> props, bool?major)
 {
     SDR.Password    = Password;
     SDR.FinalFolder = folder.DisplayName;
     SDR.Filename    = document;
     SDR.DocName     = docName;
     SDR.Properties  = props;
     if (ExistingDocument == docName)
     {
         SDR.OverwrittenExistingDocument = true;
     }
 }
        private void t04_Documents(CMISTestSystem con)
        {
            initializeClient(con);
            string checkinComment = "Test check-in comment";

            CMISFolder folder = cmisClient.GetFolderFromPath(con.SubFolder);

            folder = cmisClient.GetSubfolder(folder, sieeSubPath, con.FolderType);

            CMISType type = cmisClient.GetTypeFromId(con.StoreType);

            deleteDocument(folder, documentName);
            storeAndVerifyDocument(folder, documentName, type, con.Properties);

            if (con.VersioningType != null)
            {
                CMISDocument cmisDocument;
                deleteDocument(folder, documentName);
                Dictionary <string, object> props = new Dictionary <string, object>();
                props["cmis:objectTypeId"] = cmisClient.GetTypeFromId(con.VersioningType).Id;

                cmisClient.StoreDocument(folder, sampleDocument, documentName, props, true);
                cmisDocument = cmisClient.GetDocument(folder, documentName);
                Assert.AreEqual(con.V1_Major, getVersionString(cmisDocument));

                cmisClient.UpdateDocument(folder, sampleDocument, documentName, props, true, checkinComment);
                cmisDocument = cmisClient.GetObjectOfLatestVersion(cmisDocument, major: true);
                Assert.AreEqual(con.V2_Major, getVersionString(cmisDocument));
                Assert.AreEqual(checkinComment, cmisClient.GetCheckinComent(cmisDocument));

                if (con.SupportsMinorVersions)
                {
                    deleteDocument(folder, documentName);
                    cmisClient.StoreDocument(folder, sampleDocument, documentName, props, false);
                    cmisDocument = cmisClient.GetDocument(folder, documentName);
                    Assert.AreEqual(con.V1_Minor, getVersionString(cmisDocument));

                    cmisClient.UpdateDocument(folder, sampleDocument, documentName, props, false, checkinComment);
                    cmisDocument = cmisClient.GetObjectOfLatestVersion(cmisDocument, major: false);
                    Assert.AreEqual(con.V2_Minor, getVersionString(cmisDocument));
                    Assert.AreEqual(checkinComment, cmisClient.GetCheckinComent(cmisDocument));
                }
            }

            deleteDocument(folder, documentName);
            cmisClient.DeleteFolder(folder);
        }
        private void t06_Performance(CMISTestSystem con)
        {
            if (!runPerformaceTest)
            {
                return;
            }

            initializeClient(con);
            string documentName = "Sample document";
            string folderName   = con.SubFolder + "/" + sieeSubPath;

            CMISFolder folder = cmisClient.GetSubfolder(cmisClient.GetRootFolder(), folderName, con.FolderType);
            CMISType   type   = cmisClient.GetTypeFromId(con.StoreType);

            deleteDocument(folder, documentName);

            // pre-upload a few documents to warm up the system ...
            for (int i = 0; i != 5; i++)
            {
                doOneDocument(folder, documentName, type, con);
            }

            // do the real test
            Process p         = Process.GetCurrentProcess();
            long    memBefore = p.PeakWorkingSet64 / 1000;
            int     nofCycles = 100;

            int[] times = new int[nofCycles];
            for (int i = 0; i != nofCycles; i++)
            {
                DateTime start = DateTime.Now;
                doOneDocument(folder, documentName, type, con);
                times[i] = (int)(DateTime.Now - start).TotalMilliseconds;
                Console.WriteLine(i + " = " + times[i]);
            }
            long memAfter = p.PeakWorkingSet64 / 1000;

            Assert.AreEqual(memBefore, memAfter);
            Assert.AreEqual(true, nofCycles > 20);
            double avgStart  = average(times, 0, 9);
            double avgEnd    = average(times, nofCycles - 10, nofCycles - 1);
            double deviation = Math.Abs(avgEnd - avgStart) / avgStart;

            Assert.AreEqual(true, deviation <= .25, "deviates (avgStart=" + avgStart + " ,avgEnd=" + avgEnd + ")");
        }
Exemple #14
0
        public override List <TVIModel> GetChildren()
        {
            List <TVIModel> result = new List <TVIModel>();

            try
            {
                foreach (CMISFolder f in CMISFolder.GetAllSubFolders())
                {
                    result.Add((TVIModel) new CMISFolderNode(this, f));
                }
            }
            catch (Exception e)
            {
                SIEEMessageBox.Show(
                    "Error loading subfolders\n" + e.Message,
                    "CMIS Connector",
                    System.Windows.MessageBoxImage.Error);
            }
            return(result);
        }
Exemple #15
0
        public void StoreDocument(
            CMISFolder folder,                  // where to put the document
            string document,                    // file name of the document
            string docName,                     // name of the new document
            Dictionary <string, object> props,  // document properties
            bool?major)                         // use versioning and which one
        {
            IContentStream contentStream = getContentStream(document, docName);

            try
            {
                IFolder         iFolder = folder.IFolder(session);
                VersioningState?vs      = null;
                if (major != null)
                {
                    vs = major == true? VersioningState.Major : VersioningState.Minor;
                }
                props[PropertyIds.Name] = docName;
                iFolder.CreateDocument(props, contentStream, vs);
                props.Remove(PropertyIds.Name);
            }
            catch (CmisBaseException e) { throw new Exception(e.Message + "\n" + e.ErrorContent); }
            finally { contentStream.Stream.Dispose(); }
        }
Exemple #16
0
 public void DeleteFolder(CMISFolder folder)
 {
 }
Exemple #17
0
 public CMISFolder GetSubfolder(CMISFolder baseFolder, string pathExtension, string folderType)
 {
     SDR.UsedFolderType = folderType;
     return(new CMISFolder("4", baseFolder.DisplayName + "/" + pathExtension));
 }
Exemple #18
0
        }                           // for xml serializer

        public CMISFolderNode(CMISFolderNode parent, CMISFolder folder)
        {
            CMISFolder = folder;
            FolderPath = parent == null ? folder.DisplayName : parent.FolderPath + GetPathConcatenationString() + folder.DisplayName;
        }
        public override void ExportDocument(SIEESettings settings, SIEEDocument document, string name, SIEEFieldlist fieldlist)
        {
            CMISFolder folder  = determineFolder(fieldlist);
            string     docName = name;

            // Collision detection and handling (except for version handling)
            CMISDocument existingDocument = cmisClient.GetDocument(folder, docName + pdfExtension);

            if (existingDocument != null)
            {
                switch (mySettings.SelectedConflictHandling)
                {
                case CMISSettings.ConflictHandling.Replace:
                { cmisClient.DeleteDocument(existingDocument); break; }

                case CMISSettings.ConflictHandling.AddBlurb:
                { docName = getDocumentNameWithBlurb(docName); break; }

                case CMISSettings.ConflictHandling.AddNumber:
                { docName = getDocumentNameWithNumber(docName, folder); break; }

                default: break;
                }
            }

            // Create property list
            string checkInComment             = "OCC created version";
            Dictionary <string, object> props = new Dictionary <string, object>();

            props["cmis:objectTypeId"] = selectedTypeId;

            foreach (SIEEField f in fieldlist)
            {
                if (f.ExternalId == "cmis:checkinComment")
                {
                    checkInComment = f.Value; continue;
                }
                if (mySettings.UseSubFolderField &&
                    mySettings.SubFolderTypeFixed &&
                    f.ExternalId == mySettings.SubFolderField)
                {
                    continue;
                }
                if (mySettings.UseSubFolderField &&
                    mySettings.SubFolderTypeFromField &&
                    f.ExternalId == mySettings.SubFolderTypeField)
                {
                    continue;
                }

                try { props[f.ExternalId] = convert(mySettings, f); }
                catch (Exception e) { throw new Exception(
                                                "Error converting value for field '" + f.ExternalId + "' Value = '" + f.Value +
                                                "' \nReason: " + e.Message
                                                ); }
            }

            try
            {
                string dn = docName + pdfExtension;
                if (cmisClient.GetDocument(folder, docName + pdfExtension) == null || !versionHandling())
                {
                    bool?v = null;
                    if (versionHandling())
                    {
                        v = mySettings.Major;
                    }
                    cmisClient.StoreDocument(folder, document.PDFFileName, dn, props, v);
                }
                else
                {
                    cmisClient.UpdateDocument(folder, document.PDFFileName, dn, props, mySettings.Major, checkInComment);
                }
            }
            catch (Exception e) { trace.WriteError(e.Message); throw; }
            document.TargetDocumentId = folder + ":" + document.PDFFileName;
        }
Exemple #20
0
 public void DeleteFolder(CMISFolder folder)
 {
     session.Delete(folder.IFolder(session));
 }
 private void doOneDocument(CMISFolder folder, string documentName, CMISType type, CMISTestSystem con)
 {
     storeAndVerifyDocument(folder, documentName, type, con.Properties);
     deleteDocument(folder, documentName);
 }