Ejemplo n.º 1
0
        public static void RunExample()
        {
            Config config = LoadConfig(3);


            var dataProviders = new List <IDataProvider>();

            dataProviders.Add(new BogusDataProvider(config.DataGeneration));
            dataProviders.Add(new SqlDataProvider(new System.Data.SqlClient.SqlConnection(config.DataSource.Config.connectionString.ToString())));
            //create a data masker
            IDataMasker dataMasker = new DataMasker(dataProviders);

            //grab our dataSource from the config, note: you could just ignore the config.DataSource.Type
            //and initialize your own instance
            IDataSource dataSource = DataSourceProvider.Provide(config.DataSource.Type, config.DataSource);

            //enumerate all our tables
            foreach (TableConfig tableConfig in config.Tables)
            {
                //load data
                IEnumerable <IDictionary <string, object> > rows = dataSource.GetData(tableConfig);

                //get row coun
                var rowCount = dataSource.GetCount(tableConfig);


                //here you have two options, you can update all rows in one go, or one at a time.
                #region update all rows
                //update all rows
                var masked = rows.Select(row =>
                {
                    //mask the data
                    return(dataMasker.Mask(row, tableConfig));
                });

                dataSource.UpdateRows(masked, rowCount, tableConfig);
                #endregion
                //OR
                #region update row by row

                foreach (var row in rows)
                {
                    //mask the data
                    var maskedRow = dataMasker.Mask(row, tableConfig);
                    dataSource.UpdateRow(maskedRow, tableConfig);
                }

                #endregion
            }
        }
Ejemplo n.º 2
0
        private static void Execute(
            Config config)
        {
            WriteLine("Masking Data");
            UpdateProgress(ProgressType.Overall, 0, config.Tables.Count, "Overall Progress");

            var dataProviders = new List <IDataProvider>();

            dataProviders.Add(new BogusDataProvider(config.DataGeneration));
            dataProviders.Add(new SqlDataProvider(new System.Data.SqlClient.SqlConnection(config.DataSource.Config.connectionString.ToString())));

            //create a data masker
            IDataMasker dataMasker = new DataMasker(dataProviders);

            //grab our dataSource from the config, note: you could just ignore the config.DataSource.Type
            //and initialize your own instance
            IDataSource dataSource = DataSourceProvider.Provide(config.DataSource.Type, config.DataSource);

            for (int i = 0; i < config.Tables.Count; i++)
            {
                TableConfig tableConfig = config.Tables[i];


                var rowCount = dataSource.GetCount(tableConfig);
                UpdateProgress(ProgressType.Masking, 0, (int)rowCount, "Masking Progress");
                UpdateProgress(ProgressType.Updating, 0, (int)rowCount, "Update Progress");

                IEnumerable <IDictionary <string, object> > rows = dataSource.GetData(tableConfig);

                int rowIndex = 0;

                var maskedRows = rows.Select(row =>
                {
                    rowIndex++;

                    //update per row, or see below,
                    //dataSource.UpdateRow(row, tableConfig);
                    UpdateProgress(ProgressType.Masking, rowIndex);

                    return(dataMasker.Mask(row, tableConfig));
                });

                //update all rows
                dataSource.UpdateRows(maskedRows, rowCount, tableConfig, totalUpdated => UpdateProgress(ProgressType.Updating, totalUpdated));
                UpdateProgress(ProgressType.Overall, i + 1);
            }

            WriteLine("Done");
        }
Ejemplo n.º 3
0
        public void MaskDatatableAsyncTest()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("A");
            var r = dt.NewRow();

            r["A"] = "pfdsa";
            dt.Rows.Add(r);
            //so now we got a databable with one row and column.
            DataMasker dm = new DataMasker(new MockStrategy());

            dm.MaskDatatableAsync(dt, "A").Wait();
            //make sure it didn't mess with my dt
            Assert.IsNotNull(dt);
            Assert.AreEqual(expected: "pfdsa", actual: dt.Rows[0]["A"]);
        }
