public DirectoryBoilerplate(string sourceFolder, string ignoreExpression, IList <string> skipExtensions = null) { if (sourceFolder == null) { throw new ArgumentNullException(nameof(sourceFolder)); } _sourceFolder = new DirectoryInfo(sourceFolder).FullName; if (!Directory.Exists(_sourceFolder)) { throw new Exception($"source directory {sourceFolder} not found."); } var boilerplateInfoFile = Directory.GetFiles(sourceFolder, Constants.BoilerplateInfoFileName, SearchOption.AllDirectories).FirstOrDefault(); if (boilerplateInfoFile != null) { using (var stream = new FileStream(boilerplateInfoFile, FileMode.Open)) { Info = BoilerplateInfo.FromStream(stream); } } _skipExtensions = new HashSet <string>(skipExtensions ?? Info?.SkipExtensions ?? Constants.DefaultSkipExtensions, StringComparer.OrdinalIgnoreCase); _ignoreExpression = new Regex(ignoreExpression ?? Info?.IgnoreExpression ?? Constants.IgnoreGitExpression, RegexOptions.IgnoreCase | RegexOptions.Compiled); }
public ZipBoilerplate(string sourceZipName, IList <string> skipExtensions = null) { if (sourceZipName == null) { throw new ArgumentNullException(nameof(sourceZipName)); } _sourceZipName = new FileInfo(sourceZipName).FullName; if (!File.Exists(_sourceZipName)) { throw new FileNotFoundException("package not found", _sourceZipName); } try { using (var zip = ZipFile.OpenRead(sourceZipName)) { foreach (var entry in zip.Entries) { if (entry.Name.EqualsOrdinalIgnoreCase(Constants.BoilerplateInfoFileName)) { Info = BoilerplateInfo.FromStream(entry.Open()); using (var reader = new StreamReader(entry.Open())) { BoilerplateInfoJson = reader.ReadToEnd(); } } } } } catch (Exception ex) { #if DEBUG throw new Exception($"invalid ZIP package: {ex.ToString()}", ex); #else throw new Exception($"invalid ZIP package: {ex.Message}", ex); #endif } _skipExtensions = new HashSet <string>(skipExtensions ?? Info?.SkipExtensions ?? Constants.DefaultSkipExtensions, StringComparer.OrdinalIgnoreCase); }