protected override void OutputResult(AsyncCodeActivityContext context)
        {
            //Parse collection options if defined
            var capped = Capped.Get(context);

            if (capped is null)
            {
                capped = true;
            }
            var maxSize = MaxSize.Get(context);

            if (maxSize is null)
            {
                maxSize = 1024;
            }
            var maxCount = MaxCount.Get(context);

            if (maxCount is null)
            {
                maxCount = 1000;
            }

            var database         = Database.Get(context);
            var collection       = Collection.Get(context);
            var mongoProperty    = context.DataContext.GetProperties()[ParentScope.ParentContainerPropertyTag].GetValue(context.DataContext) as MongoProperty;
            var connectionString = mongoProperty.URL;
            var mongoClient      = new MongoClient(connectionString);

            mongoClient.GetDatabase(database).CreateCollectionAsync(collection, new CreateCollectionOptions
            {
                Capped       = capped,
                MaxSize      = maxSize,
                MaxDocuments = maxCount,
            }).Wait();
        }
Пример #2
0
        /// <summary>
        /// Set the MongoDB logger options based on the key/value application configuration properties.
        /// </summary>
        /// <param name="configuration">Represents a set of key/value application configuration properties. See <see cref="IConfiguration"/>.</param>
        public override void ReadFromConfiguration(IConfiguration configuration)
        {
            var mongoConfiguration = configuration?.GetSection("XLogger:MongoDB");

            if (mongoConfiguration == null)
            {
                throw new System.Exception("Could not load the adapter configuration properties. Make sure the application settings have the XLogger:MongoDB section.");
            }

            var logLevel = mongoConfiguration[nameof(LogLevel)];

            if (!string.IsNullOrEmpty(logLevel))
            {
                LogLevel = (LogLevel)int.Parse(logLevel);
            }
            OnDemand = bool.Parse(mongoConfiguration[nameof(OnDemand)] ?? OnDemand.ToString());

            DatabaseUrl    = mongoConfiguration[nameof(DatabaseUrl)] ?? DatabaseUrl;
            CollectionName = mongoConfiguration[nameof(CollectionName)] ?? CollectionName;
            Capped         = bool.Parse(mongoConfiguration[nameof(Capped)] ?? Capped.ToString());
            MaxSize        = long.Parse(mongoConfiguration[nameof(MaxSize)] ?? MaxSize.ToString());
            MaxDocuments   = long.Parse(mongoConfiguration[nameof(MaxDocuments)] ?? MaxDocuments.ToString());
        }