コード例 #1
0
ファイル: HubClient.cs プロジェクト: AndyCross/CloudMonitR
 public static HubClient Start()
 {
     var url = RoleEnvironment.GetConfigurationSettingValue("HubURL");
     var ret = new HubClient();
     ret._connection = new HubConnection(url);
     ret.Hub = ret._connection.CreateProxy("cloudMonitR");
     ret._connection.Start().Wait();
     return ret;
 }
コード例 #2
0
        public static CloudMonitREngine Setup()
        {
            CloudMonitREngine engine = new CloudMonitREngine();

            engine.Readers = new List <UniversalPerformanceReader>();

            Trace.WriteLine("Connecting to Hub", "Information");

            var client = HubClient.Start();

            Trace.WriteLine("Connected to Hub", "Information");

            var categories = PerformanceCounterFactory.GetPerformanceCounterCategories();

            var storage = new StorageWrapper();

            client.Hub.Invoke("connectWorker");

            client.Hub.On("onGetPerformanceCounterCategories", () =>
            {
                client.Hub.Invoke("sendPerformanceCounterCategoriesToDashboard", categories);
            });

            client.Hub.On <string, string>("onGetPerformanceCounters",
                                           (category, instance) =>
            {
                var counters = PerformanceCounterFactory.GetCountersForCategory(category, instance);
                client.Hub.Invoke("SendPerformanceCountersToDashboard", counters);
            });

            client.Hub.On <string, string>("onDeleteCounter",
                                           (counter, instance) =>
            {
                storage.DeleteCounter(counter, instance);
                try
                {
                    var r = engine.Readers.First(x => x.CounterInstance == instance &&
                                                 x.CounterName == counter);

                    engine.Readers.Remove(r);
                    r.Dispose();
                }
                catch
                {
                    // this happens when storage has already deleted the item but subsequent workers haven't caught up
                }
            });

            client.Hub.On <string, string, string>("onAddCounterToDashboard",
                                                   (category, instance, counter) =>
            {
                var itm = new PerformanceCounterItem
                {
                    CategoryName = category,
                    InstanceName = instance,
                    CounterName  = counter
                };
                var rdr = new UniversalPerformanceReader(itm);

                rdr.ValueReceived += (s, e) =>
                {
                    client.Hub.Invoke("sendDataToChart", new
                    {
                        name            = e.Name,
                        value           = e.Value,
                        instanceId      = e.InstanceId,
                        counterInstance = e.CounterInstance
                    });
                };

                storage.Add(itm);

                engine.Readers.Add(rdr);
                rdr.ReadValue();
            });

            storage.GetCounters().ForEach((x) =>
            {
                var rdr            = new UniversalPerformanceReader(x);
                rdr.ValueReceived += (s, e) =>
                {
                    client.Hub.Invoke("sendDataToChart", new
                    {
                        name            = e.Name,
                        value           = e.Value,
                        instanceId      = e.InstanceId,
                        counterInstance = e.CounterInstance
                    });
                };
                engine.Readers.Add(rdr);
            });

            return(engine);
        }
コード例 #3
0
 public SignalRTraceListener()
 {
     _client = HubClient.Start();
 }
コード例 #4
0
 public SignalRTraceListener()
 {
     _client = HubClient.Start();
 }