Exemple #1
0
        public void UnlockDocument(DocumentInfo docInfo)
        {
            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty(PropertyObjectIdentifier, docInfo.DocNumber);
            if (docInfo.VersionID > 0)
            {
                doc.SetProperty(PropertyVersionID, docInfo.VersionID);
            }
            doc.SetProperty("%STATUS", "%UNLOCK");

            int result = doc.Update();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                if (doc.ErrNumber == DMApiEmptyDocumentFileException.EmptyFileDMErrorCode)
                {
                    throw new DMApiEmptyDocumentFileException(string.Format("An attempt to check-in an empty document (document# {0})", docInfo.DocNumber), doc.ErrNumber, doc.ErrDescription);
                }
                else
                {
                    throw new DMApiException(string.Format("Cannot unlock document# {0}", docInfo.DocNumber), doc.ErrNumber, doc.ErrDescription);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Questo costruttore instanzia un documento/progetto sul documentale
 /// </summary>
 /// <param name="dst"></param>
 /// <param name="library"></param>
 /// <param name="objectType"></param>
 public ClasseDocumento(string dst, string library, string objectType)
 {
     docObject = new PCDDocObjectClass();
     docObject.SetDST(dst);
     docObject.SetProperty("%TARGET_LIBRARY", library);
     docObject.SetObjectType(objectType);
 }
Exemple #3
0
        private void DeleteLink(string linkId)
        {
            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectContentItem);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty("SYSTEM_ID", Convert.ToInt32(linkId));

            int result = doc.Delete();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot delete link {0}", linkId), doc.ErrNumber, doc.ErrDescription);
            }
        }
Exemple #4
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(DocumentSecurityToken);
            doc.SetObjectType(profileInfo.FormName);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            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)
            });
        }
Exemple #5
0
        public void DeleteProfile(int docNumber, bool clearLinks)
        {
            if (clearLinks)
            {
                ClearLinks(docNumber);
            }

            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.Delete();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot delete document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
            }
        }
Exemple #6
0
        public TrusteeInfo[] FetchTrustees(int docNumber)
        {
            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.FetchTrustees();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot fetch trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
            }

            var trustees = doc.GetTrustees();

            if (doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot get trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
            }

            var list  = new List <TrusteeInfo>();
            var count = trustees.GetSize();

            if (count > 0)
            {
                trustees.BeginIter();
                for (int i = 0; i < count; i++)
                {
                    list.Add(new TrusteeInfo(
                                 trustees.GetCurrentTrusteeName(),
                                 (TrusteeType)trustees.GetCurrentTrusteeFlags(),
                                 (AccessRights)trustees.GetCurrentTrusteeRights()));
                    trustees.NextTrustee();
                }
            }
            return(list.ToArray());
        }
Exemple #7
0
        public void AddLink(int docNumber, DocumentInfo folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }

            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectContentItem);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty(PropertyParentFolder, folder.DocNumber.ToString());
            doc.SetProperty(PropertyParentFolderVer, folder.VersionID.ToString());
            doc.SetProperty(PropertyDocNumber, docNumber.ToString());
            doc.SetProperty(PropertyParentFolderLib, LibraryName);  // we save to one library only
            //doc.SetProperty("DISPLAYNAME", docName);
            doc.SetProperty("VERSION_TYPE", "R");

            int result = doc.Create();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot link document# {0} to folder {1}", docNumber, folder.DocNumber), doc.ErrNumber, doc.ErrDescription);
            }
        }
Exemple #8
0
        public void AddLink(int docNumber, DocumentInfo folder)
        {
            if(folder == null)
                throw new ArgumentNullException("folder");

            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectContentItem);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty(PropertyParentFolder, folder.DocNumber.ToString());
            doc.SetProperty(PropertyParentFolderVer, folder.VersionID.ToString());
            doc.SetProperty(PropertyDocNumber, docNumber.ToString());
            doc.SetProperty(PropertyParentFolderLib, Library);  // we save to one library only
            //doc.SetProperty("DISPLAYNAME", docName);
            doc.SetProperty("VERSION_TYPE", "R");

            int result = doc.Create();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot link document# {0} to folder {1}", docNumber, folder.DocNumber), doc.ErrNumber, doc.ErrDescription);
        }
Exemple #9
0
        private void DeleteLink(string linkId)
        {
            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectContentItem);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty("SYSTEM_ID", Convert.ToInt32(linkId));

            int result = doc.Delete();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot delete link {0}", linkId), doc.ErrNumber, doc.ErrDescription);
        }
Exemple #10
0
        public void UpdateTrustees(int docNumber, TrusteeInfo[] trusteesToSet)
        {
            if(trusteesToSet == null)
                throw new ArgumentNullException("trusteesToSet");
            if(trusteesToSet.Length == 0)
                throw new ArgumentException("trusteesToSet is empty");

            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.FetchTrustees();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot fetch trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);

            // season greetings, DM API developers...
            var trustees = doc.GetTrustees();
            if(doc.ErrNumber != 0)
                throw new DMApiException("GetTrustees failed.", doc.ErrNumber, doc.ErrDescription);

            int size = trustees.GetSize();
            foreach(var t in trusteesToSet) {
                int idx = trustees.GetTrusteeIndex(t.Trustee, (int)t.TrusteeType);
                // funking DM API returns index equal GetSize() if trustee is not found
                if(idx == size) {
                    if(t.AccessRights != AccessRights.NoAccess)
                        trustees.AddTrustee(t.Trustee, (int)t.TrusteeType, (int)t.AccessRights);
                }
                else  // update existing
                    if(t.AccessRights == AccessRights.NoAccess)
                        trustees.DeleteTrustee(idx);
                    else
                        trustees.SetTrusteeRights(idx, (int)t.AccessRights);
            }
            result = doc.SetTrustees(trustees);
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException("SetTrustees failed.", doc.ErrNumber, doc.ErrDescription);

            result = doc.UpdateTrustees();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("UpdateTrustees failed for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);

            result = doc.Update();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot update document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
        }
