public FilePath Move(DirPath target) { var targetFile = target.CombineFile(Name); File.Move(Path, targetFile.Path); return(targetFile); }
private void AssertWebJob(DirPath artifactsSourceDir, string projectName, ILogger log) { var appSettingsFile = artifactsSourceDir.ToFile("appSettings.json"); if (appSettingsFile.Exists() == false) { log.Debug($"{projectName.Highlight()} not WebJob."); return; } var appSettingsRawContent = appSettingsFile.ReadAllText(IfNotExists.Mute).ToLowerInvariant();//lowercase to ignore case when accessing properties var appSettingsJsonDoc = JsonDocument.Parse(appSettingsRawContent); if (appSettingsJsonDoc.RootElement.TryGetProperty("webjob", out JsonElement webJobElement) == false) { log.Verbose($"{projectName.Highlight()} not WebJob. Has appsettings file but Property 'webjob' not found\r\n{appSettingsRawContent}"); return; } var webJobType = webJobElement.GetString(); log.Success($"{projectName.Highlight()} is {webJobType} WebJob!"); using var tempDir = new TempDir(); //move content to temp dir since we're copying to sub path of origin artifactsSourceDir.CopyTo(tempDir.Root, true); artifactsSourceDir.CleanIfExists(); var webJobTargetDir = artifactsSourceDir.Add("app_data", "jobs", webJobType, projectName); tempDir.Root.CopyTo(webJobTargetDir, true); }
public FilePath CopyTo(DirPath targetDir) { var target = targetDir.CombineFile(Name); CopyTo(target); return(target); }
/// <summary>This method is used to replace default (0) values for most property/field here with the value from the given <paramref name="other"/> instance.</summary> public SetupInfo MapDefaultsTo(SetupInfo other) { if (ClientNVS.IsNullOrEmpty()) { ClientNVS = other.ClientNVS.ConvertToReadOnly(); } DirPath = DirPath.MapNullOrEmptyTo(other.DirPath); ClientName = ClientName.MapNullOrEmptyTo(other.ClientName); FileNamePrefix = FileNamePrefix.MapNullOrEmptyTo(other.FileNamePrefix); CreateDirectoryIfNeeded = CreateDirectoryIfNeeded.MapDefaultTo(other.CreateDirectoryIfNeeded); MaxDataBlockSize = MaxDataBlockSize.MapDefaultTo(other.MaxDataBlockSize); NominalMaxFileSize = NominalMaxFileSize.MapDefaultTo(other.NominalMaxFileSize); FileIndexNumRows = FileIndexNumRows.MapDefaultTo(other.FileIndexNumRows); MaxFileRecordingPeriod = MaxFileRecordingPeriod.MapDefaultTo(other.MaxFileRecordingPeriod); MinInterFileCreateHoldoffPeriod = MinInterFileCreateHoldoffPeriod.MapDefaultTo(other.MinInterFileCreateHoldoffPeriod); MinNominalFileIndexWriteInterval = MinNominalFileIndexWriteInterval.MapDefaultTo(other.MinNominalFileIndexWriteInterval); MinNominalWriteAllInterval = MinNominalWriteAllInterval.MapDefaultTo(other.MinNominalWriteAllInterval); I8Offset = I8Offset.MapDefaultTo(other.I8Offset); I4Offset = I4Offset.MapDefaultTo(other.I4Offset); I2Offset = I2Offset.MapDefaultTo(other.I2Offset); return(this); }
public ProgramTests(ITestOutputHelper output) { var log = new NullLogger(); log.MessageLogged += (lvl, msg, e) => { output.WriteLine($"[{lvl}] {msg}\r\n{e}".TrimEnd('\n').TrimEnd('\r')); }; _dispatcher = new ConfigFileTransformDispatcher(log); _testRootDir = typeof(ProgramTests).Assembly.Location.ToFile().Directory; _artifactsSourceDir = _testRootDir.Add("Source"); }
private void CleanExcessiveCompileArtifacts(DirPath artifactsSourceDir, ILogger log) { _excessivePublishDirs.ForEachParallel(dir => { var excessiveDir = artifactsSourceDir.Add(dir); log.Verbose($"Cleaning excessive build output dir: {excessiveDir.FullName()}"); return(excessiveDir.DeleteIfExists()); }); }
private void CopyNugetPackages(FilePath projectFile, DirPath releaseArtifactsDir) { try { projectFile.Directory.Add("bin").EnumerateFiles("*.nupkg", SearchOption.AllDirectories) .ForEachParallel(nuget => nuget.CopyTo(releaseArtifactsDir)); } catch (Exception e) { throw new CliException($"Copy Nuget packages for {projectFile.Name} failed with {e.Message}"); } }
protected IReadOnlyList <FilePath> ResolveFiles(DirPath slnDir, string filter, string name, ILogger log) { log.Verbose($"Resolving {name.Highlight()} with filter: {filter.Highlight()}"); try { return(slnDir.EnumerateFiles(filter, SearchOption.AllDirectories).ToList());; } catch (IOException e) { log.Warning($"{e.GetType().Name.RemoveSuffix("Exception")}: {e.Message} when resolving {name.Highlight()} with {filter.Highlight()}"); return(new List <FilePath>()); } }
private void RemoveReleaseAssemblies(DirPath artifactsSourceDir, string projectName, ILogger log) { log.Info($"Removing Release Assemblies"); artifactsSourceDir.EnumerateFiles($"{projectName}.dll", SearchOption.AllDirectories) .Concat(artifactsSourceDir.EnumerateFiles($"{projectName}.pdb", SearchOption.AllDirectories)) .OrderBy(file => file.FullName()) .ForEach(file => { log.Verbose($"Removing {file.Name.Highlight()}"); file.DeleteIfExists(); }); }
private void CopyReleaseArtifacts(DirPath artifactsSourceDir, DirPath artifactsTargetDir, ILogger log) { log.Debug($"Copying RELEASE artifacts for {artifactsTargetDir.Name.Highlight()} from {artifactsSourceDir.FullName()} to {artifactsTargetDir.FullName().Highlight()}"); try { artifactsSourceDir.CopyTo(artifactsTargetDir, true); } catch (Exception e) { throw new CliException($"Copy BUILD artifacts for {artifactsTargetDir.NameWoExtension} failed with {e.Message}"); } }
private IReadOnlyList <FilePath> ResolveReleaseProjects(DirPath slnDir, string releaseProjectFilter, string excludeProjectFilter, ILogger log) { var releaseProjects = ResolveFiles(slnDir, releaseProjectFilter.TrimEnd('.').EnsureSuffix(".csproj"), "Release Projects", log).ToList(); var excludeProjects = ResolveFiles(slnDir, excludeProjectFilter.TrimEnd('.').EnsureSuffix(".csproj"), "Exclude Projects", log).ToList(); for (var i = 0; i < releaseProjects.Count; i++) { if (excludeProjects.Contains(testPrj => testPrj.FullName().Equals(releaseProjects[i].FullName(), StringComparison.InvariantCultureIgnoreCase))) { releaseProjects.RemoveAt(i); } } return(releaseProjects); }
private void ProcessDllsInBinFolderRoles(DirPath artifactsSourceDir, IReadOnlyList <string> dllsInBinFolderRoles, ILogger log) { artifactsSourceDir.EnumerateDirectories().ForEachParallel(dir => { var roleCandidate = dir.Name.Substring(dir.Name.LastIndexOf(".", StringComparison.Ordinal) + 1); if (dllsInBinFolderRoles.Contains(roleCandidate, StringComparer.InvariantCultureIgnoreCase)) { log.Debug($"Moving dlls to bin folder for {dir.Name.Highlight()}."); var binDir = dir.Add("bin").CreateIfNotExists(); dir.EnumerateFiles("*.dll").ForEachParallel(dll => dll.MoveTo(binDir)); dir.EnumerateFiles("*.pdb").ForEachParallel(pdb => pdb.MoveTo(binDir)); } }); }
/// <summary> /// Return number of files copied /// </summary> /// <param name="target"></param> /// <param name="overwrite"></param> /// <returns>Number of files copied</returns> public int CopyDirectory(DirPath target) { int files = 0; target.CreateDirectory(); foreach (var f in GetFiles()) { f.CopyTo(target.CombineFile(f.FileName)); files += 1; } foreach (var d in GetDirectories()) { files += d.CopyDirectory(target.CombineDir(d.Name)); } return(files); }
private static void CleanUpFiles() { DirPath dirPath = System.IO.Path.GetFullPath(@".\cef\Release\swiftshader"); if (dirPath.Exists) { dirPath.Delete(); } FilePath libEGLPath = System.IO.Path.GetFullPath(@".\cef\Release\libEGL.dll"); libEGLPath.DeleteIfExists(); FilePath libGLESv2Path = System.IO.Path.GetFullPath(@".\cef\Release\libGLESv2.dll"); libGLESv2Path.DeleteIfExists(); }
public Tuple <int, double> GetBanHero(int index) { lock (ImageProcessingHelper.GDILock) { var imageUtil = new ImageUtils(); var path = Path.Combine(App.AppPath, "Images\\Heroes"); var path2 = string.Format("{0}x{1}", App.AppSetting.Position.Width, App.AppSetting.Position.Height); FilePath text = Path.Combine(path, path2, "Ban", string.Format("{0}_{1:yyyyMMddhhmmss}.jpg", index, DateTime.Now)); if (!text.GetDirPath().Exists) { Directory.CreateDirectory(text.GetDirPath()); } using (var bitmap = imageUtil.CaptureBanArea(App.AppSetting.Position.BanPositions[index])) { bitmap.Save(text); } Tuple <int, double> result = null; using (var bitmap = new Bitmap(text)) { var path1 = Path.Combine(App.AppPath, "Images\\Heroes"); var path12 = string.Format("{0}x{1}", App.AppSetting.Position.Width, App.AppSetting.Position.Height); DirPath text2 = Path.Combine(path1, path12, "Ban\\Out"); if (!text2.Exists) { Directory.CreateDirectory(text2); } result = HeroIdentifier.Identify(bitmap); FilePath resultFilePath = Path.Combine(text2, result.Item1 + " " + result.Item2 + ".bmp"); if (App.Debug) { bitmap.Save(resultFilePath); } } if (!App.Debug) { text.DeleteIfExists(); } return(result); } }
public Recognizer(OcrLanguage language, string sourceDirectory = null) { _engine = OcrEngine.CreateEngine(language); TempDirectoryPath = sourceDirectory + @"\Test\"; if (!Directory.Exists(TempDirectoryPath)) { Directory.CreateDirectory(TempDirectoryPath); } var direLeft = TempDirectoryPath + @"left\"; if (!Directory.Exists(direLeft)) { Directory.CreateDirectory(direLeft); } var direRight = TempDirectoryPath + @"right\"; if (!Directory.Exists(direRight)) { Directory.CreateDirectory(direRight); } }
private SemVersion ResolveVersionFromGit(DirPath solutionDir, ILogger log) { using var repo = new Repository(solutionDir.FullName()); var shortHash = repo.Commits.First().Sha.Substring(0, 7); var tags = repo.Tags; var gitVersions = tags.Select(tag => SemVersion.Parse(tag.FriendlyName)).ToList(); log.Verbose($"Git tags found:"); gitVersions.ForEach(tag => log.Verbose(tag.ToString())); if (gitVersions.Any() == false) { log.Warning($"No tags found in git repo in {solutionDir}"); return(new SemVersion(0, 0, 0)); } var latestVersion = gitVersions.Select(v => new SemVersion(v)).Max(); latestVersion.Metadata += shortHash; log.Verbose($"Version resolved from git to {latestVersion.SemVer20String.Highlight()}"); return(latestVersion); }
private void btnBrowseDirFileToRun_Click(object sender, RoutedEventArgs e) { // Create OpenFileDialog var dlg = new OpenFileDialog(); dlg.InitialDirectory = DirPath; // Display OpenFileDialog by calling ShowDialog method var result = dlg.ShowDialog(); // Get the selected file name and save the path if (result == true) { DirFileName = dlg.FileName; var directory = DirPath.Split('\\'); var file = DirFileName.Split('\\'); var i = 0; var subFileName = ""; foreach (var word in file) { if (i > directory.Length - 1) { subFileName += "\\" + file[i]; } i++; } lblDirFilePath.Content = "File: " + subFileName; DirFileNameWithExtraDir = subFileName; isEnabledDir = true; if (parent.getSelectedClients().Count != 0) { IsEnabledDirTransfernRun = true; btnTransfernRunDir.IsEnabled = true; btnTransferDir.IsEnabled = true; } } }
public void Demo() { //Creating paths (nothing is changed on disk) FilePath file = (FilePath)@"C:\Hello\World"; DirPath directory = file.Parent; // C:\Hello RelFilePath relative = file - directory; // World relative = relative.AppendPath(".txt"); // World.txt DirPath otherDirectory = (DirPath)@"C:\New"; FilePath newFile = otherDirectory + relative; // C:\New\World.txt FilePath pdfFile = newFile.GetWithExtension("pdf"); // C:\New\World.pdf DirPath otherDir = otherDirectory.CombineDir("Strong", "Typed"); // C:\New\Strong\Typed FilePath otherFile = otherDir.CombineFile("Test.txt"); // C:\New\Strong\Typed\Test.txt //Exploring disk IEnumerable <FilePath> files = directory.GetFiles("*", SearchOption.AllDirectories); IEnumerable <DirPath> directories = directory.GetDirectories(); var baseName = file.NameWithoutExtension; bool fileExists = file.Exists(); bool dirExists = directory.Exists(); //Operations on disk directory.CreateDirectory(); file.DeleteFile(); file.WriteAllText("Hello World"); file.ClearReadOnlyAttribute(); file.SetLastWriteTimeUtc(DateTime.UtcNow); directory.DeleteDir(); file.Move(pdfFile); newFile.CopyTo(otherFile); var newTarget = newFile.CopyTo(otherDir); // otherDir + newFile.Name; otherDir.CopyDirectory(otherDirectory); //Use path as a string File.ReadAllBytes(file.Path); }
protected void InitDir(DirPath dir, ILogger log) { if (dir.Exists()) { log.Debug($"Cleaning {dir.FullName()}"); try { Repeat.Task(() => dir.CleanIfExists()) .WithOptions(o => { o.MaxTries = 3; o.RetryDelay = 3.Seconds(); }).UntilNoExceptions(); } catch (DirectoryNotFoundException) { //ignore } } else { dir.CreateIfNotExists(); } }
public void AddFile(string filePath, Stream stream) { pathProvider.WriteFile(DirPath.CombineWith(filePath), stream); }
public void AddFile(string filePath, string contents) { pathProvider.WriteFile(DirPath.CombineWith(filePath), contents); }
protected override IVirtualDirectory GetDirectoryFromBackingDirectoryOrDefault(string directoryName) { var subDir = DirPath.CombineWith(directoryName); return(new InMemoryVirtualDirectory(pathProvider, subDir)); }
public override IVirtualFile GetFile(string virtualPath) { return(pathProvider.GetFile(DirPath.CombineWith(virtualPath))); }
/// <summary> /// ハッシュ値算出 /// </summary> /// <remarks>重複チェックのために必要です。</remarks> public override int GetHashCode() { return(GetType().GetHashCode() ^ DirPath.GetHashCode()); }
protected override IVirtualDirectory GetDirectoryFromBackingDirectoryOrDefault(string directoryName) { return(new AzureAppendBlobVirtualDirectory(this.PathProvider, PathProvider.SanitizePath(DirPath.CombineWith(directoryName)))); }
public void Move(DirPath target) => Directory.Move(Path, target.Path);
public bool Transform(DirPath rootDir, params string[] environments) { return(Transform(rootDir, LogLevel.Verbose, environments)); }
public bool Transform(DirPath rootDir, LogLevel noChangesLogLevel, params string[] environments) { //arrange var operations = ScanForTransformOperations(rootDir, environments); //Act var results = environments.ForEach(env => { LogHeader(LogLevel.Verbose, $"Config Transform Operations for {env.Highlight()}"); return(operations[env].ForEachParallel(op => { var result = op.Transform(); if (result.Success) { if (result.WasUpdated) { _log.Success($@"Transform succeed for: {result}"); _log.Debug($"{nameof(result.ConfigFileAfterTransform).Highlight()}:\r\n{result.ConfigFileAfterTransform}"); } else { _log.Write(noChangesLogLevel, $@"Transform succeed but config file was NOT updated for: {result}"); _log.Debug($@"{nameof(result.ConfigFileBeforeTransform).Highlight()}: {result.ConfigFileAfterTransform} {nameof(result.TransformFileContent).Highlight()}: {result.TransformFileContent}"); } } else { _log.Error($"Transform failed for: {result}\r\n{result.Exception}"); } return result; })); }).SelectMany(result => result).ToList(); LogHeader(LogLevel.Info, $"Config Transform Operations Overview"); foreach (var result in results.Where(result => result.Success)) { _log.Success($"Transform succeed for: {result}"); } foreach (var result in results.Where(result => result.Success && result.WasUpdated == false)) { _log.Write(noChangesLogLevel, $"Transform succeed but config file was NOT updated for: {result}. See log for details"); } foreach (var result in results.Where(result => result.Success == false)) { _log.Error($"Transform failed for: {result}\r\n{result.Exception}"); } var anyFailures = results.Any(r => r.Success == false); return(anyFailures == false); }
private ConcurrentDictionary <string, ConcurrentBag <TransformOperation> > ScanForTransformOperations(DirPath rootDir, IReadOnlyCollection <string> environments) { var operations = new ConcurrentDictionary <string, ConcurrentBag <TransformOperation> >(); foreach (var environment in environments) { operations.TryAdd(environment, new ConcurrentBag <TransformOperation>()); _log.Info($"Scanning for environment: {environment.Highlight()}"); _transforms.ForEachParallel(transform => { //find transform files for Environment rootDir.EnumerateFiles($"*.{environment}.{transform.TransformFileExtension.TrimStart('.')}", SearchOption.AllDirectories).OrderBy(f => f.FullName()) .ForEachParallel(transformFile => //and convert to config operations { _log.Debug($"{transformFile.RawPath.Replace(environment, environment.Highlight())}"); //arrange var targetName = transformFile.NameWoExtension .Replace($".{environment}", string.Empty, StringComparison.InvariantCultureIgnoreCase) .EnsureSuffix($".{transform.ConfigFileExtension.TrimStart('.')}"); var targetConfigFile = transformFile.Directory().ToFile(targetName); var operation = new TransformOperation(transformFile, targetConfigFile, transform); operation.AssertFilesExist(_log); operations[environment].Add(operation); }); }); } return(operations); }