protected override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     try
     {
         using (OnboardingService onboardingService = new MsoOnboardingService())
         {
             ServiceInstanceMapValue map = null;
             try
             {
                 map = onboardingService.GetServiceInstanceMap();
             }
             catch (Exception exception)
             {
                 this.WriteError(exception, ErrorCategory.ResourceUnavailable, null, true);
             }
             string configuration = ServiceInstanceMapSerializer.ConvertServiceInstanceMapToXml(map);
             base.WriteObject(new BposPlacementConfiguration(configuration));
         }
     }
     catch (CouldNotCreateMsoOnboardingServiceException exception2)
     {
         this.WriteError(exception2, ErrorCategory.ObjectNotFound, null, true);
     }
     catch (InvalidServiceInstanceMapXmlFormatException exception3)
     {
         this.WriteError(exception3, ErrorCategory.InvalidData, null, true);
     }
     catch (Exception exception4)
     {
         this.WriteError(exception4, ErrorCategory.InvalidOperation, null, true);
     }
 }
 protected override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     using (OnboardingService onboardingService = new MsoOnboardingService())
     {
         ResultCode?result = null;
         try
         {
             result = new ResultCode?(onboardingService.SetServiceInstanceMap(this.map));
         }
         catch (Exception exception)
         {
             this.WriteError(exception, ErrorCategory.ResourceUnavailable, null, true);
         }
         if (result != null && result.Value == ResultCode.Success)
         {
             this.Configuration = ServiceInstanceMapSerializer.ConvertServiceInstanceMapToXml(this.map);
             base.WriteObject(new BposPlacementConfiguration(this.Configuration));
         }
         else
         {
             string errorStringForResultcode = MsoOnboardingService.GetErrorStringForResultcode(result);
             this.WriteError(new CouldNotUpdateServiceInstanceMapException(errorStringForResultcode), ErrorCategory.InvalidData, null, true);
         }
     }
 }
 protected override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     try
     {
         ServiceInstanceInfoValue serviceInstanceInfoValue = null;
         using (OnboardingService onboardingService = new MsoOnboardingService())
         {
             serviceInstanceInfoValue = onboardingService.GetServiceInstanceInfo(this.Identity.ToString());
         }
         if (serviceInstanceInfoValue != null)
         {
             Uri backSyncUrl = null;
             if (serviceInstanceInfoValue.Endpoint != null)
             {
                 foreach (ServiceEndpointValue serviceEndpointValue in serviceInstanceInfoValue.Endpoint)
                 {
                     if (string.Compare(serviceEndpointValue.Name, "BackSyncPSConnectionURI", true) == 0)
                     {
                         backSyncUrl = new Uri(serviceEndpointValue.Address);
                         break;
                     }
                 }
             }
             bool authorityTransferIsSupported = false;
             if (serviceInstanceInfoValue.Any != null)
             {
                 foreach (XmlElement xmlElement in serviceInstanceInfoValue.Any)
                 {
                     if (string.Compare(xmlElement.Name, "SupportsAuthorityTransfer", true) == 0)
                     {
                         authorityTransferIsSupported = true;
                         break;
                     }
                 }
             }
             BposServiceInstanceInfo sendToPipeline = new BposServiceInstanceInfo(this.Identity, "BackSyncPSConnectionURI", backSyncUrl, authorityTransferIsSupported);
             base.WriteObject(sendToPipeline);
         }
     }
     catch (CouldNotCreateMsoOnboardingServiceException exception)
     {
         this.WriteError(exception, ErrorCategory.ObjectNotFound, null, true);
     }
     catch (InvalidServiceInstanceMapXmlFormatException exception2)
     {
         this.WriteError(exception2, ErrorCategory.InvalidData, null, true);
     }
     catch (Exception exception3)
     {
         this.WriteError(exception3, ErrorCategory.InvalidOperation, null, true);
     }
 }
        protected override IFederatedServiceOnboarding CreateService()
        {
            ServiceEndpoint serviceEndpoint = null;

            try
            {
                serviceEndpoint = MsoOnboardingService.GetMsoEndpoint();
            }
            catch (Exception innerException)
            {
                throw new CouldNotCreateMsoOnboardingServiceException(Strings.CouldNotGetMsoEndpoint, innerException);
            }
            IFederatedServiceOnboarding result;

            try
            {
                EndpointAddress remoteAddress = new EndpointAddress(serviceEndpoint.Uri, new AddressHeader[0]);
                FederatedServiceOnboardingClient federatedServiceOnboardingClient = new FederatedServiceOnboardingClient(new WSHttpBinding(SecurityMode.Transport)
                {
                    Security =
                    {
                        Transport                =
                        {
                            ClientCredentialType = HttpClientCredentialType.Certificate
                        }
                    },
                    MaxBufferPoolSize      = 5242880L,
                    MaxReceivedMessageSize = 5242880L
                }, remoteAddress);
                X509Certificate2 certificate = TlsCertificateInfo.FindFirstCertWithSubjectDistinguishedName(serviceEndpoint.CertificateSubject);
                federatedServiceOnboardingClient.ClientCredentials.ClientCertificate.Certificate = certificate;
                result = federatedServiceOnboardingClient;
            }
            catch (Exception ex)
            {
                throw new CouldNotCreateMsoOnboardingServiceException(ex.Message, ex);
            }
            return(result);
        }
 protected override void InternalProcessRecord()
 {
     base.InternalProcessRecord();
     try
     {
         ResultCode?result = null;
         using (OnboardingService onboardingService = new MsoOnboardingService())
         {
             ServiceInstanceInfoValue serviceInstanceInfoValue = onboardingService.GetServiceInstanceInfo(this.Identity.ToString());
             if (serviceInstanceInfoValue == null)
             {
                 serviceInstanceInfoValue = new ServiceInstanceInfoValue();
             }
             bool flag = false;
             if (serviceInstanceInfoValue.Endpoint != null)
             {
                 foreach (ServiceEndpointValue serviceEndpointValue in serviceInstanceInfoValue.Endpoint)
                 {
                     if (string.Compare(serviceEndpointValue.Name, "BackSyncPSConnectionURI", true) == 0)
                     {
                         flag = true;
                         serviceEndpointValue.Address = this.BackSyncUrl.ToString();
                         break;
                     }
                 }
             }
             else
             {
                 serviceInstanceInfoValue.Endpoint = new ServiceEndpointValue[0];
             }
             if (!flag)
             {
                 ServiceEndpointValue serviceEndpointValue2 = new ServiceEndpointValue();
                 serviceEndpointValue2.Name    = "BackSyncPSConnectionURI";
                 serviceEndpointValue2.Address = this.BackSyncUrl.ToString();
                 int num = serviceInstanceInfoValue.Endpoint.Length + 1;
                 ServiceEndpointValue[] array = new ServiceEndpointValue[num];
                 serviceInstanceInfoValue.Endpoint.CopyTo(array, 0);
                 array[num - 1] = serviceEndpointValue2;
                 serviceInstanceInfoValue.Endpoint = array;
             }
             if (this.SupportsAuthorityTransfer)
             {
                 bool flag2 = false;
                 if (serviceInstanceInfoValue.Any != null)
                 {
                     foreach (XmlElement xmlElement in serviceInstanceInfoValue.Any)
                     {
                         if (string.Compare(xmlElement.Name, "SupportsAuthorityTransfer", true) == 0)
                         {
                             flag2 = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     serviceInstanceInfoValue.Any = new XmlElement[0];
                 }
                 if (!flag2)
                 {
                     XmlDocument  xmlDocument = new SafeXmlDocument();
                     XmlElement   xmlElement2 = xmlDocument.CreateElement("SupportsAuthorityTransfer", "http://schemas.microsoft.com/online/directoryservices/exchange/2011/01");
                     int          num2        = serviceInstanceInfoValue.Any.Length + 1;
                     XmlElement[] array2      = new XmlElement[num2];
                     serviceInstanceInfoValue.Any.CopyTo(array2, 0);
                     array2[num2 - 1]             = xmlElement2;
                     serviceInstanceInfoValue.Any = array2;
                 }
             }
             else if (serviceInstanceInfoValue.Any != null)
             {
                 XmlElement[] array3 = new XmlElement[0];
                 foreach (XmlElement xmlElement3 in serviceInstanceInfoValue.Any)
                 {
                     if (string.Compare(xmlElement3.Name, "SupportsAuthorityTransfer", true) != 0)
                     {
                         Array.Resize <XmlElement>(ref array3, array3.Length + 1);
                         array3[array3.Length - 1] = xmlElement3;
                     }
                 }
                 serviceInstanceInfoValue.Any = array3;
             }
             result = new ResultCode?(onboardingService.SetServiceInstanceInfo(this.Identity.ToString(), serviceInstanceInfoValue));
             if (result == null || result.Value != ResultCode.Success)
             {
                 string errorStringForResultcode = MsoOnboardingService.GetErrorStringForResultcode(result);
                 this.WriteError(new CouldNotUpdateServiceInstanceMapException(errorStringForResultcode), ErrorCategory.InvalidData, null, true);
             }
         }
     }
     catch (CouldNotCreateMsoOnboardingServiceException exception)
     {
         this.WriteError(exception, ErrorCategory.ObjectNotFound, null, true);
     }
     catch (InvalidServiceInstanceMapXmlFormatException exception2)
     {
         this.WriteError(exception2, ErrorCategory.InvalidData, null, true);
     }
     catch (Exception exception3)
     {
         this.WriteError(exception3, ErrorCategory.InvalidOperation, null, true);
     }
 }