示例#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
            }
        }
示例#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");
        }
示例#3
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");
        }
示例#4
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);
            }
        }
示例#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);
                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);
            }
        }