コード例 #1
0
 private static void ThrowOnDeleteBuiltInResource(IEnumerable <UniqueIdentifier> ids)
 {
     foreach (UniqueIdentifier id in ids)
     {
         MessageComposer.ThrowOnDeleteBuiltInResource(id);
     }
 }
コード例 #2
0
        internal static Message CreateEnumerateMessage(string filter, int pageSize, IEnumerable <string> attributes, IEnumerable <SortingAttribute> sortingAttributes, CultureInfo locale)
        {
            Enumerate request = new Enumerate();

            request.Filter      = new FilterType(filter);
            request.MaxElements = pageSize < 0 ? MessageComposer.DefaultPageSize : pageSize.ToString();

            if (attributes != null)
            {
                request.Selection = MessageComposer.AddMandatoryAttributes(attributes, locale).ToArray();
            }

            if (sortingAttributes != null && sortingAttributes.Any())
            {
                request.Sorting                   = new Sorting();
                request.Sorting.Dialect           = Namespaces.ResourceManagement;
                request.Sorting.SortingAttributes = sortingAttributes.ToArray();
            }

            if (locale != null)
            {
                request.LocalePreferences    = new LocalePreferenceType[1];
                request.LocalePreferences[0] = new LocalePreferenceType(locale, 1);
            }

            Message requestMessage = Message.CreateMessage(MessageVersion.Default, Namespaces.Enumerate, new SerializerBodyWriter(request));

            requestMessage.AddHeader(Namespaces.ResourceManagement, "IncludeCount", null);

            return(requestMessage);
        }
コード例 #3
0
        public void Create(ResourceObject resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            try
            {
                using (Message message = MessageComposer.CreateCreateMessage(resource))
                {
                    using (Message responseMessage = this.Invoke((c) => c.Create(message)))
                    {
                        responseMessage.ThrowOnFault();

                        ResourceCreatedType response = responseMessage.DeserializeMessageWithPayload <ResourceCreatedType>();
                        UniqueIdentifier    id       = new UniqueIdentifier(response.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Text);
                        resource.CompleteCreateOperation(id);
                    }
                }
            }
            catch (FaultException <RepresentationFailures> e)
            {
                throw InvalidRepresentationException.GetException(e.Detail);
            }
        }
