Exemplo n.º 1
0
        public void TestCreateAndDeleteEmptyCustomProfile()
        {
            DMLogin.ServerName = DMTestEnvironment.Server;
            DMLogin.Password = TestHelperSecure.MyPassword;
            string newDocName = Guid.NewGuid().ToString();
            string dst = DMLogin.Dst;

            ProfileInfo profile = new ProfileInfo() { FormName = "CUSTOM_PROFILE_FORM" };
            profile.Properties = new Dictionary<string, string>() {
                { "DOCNAME", newDocName },
                { "APP_ID", "MS WORD" },
                { "AUTHOR_ID", "JDOE" },
                { "TYPIST_ID", "JDOE" },
                { "TYPE_ID", "REPORT" },
                { "CUSTOM_PROP", "NEW VAL" }
            };

            DMDocument doc = new DMDocument() { Dst = dst, Library = DMLogin.Library };

            // create
            var docInfo = doc.CreateProfile(profile);
            Assert.IsNotNull(docInfo);
            Assert.IsTrue(docInfo.DocNumber > 0);
            Assert.IsTrue(docInfo.VersionID > 0);

            // unlock (check-in). We are okay with creating a profile without a document file
            try {
                doc.UnlockDocument(docInfo);
            }
            catch(DMApiEmptyDocumentFileException) {
            }

            // delete
            doc.DeleteProfile(docInfo.DocNumber);
        }
Exemplo n.º 2
0
        public void TestCreateAndDeleteDocument()
        {
            DMLogin.ServerName = DMTestEnvironment.Server;
            DMLogin.Password = TestHelperSecure.MyPassword;
            string dst = DMLogin.Dst;
            string newDocName = Guid.NewGuid().ToString();

            ProfileInfo profile = new ProfileInfo() { FormName = "STANDARD_P" };
            profile.Properties = new Dictionary<string, string>() {
                    { "DOCNAME", newDocName },
                    { "APP_ID", "NOTEPAD" },
                    { "AUTHOR_ID", "JDOE" },
                    { "TYPIST_ID", "JDOE" }
                };
            DMDocument doc = new DMDocument() { Dst = dst, Library = DMLogin.Library };

            string fileName = Path.GetTempFileName();
            File.WriteAllText(fileName, "hello world!\r\n");
            try {
                var docInfo = doc.CreateDocument(profile, fileName);
                Assert.IsNotNull(docInfo);
                Assert.IsTrue(docInfo.DocNumber > 0);
                Assert.IsTrue(docInfo.VersionID > 0);
                //TODO download content and check

                doc.DeleteProfile(docInfo.DocNumber);
            }
            finally {
                File.Delete(fileName);
            }
        }
Exemplo n.º 3
0
 public DocumentInfo CreateDocument(ProfileInfo profile, string localPath)
 {
     if(string.IsNullOrWhiteSpace(localPath))
         throw new ArgumentNullException(localPath);
     bool isDir = (File.GetAttributes(localPath) & FileAttributes.Directory) == FileAttributes.Directory;
     if(isDir)
         return CreateProfile(profile);
     else
         using(var source = new FileStream(localPath, FileMode.Open, FileAccess.Read)) {
             return CreateDocument(profile, source);
         }
 }
Exemplo n.º 4
0
 public DocumentInfo CreateDocument(ProfileInfo profile, Stream source)
 {
     var doc = CreateProfile(profile);
     if(source != null) {
         try {
             var target = GetPcdPutStream(doc);
             UploadContent(source, target);
             UnlockDocument(doc);
         }
         catch {
             // TODO delete profile
             throw;
         }
     }
     return doc;
 }
