///// <summary> ///// Create a new, ephermal metric to watch ///// </summary> ///// <param name="pipeline"></param> ///// <param name="jsAggregator"></param> ///// <param name="name"></param> ///// <param name="connection"></param> ///// <param name="connectionId"></param> //public JavascriptMetricConnection(EventPipeline pipeline, string jsAggregator, string name, IConnection connection, string connectionId, string javascriptId) { // _connection = connection; // _javascriptId = javascriptId; // _connectionId = connectionId; // var jsMetric = new JavascriptMetric(name, jsAggregator); // jsMetric.Updated(connectionId, Updated); // pipeline.AddProcessor(jsMetric); // SendUpdates(); //} /// <summary> /// Bind to an existing metric given by "name" /// </summary> /// <param name="pipeline"></param> /// <param name="name"></param> /// <param name="connection"></param> /// <param name="connectionId"></param> public JavascriptMetricConnection(EventPipeline pipeline, string name, IConnection connection, string connectionId, string javascriptId, string keyFilter, TimePeriod period) { _connection = connection; _connectionId = connectionId; _javascriptId = javascriptId; _timePeriod = period; _keyFilter = PeriodMetric.BaseKey(name, _timePeriod, keyFilter); if (string.IsNullOrEmpty(_keyFilter)) { _keyFilter = "*"; } // Try to find the metric, and add a watcher var processor = pipeline.GetProcessor(name); if (processor == null) { throw new Exception(string.Format("Unable to find metric with name {0}", name)); } var jsMetric = processor as JavascriptMetric; if (jsMetric == null) { throw new Exception(string.Format("Found metric with name {0}, but its not a JavascriptMetric", name)); } jsMetric.Updated(_connectionId, Updated); SendUpdates(); }
/// <summary> /// Bind to an existing metric given by "name" /// </summary> /// <param name="pipeline"></param> /// <param name="name"></param> /// <param name="connection"></param> /// <param name="connectionId"></param> public MetricConnection(EventPipeline pipeline, IConnection connection, string connectionId, string jsonMetric, string clientId) { _connection = connection; _connectionId = connectionId; _clientId = clientId; _jsonMetric = JsonConvert.DeserializeObject<JsonMetric>(jsonMetric); // Try to find the metric, and add a watcher var metric = pipeline.GetProcessor(_jsonMetric.Name) as MetricProcessor; if (metric == null) { // Its new so we need to create a new one... var filePath = Path.Combine(PathManager.BasePath, "user", "metric", _jsonMetric.Name + ".json"); //if (!File.Exists(filePath)) { var formattedJson = JsonConvert.SerializeObject(_jsonMetric, Formatting.Indented); File.WriteAllText(filePath, formattedJson); //} metric = new MetricProcessor(_jsonMetric.Name, _jsonMetric); pipeline.AddProcessor(metric); } metric.Updated(_connectionId, WriteValueUpdate); metric.Error(_connectionId, WriteErrorUpdate); SendUpdates(metric); }