private void modeApply(string[] obj) { //required options: name of source (filename or schema.table), the column to apply it on, and the type of mask to apply (must be defined in the maskingoptions enum in the enumerations file) //optional option: a method to use with the masking strategy, check the actual maskingstrategies to see how the method is used (for replace the 'method' is simply the string value to use in the replacement action if (!obj.Length.Between(3, 4)) { Console.Error.WriteLine("Argument error, correct usage: rds mask -ADD {sourcename} {masktype} [method]"); } string filename = obj[0] + Settings.DataSourceFileExtension; string colName = obj[1]; string type = obj[2]; string method = obj.ElementAtOrDefault(3); //null values will be passed on, this is intended MaskingOptions typeEnum = (MaskingOptions)Enum.Parse(typeof(MaskingOptions), type, ignoreCase: true); Tuple <MaskingOptions, string> dictValue = new Tuple <MaskingOptions, string>(typeEnum, method); var dirinf = new DirectoryInfo($"{Directory.GetCurrentDirectory()}\\{Settings.RdsDirectoryName}"); var sourceInf = dirinf.EnumerateFiles().Where( file => file.Name == filename).FirstOrDefault(); if (sourceInf == null) { Console.Error.Write($"File with name {filename} could not be found."); return; } DataSourceInformation dsi = DataSourceInformation.LoadFromFile(sourceInf.FullName); dsi.MaskingInformation.Add(colName, dictValue); dsi.SaveToFile(sourceInf.FullName); }
public static void Run() { //ExStart:ManualImageMasking // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); Console.WriteLine("Running example ManualImageMasking"); string sourceFileName = dataDir + "Colored by Faith_small.png"; string outputFileName = dataDir + "Colored by Faith_small_manual.png"; GraphicsPath manualMask = new GraphicsPath(); Figure firstFigure = new Figure(); firstFigure.AddShape(new EllipseShape(new RectangleF(100, 30, 40, 40))); firstFigure.AddShape(new RectangleShape(new RectangleF(10, 200, 50, 30))); manualMask.AddFigure(firstFigure); GraphicsPath subPath = new GraphicsPath(); Figure secondFigure = new Figure(); secondFigure.AddShape( new PolygonShape( new PointF[] { new PointF(310, 100), new PointF(350, 200), new PointF(250, 200) }, true)); secondFigure.AddShape(new PieShape(new RectangleF(10, 10, 80, 80), 30, 120)); subPath.AddFigure(secondFigure); manualMask.AddPath(subPath); using (RasterImage image = (RasterImage)Image.Load(sourceFileName)) { MaskingOptions maskingOptions = new MaskingOptions() { Method = SegmentationMethod.Manual, Args = new ManualMaskingArgs { Mask = manualMask }, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType .TruecolorWithAlpha, Source = new StreamSource( new MemoryStream()) }, }; MaskingResult[] maskingResults = new ImageMasking(image).Decompose(maskingOptions); using (Image resultImage = maskingResults[1].GetImage()) { resultImage.Save(outputFileName); } } Console.WriteLine("Finished example ManualImageMasking"); }
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."); }
public static void Run() { Console.WriteLine("Running example AutoImageMasking"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); string sourceFileName = dataDir + "Colored by Faith_small.png"; string inputPointsFileName = dataDir + "Colored by Faith_small.dat"; AutoMaskingArgs maskingArgs = new AutoMaskingArgs(); FillInputPoints(inputPointsFileName, maskingArgs); string outputFileName = dataDir + "Colored by Faith_small_auto.png"; using (RasterImage image = (RasterImage)Image.Load(sourceFileName)) { MaskingOptions maskingOptions = new MaskingOptions() { Method = SegmentationMethod.GraphCut, Args = maskingArgs, Decompose = false, ExportOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha, Source = new StreamSource(new MemoryStream()) }, }; MaskingResult[] maskingResults = new ImageMasking(image).Decompose(maskingOptions); using (Image resultImage = maskingResults[1].GetImage()) { resultImage.Save(outputFileName); } } Console.WriteLine("Finished example AutoImageMasking"); }
/// <summary> /// Destructure.ByMaskingProperties takes one or more property names, e.g. "Hash", and uses them to determine which /// properties are masked when an object of is destructured by serilog. /// </summary> /// <param name="configuration">The logger configuration to apply configuration to.</param> /// <param name="opts"><see cref="Action"/> to configure <see cref="MaskingOptions"/>.</param> /// <returns>An object allowing configuration to continue.</returns> public static LoggerConfiguration ByMaskingProperties(this LoggerDestructuringConfiguration configuration, Action<MaskingOptions> opts) { var maskingOptions = new MaskingOptions(); opts(maskingOptions); return configuration.With(new DestructureByMaskingPolicy(maskingOptions)); }
public static IMaskingStrategy CreateStrategyFromMaskingOption(MaskingOptions option, string maskingMethod = null) { IMaskingStrategy ret = m_OptionToStrategyFactoryMethods[option](maskingMethod); return(ret); }