private static SyntheticsJsonRoot GetNamedMonitors(GetMonitors monitorRetriver, string monitorsNamesCollection)
        {
            var monitorNames = monitorsNamesCollection.Split(',');

            var monitorsArray = new Monitor[monitorNames.Length];

            for (var counter = 0; counter < monitorNames.Length; counter++)
            {
                var monitor = monitorRetriver.GetMonitorByName(monitorNames[counter]);
                if (monitor != null)
                {
                    monitorsArray[counter] = monitor;
                }
                else
                {
                    //we need a monitor name from setup to identify an error
                    monitorsArray[counter] = new Monitor
                    {
                        Name = monitorNames[counter]
                    };
                }
            }

            var monitorsCollection = new SyntheticsJsonRoot
            {
                Count    = monitorNames.Length,
                Monitors = monitorsArray
            };

            return(monitorsCollection);
        }
        public override bool Execute()
        {
            var changeAllMonitors = string.IsNullOrWhiteSpace(MonitorsNamesCollection);

            var monitorRetriver = new GetMonitors(SyntheticsApiKey);
            var monitorUpdater  = new UpdateMonitor(SyntheticsApiKey);

            Log.LogMessage("Starting API operations", MessageImportance.Low);

            var monitorsCollection = changeAllMonitors ? monitorRetriver.GetAllMonitors() : GetNamedMonitors(monitorRetriver, MonitorsNamesCollection);

            if (!monitorsCollection.Monitors.Any())
            {
                Log.LogMessage(MessageImportance.High, "Could not retrieve any monitors for given set of parameters");
                return(false);
            }


            for (int counter = 0; counter < monitorsCollection.Count; counter++)
            {
                var monitor     = monitorsCollection.Monitors[counter];
                var monitorName = !string.IsNullOrWhiteSpace(monitor.Name) ? monitor.Name : "UNRETRIEVABLE";
                Log.LogMessage(MessageImportance.Low, "Updating monitor '{0}' to status '{1}'", monitorName, GetTargetStatus(EnableMonitors));
                var updateStatus = monitorUpdater.Execute(monitor, EnableMonitors);
                if (!updateStatus)
                {
                    //failure encountered during monitor update
                    Log.LogError("Could change monitor '{0}' to status '{1}'", monitorName, GetTargetStatus(EnableMonitors));
                }
            }

            Log.LogMessage("Finished API operations", MessageImportance.Low);

            return(true);
        }
        protected void SetUp()
        {
            var appSettingKey = ConfigurationManager.AppSettings.Get("ApiKey");

            this.apiKey             = !string.IsNullOrWhiteSpace(appSettingKey) ? appSettingKey : string.Empty;
            monitorRetriver         = new GetMonitors(this.apiKey);
            this.monitorsCollection = this.monitorRetriver.GetAllMonitors();
        }
 public static void HandleGetMonitors(GetMonitors command, Client client)
 {
     if (Screen.AllScreens.Length > 0)
     {
         client.Send(new GetMonitorsResponse {
             Number = Screen.AllScreens.Length
         });
     }
 }
Exemple #5
0
        public void GetMonitors(IRequest request, IResponse response, MonitorStore monitorStore)
        {
            var outputs = new GetMonitors();

            foreach (var monitor in monitorStore)
            {
                outputs.WriteLine(monitor);
            }

            response.SetContext(outputs);
        }
Exemple #6
0
        public void GetMonitors(IRequest request, IResponse response, MonitorStore monitorStore)
        {
            var outputs = new GetMonitors();

            Action action = () =>
            {
                foreach (var monitor in monitorStore)
                {
                    outputs.WriteLine(monitor);
                }

                response.SetContext(outputs);
            };

            CallMainThread(request, action);
        }
Exemple #7
0
        public void GetMonitorsIndex(IResponse response, [Inject("Debugger.WebMonitor.Monitor.IndexMonitor")] IEnumerable <string> indexShow, MonitorStore monitorStore)
        {
            var outputs = new GetMonitors();

            if (indexShow != null)
            {
                foreach (var monitor in indexShow)
                {
                    var result = monitorStore.FindMoitor(monitor);
                    if (result != null)
                    {
                        outputs.WriteLine(result);
                    }
                }
            }

            response.SetContext(outputs);
        }
Exemple #8
0
        public void GetMonitorsIndex(IRequest request, IResponse response, [Inject("DebuggerProvider.IndexMonitor")] IEnumerable <string> indexShow, MonitorStore monitorStore)
        {
            var    outputs = new GetMonitors();
            Action action  = () =>
            {
                if (indexShow != null)
                {
                    foreach (var monitor in indexShow)
                    {
                        var result = monitorStore.FindMoitor(monitor);
                        if (result != null)
                        {
                            outputs.WriteLine(result);
                        }
                    }
                }
                response.SetContext(outputs);
            };

            CallMainThread(request, action);
        }
 private void Execute(ISender client, GetMonitors message)
 {
     client.Send(new GetMonitorsResponse {
         Number = Screen.AllScreens.Length
     });
 }