Exemple #11
0
        public void UnlockDocument(DocumentInfo docInfo)
        {
            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty(PropertyObjectIdentifier, docInfo.DocNumber);
            if(docInfo.VersionID > 0)
                doc.SetProperty(PropertyVersionID, docInfo.VersionID);
            doc.SetProperty("%STATUS", "%UNLOCK");

            int result = doc.Update();
            if(result != S_OK || doc.ErrNumber != 0)
                if(doc.ErrNumber == DMApiEmptyDocumentFileException.EmptyFileDMErrorCode)
                    throw new DMApiEmptyDocumentFileException(string.Format("An attempt to check-in an empty document (document# {0})", docInfo.DocNumber), doc.ErrNumber, doc.ErrDescription);
                else
                    throw new DMApiException(string.Format("Cannot unlock document# {0}", docInfo.DocNumber), doc.ErrNumber, doc.ErrDescription);
        }
Exemple #12
0
        public TrusteeInfo[] FetchTrustees(int docNumber)
        {
            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.FetchTrustees();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot fetch trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);

            var trustees = doc.GetTrustees();
            if(doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot get trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);

            var list = new List<TrusteeInfo>();
            var count = trustees.GetSize();
            if(count > 0) {
                trustees.BeginIter();
                for(int i = 0; i < count; i++) {
                    list.Add(new TrusteeInfo(
                        trustees.GetCurrentTrusteeName(),
                        (TrusteeType)trustees.GetCurrentTrusteeFlags(),
                        (AccessRights)trustees.GetCurrentTrusteeRights()));
                    trustees.NextTrustee();

                }
            }
            return list.ToArray();
        }
Exemple #13
0
        public void DeleteProfile(int docNumber, bool clearLinks)
        {
            if(clearLinks)
                ClearLinks(docNumber);

            var doc = new PCDDocObjectClass();
            doc.SetDST(Dst);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, Library);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.Delete();
            if(result != S_OK || doc.ErrNumber != 0)
                throw new DMApiException(string.Format("Cannot delete document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
        }
Exemple #14
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) };
        }
Exemple #15
0
 /// <summary>
 /// </summary>
 public void SetVersionDirective(string directive)
 {
     docObject.SetProperty("%VERSION_DIRECTIVE", directive);
 }
Exemple #16
0
        public void UpdateTrustees(int docNumber, TrusteeInfo[] trusteesToSet)
        {
            if (trusteesToSet == null)
            {
                throw new ArgumentNullException("trusteesToSet");
            }
            if (trusteesToSet.Length == 0)
            {
                throw new ArgumentException("trusteesToSet is empty");
            }

            var doc = new PCDDocObjectClass();

            doc.SetDST(DocumentSecurityToken);
            doc.SetObjectType(ObjectFormDefaultProfile);
            doc.SetProperty(PropertyTargetLibrary, LibraryName);
            doc.SetProperty(PropertyObjectIdentifier, docNumber);

            int result = doc.FetchTrustees();

            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException(string.Format("Cannot fetch trustees for document# {0}.", docNumber), doc.ErrNumber, doc.ErrDescription);
            }

            // season greetings, DM API developers...
            var trustees = doc.GetTrustees();

            if (doc.ErrNumber != 0)
            {
                throw new DMApiException("GetTrustees failed.", doc.ErrNumber, doc.ErrDescription);
            }

            int size = trustees.GetSize();

            foreach (var t in trusteesToSet)
            {
                int idx = trustees.GetTrusteeIndex(t.Trustee, (int)t.TrusteeType);
                // funking DM API returns index equal GetSize() if trustee is not found
                if (idx == size)
                {
                    if (t.AccessRights != AccessRights.NoAccess)
                    {
                        trustees.AddTrustee(t.Trustee, (int)t.TrusteeType, (int)t.AccessRights);
                    }
                }
                else  // update existing
                if (t.AccessRights == AccessRights.NoAccess)
                {
                    trustees.DeleteTrustee(idx);
                }
                else
                {
                    trustees.SetTrusteeRights(idx, (int)t.AccessRights);
                }
            }
            result = doc.SetTrustees(trustees);
            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException("SetTrustees failed.", doc.ErrNumber, doc.ErrDescription);
            }

            result = doc.UpdateTrustees();
            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException($"UpdateTrustees failed for document# {docNumber}.", doc.ErrNumber, doc.ErrDescription);
            }

            result = doc.Update();
            if (result != S_OK || doc.ErrNumber != 0)
            {
                throw new DMApiException($"Cannot update document# {docNumber}.", doc.ErrNumber, doc.ErrDescription);
            }
        }