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); }
private void LoadObjectDefinition(IMongoDatabase database, ObjectDefinitionLookups lookups) { IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("ObjectDefinition"); IAsyncCursor <BsonDocument> mongoCursor = collection.FindSync(new BsonDocument()); while (mongoCursor.MoveNext()) { foreach (BsonDocument item in mongoCursor.Current) { ObjectDefinition objectDefinition = new ObjectDefinition(); objectDefinition.ObjectDefinitionID = BsonHelper.GetGuid(item, "_id"); objectDefinition.ObjectID = BsonHelper.GetString(item, "ObjectID"); objectDefinition.OrganisationID = BsonHelper.GetInteger(item, "OrganisationID"); if (objectDefinition.OrganisationID.HasValue && (objectDefinition.OrganisationID.Value == 0)) { objectDefinition.OrganisationID = null; } objectDefinition.Name = BsonHelper.GetString(item, "Name"); objectDefinition.MIMEType = BsonHelper.GetString(item, "MIMEType"); objectDefinition.Description = BsonHelper.GetString(item, "Description"); objectDefinition.SerialisationName = BsonHelper.GetString(item, "SerialisationName"); objectDefinition.Singleton = BsonHelper.GetBoolean(item, "Singleton"); if (item.Contains("Properties")) { BsonArray array = item["Properties"].AsBsonArray; foreach (BsonValue arrayItem in array) { BsonDocument propertyItem = arrayItem.AsBsonDocument; if (propertyItem != null) { if (objectDefinition.Properties == null) { objectDefinition.Properties = new List <PropertyDefinition>(); } PropertyDefinition property = new PropertyDefinition(); property.PropertyDefinitionID = BsonHelper.GetGuid(propertyItem, "_id"); property.PropertyID = BsonHelper.GetString(propertyItem, "PropertyID"); property.Name = BsonHelper.GetString(propertyItem, "Name"); property.Description = BsonHelper.GetString(propertyItem, "Description"); property.DataType = (TPropertyDataType)propertyItem["DataType"].AsInt32; if (propertyItem.Contains("DataTypeLength")) { property.DataTypeLength = propertyItem["DataTypeLength"].AsInt32; } property.MIMEType = BsonHelper.GetString(propertyItem, "MIMEType"); property.MinValue = BsonHelper.GetString(propertyItem, "MinValue"); property.MaxValue = BsonHelper.GetString(propertyItem, "MaxValue"); property.Units = BsonHelper.GetString(propertyItem, "Units"); property.IsCollection = BsonHelper.GetBoolean(propertyItem, "IsCollection"); property.IsMandatory = BsonHelper.GetBoolean(propertyItem, "IsMandatory"); property.Access = (TAccessRight)propertyItem["Access"].AsInt32; if (propertyItem.Contains("SortOrder")) { property.SortOrder = propertyItem["SortOrder"].AsInt32; } property.SerialisationName = BsonHelper.GetString(propertyItem, "SerialisationName"); property.CollectionItemSerialisationName = BsonHelper.GetString(propertyItem, "CollectionItemSerialisationName"); objectDefinition.Properties.Add(property); } } } lookups.AddObjectDefinition(objectDefinition); } } }
public List <Server> GetServers() { List <Server> result = _CachedLWM2MServers; if (result == null) { lock (this) { result = _CachedLWM2MServers; if (result == null) { result = new List <Server>(); IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("Server"); IAsyncCursor <BsonDocument> mongoCursor = collection.FindSync(new BsonDocument()); while (mongoCursor.MoveNext()) { foreach (BsonDocument item in mongoCursor.Current) { LWM2MServer lwm2mServer = new LWM2MServer(); lwm2mServer.Url = BsonHelper.GetString(item, "_id"); lwm2mServer.Lifetime = (uint)BsonHelper.GetInt64(item, "Lifetime"); lwm2mServer.DefaultMinimumPeriod = (uint?)BsonHelper.GetLong(item, "DefaultMinimumPeriod"); lwm2mServer.DefaultMaximumPeriod = (uint?)BsonHelper.GetLong(item, "DefaultMaximumPeriod"); lwm2mServer.DisableTimeout = (uint?)BsonHelper.GetLong(item, "DisableTimeout"); lwm2mServer.NotificationStoringWhenOffline = BsonHelper.GetBoolean(item, "NotificationStoringWhenOffline"); lwm2mServer.Binding = (TBindingMode)BsonHelper.GetInt32(item, "Binding"); if (item.Contains("ServerIdentities")) { BsonArray array = item["ServerIdentities"].AsBsonArray; foreach (BsonValue arrayItem in array) { BsonDocument pskIdentityDoc = arrayItem.AsBsonDocument; if (pskIdentityDoc != null) { PSKIdentity pskIdentity = new PSKIdentity(); pskIdentity.Identity = BsonHelper.GetString(pskIdentityDoc, "_id"); pskIdentity.Secret = BsonHelper.GetString(pskIdentityDoc, "Secret"); lwm2mServer.AddServerIdentity(pskIdentity); } } } if (item.Contains("ServerCertificate")) { BsonDocument serverCertificateDoc = item["ServerCertificate"].AsBsonDocument; if (serverCertificateDoc != null) { lwm2mServer.ServerCertificate = new Certificate(); lwm2mServer.ServerCertificate.CertificateFormat = (TCertificateFormat)BsonHelper.GetInt32(serverCertificateDoc, "_id"); lwm2mServer.ServerCertificate.RawCertificate = BsonHelper.GetString(serverCertificateDoc, "RawCertificate"); } } Server server = new Server(lwm2mServer); server.ShortServerID = result.Count + 1; foreach (Model.Security endPoint in server.EndPoints) { endPoint.ShortServerID = server.ShortServerID; } #if DEBUG if (lwm2mServer.Url.ToLower().Contains(Environment.MachineName.ToLower())) { result.Add(server); } #else result.Add(server); #endif } } _CachedLWM2MServers = result; } } } return(result); }