/// <summary>
        /// Creates the async version of the client
        /// </summary>
        /// <param name="client">Synchronous service client</param>
        public static DiscoveryWebProxyAsyncClient ToAsyncClient(this DiscoveryWebProxyClient client)
        {
            var asyncClient = new DiscoveryWebProxyAsyncClient(client.Endpoint.Address.Uri, client.Endpoint.Binding.SendTimeout);

            asyncClient.HeaderToken      = client.HeaderToken;
            asyncClient.SdkClientVersion = client.SdkClientVersion;
            return(asyncClient);
        }
Пример #2
0
        /// <summary>
        /// Get organization data for a specific known region only
        /// </summary>
        /// <param name="creds"></param>
        /// <param name="dataCenter"></param>
        /// <returns></returns>
        public static List <OrganizationDetail> GetOrganizationsForDataCenter(string userName, string password, DataCenter dataCenter)
        {
            if (dataCenter == DataCenter.Unknown)
            {
                throw new ArgumentOutOfRangeException("DataCenter.Unknown cannot be used as a parameter for this method.");
            }

            //Get the DataCenter URL from the Description Attribute applied for the DataCenter member
            var type       = typeof(DataCenter);
            var memInfo    = type.GetMember(dataCenter.ToString());
            var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
            Uri targeturl  = new Uri(((DescriptionAttribute)attributes[0]).Description);

            var organizations = new List <OrganizationDetail>();

            using (var dsvc = new DiscoveryWebProxyClient(targeturl))
            {
                dsvc.HeaderToken = GetAccessToken(userName, password, targeturl);

                RetrieveOrganizationsRequest orgsRequest = new RetrieveOrganizationsRequest()
                {
                    AccessType = EndpointAccessType.Default,
                    Release    = OrganizationRelease.Current
                };

                try
                {
                    RetrieveOrganizationsResponse response = (RetrieveOrganizationsResponse)dsvc.Execute(orgsRequest);

                    organizations = response.Details.ToList();
                }
                catch (System.ServiceModel.Security.SecurityAccessDeniedException)
                {
                    //This error is expected for regions where the user has no organizations
                }
            };
            return(organizations);
        }