예제 #1
0
        private static async Task UpdateTenants(string tenantsApiUrl, string tenantsApiKey, IEnumerable <string> dashboardfiles, string region)
        {
            var templatesAggregator  = new GenerateJson(dashboardfiles);
            var templatesAggregatted = templatesAggregator.GenerateBatchJson();

            templatesAggregator.ValidateJson(templatesAggregatted);
            var client = new TenantServiceClient(new TenantServiceClientSettings {
                AccessKey = tenantsApiKey, BaseUrl = new System.Uri(tenantsApiUrl)
            }, new HttpClient());
            var tenants = await client.GetListAsync();

            foreach (var tenant in tenants)
            {
                if (tenant.Region.ToUpperInvariant() != region.ToUpperInvariant())
                {
                    continue;
                }
                Console.WriteLine($"{tenant.Name,-30} {tenant.Region,-15} {tenant.Id}");
                var application = tenant.Applications.FirstOrDefault();
                var binding     = tenant.AuthorityBindings.FirstOrDefault(a => "APIV2" == a.Site.ToUpperInvariant());

                var tenantInfo = new TenantInfo
                {
                    Name      = tenant.Name,
                    Id        = tenant.Id.ToString(),
                    AppId     = application.AppId.ToString(),
                    AppSecret = application.AppSecret,
                    ApiV2Url  = binding.AuthorityBinding
                };

                var updater = new DashboardTenantUpdater(tenantInfo, new HttpClient(), templatesAggregatted);
                await updater.DoUpdateAsync();
            }
        }
 /// <summary>Snippet for GetTenant</summary>
 public void GetTenantResourceNames()
 {
     // Snippet: GetTenant(TenantName, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     TenantName name = TenantName.FromProjectTenant("[PROJECT]", "[TENANT]");
     // Make the request
     Tenant response = tenantServiceClient.GetTenant(name);
     // End snippet
 }
 /// <summary>Snippet for UpdateTenant</summary>
 public void UpdateTenant()
 {
     // Snippet: UpdateTenant(Tenant, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     Tenant tenant = new Tenant();
     // Make the request
     Tenant response = tenantServiceClient.UpdateTenant(tenant);
     // End snippet
 }
 /// <summary>Snippet for GetTenant</summary>
 public void GetTenant()
 {
     // Snippet: GetTenant(string, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     string name = "projects/[PROJECT]/tenants/[TENANT]";
     // Make the request
     Tenant response = tenantServiceClient.GetTenant(name);
     // End snippet
 }
 /// <summary>Snippet for CreateTenant</summary>
 public void CreateTenant()
 {
     // Snippet: CreateTenant(string, Tenant, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     string parent = "projects/[PROJECT]";
     Tenant tenant = new Tenant();
     // Make the request
     Tenant response = tenantServiceClient.CreateTenant(parent, tenant);
     // End snippet
 }
예제 #6
0
        /// <summary>Snippet for DeleteTenant</summary>
        public void DeleteTenant()
        {
            // Snippet: DeleteTenant(TenantName,CallSettings)
            // Create client
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            // Initialize request argument(s)
            TenantName name = new TenantName("[PROJECT]", "[TENANT]");

            // Make the request
            tenantServiceClient.DeleteTenant(name);
            // End snippet
        }
 /// <summary>Snippet for CreateTenant</summary>
 public void CreateTenantResourceNames()
 {
     // Snippet: CreateTenant(ProjectName, Tenant, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     ProjectName parent = ProjectName.FromProject("[PROJECT]");
     Tenant      tenant = new Tenant();
     // Make the request
     Tenant response = tenantServiceClient.CreateTenant(parent, tenant);
     // End snippet
 }
예제 #8
0
        // [START job_search_delete_tenant_beta]
        public static object DeleteTenant(string projectId, string tenantId)
        {
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            TenantName          tenantName          = new TenantName(projectId, tenantId);
            DeleteTenantRequest request             = new DeleteTenantRequest
            {
                TenantName = tenantName
            };

            tenantServiceClient.DeleteTenant(request);
            Console.WriteLine($"Deleted Tenant.");
            return(0);
        }
