Exemple #1
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 #2
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 #3
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 #4
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);
            }
        }