コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
                }
            }
        }