Esempio n. 1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                          .Value;

            if (name == null)
            {
                // Get request body
                dynamic data = await req.Content.ReadAsAsync <object>();

                name = data?.name;
            }


            var webClient = new WebClient();
            var json      = webClient.DownloadString("https://developer.microsoft.com/en-us/reactor/api/sp/events?from=2018-10-01T00%3A00%3A00.111Z&to=2018-10-31T00%3A00%3A00.111Z");

            var reactorClient = new ReactorClient();



            return(name == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
                : req.CreateResponse(HttpStatusCode.OK, "Hello " + name));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Nuclear Watchdog");

            HeartbeatClient client = new HeartbeatClient();
            HeartbeatSender heartbeatSender = new HeartbeatSender(client);

            try {
                heartbeatSender.Register();
            } catch (System.ServiceModel.EndpointNotFoundException)
            {
                Console.WriteLine("Failed to connect to the heartbeat receiver service.");
                Console.WriteLine("Are you sure the service is running?");
                Environment.Exit(1);
            }

            ReactorClient reactor = new ReactorClient();
            ReactorMonitor reactorMonitor = new ReactorMonitor(heartbeatSender, reactor, 350);

            Thread reactorMonitorThread = new Thread(new ThreadStart(reactorMonitor.Monitor));
            reactorMonitorThread.Start();

            Thread heartbeatThread = new Thread(new ThreadStart(heartbeatSender.Beat));
            heartbeatThread.Start();

            // Run for 60 seconds
            Thread.Sleep(60000);

            reactorMonitorThread.Abort();
            reactorMonitorThread.Join();

            heartbeatThread.Abort();
            heartbeatThread.Join();

            heartbeatSender.Unregister();

            Console.WriteLine("Stopping Nuclear Watchdog");
        }
Esempio n. 3
0
 public ReactorMonitor(HeartbeatSender heartbeatSender, ReactorClient reactor, double threshold)
 {
     this.random = new Random();
     this.heartbeatSender = heartbeatSender;
     this.reactor = reactor;
     this.threshold = threshold;
 }