예제 #1
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new AuditClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
예제 #2
0
        public static async Task MainChangeRegion()
        {
            logger.Info("Starting example");
            AuditClient client = null;

            try
            {
                // Assumption: the compartment id has been set in environment variable.
                var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
                logger.Info(compartmentId);

                // ListEvents
                var listEventsRequest = new ListEventsRequest
                {
                    CompartmentId = compartmentId,
                    StartTime     = DateTime.Now.AddDays(-1),
                    EndTime       = DateTime.Now
                };

                // Create AuditClient
                var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");

                using (client = new AuditClient(provider, new ClientConfiguration()))
                {
                    logger.Info($"AuditClient created. Region is set to: {provider.Region}");
                    ListEventsResponse listEventsResp = await GetEvents(client, listEventsRequest);

                    logger.Info($"Received {listEventsResp?.Items.Count} items");
                }

                // Change the region to US_ASHBURN_1 using SetRegion Call
                // We cannot use the same client to change the region. See:
                // https://stackoverflow.com/questions/51478525/httpclient-this-instance-has-already-started-one-or-more-requests-properties-ca
                using (client = new AuditClient(provider, new ClientConfiguration()))
                {
                    client.SetRegion(Region.US_ASHBURN_1);
                    logger.Info("Changing region to US_ASHBURN_1");
                    ListEventsResponse listEventsRespDiffRegion = await GetEvents(client, listEventsRequest);

                    logger.Info($"Received {listEventsRespDiffRegion?.Items.Count} items");
                }
            }
            catch (Exception e)
            {
                logger.Error($"Failed Change Region example: {e.Message}");
            }
        }