コード例 #1
0
ファイル: MetricConnection.cs プロジェクト: GrowingData/Mung
        /// <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);
        }
コード例 #2
0
ファイル: MetricConnection.cs プロジェクト: GrowingData/Mung
 public void SendUpdates(MetricProcessor metric)
 {
     _connection.Send(_connectionId, new {
         ClientId = _clientId,
         Metric = metric.CurrentState.Values,
         Success = true
     });
 }
コード例 #3
0
ファイル: MetricFactory.cs プロジェクト: GrowingData/Mung
        public void AddPersistentMetric(string name, string json)
        {
            _pipeline.RemoveProcessor(name);

            var metric = JsonConvert.DeserializeObject<JsonMetric>(json);

            var newProcessor = new MetricProcessor(name, metric);

            _pipeline.AddProcessor(newProcessor);
        }
コード例 #4
0
        public void AddPersistentMetric(string name, string json)
        {
            _pipeline.RemoveProcessor(name);


            var metric = JsonConvert.DeserializeObject <JsonMetric>(json);

            var newProcessor = new MetricProcessor(name, metric);

            _pipeline.AddProcessor(newProcessor);
        }
コード例 #5
0
ファイル: MetricConnection.cs プロジェクト: GrowingData/Mung
 public void WriteValueUpdate(MetricProcessor metric)
 {
     SendUpdates(metric);
 }