Beispiel #1
0
        static void Main(string[] args)
        {
            // This is only needed for non-vnet VMs! VNET VMs can use the known endpoint
            Uri scheduledEventsEndpoint =
                ScheduledEventsEndpointDiscovery.ScheduledEventsUtility.ObtainScheduledEventsUri();

            Console.WriteLine("Scheduled Events URI: {0}", scheduledEventsEndpoint);

            client = new ScheduledEventsClient(scheduledEventsEndpoint);

            while (true)
            {
                Console.WriteLine("Getting the Scheduled Events Document...\n");

                // Get the events json string
                string json = client.GetDocument();
                Console.WriteLine($"Scheduled Events Document: {json}\n");

                // Deserialize using Newtonsoft.Json
                ScheduledEventsDocument scheduledEventsDocument = JsonConvert.DeserializeObject <ScheduledEventsDocument>(json);

                // React to events
                HandleEvents(scheduledEventsDocument.Events);

                // Wait for user response
                Console.WriteLine("Press Enter to approve executing events\n");
                Console.ReadLine();

                // Create approval document and approve events
                ScheduledEventsApproval scheduledEventsApprovalDocument = new ScheduledEventsApproval()
                {
                    DocumentIncarnation = scheduledEventsDocument.DocumentIncarnation
                };

                foreach (CloudControlEvent ccevent in scheduledEventsDocument.Events)
                {
                    scheduledEventsApprovalDocument.StartRequests.Add(new StartRequest(ccevent.EventId));
                }

                if (scheduledEventsApprovalDocument.StartRequests.Count > 0)
                {
                    // Serialize using Newtonsoft.Json
                    string approveEventsJsonDocument =
                        JsonConvert.SerializeObject(scheduledEventsApprovalDocument);

                    Console.WriteLine($"Approving events with json: {approveEventsJsonDocument}\n");
                    client.PostResponse(approveEventsJsonDocument);
                }

                Console.WriteLine("Complete. Press enter to repeat\n\n");
                Console.ReadLine();
                Console.Clear();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Uri scheduledEventsEndpoint;

            Console.WriteLine("Is this virtual machine VNET Enabled? Y/N");
            string response = Console.ReadLine();
            bool   vNet     = string.Equals("Y", response, StringComparison.OrdinalIgnoreCase);

            if (vNet)
            {
                // Use the known endpoint available for VNET VMs
                scheduledEventsEndpoint = new Uri("http://169.254.169.254/metadata/scheduledevents?api-version=2017-08-01");
            }
            else
            {
                // Use discovery utility to discover the endpoint
                scheduledEventsEndpoint = ScheduledEventsEndpointDiscovery.ScheduledEventsUtility.ObtainScheduledEventsUri();
            }

            Console.WriteLine("Scheduled Events URI: {0}", scheduledEventsEndpoint);

            client = new ScheduledEventsClient(scheduledEventsEndpoint);

            while (true)
            {
                Console.WriteLine("Getting the Scheduled Events Document...\n");

                // Get the events json string
                string json = client.GetScheduledEvents();
                Console.WriteLine($"Scheduled Events Document: {json}\n");

                // Deserialize using Newtonsoft.Json
                ScheduledEventsDocument scheduledEventsDocument = JsonConvert.DeserializeObject <ScheduledEventsDocument>(json);

                // React to events
                HandleEvents(scheduledEventsDocument.Events);

                // Wait for user response
                Console.WriteLine("Press Enter to approve all scheduled events\n");
                Console.ReadLine();

                // Create approval document and approve events
                ScheduledEventsApproval scheduledEventsApprovalDocument = new ScheduledEventsApproval()
                {
                    DocumentIncarnation = scheduledEventsDocument.DocumentIncarnation
                };

                foreach (ScheduledEvent e in scheduledEventsDocument.Events)
                {
                    scheduledEventsApprovalDocument.StartRequests.Add(new StartRequest(e.EventId));
                }

                if (scheduledEventsApprovalDocument.StartRequests.Count > 0)
                {
                    // Serialize using Newtonsoft.Json
                    string approveEventsJsonDocument =
                        JsonConvert.SerializeObject(scheduledEventsApprovalDocument);

                    Console.WriteLine($"Approving events with json: {approveEventsJsonDocument}\n");
                    client.ExpediteScheduledEvents(approveEventsJsonDocument);
                }

                Console.WriteLine("Complete. Press enter to repeat\n\n");
                Console.ReadLine();
                Console.Clear();
            }
        }