예제 #9
0
        // [START job_search_get_tenant_beta]
        public static object GetTenant(string projectId, string tenantId)
        {
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            TenantName          name    = new TenantName(projectId, tenantId);
            GetTenantRequest    request = new GetTenantRequest
            {
                TenantName = name
            };
            Tenant response = tenantServiceClient.GetTenant(request);

            Console.WriteLine($"Name: {response.Name}");
            Console.WriteLine($"External ID: {response.ExternalId}");
            return(0);
        }
예제 #10
0
 /// <summary>Snippet for UpdateTenant</summary>
 public void UpdateTenant_RequestObject()
 {
     // Snippet: UpdateTenant(UpdateTenantRequest,CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     UpdateTenantRequest request = new UpdateTenantRequest
     {
         Tenant = new Tenant(),
     };
     // Make the request
     Tenant response = tenantServiceClient.UpdateTenant(request);
     // End snippet
 }
 /// <summary>Snippet for GetTenant</summary>
 public void GetTenantRequestObject()
 {
     // Snippet: GetTenant(GetTenantRequest, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     GetTenantRequest request = new GetTenantRequest
     {
         TenantName = TenantName.FromProjectTenant("[PROJECT]", "[TENANT]"),
     };
     // Make the request
     Tenant response = tenantServiceClient.GetTenant(request);
     // End snippet
 }
        /// <summary>Snippet for DeleteTenantAsync</summary>
        public async Task DeleteTenantAsync()
        {
            // Snippet: DeleteTenantAsync(string, CallSettings)
            // Additional: DeleteTenantAsync(string, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            string name = "projects/[PROJECT]/tenants/[TENANT]";
            // Make the request
            await tenantServiceClient.DeleteTenantAsync(name);

            // End snippet
        }
        /// <summary>Snippet for DeleteTenantAsync</summary>
        public async Task DeleteTenantResourceNamesAsync()
        {
            // Snippet: DeleteTenantAsync(TenantName, CallSettings)
            // Additional: DeleteTenantAsync(TenantName, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            TenantName name = TenantName.FromProjectTenant("[PROJECT]", "[TENANT]");
            // Make the request
            await tenantServiceClient.DeleteTenantAsync(name);

            // End snippet
        }
예제 #14
0
        /// <summary>Snippet for GetTenantAsync</summary>
        public async Task GetTenantAsync()
        {
            // Snippet: GetTenantAsync(TenantName,CallSettings)
            // Additional: GetTenantAsync(TenantName,CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            TenantName name = new TenantName("[PROJECT]", "[TENANT]");
            // Make the request
            Tenant response = await tenantServiceClient.GetTenantAsync(name);

            // End snippet
        }
        /// <summary>Snippet for UpdateTenantAsync</summary>
        public async Task UpdateTenantAsync()
        {
            // Snippet: UpdateTenantAsync(Tenant, CallSettings)
            // Additional: UpdateTenantAsync(Tenant, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            Tenant tenant = new Tenant();
            // Make the request
            Tenant response = await tenantServiceClient.UpdateTenantAsync(tenant);

            // End snippet
        }
 /// <summary>Snippet for CreateTenant</summary>
 public void CreateTenantRequestObject()
 {
     // Snippet: CreateTenant(CreateTenantRequest, CallSettings)
     // Create client
     TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
     // Initialize request argument(s)
     CreateTenantRequest request = new CreateTenantRequest
     {
         ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
         Tenant = new Tenant(),
     };
     // Make the request
     Tenant response = tenantServiceClient.CreateTenant(request);
     // End snippet
 }
