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); }
private void LoadMetricBase(MetricBase result, BsonDocument item) { result.Name = BsonHelper.GetString(item, "Name"); result.Value = BsonHelper.GetLong(item, "Value").Value; }