private void LoadDependencies() { var directory = new Uri( Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) ?? throw new InvalidOperationException("Assembly somehow not in a directory") ).AbsolutePath; var assemblies = new string[] { } .Concat(Directory.GetFiles(directory, @"ScientiaMagica*.dll")) .Concat(Directory.GetFiles(directory, @"*.Main.dll")) .Select(s => new Uri(s).AbsolutePath) .Select(GetPluginAssembly); foreach (var assembly in assemblies) { foreach (var pluginType in assembly.GetTypes()) { if (!pluginType.ImplementsServiceType <IPlugin>()) { continue; } var instance = Activator.CreateInstance(pluginType) as IPlugin; instance?.Load(_container); } } }
public void TestExtractionError() { using var tmpdir = new TemporaryDirectory(); DirectoryInfo input = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject")); DirectoryInfo output = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject.Test/doctests")); string inputPath = Path.Join(input.FullName, "SomeProgram.cs"); File.WriteAllText( inputPath, @"/// <code doctest=""true""> /// var a = 0; /// // --- /// var x = 1; /// </code> "); using var consoleCapture = new ConsoleCapture(); int exitCode = Program.MainWithCode(new[] { "--input", input.FullName, "--output", output.FullName }); string nl = Environment.NewLine; Assert.AreEqual(1, exitCode); Assert.AreEqual( $"Failed to extract doctest(s) from: {inputPath}{nl}" + $"* Line 1, column 1: Expected only using directives in the header, but got: FieldDeclaration{nl}", consoleCapture.Output()); }
public void TestCheckShouldntExist() { using var tmpdir = new TemporaryDirectory(); DirectoryInfo input = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject")); DirectoryInfo output = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject.Test/doctests")); string inputPath = Path.Join(input.FullName, "SomeProgram.cs"); string outputPath = Path.Join(output.FullName, "DocTestSomeProgram.cs"); File.WriteAllText(inputPath, "no code"); File.WriteAllText(outputPath, "unexpected content"); using var consoleCapture = new ConsoleCapture(); int exitCode = Program.MainWithCode( new[] { "--input", input.FullName, "--output", output.FullName, "--check" }); string nl = Environment.NewLine; Assert.AreEqual(1, exitCode); Assert.AreEqual( $"No doctests found in: {inputPath}; the output should not exist: {outputPath}{nl}", consoleCapture.Output()); }
public IEnumerable <DirRef> Directories(string searchPattern = "*.*", bool recurse = false) { foreach (var dirName in IODirectory.EnumerateDirectories(Path, searchPattern, recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly)) { yield return(Dir(dirName)); } }
public static List <SearchItem> GetAllItems() { string path = Directory.GetCurrentDirectory() + @"\mtad\"; //建立索引搜索,指定索引目录 IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(new System.IO.DirectoryInfo(path)), true); //获取最大文档数量 var count = searcher.MaxDoc(); var searchItems = new List <SearchItem>(); for (int i = 0; i < count; i++) { var document = searcher.Doc(i); //var fields = document.GetFields(); var id = document.GetValues("id")[0]; var tablename = document.GetValues("tablename")[0]; var acronym = document.GetValues("acronym")[0]; var english = document.GetValues("english")[0]; var chinese = document.GetValues("chinese")[0]; var explain = document.GetValues("explain")[0]; var searchItem = new SearchItem { Id = id, TableName = tablename, Acronym = acronym, English = english, Chinese = chinese, Explain = explain }; searchItems.Add(searchItem); } return(searchItems); }
public void TestNoDoctest() { using var tmpdir = new TemporaryDirectory(); DirectoryInfo input = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject")); DirectoryInfo output = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject.Test/doctests")); string inputPath = Path.Join(input.FullName, "SomeProgram.cs"); string outputPath = Path.Join(output.FullName, "DocTestSomeProgram.cs"); File.WriteAllText(inputPath, "no doctests"); using var consoleCapture = new ConsoleCapture(); int exitCode = Program.MainWithCode( new[] { "--input-output", $"{input.FullName}{Path.PathSeparator}{output.FullName}", "--verbose" }); string nl = Environment.NewLine; Assert.AreEqual(0, exitCode); Assert.AreEqual( $"No doctests found in: {inputPath}{nl}", consoleCapture.Output()); Assert.IsFalse(File.Exists(outputPath)); }
public static List <string> ListAasxPaths() { var variable = "SAMPLE_AASX_DIR"; var sampleAasxDir = System.Environment.GetEnvironmentVariable(variable); if (sampleAasxDir == null) { throw new InvalidOperationException( $"The environment variable {variable} has not been set. " + "Did you set it manually to the directory containing sample AASXs? " + "Otherwise, run the test through Test.ps1?"); } if (!Directory.Exists(sampleAasxDir)) { throw new InvalidOperationException( $"The directory containing the sample AASXs does not exist or is not a directory: " + $"{sampleAasxDir}; did you download the samples with DownloadSamples.ps1?"); } var result = Directory.GetFiles(sampleAasxDir) .Where(p => Path.GetExtension(p) == ".aasx") .ToList(); result.Sort(); return(result); }
public IEnumerable <FileRef> Files() { foreach (var fileName in IODirectory.EnumerateFiles(Path)) { yield return(File(fileName)); } }
public static void SaveImage(this IPathCollection shape, params string[] path) { shape = shape.Translate(-shape.Bounds.Location) // touch top left .Translate(new Vector2(10)); // move in from top left string fullPath = IOPath.GetFullPath(IOPath.Combine("Output", IOPath.Combine(path))); // pad even amount around shape int width = (int)(shape.Bounds.Left + shape.Bounds.Right); int height = (int)(shape.Bounds.Top + shape.Bounds.Bottom); using (var img = new Image <Rgba32>(width, height)) { img.Mutate(i => i.Fill(Color.DarkBlue)); foreach (IPath s in shape) { // In ImageSharp.Drawing.Paths there is an extension method that takes in an IShape directly. img.Mutate(i => i.Fill(Color.HotPink, s)); } // img.Draw(Color.LawnGreen, 1, new ShapePath(shape)); // Ensure directory exists IODirectory.CreateDirectory(IOPath.GetDirectoryName(fullPath)); img.Save(fullPath); } }
private void GenerateRightClickOpenMenu(ICollection <string> added) { int n = gridSummary.mFoldersToOpen.Count; bool first = true; foreach (KeyValuePair <int, List <string> > kvp in show.AllExistngFolderLocations()) { foreach (string folder in kvp.Value) { if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder) && !added.Contains(folder)) { added.Add(folder); // don't show the same folder more than once if (first) { GenerateSeparator(gridSummary.showRightClickMenu); first = false; } GenerateMenu(gridSummary.showRightClickMenu, "Open: " + folder, (int)RightClickCommands.kOpenFolderBase + n); gridSummary.mFoldersToOpen.Add(folder); n++; } } } }
public IWorldInstance Deserialise(string worldName) { string directory = Directory.GetCurrentDirectory() + "/save/" + worldName; string json = File.ReadAllText(directory + "/relationships.dat"); Dictionary tempDict = this.GetDictionary(json); GlobalConstants.GameManager.RelationshipHandler.Load(tempDict); json = File.ReadAllText(directory + "/entities.dat"); tempDict = this.GetDictionary(json); GlobalConstants.GameManager.EntityHandler.Load(tempDict); json = File.ReadAllText(directory + "/items.dat"); tempDict = this.GetDictionary(json); GlobalConstants.GameManager.ItemHandler.Load(tempDict); json = File.ReadAllText(directory + "/quests.dat"); tempDict = this.GetDictionary(json); GlobalConstants.GameManager.QuestTracker.Load(tempDict); json = File.ReadAllText(directory + "/world.dat"); tempDict = this.GetDictionary(json); IWorldInstance overworld = new WorldInstance(); overworld.Load(tempDict); return(overworld); }
private void GenerateOpenMenu([NotNull] Season seas, ICollection <string> added) { Dictionary <int, List <string> > afl = show.AllExistngFolderLocations(); if (!afl.ContainsKey(seas.SeasonNumber)) { return; } int n = gridSummary.mFoldersToOpen.Count; bool first = true; foreach (string folder in afl[seas.SeasonNumber]) { if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder) && !added.Contains(folder)) { added.Add(folder); // don't show the same folder more than once if (first) { GenerateSeparator(gridSummary.showRightClickMenu); first = false; } GenerateMenu(gridSummary.showRightClickMenu, "Open: " + folder, (int)RightClickCommands.kOpenFolderBase + n); gridSummary.mFoldersToOpen.Add(folder); n++; } } }
/// <summary> /// Delete the files for this piece of the game, including the folder their /// stored in. /// </summary> public void DeleteFolder() { if (D.Exists(path)) { D.Delete(path, true); } }
private static void Main(string[] args) { bool removeDirectory; string temporaryDirectory = GetTemporaryDirectory(out removeDirectory); Console.WriteLine("Working directory: {0}", temporaryDirectory); try { IPackageRepository sourceRepository = PackageRepositoryFactory.Default.CreateRepository("https://www.nuget.org/api/v2/"); PackageManager packageManager = new PackageManager(sourceRepository, temporaryDirectory); packageManager.PackageInstalled += HandlePackageInstalled; packageManager.InstallPackage("Microsoft.Bcl.Immutable", SemanticVersion.Parse("1.0.34")); packageManager.InstallPackage("System.Collections.Immutable", SemanticVersion.Parse("1.1.33-beta")); using (PEReader referenceAssembly = new PEReader(File.OpenRead(Path.Combine(temporaryDirectory, "Microsoft.Bcl.Immutable.1.0.34", "lib", "portable-net45+win8+wp8+wpa81", "System.Collections.Immutable.dll")))) { using (PEReader newAssembly = new PEReader(File.OpenRead(Path.Combine(temporaryDirectory, "System.Collections.Immutable.1.1.33-beta", "lib", "portable-net45+win8+wp8+wpa81", "System.Collections.Immutable.dll")))) { Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, null); analyzer.Run(); } } } finally { if (removeDirectory) { Directory.Delete(temporaryDirectory, true); } } }
private void GenerateRightClickOpenMenu(ICollection <string> added) { bool first = true; foreach (KeyValuePair <int, SafeList <string> > kvp in show.AllExistngFolderLocations().OrderBy(pair => pair.Key)) { foreach (string folder in kvp.Value) { if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder) && !added.Contains(folder)) { added.Add(folder); // don't show the same folder more than once if (first) { GenerateSeparator(gridSummary.showRightClickMenu); first = false; } AddRcMenuItem(gridSummary.showRightClickMenu, "Open: " + folder, (sender, args) => { Helpers.OpenFolder(folder); }); } } } }
public void TestCreateEntityIndex5k() { const string filename = "Resources/EntityIndex5k.nt"; const string outputPath = "CreateEntityIndex5k"; outputPath.DeleteIfExists(); Assert.False(Directory.Exists(outputPath)); new EntitiesIndexer(filename, outputPath).Index(); Assert.True(Directory.Exists(outputPath)); var queryBerlin = new SingleLabelEntityQuery(outputPath, "Berli").Query().ToArray(); Assert.NotEmpty(queryBerlin); var result = queryBerlin[0]; Assert.Equal("Q64", result.Id); Assert.Equal("Berlin", result.Label); Assert.Equal("capital city of Germany", result.Description); Assert.Contains("Berlin, Germany", result.AltLabels); var properties = result.Properties.Select(x => x.Id).ToArray(); Assert.Contains("P17", properties); Assert.Contains("P1376", properties); Assert.False(result.IsType); Assert.Contains("Q515", result.ParentTypes); Assert.Contains("Q5119", result.ParentTypes); //Assert.Contains("Q999", result.SubClass); outputPath.DeleteIfExists(); }
public void TestCreatePropertyIndexAndMapResults() { const string filename = "Resources/PropertyIndex5k.nt"; const string propertiesIndexPath = "CreatePropertyIndexMapResults"; const string entitiesIndexPath = "CreatePropertyIndexMapResults-EntitiesIndex"; propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); new EntitiesIndexer(filename, entitiesIndexPath).Index(); new PropertiesIndexer(filename, propertiesIndexPath, entitiesIndexPath).Index(); Assert.True(Directory.Exists(propertiesIndexPath)); var queryCity = new SingleLabelPropertyQuery(propertiesIndexPath, "located").Query().ToArray(); Assert.NotEmpty(queryCity); var result = queryCity[0]; Assert.Equal("P131", result.Id); Assert.Equal("located in the administrative territorial entity", result.Label); Assert.Equal("the item is located on the territory of the following administrative entity...", result.Description); Assert.Contains("is located in", result.AltLabels); Assert.Contains("is in the county of", result.AltLabels); Assert.Contains("is in the city of", result.AltLabels); Assert.NotEqual(0, result.Rank); propertiesIndexPath.DeleteIfExists(); entitiesIndexPath.DeleteIfExists(); }
public static void TestCreateIndexAddTypesFields() { const string filename = "Resources/EntityIndexTypes.nt"; const string outputPath = "CreateIndexAddTypesFields"; outputPath.DeleteIfExists(); Assert.False(Directory.Exists(outputPath)); new EntitiesIndexer(filename, outputPath).Index(); var obama = new SingleIdEntityQuery(outputPath, "Q76").Query().FirstOrDefault(); var person = new SingleIdEntityQuery(outputPath, "Q5").Query().FirstOrDefault(); var country = new SingleIdEntityQuery(outputPath, "Q17").Query().FirstOrDefault(); var chile = new SingleIdEntityQuery(outputPath, "Q298").Query().FirstOrDefault(); Assert.Equal("Q76", obama.Id); Assert.Equal("Q5", person.Id); Assert.Equal("Q17", country.Id); Assert.Equal("Q298", chile.Id); Assert.False(obama.IsType); Assert.False(chile.IsType); Assert.True(person.IsType); Assert.True(country.IsType); outputPath.DeleteIfExists(); }
protected virtual void eraseTempDir() { if (Directory.Exists(tmpdir)) { Directory.Delete(tmpdir, true); } }
public static void DeleteDirectoryRecursively(string path) { if (Directory.Exists(path)) { DirectoryExtensions.DeleteRecursively(path); } }
private static string GetInitialDirectoryToUse(string initialDirectory, bool overridePersistedInitialDirectory, Guid persistenceSlot) { string path = initialDirectory; if (persistenceSlot != Guid.Empty && !overridePersistedInitialDirectory) { if (!_persistedDirectories.TryGetValue(persistenceSlot, out path)) { path = initialDirectory; } } try { path = Path.GetFullPath(path); if (!Directory.Exists(path)) { path = DefaultDirectory; } } catch (ArgumentException) { path = DefaultDirectory; } return(path); }
/// <summary> /// Проверяет наличие папок data и data/images, в которых лежит БД и изображение /// </summary> private void CheckFolder() { if ((!Directory.Exists(dataPath)) || (Directory.Exists(dataPath) && !Directory.Exists(imagesPath))) { Directory.CreateDirectory(imagesPath); } }
public DerivedValueHandler( IEntityStatisticHandler statisticHandler, IEntitySkillHandler skillHandler) { this.ValueExtractor = new JSONValueExtractor(); this.StatisticHandler = statisticHandler; this.SkillHandler = skillHandler; this.ENTITY_FILE = Directory.GetCurrentDirectory() + GlobalConstants.ASSETS_FOLDER + GlobalConstants.DATA_FOLDER + "EntityDerivedValues.json"; this.ITEM_FILE = Directory.GetCurrentDirectory() + GlobalConstants.ASSETS_FOLDER + GlobalConstants.DATA_FOLDER + "ItemDerivedValues.json"; this.DerivedValueOutlineColours = new System.Collections.Generic.Dictionary <string, Color>(); this.DerivedValueBarColours = new System.Collections.Generic.Dictionary <string, Color>(); this.DerivedValueTextColours = new System.Collections.Generic.Dictionary <string, Color>(); this.Load(); this.Formulas = new System.Collections.Generic.Dictionary <string, DerivedValueData>(this.EntityStandardFormulas); foreach (KeyValuePair <string, DerivedValueData> pair in this.ItemStandardFormulas) { this.Formulas.Add(pair.Key, pair.Value); } }
public void TestIndexWithDifferentIdsHasCorrectRankingFields() { const string filename = "Resources/EntityIndexPageRankDifferentIds.nt"; const string outputPath = "IndexWithDifferentIdsHasCorrectRankingFields"; var nodesGraph = EntityPageRank.BuildSimpleNodesGraph(filename); var ranks = EntityPageRank.CalculateRanks(nodesGraph, 20); Assert.Equal(1, Math.Round(ranks.Sum()), 10); outputPath.DeleteIfExists(); Assert.False(Directory.Exists(outputPath)); new EntitiesIndexer(filename, outputPath).Index(); using (var luceneDirectory = FSDirectory.Open(outputPath.GetOrCreateDirectory())) { using (var reader = DirectoryReader.Open(luceneDirectory)) { Assert.True(Directory.Exists(outputPath)); var docCount = reader.MaxDoc; Assert.Equal(7, docCount); for (var i = 0; i < docCount; i++) { var doc = reader.Document(i); double.TryParse(doc.GetValue(Labels.Rank), out var rank); Assert.Equal(ranks[i].ToThreeDecimals(), rank.ToThreeDecimals()); } } } outputPath.DeleteIfExists(); }
public IFileSource.IDirectory CreateSubDirectory() { string newPath = this.Path + "/" + "New Directory"; Directories.CreateDirectory(newPath); return(new Directory(newPath, (LocalFileSource)this.Source)); }
// We have to move the folder separation into the file name // e.g. "myfolder"\"myassembly.iam" => "myfolder\myassembly.iam" // On windows we might have to URL encode this, i.e. // "myfolder%2Fmyassembly.iam" public void flattenFolder(string folder, string rootFolder, string path) { const string separator = "%2F"; if (folder != rootFolder) { string[] filePaths = Directory.GetFiles(folder); foreach (string filePath in filePaths) { string fileName = path + Path.GetFileName(filePath); string filePathNew = Path.Combine(rootFolder, fileName); File.Move(filePath, filePathNew); } } string[] directoryPaths = Directory.GetDirectories(folder); foreach (string directoryPath in directoryPaths) { string directoryName = Path.GetFileName(directoryPath); // move its contents first flattenFolder(directoryPath, rootFolder, path + directoryName + separator); // Then delete it try { Directory.Delete(directoryPath); } catch (Exception ex) { LogTrace(ex.Message + ": " + directoryPath); } } }
public void TestCheckDoesntExist() { using var tmpdir = new TemporaryDirectory(); DirectoryInfo input = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject")); DirectoryInfo output = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject.Test/doctests")); string inputPath = Path.Join(input.FullName, "SomeProgram.cs"); string outputPath = Path.Join(output.FullName, "DocTestSomeProgram.cs"); File.WriteAllText( inputPath, @"/// <code doctest=""true""> /// var x = 1; /// </code> "); // Test pre-condition Assert.IsFalse(File.Exists(outputPath)); using var consoleCapture = new ConsoleCapture(); int exitCode = Program.MainWithCode( new[] { "--input", input.FullName, "--output", output.FullName, "--check" }); string nl = Environment.NewLine; Assert.AreEqual(1, exitCode); Assert.AreEqual($"Output file does not exist: {inputPath} -> {outputPath}{nl}", consoleCapture.Output()); }
private void GenerateOpenMenu([NotNull] ProcessedSeason seas, ICollection <string> added) { Dictionary <int, SafeList <string> > afl = show.AllExistngFolderLocations(); if (!afl.ContainsKey(seas.SeasonNumber)) { return; } bool first = true; foreach (string folder in afl[seas.SeasonNumber].OrderBy(s => s)) { if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder) && !added.Contains(folder)) { added.Add(folder); // don't show the same folder more than once if (first) { GenerateSeparator(gridSummary.showRightClickMenu); first = false; } AddRcMenuItem(gridSummary.showRightClickMenu, "Open: " + folder, (sender, args) => { Helpers.OpenFolder(folder); }); } } }
public void TestDoctest() { using var tmpdir = new TemporaryDirectory(); DirectoryInfo input = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject")); DirectoryInfo output = Directory.CreateDirectory(Path.Join(tmpdir.Path, "SomeProject.Test/doctests")); string inputPath = Path.Join(input.FullName, "SomeProgram.cs"); string outputPath = Path.Join(output.FullName, "DocTestSomeProgram.cs"); File.WriteAllText( inputPath, @"/// <code doctest=""true""> /// var x = 1; /// </code> "); using var consoleCapture = new ConsoleCapture(); int exitCode = Program.MainWithCode(new[] { "--input", input.FullName, "--output", output.FullName }); string nl = Environment.NewLine; Assert.AreEqual(0, exitCode); Assert.AreEqual( $"Generated doctest(s) for: {inputPath} -> {outputPath}{nl}", consoleCapture.Output()); }
private void CreateDrawing(Document doc) { double viewScale = 0.05; // Update this for your drawing path, could add this to the web UI // Change file name and update all IDW files and WorkItem args to support DWG string templateLoc = "<your drawing path here>"; // "/Drawings/Drawing.idw" // This gets the working directory of the Assembly DirectoryInfo parentDir = Directory.GetParent(Path.GetFullPath(doc.FullFileName)); // Need one more directory up to get to the templates DirectoryInfo baseDir = Directory.GetParent(parentDir.FullName); string templateFile = baseDir.FullName + templateLoc; LogTrace("Adding Drawing template: " + templateFile); DrawingDocument drawingDoc = (DrawingDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFile); LogTrace("Getting the first sheet"); Sheet sheet = drawingDoc.Sheets[1]; Point2d point1 = inventorApplication.TransientGeometry.CreatePoint2d(80, 40); // front view Point2d point2 = inventorApplication.TransientGeometry.CreatePoint2d(21, 29); // top view LogTrace("Adding Drawing Views..."); DrawingView baseView = sheet.DrawingViews.AddBaseView((_Document)doc, point1, viewScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "My View"); DrawingView projectedView = sheet.DrawingViews.AddProjectedView(baseView, point2, DrawingViewStyleEnum.kShadedDrawingViewStyle, viewScale); }