コード例 #4
0
        public void Approve(UniqueIdentifier workflowInstance, UniqueIdentifier approvalRequest, bool approve, string reason = null)
        {
            if (workflowInstance == null)
            {
                throw new ArgumentNullException(nameof(workflowInstance));
            }

            if (approvalRequest == null)
            {
                throw new ArgumentNullException(nameof(approvalRequest));
            }

            ApprovalResponse response = new ApprovalResponse
            {
                Decision = approve ? ResourceFactoryClient.ApprovedText : ResourceFactoryClient.RejectedText,
                Reason   = reason,
                Approval = approvalRequest.ToString()
            };


            using (Message message = MessageComposer.CreateApprovalMessage(workflowInstance, response))
            {
                using (Message responseMessage = this.Invoke((c) => c.Create(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #5
0
        public void Create(IEnumerable <ResourceObject> resources)
        {
            if (resources == null)
            {
                throw new ArgumentNullException(nameof(resources));
            }

            ResourceObject[] resourceArray = resources.ToArray();

            try
            {
                using (Message message = MessageComposer.CreateCreateMessage(resourceArray))
                {
                    using (Message responseMessage = this.Invoke((c) => c.Create(message)))
                    {
                        responseMessage.ThrowOnFault();

                        foreach (ResourceObject resource in resourceArray)
                        {
                            resource.CompleteCreateOperation(resource.ObjectID);
                        }
                    }
                }
            }
            catch (FaultException <RepresentationFailures> e)
            {
                throw InvalidRepresentationException.GetException(e.Detail);
            }
        }
コード例 #6
0
        internal static Message CreateGetMessage(UniqueIdentifier id, IEnumerable <string> attributes, CultureInfo locale)
        {
            Get op = null;

            if (attributes != null && attributes.Any())
            {
                op             = new Get();
                op.Dialect     = Namespaces.RMIdentityAttributeType;
                op.Expressions = MessageComposer.AddMandatoryAttributes(attributes, locale).ToArray();
            }

            Message message;

            if (op == null)
            {
                message = Message.CreateMessage(MessageVersion.Default, Namespaces.Get);
            }
            else
            {
                message = Message.CreateMessage(MessageVersion.Default, Namespaces.Get, new SerializerBodyWriter(op));
                message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true);
            }

            if (locale != null)
            {
                message.AddHeader(AttributeNames.Locale, locale);
            }

            message.AddHeader(HeaderConstants.ResourceReferenceProperty, id.ToString());

            return(message);
        }
コード例 #7
0
        public ResourceObject Get(UniqueIdentifier id, IEnumerable <string> attributes, CultureInfo locale)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            bool partialResponse = attributes != null;

            GetResponse r = new GetResponse();

            using (Message message = MessageComposer.CreateGetMessage(id, attributes, locale))
            {
                using (Message responseMessage = this.Invoke((c) => c.Get(message)))
                {
                    responseMessage.ThrowOnFault();

                    if (partialResponse)
                    {
                        GetResponse response = responseMessage.DeserializeMessageWithPayload <GetResponse>();
                        return(new ResourceObject(response.Results.OfType <XmlElement>(), this.client, locale));
                    }
                    else
                    {
                        XmlDictionaryReader fullObject = responseMessage.GetReaderAtBodyContents();
                        return(new ResourceObject(fullObject, this.client, locale));
                    }
                }
            }
        }
コード例 #8
0
 internal void Release(EnumerationContextType context)
 {
     using (Message releaseRequest = MessageComposer.GenerateReleaseMessage(context))
     {
         using (Message responseMessage = Release(releaseRequest))
         {
             releaseRequest.ThrowOnFault();
         }
     }
 }
コード例 #9
0
 public void Delete(UniqueIdentifier id)
 {
     using (Message message = MessageComposer.CreateDeleteMessage(id))
     {
         using (Message responseMessage = this.Invoke((c) => c.Delete(message)))
         {
             responseMessage.ThrowOnFault();
         }
     }
 }
コード例 #10
0
        internal static Message CreateCreateMessage(ResourceObject[] resources)
        {
            Create op = new Create();

            op.Dialect = Namespaces.RMIdentityAttributeType;

            if (resources == null || resources.Length == 0)
            {
                throw new ArgumentNullException(nameof(resources));
            }
            else if (resources.Length == 1)
            {
                return(MessageComposer.CreateCreateMessage(resources[0]));
            }

            List <FragmentType> fragments = new List <FragmentType>();

            foreach (ResourceObject resource in resources)
            {
                foreach (PutFragmentType fragment in resource.GetPutFragements())
                {
                    fragment.TargetIdentifier = resource.ObjectID.ToString(false);
                    fragments.Add(fragment);
                }

                // Add Object ID
                PutFragmentType fragmentObjectID = new PutFragmentType(
                    AttributeNames.ObjectID,
                    ModeType.Insert,
                    AttributeNames.ObjectID,
                    null,
                    false,
                    resource.ObjectID.ToString(false));

                fragmentObjectID.TargetIdentifier = resource.ObjectID.ToString(false);
                fragments.Add(fragmentObjectID);
            }

            if (fragments.Count == 0)
            {
                return(null);
            }

            op.Fragments = fragments.ToArray();

            Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Create, new SerializerBodyWriter(op));

            message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true);
            message.AddHeader(Namespaces.ResourceManagement, HeaderConstants.CompositeTypeOperation, null);
            message.AddHeader(HeaderConstants.ResourceReferenceProperty, resources.Select(t => t.ObjectID.ToString(false)).ToCommaSeparatedString());

            return(message);
        }
コード例 #11
0
        internal PullResponse Pull(EnumerationContextType context, int pageSize)
        {
            using (Message pullRequest = MessageComposer.GeneratePullMessage(context, pageSize))
            {
                using (Message responseMessage = this.Invoke((c) => c.Pull(pullRequest)))
                {
                    responseMessage.ThrowOnFault();

                    PullResponse pullResponseTyped = responseMessage.DeserializeMessageWithPayload <PullResponse>();
                    return(pullResponseTyped);
                }
            }
        }
コード例 #12
0
        public void Delete(IEnumerable <UniqueIdentifier> resourceIDs)
        {
            if (resourceIDs == null)
            {
                throw new ArgumentNullException(nameof(resourceIDs));
            }

            using (Message message = MessageComposer.CreateDeleteMessage(resourceIDs.ToArray()))
            {
                using (Message responseMessage = this.Invoke((c) => c.Delete(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #13
0
        public void Delete(IEnumerable <UniqueIdentifier> resourceIDs)
        {
            if (!resourceIDs.Any())
            {
                return;
            }

            using (Message message = MessageComposer.CreateDeleteMessage(resourceIDs))
            {
                using (Message responseMessage = this.Invoke((c) => c.Delete(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #14
0
        internal void Release(EnumerationContextType context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            using (Message releaseRequest = MessageComposer.GenerateReleaseMessage(context))
            {
                using (Message responseMessage = this.Release(releaseRequest))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #15
0
        public void Delete(UniqueIdentifier id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            using (Message message = MessageComposer.CreateDeleteMessage(id))
            {
                using (Message responseMessage = this.Invoke((c) => c.Delete(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #16
0
        internal static Message CreateDeleteMessage(UniqueIdentifier id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            MessageComposer.ThrowOnDeleteBuiltInResource(id);

            Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Delete);

            message.AddHeader(HeaderConstants.ResourceReferenceProperty, id.ToString());

            return(message);
        }
コード例 #17
0
        internal XmlDictionaryReader GetFullObjectForUpdate(ResourceObject resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            using (Message message = MessageComposer.CreateGetMessage(resource.ObjectID, null, resource.Locale, resource.HasPermissionHints))
            {
                using (Message responseMessage = this.Invoke((c) => c.Get(message)))
                {
                    responseMessage.ThrowOnFault();

                    return(responseMessage.GetReaderAtBodyContents());
                }
            }
        }
コード例 #18
0
        private EnumerateResponse Enumerate(string filter, int pageSize, IEnumerable <string> attributesToReturn, IEnumerable <SortingAttribute> sortingAttributes, CultureInfo locale)
        {
            if (pageSize < 0)
            {
                pageSize = DefaultPageSize;
            }

            using (Message requestMessage = MessageComposer.CreateEnumerateMessage(filter, pageSize, attributesToReturn, sortingAttributes, locale))
            {
                using (Message responseMessage = this.Invoke((c) => c.Enumerate(requestMessage)))
                {
                    responseMessage.ThrowOnFault();

                    EnumerateResponse response = responseMessage.DeserializeMessageWithPayload <EnumerateResponse>();
                    return(response);
                }
            }
        }
コード例 #19
0
        internal static Message CreatePutMessage(IEnumerable <ResourceObject> resources)
        {
            int count = resources.Count();

            if (count == 0)
            {
                throw new ArgumentNullException("resources");
            }
            else if (count == 1)
            {
                return(MessageComposer.CreatePutMessage(resources.First(), null));
            }

            Put op = new Put();

            op.Dialect = Namespaces.RMIdentityAttributeType;
            List <PutFragmentType> fragments = new List <PutFragmentType>();

            foreach (ResourceObject resource in resources)
            {
                foreach (PutFragmentType fragment in resource.GetPutFragements())
                {
                    fragment.TargetIdentifier = resource.ObjectID.Value;
                    fragments.Add(fragment);
                }
            }

            if (fragments.Count == 0)
            {
                return(null);
            }

            op.Fragments = fragments.ToArray();
            Message message;

            message = Message.CreateMessage(MessageVersion.Default, Namespaces.Put, new SerializerBodyWriter(op));
            message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true);
            message.AddHeader(Namespaces.ResourceManagement, HeaderConstants.CompositeTypeOperation, null);
            message.AddHeader(HeaderConstants.ResourceReferenceProperty, resources.Select(t => t.ObjectID.ToString()).ToCommaSeparatedString());

            return(message);
        }
コード例 #20
0
        public void Put(IEnumerable <ResourceObject> resources)
        {
            if (resources == null)
            {
                throw new ArgumentNullException("resources");
            }

            using (Message message = MessageComposer.CreatePutMessage(resources))
            {
                if (message == null)
                {
                    return;
                }

                using (Message responseMessage = this.Invoke((c) => c.Put(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #21
0
        public void Put(ResourceObject resource, CultureInfo locale)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            using (Message message = MessageComposer.CreatePutMessage(resource, locale))
            {
                if (message == null)
                {
                    return;
                }

                using (Message responseMessage = this.Invoke((c) => c.Put(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
コード例 #22
0
        internal static Message CreateDeleteMessage(UniqueIdentifier[] ids)
        {
            if (ids == null || ids.Length == 0)
            {
                throw new ArgumentNullException(nameof(ids));
            }
            else if (ids.Length == 1)
            {
                return(MessageComposer.CreateDeleteMessage(ids.First()));
            }

            MessageComposer.ThrowOnDeleteBuiltInResource(ids);

            Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Delete);

            message.AddHeader(Namespaces.ResourceManagement, HeaderConstants.CompositeTypeOperation, null);
            message.AddHeader(HeaderConstants.ResourceReferenceProperty, ids.Select(t => t.ToString()).ToCommaSeparatedString());

            return(message);
        }