public Delegate GetFormatter <T, TParameters>( // TODO: // Include<T,TParameters> include = null, Include <T> include = null, Func <ChainNode, IEnumerable <MemberInfo> > leafRule = null, Action <RulesDictionary <T> > config = null, bool useToString = false, string dateTimeFormat = null, string floatingPointFormat = null, bool objectAsArray = false, bool handleEmptyObjectLiteral = true, bool handleEmptyArrayLiteral = true, Func <StringBuilder, bool> nullSerializer = null, bool handleNullProperty = true, Func <StringBuilder, bool> nullArraySerializer = null, bool handleNullArrayProperty = true, string rootAsProperty = null, Action <IJsonRootPropertyAppender, TParameters> rootPropertyAppender = null, bool rootHandleNull = true, bool rootHandleEmptyLiteral = true, int stringBuilderCapacity = 16) { if (formatter != null) { return(formatter); } else { ChainNode root = IncludeExtensions.CreateChainNode(include); if (include == null) { var type = typeof(T); if (type.IsAssociativeArrayType()) { root.AppendLeafs(leafRule ?? LeafRuleManager.DefaultEfCore); } } else { if (leafRule != null) { root.AppendLeafs(leafRule); } } formatter = JsonManager.ComposeFormatter <T, TParameters>(root: root, config: config, useToString: useToString, dateTimeFormat: dateTimeFormat, floatingPointFormat: floatingPointFormat, objectAsArray: objectAsArray, handleEmptyObjectLiteral: handleEmptyObjectLiteral, handleEmptyArrayLiteral: handleEmptyArrayLiteral, nullSerializer: nullSerializer, handleNullProperty: handleNullProperty, nullArraySerializer: nullArraySerializer, handleNullArrayProperty: handleNullArrayProperty, rootAsProperty: rootAsProperty, rootPropertyAppender: rootPropertyAppender, rootHandleNull: rootHandleNull, rootHandleEmptyLiteral: rootHandleEmptyLiteral, stringBuilderCapacity); return(formatter); } }
public AssetsSearchWithExtension(string _rootpath, string[] SelfExtension) : base(_rootpath) { foreach (var extension in SelfExtension) { IncludeExtensions.Add(extension); } }
public ModelSearch(string _rootpath) : base(_rootpath) { foreach (var extension in SelfExtension) { IncludeExtensions.Add(extension); } }
public async Task <FileStatistics> ProcessDir(string path, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var info = new DirectoryInfo(path); var dirs = info.GetDirectories(); var files = info.GetFiles(); if (IncludeExtensions.Count > 0) { files = files .Where(p => IncludeExtensions.Contains(Path.GetExtension(p.Name))) .ToArray(); } var dirTasks = dirs.Select(p => Task.Run( () => ProcessDir(Path.Combine(path, p.Name), cancellationToken), cancellationToken)); var fileTasks = files.Select(p => Task.Run( () => ProcessFile(Path.Combine(path, p.Name), cancellationToken), cancellationToken)); var allTasks = dirTasks.Concat(fileTasks).ToArray(); await Task.WhenAll(allTasks).ConfigureAwait(false); var statistics = new FileStatistics() { Count = 0, Size = 0, Lines = files.Length }; statistics = allTasks.Aggregate(statistics, (acc, task) => acc.CombineWith(task.Result)); AddFileStatistics(path, true, statistics); return(statistics); }
string[] FilterFiles(string[] files) { return(files.Where(p => { var extension = GetFullFileExtension(Path.GetFileName(p)); return IncludeExtensions.Contains(extension) && !ExcludeExtensions.Contains(extension); }).ToArray()); }
public void Load(ISettingsStore settings) { var model = FileSettings.Load(settings); IncludeFolders.Load(model); IncludeExtensions.Load(model); ExcludeFolders.Load(model); ExcludePatterns.Load(model); }
public static Func <IEnumerable <T>, TP, string> ComposeEnumerableFormatter <T, TP>( this Include <T> include , Action <RulesDictionary <T> > config = null , bool useToString = false , string dateTimeFormat = null , string floatingPointFormat = null , bool objectAsArray = false , bool handleEmptyObjectLiteral = true , bool handleEmptyArrayLiteral = true , Func <StringBuilder, bool> nullSerializer = null , bool handleNullProperty = true , Func <StringBuilder, bool> nullArraySerializer = null , bool handleNullArrayProperty = true , string rootAsProperty = null , Action <IJsonRootPropertyAppender, TP> rootPropertyAppender = null , bool rootHandleNull = true , bool rootHandleEmptyLiteral = true , int stringBuilderCapacity = 16 , Func <LambdaExpression, Delegate> compile = null , bool doCompileInnerLambdas = true) { if (compile == null) { compile = StandardCompile; } ChainNode root = IncludeExtensions.CreateChainNode(include); if (include == null && config == null) { var type = typeof(T); if (type.IsAssociativeArrayType()) { root.AppendLeafs(); } } return(ComposeEnumerableFormatter(root: root, config: config, useToString: useToString, dateTimeFormat: dateTimeFormat, floatingPointFormat: floatingPointFormat, objectAsArray: objectAsArray, handleEmptyObjectLiteral: handleEmptyObjectLiteral, handleEmptyArrayLiteral: handleEmptyArrayLiteral, nullSerializer: nullSerializer, handleNullProperty: handleNullProperty, nullArraySerializer: nullArraySerializer, handleNullArrayProperty: handleNullArrayProperty, rootAsProperty: rootAsProperty, rootPropertyAppender: rootPropertyAppender, rootHandleNull: rootHandleNull, rootHandleLiteral: rootHandleEmptyLiteral, stringBuilderCapacity: stringBuilderCapacity, compile: compile, doCompileInnerLambdas: doCompileInnerLambdas)); }
public void Save(ISettingsStore settings) { var model = new FileSettings(); IncludeFolders.Populate(ref model); IncludeExtensions.Populate(ref model); ExcludeFolders.Populate(ref model); ExcludePatterns.Populate(ref model); model.Save(settings); if (!_hasChanges) { _hasChanges = IncludeFolders.IsDirty || IncludeExtensions.IsDirty || ExcludeFolders.IsDirty || ExcludePatterns.IsDirty; } }
public ConversionOptions GetConfiguration() { var options = new ConversionOptions(); if (Path.HasValue()) { options.Paths = Path.Values; } if (File.HasValue()) { options.Files = File.Values; } if (List.HasValue()) { options.ListFile = List.Value(); } if (options.Paths.Count == 0 && options.Files.Count == 0 && String.IsNullOrEmpty(options.ListFile)) { throw new ConfigurationException("Nothing to process, must specify one of --path, --file or --list"); } if (IndentStyle.HasValue()) { var style = IndentStyle.Value().ToLower(); if (style == "tabs") { options.Indentation = IndentationStyle.Tabs; } else if (style == "spaces") { options.Indentation = IndentationStyle.Spaces; } else if (style == "leave") { options.Indentation = IndentationStyle.Leave; } else { throw new ConfigurationException($"'{style}' is an invalid indentation style"); } } if (LineEndings.HasValue()) { var lineEndingStyle = LineEndings.Value().ToLower(); if (lineEndingStyle == "crlf") { options.LineEndingStyle = LineEnding.CRLF; } else if (lineEndingStyle == "lf") { options.LineEndingStyle = LineEnding.LF; } else { throw new ConfigurationException("Line Endings must be crlf or lf"); } } options.StripTrailingSpaces = StripTrailingSpaces.HasValue(); // no point going any further if one of the change options isn't actually specified if (options.StripTrailingSpaces == false && options.Indentation == IndentationStyle.Leave && options.LineEndingStyle == LineEnding.Leave) { throw new ConfigurationException("Nothing to do, you must specify one of --strip-trailing-spaces, --line-endings or --indent"); } if (TabWidth.HasValue()) { if (!Int32.TryParse(TabWidth.Value(), out int tabWidth)) { throw new ConfigurationException("tabwidth must be a valid number"); } options.TabWidth = tabWidth; } if (IncludeExtensions.HasValue()) { options.IncludeExtensions = ParseFileExtensionsOption(IncludeExtensions.Values); } if (ExcludeExtensions.HasValue()) { options.ExcludeExtensions = ParseFileExtensionsOption(ExcludeExtensions.Values); } if (ExcludeFolders.HasValue()) { options.ExcludeFolders = ExcludeFolders.Values; } // the presence of recurse|dryrun means it's on, there is no value options.Recurse = Recurse.HasValue(); options.DryRun = DryRun.HasValue(); options.Verbose = Verbose.HasValue(); return(options); }