Esempio n. 1
0
 public static MongoDbAuditStoreProvider WithServer(this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider,
                                                    string serverName)
 {
     if (serverName.Contains("mongodb://"))
     {
         throw new ArgumentException("Please specify servername only");
     }
     @mongoDbAuditStoreProvider.ServerName = serverName;
     return(@mongoDbAuditStoreProvider);
 }
Esempio n. 2
0
        public static MongoDbAuditStoreProvider Start(this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider)
        {
            var settings = new MongoClientSettings
            {
                ClusterConfigurator = cb => cb.ConfigureCluster(c => c.With(serverSelectionTimeout:
                                                                            TimeSpan.FromMilliseconds(@mongoDbAuditStoreProvider.TimeoutMilliseconds))),
                Server = new MongoServerAddress(@mongoDbAuditStoreProvider.ServerName)
            };

            @mongoDbAuditStoreProvider.Client = new MongoClient(settings);
            return(@mongoDbAuditStoreProvider);
        }
Esempio n. 3
0
        public void Main(string[] args)
        {
            var config = new ConfigurationBuilder(@"C:\VSProjects\Precisionsoft\Decidify\trunk\Decidify.UI")
                .AddJsonFile("config.json");
            var mongoProvider = new MongoDbAuditStoreProvider()
                .WithConfiguration(config.Build())
                .Start();

            using (var myDbContext = new MyDBContext(mongoProvider))
            {
                myDbContext.Database.EnsureDeleted();
                myDbContext.Database.EnsureCreated();

                var customer = new Customer()
                {
                    FirstName = "TestFirstName",
                    LastName = "TEstLAstNAme"
                };
                myDbContext.Customers.Add(customer);

                var auditablePropCount =
                    customer.GetType()
                        .GetProperties()
                        .Count(p => !p.GetCustomAttributes(typeof (DoNotAudit), true).Any());

                var nonAuditablePropCount =
                    customer.GetType()
                        .GetProperties()
                        .Count(p => p.GetCustomAttributes(typeof(DoNotAudit), true).Any());
                myDbContext.SaveChanges("Test User");

                Console.WriteLine($"Added object with {auditablePropCount} auditable properties and {nonAuditablePropCount} non-auditable properties." );

                var auditLogs = myDbContext.GetAuditLogs()?.ToList();
                Console.WriteLine($"Audit log contains {auditLogs?.Count()} entries.");
                //foreach (var auditLog in myDbContext.GetAuditLogs())
                //{
                //    Console.WriteLine($"AuditLogId:{auditLog.AuditLogId} TableName:{auditLog.TableName} ColumnName:{auditLog.ColumnName} OriginalValue:{auditLog.OriginalValue} NewValue:{auditLog.NewValue} EventDateTime:{auditLog.EventDateTime}");
                //}

                //if (auditLogs.Count() == auditablePropCount)
                //    Console.WriteLine("Test succeeded.");
                //else
                //    throw new Exception("Something is wrong.");

                Console.Read();
                myDbContext.Database.EnsureDeleted();
            }
        }
Esempio n. 4
0
        public static MongoDbAuditStoreProvider WithConfiguration(
            this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider, IConfiguration configuration)
        {
            var configSection = configuration.GetSection($"{nameof(MongoDbAuditStoreProvider)}");

            if (configSection == null)
            {
                throw new ArgumentException(
                          $"Not configuration section named {nameof(MongoDbAuditStoreProvider)} found.");
            }
            if (!configSection.GetChildren().Any())
            {
                throw new ArgumentException(
                          $"Configuration section {nameof(MongoDbAuditStoreProvider)} did not contain any settings.");
            }

            var serverName          = configSection["Server"];
            var timeoutMilliseconds = configSection["TimeoutMilliseconds"];
            var databaseName        = configSection["DatabaseName"];
            var collectionName      = configSection["CollectionName"];

            @mongoDbAuditStoreProvider.ServerName = string.IsNullOrEmpty(serverName)
                ? @mongoDbAuditStoreProvider.ServerName
                : serverName;
            @mongoDbAuditStoreProvider.TimeoutMilliseconds = string.IsNullOrEmpty(timeoutMilliseconds)
                ? @mongoDbAuditStoreProvider.TimeoutMilliseconds
                : int.Parse(timeoutMilliseconds);
            @mongoDbAuditStoreProvider.DatabaseName = string.IsNullOrEmpty(databaseName)
                ? @mongoDbAuditStoreProvider.DatabaseName
                : databaseName;
            @mongoDbAuditStoreProvider.CollectionName = string.IsNullOrEmpty(collectionName)
                ? @mongoDbAuditStoreProvider.CollectionName
                : collectionName;

            return(@mongoDbAuditStoreProvider);
        }
Esempio n. 5
0
 public static MongoDbAuditStoreProvider WithCollection(
     this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider, string collectionName)
 {
     @mongoDbAuditStoreProvider.CollectionName = collectionName;
     return(@mongoDbAuditStoreProvider);
 }
Esempio n. 6
0
 public static MongoDbAuditStoreProvider WithDatabase(this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider,
                                                      string databaseName)
 {
     @mongoDbAuditStoreProvider.DatabaseName = databaseName;
     return(@mongoDbAuditStoreProvider);
 }
Esempio n. 7
0
 public static MongoDbAuditStoreProvider WithTimeOut(this MongoDbAuditStoreProvider @mongoDbAuditStoreProvider,
                                                     int timeoutMilliseconds)
 {
     @mongoDbAuditStoreProvider.TimeoutMilliseconds = timeoutMilliseconds;
     return(@mongoDbAuditStoreProvider);
 }