Exemplo n.º 1
0
        public void SaveMetric(ClientMetric metric, TObjectState state)
        {
            Dictionary <string, BsonValue> clientMetricValues = new Dictionary <string, BsonValue>();

            clientMetricValues.Add("Incremental", metric.Incremental);
            SaveMetric(metric, state, metric.ClientID.ToByteArray(), CLIENT_METRICS_COLLECTION, clientMetricValues);
        }
Exemplo n.º 2
0
        public IActionResult GetMetric(string clientID, string metricID)
        {
            IActionResult result;
            Guid          clientIDGuid;

            if (StringUtils.GuidTryDecode(clientID, out clientIDGuid))
            {
                string       rootUrl = Request.GetRootUrl();
                ClientMetric metric  = BusinessLogicFactory.Metrics.GetMetric(clientIDGuid, metricID);
                if (metric != null)
                {
                    ServiceModels.Metric response = new ServiceModels.Metric(metric);
                    response.AddSelfLink(string.Concat(rootUrl, "/clients/", clientID, "/metrics/", metricID), false, false);
                    result = Request.GetObjectResult(response);
                }
                else
                {
                    result = new NotFoundResult();
                }
            }
            else
            {
                result = new NotFoundResult();
            }

            return(result);
        }
Exemplo n.º 3
0
        private ClientMetric LoadClientMetric(Guid clientID, BsonDocument item)
        {
            ClientMetric result = new ClientMetric();

            result.ClientID    = clientID;
            result.Incremental = BsonHelper.GetBoolean(item, "Incremental");
            LoadMetricBase(result, item);
            return(result);
        }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        ClientMetric IDALMetrics.GetMetric(Guid clientID, string metricName)
        {
            ClientMetric result = null;

            BsonDocument document = GetMetricDocument(clientID.ToByteArray(), metricName, CLIENT_METRICS_COLLECTION);

            if (document != null)
            {
                result = LoadClientMetric(clientID, document);
            }

            return(result);
        }