Ejemplo n.º 4
0
        private static void Execute(
            Config config)
        {
            WriteLine("Masking Data");
            UpdateProgress(ProgressType.Overall, 0, config.Tables.Count, "Overall Progress");

            //create a data masker
            IDataMasker dataMasker = new DataMasker(new DataGenerator(config.DataGeneration));

            //grab our dataSource from the config, note: you could just ignore the config.DataSource.Type
            //and initialize your own instance
            IDataSource dataSource = DataSourceProvider.Provide(config.DataSource.Type, config.DataSource);

            for (int i = 0; i < config.Tables.Count; i++)
            {
                TableConfig tableConfig = config.Tables[i];


                //load the data, this needs optimizing for large tables
                IEnumerable <IDictionary <string, object> > rows = dataSource.GetData(tableConfig);
                UpdateProgress(ProgressType.Masking, 0, rows.Count(), "Masking Progress");
                UpdateProgress(ProgressType.Updating, 0, rows.Count(), "Update Progress");
                int rowIndex = 0;
                foreach (IDictionary <string, object> row in rows)
                {
                    //mask each row
                    dataMasker.Mask(row, tableConfig);
                    rowIndex++;

                    //update per row, or see below,
                    //dataSource.UpdateRow(row, tableConfig);
                    UpdateProgress(ProgressType.Masking, rowIndex);
                }


                //update all rows
                dataSource.UpdateRows(rows, tableConfig, totalUpdated => UpdateProgress(ProgressType.Updating, totalUpdated));
                UpdateProgress(ProgressType.Overall, i + 1);
            }

            WriteLine("Done");
        }
Ejemplo n.º 5
0
        public static void Example1()
        {
            Config      config     = LoadConfig(1);
            IDataMasker dataMasker = new DataMasker(new DataGenerator(config.DataGeneration));
            IDataSource dataSource = DataSourceProvider.Provide(config.DataSource.Type, config.DataSource);

            foreach (TableConfig tableConfig in config.Tables)
            {
                IEnumerable <IDictionary <string, object> > rows = dataSource.GetData(tableConfig);
                foreach (IDictionary <string, object> row in rows)
                {
                    dataMasker.Mask(row, tableConfig);

                    //update per row
                    //dataSource.UpdateRow(row, tableConfig);
                }

                //update all rows
                dataSource.UpdateRows(rows, tableConfig);
            }
        }
Ejemplo n.º 6
0
        private async Task ApplyMask(Dictionary <string, Tuple <MaskingOptions, string> > maskingInformation, IEnumerable <DataRow> dataRows)
        {
            Console.Out.WriteLine("Combining multiple strategies into one...");
            List <IMaskingStrategy> strats = new List <IMaskingStrategy>();

            foreach (var item in maskingInformation)
            {
                string         colName  = item.Key;
                MaskingOptions option   = item.Value.Item1;
                string         method   = item.Value.Item2;
                var            strategy = MaskingStrategyFactory.CreateStrategyFromMaskingOption(option, method);
                strategy.Initialize(dataRows.First().Table, colName); //'must call this here for aggregatre strategies
                Console.Out.WriteLine($"Applying datamask of type {option} to column {colName}");
                strats.Add(strategy);
            }
            IMaskingStrategy CombinedStrategy = MaskingStrategyFactory.CombineStrategiesIntoSingleStrategy(strats);
            DataMasker       masker           = new DataMasker(CombinedStrategy);
            await masker.MaskDataRowEnumerableAsync(dataRows, "allcols");

            Console.Out.WriteLine("Strategies executed.");
        }
Ejemplo n.º 7
0
        public static void Example1()
        {
            Config      config     = LoadConfig(1);
            IDataMasker dataMasker = new DataMasker(new DataGenerator(config.DataGeneration));
            IDataSource dataSource = DataSourceProvider.Provide(config.DataSource.Type, config.DataSource);

            foreach (TableConfig tableConfig in config.Tables)
            {
                IEnumerable <IDictionary <string, object> > rows = dataSource.GetData(tableConfig);
                var rowCount = dataSource.GetCount(tableConfig);

                var masked = rows.Select(row =>
                {
                    return(dataMasker.Mask(row, tableConfig));

                    //update per row
                    //dataSource.UpdateRow(row, tableConfig);
                });

                //update all rows
                dataSource.UpdateRows(masked, rowCount, tableConfig);
            }
        }
Ejemplo n.º 8
0
 public void DataMaskerConstructorTest()
 {
     DataMasker dm = new DataMasker(new MockStrategy());
 }