protected override void VisitWhereBetween(Content.Query.Expressions.WhereBetweenExpression expression) { var query = QueryBuilder.Query.GT(expression.FieldName, BsonHelper.Create(expression.Start)) .LT(BsonHelper.Create(expression.End)); SetQuery(query); }
private BsonDocument GetMetricDocument(BsonValue id, string metricName, string collectionName) { BsonDocument metricDocument = null; IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(collectionName); // FIXME: Filter by ID + MetricName rather than doing a linear search FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", id); BsonDocument doc = collection.Find(filter).FirstOrDefault(); if (doc != null) { foreach (BsonDocument embeddedDocument in (doc["Metrics"] as BsonArray)) { if (metricName.Equals(BsonHelper.GetString(embeddedDocument, "Name"))) { metricDocument = embeddedDocument; break; } } } return(metricDocument); }
/// <summary> /// /// </summary> /// <param name="_objectIdentifier"></param> /// <returns></returns> public T Get(Guid _objectIdentifier) { BsonBinaryData id = new BsonBinaryData(_objectIdentifier.ToByteArray()); BsonDocument doc = MongoCollection.FindOneById(id); return(BsonHelper.Get <T>(doc)); }
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 AccessKey LoadAccessKey(BsonDocument item) { AccessKey result = new AccessKey(); result.Key = BsonHelper.GetString(item, "_id"); result.OrganisationID = BsonHelper.GetInt32(item, "OrganisationID"); result.Name = BsonHelper.GetString(item, "Name"); result.Secret = BsonHelper.GetString(item, "Secret"); return(result); }
public List <BootstrapServer> GetBootstrapServers() { List <BootstrapServer> result = _CachedBootstrapServers; if (result == null) { lock (this) { result = _CachedBootstrapServers; if (result == null) { result = new List <BootstrapServer>(); IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("BootstrapServer"); IAsyncCursor <BsonDocument> mongoCursor = collection.FindSync(new BsonDocument()); while (mongoCursor.MoveNext()) { foreach (BsonDocument item in mongoCursor.Current) { BootstrapServer bootstrapServer = new BootstrapServer(); bootstrapServer.Url = BsonHelper.GetString(item, "_id"); 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"); bootstrapServer.AddServerIdentity(pskIdentity); } } } if (item.Contains("ServerCertificate")) { BsonDocument serverCertificateDoc = item["ServerCertificate"].AsBsonDocument; if (serverCertificateDoc != null) { bootstrapServer.ServerCertificate = new Certificate(); bootstrapServer.ServerCertificate.CertificateFormat = (TCertificateFormat)BsonHelper.GetInt32(serverCertificateDoc, "_id"); bootstrapServer.ServerCertificate.RawCertificate = BsonHelper.GetString(serverCertificateDoc, "RawCertificate"); } } result.Add(bootstrapServer); } } _CachedBootstrapServers = result; } } } return(result); }
/// <summary> /// /// </summary> /// <param name="_cursor"></param> /// <returns></returns> public List <T> GetList(MongoCursor _cursor) { List <T> items = new List <T>(); foreach (BsonDocument doc in _cursor) { items.Add(BsonHelper.Get <T>(doc)); } return(items); }
/// <summary> /// /// </summary> /// <typeparam name="U"></typeparam> /// <param name="_mongoQuery"></param> /// <returns></returns> public U GetOneItem <U>(IMongoQuery _mongoQuery) where U : AbstractTGObject, new() { BsonDocument doc = MongoCollection.FindOne(_mongoQuery); if (doc != null) { return(BsonHelper.Get <U>(doc)); } return(null); }
/// <summary> /// /// </summary> /// <typeparam name="U"></typeparam> /// <param name="_mongoCursor"></param> /// <returns></returns> public U GetOneItem <U>(MongoCursor _mongoCursor) where U : AbstractTGObject, new() { MongoCursor cursor = _mongoCursor.SetLimit(1); foreach (BsonDocument doc in cursor) { U obj = BsonHelper.Get <U>(doc); return(obj); } return(null); }
private Client LoadClientFromDoc(BsonDocument doc) { Client result = null; if (doc != null) { result = new Client(); result.ClientID = BsonHelper.GetGuid(doc, "_id"); result.Name = BsonHelper.GetString(doc, "Name"); result.OrganisationID = BsonHelper.GetInt32(doc, "OrganisationID"); result.Lifetime = BsonHelper.GetDateTime(doc, "Lifetime"); string versionText = BsonHelper.GetString(doc, "Version"); Version version; if (Version.TryParse(versionText, out version)) { result.Version = version; } result.BindingMode = (TBindingMode)BsonHelper.GetInt32(doc, "BindingMode"); result.SMSNumber = BsonHelper.GetString(doc, "SMSNumber"); result.Server = BsonHelper.GetString(doc, "Server"); result.LastActivityTime = BsonHelper.GetDateTime(doc, "LastActivityTime"); result.LastUpdateActivityTime = result.LastActivityTime; if (doc.Contains("SupportedTypes")) { BsonArray array = doc["SupportedTypes"].AsBsonArray; foreach (BsonValue arrayItem in array) { BsonDocument supportedTypeDoc = arrayItem.AsBsonDocument; if (supportedTypeDoc != null) { ObjectType supportedType = new ObjectType(); supportedType.ObjectTypeID = BsonHelper.GetInt32(supportedTypeDoc, "_id"); supportedType.Path = BsonHelper.GetString(supportedTypeDoc, "Path"); if (supportedTypeDoc.Contains("Instances")) { BsonArray instances = supportedTypeDoc["Instances"].AsBsonArray; foreach (BsonValue instance in instances) { supportedType.Instances.Add(instance.AsInt32); } } if (result.SupportedTypes == null) { result.SupportedTypes = new ObjectTypes(); } result.SupportedTypes.AddObjectType(supportedType); } } } } return(result); }
private PSKIdentity LoadPSKIdentityFromDoc(BsonDocument doc) { PSKIdentity result = null; if (doc != null) { result = new PSKIdentity(); result.Identity = BsonHelper.GetString(doc, "_id"); result.Secret = BsonHelper.GetString(doc, "Secret"); result.OrganisationID = BsonHelper.GetInt32(doc, "OrganisationID"); } return(result); }
public List <T> GetByQuery(Guid _objectParentIdentifier) { List <T> objRet = new List <T>(); var query = new QueryDocument { { "ParentGuid", _objectParentIdentifier.ToString() } }; foreach (BsonDocument doc in MongoCollection.Find(query)) { objRet.Add(BsonHelper.Get <T>(doc)); } return(objRet); }
public void SaveClient(Client client, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("Client"); EnsureIndexExists <BsonDocument>(collection, "OrganisationID"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", client.ClientID.ToByteArray()); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", client.ClientID); BsonHelper.SetValue(doc, "Name", client.Name); BsonHelper.SetValue(doc, "OrganisationID", client.OrganisationID); BsonHelper.SetValue(doc, "Lifetime", client.Lifetime); BsonHelper.SetValue(doc, "Version", client.Version.ToString()); BsonHelper.SetValue(doc, "BindingMode", (int)client.BindingMode); BsonHelper.SetValue(doc, "SMSNumber", client.SMSNumber); BsonHelper.SetValue(doc, "Server", client.Server); BsonHelper.SetValue(doc, "LastActivityTime", client.LastActivityTime); if (client.SupportedTypes.Count > 0) { BsonArray array = new BsonArray(); foreach (ObjectType supportedType in client.SupportedTypes) { BsonDocument supportedTypeDoc = new BsonDocument(); BsonHelper.SetValue(supportedTypeDoc, "_id", supportedType.ObjectTypeID); BsonHelper.SetValue(supportedTypeDoc, "Path", supportedType.Path); if (supportedType.Instances.Count > 0) { BsonArray instances = new BsonArray(); foreach (int instance in supportedType.Instances) { instances.Add(instance); } supportedTypeDoc.Add("Instances", instances); } array.Add(supportedTypeDoc); } doc.Add("SupportedTypes", array); } UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } }
public void AllocateBootstrapServer(int organisationID, BootstrapServer bootstrapServer) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("OrganisationBootstrapServer"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", organisationID); BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", organisationID); BsonHelper.SetValue(doc, "Url", bootstrapServer.Url); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); }
public List <OrganisationMetric> GetMetrics(int organisationID) { List <OrganisationMetric> result = new List <OrganisationMetric>(); IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(ORGANISATION_METRICS_COLLECTION); BsonDocument doc = collection.Find(Builders <BsonDocument> .Filter.Eq("_id", organisationID)).FirstOrDefault(); if (doc != null) { foreach (BsonDocument embeddedDocument in BsonHelper.GetArray(doc, "Metrics")) { result.Add(LoadOrganisationMetric(organisationID, embeddedDocument)); } } return(result); }
public List <ClientMetric> GetMetrics(Guid clientID) { List <ClientMetric> result = new List <ClientMetric>(); IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(CLIENT_METRICS_COLLECTION); BsonDocument doc = collection.Find(Builders <BsonDocument> .Filter.Eq("_id", clientID.ToByteArray())).FirstOrDefault(); if (doc != null) { foreach (BsonDocument embeddedDocument in BsonHelper.GetArray(doc, "Metrics")) { result.Add(LoadClientMetric(clientID, embeddedDocument)); } } return(result); }
/// <summary> /// Does not modify the version guid. /// </summary> /// <param name="_obj"></param> public void PersistFromPropagation(T _obj) { if (HasParent && _obj.ParentGuid == null) { throw new Exception("Parent Guid not specified."); } _obj.PersistedDateTime = DateTime.UtcNow; BsonDocument document = BsonHelper.Get(_obj); MongoCollection.Save(document); PostPersist(_obj); }
public void SaveLWM2MServer(LWM2MServer lwm2mServer, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("Server"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", lwm2mServer.Url); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", lwm2mServer.Url); BsonHelper.SetValue(doc, "Lifetime", lwm2mServer.Lifetime); BsonHelper.SetValue(doc, "DefaultMinimumPeriod", lwm2mServer.DefaultMinimumPeriod); BsonHelper.SetValue(doc, "DefaultMaximumPeriod", lwm2mServer.DefaultMaximumPeriod); BsonHelper.SetValue(doc, "DisableTimeout", lwm2mServer.DisableTimeout); BsonHelper.SetValue(doc, "NotificationStoringWhenOffline", lwm2mServer.NotificationStoringWhenOffline); BsonHelper.SetValue(doc, "Binding", (int)lwm2mServer.Binding); if (lwm2mServer.ServerIdentities != null && lwm2mServer.ServerIdentities.Count > 0) { BsonArray array = new BsonArray(); foreach (PSKIdentity pskIdentity in lwm2mServer.ServerIdentities) { BsonDocument pskIdentityDoc = new BsonDocument(); BsonHelper.SetValue(pskIdentityDoc, "_id", pskIdentity.Identity); BsonHelper.SetValue(pskIdentityDoc, "Secret", pskIdentity.Secret); array.Add(pskIdentityDoc); } doc.Add("ServerIdentities", array); } if (lwm2mServer.ServerCertificate != null) { BsonDocument serverCertificateDoc = new BsonDocument(); BsonHelper.SetValue(serverCertificateDoc, "_id", (int)lwm2mServer.ServerCertificate.CertificateFormat); BsonHelper.SetValue(serverCertificateDoc, "RawCertificate", lwm2mServer.ServerCertificate.RawCertificate); doc.Add("ServerCertificate", serverCertificateDoc); } UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange("LWM2MServer", string.Empty); }
private void SaveMetric(MetricBase metric, TObjectState state, BsonValue id, string collectionName, Dictionary <string, BsonValue> values) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(collectionName); if (state == TObjectState.Add) { BsonDocument newItem = new BsonDocument(); BsonHelper.SetValue(newItem, "Name", metric.Name); BsonHelper.SetValue(newItem, "Value", metric.Value); foreach (KeyValuePair <string, BsonValue> pair in values) { newItem[pair.Key] = pair.Value; } FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", id); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.AddToSet("Metrics", newItem); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.UpdateOne(filter, update, options); } else if (state == TObjectState.Update) { FilterDefinition <BsonDocument> clientOrOrganisationIDFilter = Builders <BsonDocument> .Filter.Eq("_id", id); FilterDefinition <BsonDocument> metricNameFilter = Builders <BsonDocument> .Filter.Eq("Metrics.Name", metric.Name); FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.And(clientOrOrganisationIDFilter, metricNameFilter); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.Set("Metrics.$.Value", metric.Value); collection.UpdateOne(filter, update); } else if (state == TObjectState.Delete) { FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", id); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.PullFilter("Metrics", Builders <BsonDocument> .Filter.Eq("Name", metric.Name)); collection.UpdateOne(filter, update); } }
public List <Guid> GetBlacklistedClientIDs(int organisationID) { List <Guid> blacklistedClientIDs = new List <Guid>(); IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("BlacklistedClient"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("OrganisationID", organisationID); IAsyncCursor <BsonDocument> mongoCursor = collection.FindSync(query); while (mongoCursor.MoveNext()) { foreach (BsonDocument doc in mongoCursor.Current) { Guid clientID = BsonHelper.GetGuid(doc, "_id"); blacklistedClientIDs.Add(clientID); } } return(blacklistedClientIDs); }
public void SaveSubscription(Subscription subscription, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(COLLECTION_NAME); EnsureIndexExists <BsonDocument>(collection, "OrganisationID"); EnsureIndexExists <BsonDocument>(collection, "ClientID"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", subscription.SubscriptionID.ToByteArray()); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", subscription.SubscriptionID); BsonHelper.SetValue(doc, "OrganisationID", subscription.OrganisationID); BsonHelper.SetValue(doc, "ClientID", subscription.ClientID); BsonHelper.SetValue(doc, "DefinitionID", subscription.ObjectDefinitionID); BsonHelper.SetValue(doc, "ObjectID", subscription.ObjectID); BsonHelper.SetValue(doc, "SubscriptionType", (int)subscription.SubscriptionType); BsonHelper.SetValue(doc, "PropertyDefinitionID", subscription.PropertyDefinitionID); BsonHelper.SetValue(doc, "Url", subscription.Url); BsonHelper.SetValue(doc, "AcceptContentType", subscription.AcceptContentType); if (subscription.NotificationParameters != null) { MemoryStream stream = new MemoryStream(); subscription.NotificationParameters.Serialise(stream); BsonHelper.SetValue(doc, "NotificationParameters", StringUtils.Encode(stream.ToArray())); } UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange(COLLECTION_NAME, StringUtils.GuidEncode(subscription.SubscriptionID)); }
public List <T> GetByQuery( Guid _objectParentIdentifier, string[] _objectVersionIdentifiers) { List <T> objRet = new List <T>(); foreach (string objectVersionIdentifier in _objectVersionIdentifiers) { var query = new QueryDocument { { "ParentGuid", _objectParentIdentifier.ToString() }, { "VersionGuid", objectVersionIdentifier } }; foreach (BsonDocument doc in MongoCollection.Find(query)) { objRet.Add(BsonHelper.Get <T>(doc)); } } return(objRet); }
protected override global::MongoDB.Driver.MongoCursor <global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor) { var parentQuery = (ParentQuery)this.ContentQuery; MongoDBQueryTranslator translator = new MongoDBQueryTranslator(); var children = ((IEnumerable <TextContent>)(translator.Translate(parentQuery.ChildrenQuery)).Execute()); if (parentQuery.ParentFolder != null) { visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", parentQuery.ParentFolder.FullName)); } if (children.Count() > 0) { visitor.SetQuery(QueryBuilder.Query.In("UUID", children.Select(it => BsonHelper.Create(it.ParentUUID)).ToArray())); return(parentQuery.ParentSchema.GetCollection().Find(visitor.QueryComplete)); } return(null); }
public void SaveBootstrapServer(BootstrapServer bootstrapServer, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("BootstrapServer"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", bootstrapServer.Url); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", bootstrapServer.Url); if (bootstrapServer.ServerIdentities != null && bootstrapServer.ServerIdentities.Count > 0) { BsonArray array = new BsonArray(); foreach (PSKIdentity pskIdentity in bootstrapServer.ServerIdentities) { BsonDocument pskIdentityDoc = new BsonDocument(); BsonHelper.SetValue(pskIdentityDoc, "_id", pskIdentity.Identity); BsonHelper.SetValue(pskIdentityDoc, "Secret", pskIdentity.Secret); array.Add(pskIdentityDoc); } doc.Add("ServerIdentities", array); } if (bootstrapServer.ServerCertificate != null) { BsonDocument serverCertificateDoc = new BsonDocument(); BsonHelper.SetValue(serverCertificateDoc, "_id", (int)bootstrapServer.ServerCertificate.CertificateFormat); BsonHelper.SetValue(serverCertificateDoc, "RawCertificate", bootstrapServer.ServerCertificate.RawCertificate); doc.Add("ServerCertificate", serverCertificateDoc); } UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange("BootstrapServer", string.Empty); }
public BootstrapServer GetBootstrapServer(int organisationID) { BootstrapServer result = null; IMongoDatabase database = GetDatabase(DATABASE_NAME, false); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("OrganisationBootstrapServer"); BsonDocument doc = collection.Find(Builders <BsonDocument> .Filter.Eq("_id", organisationID)).FirstOrDefault(); if (doc != null) { string url = BsonHelper.GetString(doc, "Url"); List <BootstrapServer> bootstrapServers = GetBootstrapServers(); foreach (BootstrapServer item in bootstrapServers) { if (string.Compare(url, item.Url, true) == 0) { result = item; break; } } } return(result); }
public void SaveAccessKey(AccessKey accessKey, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("AccessKey"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", accessKey.Key); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", accessKey.Key); BsonHelper.SetValue(doc, "OrganisationID", accessKey.OrganisationID); BsonHelper.SetValue(doc, "Name", accessKey.Name); BsonHelper.SetValue(doc, "Secret", accessKey.Secret); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange("AccessKey", accessKey.Key); }
public void SaveBlacklistedClient(Client client, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("BlacklistedClient"); EnsureIndexExists <BsonDocument>(collection, "OrganisationID"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", client.ClientID.ToByteArray()); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", client.ClientID); BsonHelper.SetValue(doc, "OrganisationID", client.OrganisationID); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange("BlacklistedClient", StringUtils.GuidEncode(client.ClientID)); }
private Subscription LoadSubscription(BsonDocument item) { Subscription result = new Subscription(); result.SubscriptionID = BsonHelper.GetGuid(item, "_id"); result.OrganisationID = BsonHelper.GetInt32(item, "OrganisationID"); result.ClientID = BsonHelper.GetGuid(item, "ClientID"); result.ObjectDefinitionID = BsonHelper.GetGuid(item, "DefinitionID"); result.ObjectID = BsonHelper.GetString(item, "ObjectID"); result.SubscriptionType = (TSubscriptionType)BsonHelper.GetInt32(item, "SubscriptionType"); result.PropertyDefinitionID = BsonHelper.GetGuid(item, "PropertyDefinitionID"); result.Url = BsonHelper.GetString(item, "Url"); result.AcceptContentType = BsonHelper.GetString(item, "AcceptContentType"); byte[] serialisedNotificationParameters = StringUtils.Decode(BsonHelper.GetString(item, "NotificationParameters")); if (serialisedNotificationParameters != null) { result.NotificationParameters = NotificationParameters.Deserialise(new MemoryStream(serialisedNotificationParameters)); } return(result); }
public void SavePSKIdentity(PSKIdentity pskIdentity, TObjectState state) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(COLLECTION_NAME); EnsureIndexExists <BsonDocument>(collection, "OrganisationID"); FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Eq("_id", pskIdentity.Identity); if ((state == TObjectState.Add) || (state == TObjectState.Update)) { BsonDocument doc = new BsonDocument(); BsonHelper.SetValue(doc, "_id", pskIdentity.Identity); BsonHelper.SetValue(doc, "Secret", pskIdentity.Secret); BsonHelper.SetValue(doc, "OrganisationID", pskIdentity.OrganisationID); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.ReplaceOne(query, doc, options); } else if (state == TObjectState.Delete) { collection.DeleteOne(query); } BroadcastTableChange(COLLECTION_NAME, pskIdentity.Identity); }
/// <summary> /// Unconfirmed persist of data. Should only be used on low value data. /// </summary> /// <param name="_obj"></param> public void LazyPersist(T _obj) { BsonDocument document = BsonHelper.Get(_obj); MongoCollection.Save(document, WriteConcern.Unacknowledged); }