public void BasicTest() { var symlinkMap = new Dictionary <string, string> { [A("X", "symlink1.lnk")] = A("X", "target1"), [A("X", "symlink2.lnk")] = A("X", "target2") }; var file = GetFullPath("SymlinkDefinition"); var pathMapSerializer = new PathMapSerializer(file); foreach (var mapping in symlinkMap) { pathMapSerializer.OnNext(mapping); } ((IObserver <KeyValuePair <string, string> >)pathMapSerializer).OnCompleted(); PathTable newPathTable = new PathTable(); var loadedSymlinkMap = PathMapSerializer.LoadAsync(file, newPathTable).Result; foreach (var mapping in loadedSymlinkMap) { var source = mapping.Key.ToString(newPathTable); var target = mapping.Value.ToString(newPathTable); XAssert.IsTrue(symlinkMap.ContainsKey(source)); XAssert.AreEqual(symlinkMap[source], target); } }
/// <summary> /// Load symlink definitions serialized using <see cref="PathMapSerializer"/> /// </summary> public static async Task <Possible <SymlinkDefinitions> > TryLoadAsync( LoggingContext loggingContext, PathTable pathTable, string filePath, string symlinksDebugPath, ITempDirectoryCleaner tempDirectoryCleaner = null) { try { var pathMap = await PathMapSerializer.LoadAsync(filePath, pathTable); var definitions = new SymlinkDefinitions(pathTable, pathMap); Logger.Log.SymlinkFileTraceMessage( loggingContext, I($"Loaded symlink definitions with {definitions.m_symlinkDefinitionMap.Count} entries and {definitions.m_directorySymlinkContents.Count} directories.")); if (EngineEnvironmentSettings.DebugSymlinkDefinitions && symlinksDebugPath != null) { FileUtilities.DeleteFile(symlinksDebugPath, tempDirectoryCleaner: tempDirectoryCleaner); using (var writer = new StreamWriter(symlinksDebugPath)) { foreach (var entry in pathMap) { writer.WriteLine("Source: {0}", entry.Key.ToString(pathTable)); writer.WriteLine("Target: {0}", entry.Value.ToString(pathTable)); } } } return(definitions); } catch (Exception ex) { Logger.Log.FailedLoadSymlinkFile(loggingContext, ex.GetLogEventMessage()); return(new Failure <string>("Failed loading symlink definition file")); } }