예제 #17
0
        /// <summary>Snippet for DeleteTenant</summary>
        public void DeleteTenant_RequestObject()
        {
            // Snippet: DeleteTenant(DeleteTenantRequest,CallSettings)
            // Create client
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            // Initialize request argument(s)
            DeleteTenantRequest request = new DeleteTenantRequest
            {
                TenantName = new TenantName("[PROJECT]", "[TENANT]"),
            };

            // Make the request
            tenantServiceClient.DeleteTenant(request);
            // End snippet
        }
        /// <summary>Snippet for CreateTenantAsync</summary>
        public async Task CreateTenantAsync()
        {
            // Snippet: CreateTenantAsync(string, Tenant, CallSettings)
            // Additional: CreateTenantAsync(string, Tenant, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            string parent = "projects/[PROJECT]";
            Tenant tenant = new Tenant();
            // Make the request
            Tenant response = await tenantServiceClient.CreateTenantAsync(parent, tenant);

            // End snippet
        }
        /// <summary>Snippet for CreateTenantAsync</summary>
        public async Task CreateTenantResourceNamesAsync()
        {
            // Snippet: CreateTenantAsync(ProjectName, Tenant, CallSettings)
            // Additional: CreateTenantAsync(ProjectName, Tenant, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            ProjectName parent = ProjectName.FromProject("[PROJECT]");
            Tenant      tenant = new Tenant();
            // Make the request
            Tenant response = await tenantServiceClient.CreateTenantAsync(parent, tenant);

            // End snippet
        }
        /// <summary>Snippet for ListTenantsAsync</summary>
        public async Task ListTenantsRequestObjectAsync()
        {
            // Snippet: ListTenantsAsync(ListTenantsRequest, CallSettings)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListTenantsRequest request = new ListTenantsRequest
            {
                ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListTenantsResponse, Tenant> response = tenantServiceClient.ListTenantsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Tenant item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListTenantsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Tenant item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int           pageSize   = 10;
            Page <Tenant> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Tenant item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        /// <summary>Snippet for DeleteTenantAsync</summary>
        public async Task DeleteTenantRequestObjectAsync()
        {
            // Snippet: DeleteTenantAsync(DeleteTenantRequest, CallSettings)
            // Additional: DeleteTenantAsync(DeleteTenantRequest, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            DeleteTenantRequest request = new DeleteTenantRequest
            {
                TenantName = TenantName.FromProjectTenant("[PROJECT]", "[TENANT]"),
            };
            // Make the request
            await tenantServiceClient.DeleteTenantAsync(request);

            // End snippet
        }
        // [START job_search_list_tenants_beta]
        public static object ListTenants(string projectId)
        {
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            ProjectName         parent  = new ProjectName(projectId);
            ListTenantsRequest  request = new ListTenantsRequest
            {
                ParentAsProjectName = parent
            };
            var tenants = tenantServiceClient.ListTenants(request);

            foreach (var tenant in tenants)
            {
                Console.WriteLine($"Tenant Name: {tenant.Name}");
                Console.WriteLine($"External ID: {tenant.ExternalId}");
            }
            return(0);
        }
        /// <summary>Snippet for CreateTenantAsync</summary>
        public async Task CreateTenantRequestObjectAsync()
        {
            // Snippet: CreateTenantAsync(CreateTenantRequest, CallSettings)
            // Additional: CreateTenantAsync(CreateTenantRequest, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateTenantRequest request = new CreateTenantRequest
            {
                ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
                Tenant = new Tenant(),
            };
            // Make the request
            Tenant response = await tenantServiceClient.CreateTenantAsync(request);

            // End snippet
        }
        /// <summary>Snippet for UpdateTenantAsync</summary>
        public async Task UpdateTenantRequestObjectAsync()
        {
            // Snippet: UpdateTenantAsync(UpdateTenantRequest, CallSettings)
            // Additional: UpdateTenantAsync(UpdateTenantRequest, CancellationToken)
            // Create client
            TenantServiceClient tenantServiceClient = await TenantServiceClient.CreateAsync();

            // Initialize request argument(s)
            UpdateTenantRequest request = new UpdateTenantRequest
            {
                Tenant     = new Tenant(),
                UpdateMask = new FieldMask(),
            };
            // Make the request
            Tenant response = await tenantServiceClient.UpdateTenantAsync(request);

            // End snippet
        }
        /// <summary>Snippet for ListTenants</summary>
        public void ListTenantsResourceNames()
        {
            // Snippet: ListTenants(ProjectName, string, int?, CallSettings)
            // Create client
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            // Initialize request argument(s)
            ProjectName parent = ProjectName.FromProject("[PROJECT]");
            // Make the request
            PagedEnumerable <ListTenantsResponse, Tenant> response = tenantServiceClient.ListTenants(parent);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (Tenant item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (ListTenantsResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Tenant item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int           pageSize   = 10;
            Page <Tenant> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Tenant item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        // [START job_search_create_tenant_beta]
        public static object CreateTenant(string projectId, string externalId)
        {
            TenantServiceClient tenantServiceClient = TenantServiceClient.Create();
            Tenant tenant = new Tenant
            {
                ExternalId = externalId,
            };
            ProjectName         parent  = new ProjectName(projectId);
            CreateTenantRequest request = new CreateTenantRequest
            {
                ParentAsProjectName = parent,
                Tenant = tenant
            };
            Tenant response = tenantServiceClient.CreateTenant(request);

            Console.WriteLine($"Created Tenant.");
            Console.WriteLine($"Name: {response.Name}");
            Console.WriteLine($"External ID: {response.ExternalId}");
            return(0);
        }
        public static TenantServiceClient GetAfariaServiceTenant(Dictionary<string, string> server, Dictionary<string, string> credentials)
        {
            string tenantApiAddr = String.Format("net.tcp://{0}:{1}/AfariaService/{2}", server["IPAddr"], server["Port"], "Tenant");
            TenantServiceClient svcTenant = new TenantServiceClient("NetTcpBinding_ITenantService", tenantApiAddr);
            svcTenant.ClientCredentials.Windows.ClientCredential.Domain = credentials["Domain"];
            svcTenant.ClientCredentials.Windows.ClientCredential.UserName = credentials["UserName"];
            svcTenant.ClientCredentials.Windows.ClientCredential.Password = credentials["Password"];
            logger.Info("Creating Tenant service: {0}", tenantApiAddr);

            return svcTenant;
        }
 public static void CloseAfariaServiceTenant(TenantServiceClient svcTenant)
 {
     try
     {
         if (svcTenant != null)
         {
             // Get the state of the service
             System.ServiceModel.CommunicationState commState = svcTenant.State;
             // If the service is faulted, we still need to abort
             if (commState == System.ServiceModel.CommunicationState.Faulted)
             {
                 svcTenant.Abort();
             }
             // If the state is not already closed or in the process of closing, we should close the context
             else if (commState != System.ServiceModel.CommunicationState.Closing ||
                 commState != System.ServiceModel.CommunicationState.Closed)
             {
                 // Get the context info to get the context ID, although we saved this in the context string variable
                 Tenant.ContextInfo ci = svcTenant.GetContextInfo();
                 // Assure that there is a valid context ID
                 if (!string.IsNullOrWhiteSpace(ci.ContextId))
                 {
                     // Close the context
                     svcTenant.CloseContext();
                 }
                 // Now close the service
                 svcTenant.Close();
             }
             // If the channel is closing/closed, attempt to close out the context, but don't need to close state
             else
             {
                 // We will likely throw an exception here.
                 svcTenant.CloseContext();
             }
             svcTenant = null;
         }
     }
     catch (Exception ex)
     {
         // Just ouput the exception, proper handling should initiate a new service, initiate the context to the previous,
         // and then close out the context and service
         Console.WriteLine(ex.Message.ToString());
         logger.Error("Error while closing Tenant service", ex);
     }
 }