Exemplo n.º 5
0
 public object Clone()
 {
     var result = new ProfileInfo { FormName = this.FormName };
     if(Properties != null)
         result.Properties = new Dictionary<string, string>(Properties);
     if(Trustees != null)
         result.Trustees = new List<TrusteeInfo>(Trustees);
     return result;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a document profile
        /// </summary>
        /// <param name="profileInfo"></param>
        /// <returns>Returns the document number and the version of newly created profile.</returns>
        public DocumentInfo CreateProfile(ProfileInfo profileInfo)
        {
            if(profileInfo == null)
                throw new ArgumentNullException("profileInfo");
            if(profileInfo.Properties == null)
                throw new ArgumentNullException("profileInfo.Properties");

            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(profileInfo.FormName);
            doc.SetProperty(PropertyTargetLibrary, Library);
            foreach (var pair in profileInfo.Properties)
                doc.SetProperty(pair.Key, pair.Value);

            if(profileInfo.Trustees != null)
                foreach(TrusteeInfo t in profileInfo.Trustees)
                    doc.SetTrustee(t.Trustee, (int)t.TrusteeType, (int)t.AccessRights);

            int result = doc.Create();

            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException("Cannot create profile.", doc.ErrNumber, doc.ErrDescription);

            object docNum = doc.GetReturnProperty(PropertyObjectIdentifier);
            object verID = doc.GetReturnProperty(PropertyVersionID);
            return new DocumentInfo { DocNumber = Convert.ToInt32(docNum), VersionID = Convert.ToInt32(verID) };
        }
Exemplo n.º 7
0
        public void TestCreateFolder_LinkToFolder_DeleteFolder()
        {
            DMLogin.ServerName = DMTestEnvironment.Server;
            DMLogin.Password = TestHelperSecure.MyPassword;
            string newDocName = Guid.NewGuid().ToString();
            string dst = DMLogin.Dst;

            ProfileInfo profile = new ProfileInfo() { FormName = "STANDARD_P" };
            profile.Properties = new Dictionary<string, string>() {
                    { "DOCNAME", newDocName },
                    { "APP_ID", "FOLDER" },
                    { "AUTHOR_ID", "JDOE" },
                    { "TYPIST_ID", "NKHORIN" }
                };

            DMDocument doc = new DMDocument() { Dst = dst, Library = DMLogin.Library };

            // create
            var docInfo = doc.CreateProfile(profile);
            Assert.IsNotNull(docInfo);
            Assert.IsTrue(docInfo.DocNumber > 0);
            Assert.IsTrue(docInfo.VersionID > 0);

            try {
                // no need to unlock a folder

                // link to an existing folder (we looked up its DOCNUMBER and VERSIONID)
                var parent = new DocumentInfo { DocNumber = 12070617, VersionID = 12681993 };
                doc.AddLink(docInfo.DocNumber, parent);
            }
            finally {
                // clear links and delete
                doc.DeleteProfile(docInfo.DocNumber, true);
            }
        }
Exemplo n.º 8
0
        public void TestCreateAndDeleteFolder()
        {
            DMLogin.ServerName = DMTestEnvironment.Server;
            DMLogin.Password = TestHelperSecure.MyPassword;
            string newDocName = Guid.NewGuid().ToString();
            string dst = DMLogin.Dst;

            ProfileInfo profile = new ProfileInfo() { FormName = "STANDARD_P" };
            profile.Properties = new Dictionary<string, string>() {
                    { "DOCNAME", newDocName },
                    { "APP_ID", "FOLDER" },
                    { "AUTHOR_ID", "JDOE" },
                    { "TYPIST_ID", "JDOE" }
                };
            profile.Trustees = new List<TrusteeInfo>() {
                new TrusteeInfo("DOCS_USERS", TrusteeType.Group, AccessRights.ReadOnly)
            };

            DMDocument doc = new DMDocument() { Dst = dst, Library = DMLogin.Library };

            // create
            var docInfo = doc.CreateProfile(profile);
            Assert.IsNotNull(docInfo);
            Assert.IsTrue(docInfo.DocNumber > 0);
            Assert.IsTrue(docInfo.VersionID > 0);

            // no need to unlock a folder

            // delete
            doc.DeleteProfile(docInfo.DocNumber);
        }