Example #1
0
 private OrganisationMetric LoadOrganisationMetric(int organisationID, BsonDocument item)
 {
     OrganisationMetric result = new OrganisationMetric();
     result.OrganisationID = organisationID;
     LoadMetricBase(result, item);
     return result;
 }
Example #2
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);
                }
            }
        }
Example #3
0
 /*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);
 }
Example #4
0
 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);
     }
 }