示例#1
0
        private Entity GenerateCrmEntity()
        {
            Entity crmServiceEndpoint = new Entity("serviceendpoint")
            {
                Attributes = new AttributeCollection()
            };

            crmServiceEndpoint.Attributes.Add("name", Name);
            crmServiceEndpoint.Attributes.Add("solutionnamespace", Namespace);
            crmServiceEndpoint.Attributes.Add("path", Path);
            crmServiceEndpoint.Attributes.Add("contract", new OptionSetValue((int)Contract));
            crmServiceEndpoint.Attributes.Add("userclaim", new OptionSetValue((int)Claim));
            if (!string.IsNullOrWhiteSpace(Description))
            {
                crmServiceEndpoint.Attributes.Add("description", Description);
            }
            if (Federated.ToBool() == true)
            {
                crmServiceEndpoint.Attributes.Add("connectionmode", new OptionSetValue((int)CrmServiceEndpointConnectionMode.Federated));
            }
            else
            {
                crmServiceEndpoint.Attributes.Add("connectionmode", new OptionSetValue((int)CrmServiceEndpointConnectionMode.Normal));
            }

            return(crmServiceEndpoint);
        }
示例#2
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if ((int)Claim == 0)
            {
                Claim = CrmServiceEndpointUserClaim.None;
            }
            if (Contract == CrmServiceEndpointContract.Rest && Federated.ToBool() == true)
            {
                throw new Exception("Federated mode not suppored for REST contract.");
            }
            ValidateNameUnique(_repository, Name);

            Guid newId = _repository.Add(GenerateCrmEntity());

            if (PassThru)
            {
                WriteObject(_repository.Get("serviceendpoint", newId));
            }
        }
示例#3
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Entity crmServiceEndpoint = _repository.Get("serviceendpoint", Id);

            Contract  = Contract ?? (CrmServiceEndpointContract)crmServiceEndpoint.GetAttributeValue <OptionSetValue>("contract").Value;
            Claim     = Claim ?? (CrmServiceEndpointUserClaim)crmServiceEndpoint.GetAttributeValue <OptionSetValue>("userclaim").Value;
            Federated = Federated.IsPresent ? Federated : new SwitchParameter(crmServiceEndpoint.GetAttributeValue <OptionSetValue>("connectionmode").Value == (int)CrmServiceEndpointConnectionMode.Federated);

            if (Contract == CrmServiceEndpointContract.Rest && Federated.ToBool() == true)
            {
                throw new Exception("Federated mode not suppored for REST contract.");
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                ValidateNameUnique(_repository, Id, Name);
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                if (crmServiceEndpoint.Contains("name"))
                {
                    crmServiceEndpoint.Attributes["name"] = Name;
                }
                else
                {
                    crmServiceEndpoint.Attributes.Add("name", Name);
                }
            }
            if (!string.IsNullOrWhiteSpace(Namespace))
            {
                if (crmServiceEndpoint.Contains("solutionnamespace"))
                {
                    crmServiceEndpoint.Attributes["solutionnamespace"] = Namespace;
                }
                else
                {
                    crmServiceEndpoint.Attributes.Add("solutionnamespace", Namespace);
                }
            }
            if (!string.IsNullOrWhiteSpace(Path))
            {
                if (crmServiceEndpoint.Contains("path"))
                {
                    crmServiceEndpoint.Attributes["path"] = Path;
                }
                else
                {
                    crmServiceEndpoint.Attributes.Add("path", Path);
                }
            }
            if (Description != null)
            {
                string description = string.IsNullOrWhiteSpace(Description) ? null : Description;
                if (crmServiceEndpoint.Contains("description"))
                {
                    crmServiceEndpoint.Attributes["description"] = description;
                }
                else
                {
                    crmServiceEndpoint.Attributes.Add("description", description);
                }
            }


            crmServiceEndpoint.Attributes["contract"]  = new OptionSetValue((int)Contract);
            crmServiceEndpoint.Attributes["userclaim"] = new OptionSetValue((int)Claim);
            if (Federated.ToBool() == true)
            {
                crmServiceEndpoint.Attributes["connectionmode"] = new OptionSetValue((int)CrmServiceEndpointConnectionMode.Federated);
            }
            else
            {
                crmServiceEndpoint.Attributes["connectionmode"] = new OptionSetValue((int)CrmServiceEndpointConnectionMode.Normal);
            }

            _repository.Update(crmServiceEndpoint);
            if (PassThru)
            {
                WriteObject(_repository.Get("serviceendpoint", Id));
            }
        }