コード例 #1
0
ファイル: DALMetrics.cs プロジェクト: tuga1975/DeviceServer
        private OrganisationMetric LoadOrganisationMetric(int organisationID, BsonDocument item)
        {
            OrganisationMetric result = new OrganisationMetric();

            result.OrganisationID = organisationID;
            LoadMetricBase(result, item);
            return(result);
        }
コード例 #2
0
ファイル: Metrics.cs プロジェクト: tuga1975/DeviceServer
        private void OnUpdateMetrics(string server, ServiceEventMessage message)
        {
            Guid clientID       = StringUtils.GuidDecode((string)message.Parameters["ClientID"]);
            int  organisationID = (int)((long)message.Parameters["OrganisationID"]);

            List <ClientMetric> metrics = (List <ClientMetric>)message.Parameters["Metrics"];

            foreach (ClientMetric parameter in metrics)
            {
                string       metricName   = parameter.Name;
                long         oldValue     = 0;
                long         newValue     = parameter.Value;
                ClientMetric clientMetric = DataAccessFactory.Metrics.GetMetric(clientID, metricName);
                if (clientMetric == null)
                {
                    clientMetric             = new ClientMetric();
                    clientMetric.Name        = metricName;
                    clientMetric.Value       = newValue;
                    clientMetric.ClientID    = clientID;
                    clientMetric.Incremental = parameter.Incremental;
                    DataAccessFactory.Metrics.SaveMetric(clientMetric, TObjectState.Add);
                }
                else
                {
                    oldValue = clientMetric.Value;
                    if (clientMetric.Incremental)
                    {
                        clientMetric.Value += newValue;
                        newValue            = clientMetric.Value;
                    }
                    else
                    {
                        clientMetric.Value = newValue;
                    }
                    DataAccessFactory.Metrics.SaveMetric(clientMetric, TObjectState.Update);
                }

                long change = newValue - oldValue;
                OrganisationMetric organisationMetric = DataAccessFactory.Metrics.GetMetric(organisationID, metricName);
                if (organisationMetric == null)
                {
                    organisationMetric                = new OrganisationMetric();
                    organisationMetric.Name           = metricName;
                    organisationMetric.Value          = change;
                    organisationMetric.OrganisationID = organisationID;
                    DataAccessFactory.Metrics.SaveMetric(organisationMetric, TObjectState.Add);
                }
                else
                {
                    organisationMetric.Value += change;
                    DataAccessFactory.Metrics.SaveMetric(organisationMetric, TObjectState.Update);
                }
            }
        }
コード例 #3
0
ファイル: DALMetrics.cs プロジェクト: tuga1975/DeviceServer
        public OrganisationMetric GetMetric(int organisationID, string metricName)
        {
            OrganisationMetric result = null;

            BsonDocument document = GetMetricDocument(organisationID, metricName, ORGANISATION_METRICS_COLLECTION);

            if (document != null)
            {
                result = LoadOrganisationMetric(organisationID, document);
            }

            return(result);
        }
コード例 #4
0
        public IActionResult GetMetric(string metricID)
        {
            IActionResult      result;
            string             rootUrl = Request.GetRootUrl();
            OrganisationMetric metric  = BusinessLogicFactory.Metrics.GetMetric(User.GetOrganisationID(), metricID);

            if (metric != null)
            {
                ServiceModels.Metric response = new ServiceModels.Metric(metric);
                response.AddSelfLink(string.Concat(rootUrl, "/metrics/", metricID), false, false);
                result = Request.GetObjectResult(response);
            }
            else
            {
                result = new NotFoundResult();
            }
            return(result);
        }
コード例 #5
0
ファイル: Metrics.cs プロジェクト: tuga1975/DeviceServer
        private void UpdateClientsConnectedMetric(string server, ServiceEventMessage message)
        {
            int organisationID = (int)((long)message.Parameters["OrganisationID"]);
            OrganisationMetric clientsConnectedMetric = DataAccessFactory.Metrics.GetMetric(organisationID, MetricNames.NumberClients);
            int numClientsConnected = BusinessLogicFactory.Clients.GetConnectedClients(organisationID).Count;

            if (clientsConnectedMetric == null)
            {
                clientsConnectedMetric                = new OrganisationMetric();
                clientsConnectedMetric.Name           = MetricNames.NumberClients;
                clientsConnectedMetric.Value          = Math.Max(numClientsConnected, 0);
                clientsConnectedMetric.OrganisationID = organisationID;
                DataAccessFactory.Metrics.SaveMetric(clientsConnectedMetric, TObjectState.Add);
            }
            else
            {
                clientsConnectedMetric.Value = numClientsConnected;
                DataAccessFactory.Metrics.SaveMetric(clientsConnectedMetric, TObjectState.Update);
            }
        }
コード例 #6
0
ファイル: DALMetrics.cs プロジェクト: tuga1975/DeviceServer
        /*private void OnNotification(object sender, NotificationEventArgs e)
         * {
         *  if (!string.IsNullOrEmpty(e.ID))
         *      _Metrics.Remove(StringUtils.GuidDecode(e.ID));
         * }*/

        public void SaveMetric(OrganisationMetric metric, TObjectState state)
        {
            Dictionary <string, BsonValue> organisationMetricValues = new Dictionary <string, BsonValue>();

            SaveMetric(metric, state, metric.OrganisationID, ORGANISATION_METRICS_COLLECTION, organisationMetricValues);
        }