public void ChangeExtensionWithNull() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, @"x:\directory\File.txt"); // Execute var result = file.ChangeExtension(a_extension: null); }
public void CopyInWithNotExistingDirectory() { // Setup var fileSystem = new PathTree <string>(); var directory = fileSystem.CreateDirectory(@"\directory"); var file = new PathFile <string>(fileSystem, @"\noexisty\file1.dat"); // Execute directory.CopyIn(file); }
public void ChangeExtensionOnNotRootedFile() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, @"File.txt"); // Execute var result = file.ChangeExtension("jpg"); Assert.AreEqual("File.jpg", result.Name); Assert.AreEqual("File.jpg", result.Path); }
public void CallExistsWithNotExistingFile() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\file\\does\\not\\exist.dat"); // Execute var result = file.Exists; // Assert Assert.IsFalse(result); }
public void ConstructPathFile() { // Setup var pathTree = new PathTree <string>(); // Execute var file = new PathFile <string>(pathTree, "\\file.dat"); // Assert Assert.AreEqual("\\file.dat", file.Path); Assert.AreSame(pathTree, file.FileSystem); }
public void ChangeExtensionOnNotRootedFile() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, @"File.txt"); // Execute var result = file.ChangeExtension("jpg"); Assert.AreEqual("File.jpg", result.Name); Assert.AreEqual("File.jpg", result.Path); }
public void CopyFromWithNotExistingSource() { // Setup var pathTree = new PathTree <string>(); pathTree.CreateDirectory(@"x:\directory"); var source = new PathFile <string>(pathTree, @"x:\directory\File.bmp"); var file = new PathFile <string>(pathTree, @"x:\directory\file2.bmp"); // Execute file.CopyFrom(source); }
public void CallExistsWithNotExistingFile() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, "\\file\\does\\not\\exist.dat"); // Execute var result = file.Exists; // Assert Assert.IsFalse(result); }
public void GetName() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute var result = file.Name; // Assert Assert.AreEqual("file.txt", result); }
public void CreateFile() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Create("Value"); // Assert Assert.IsTrue(file.Exists); Assert.AreEqual("Value", file.Value); }
public void GetDirectory() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute var result = file.Directory; // Assert Assert.IsNotNull(result); Assert.AreEqual("a", result.Name); }
public void DeleteFile() { // Setup var pathTree = new PathTree <string>(); var file = new PathFile <string>(pathTree, "\\this\\is\\a\\file.txt"); file.Create("Value"); // Execute file.Delete(); // Assert Assert.IsFalse(file.Exists); }
public void DeleteNotExistingFile() { // Setup var pathTree = new PathTree <string>(); pathTree.CreateDirectory("\\this\\is\\a"); var file = new PathFile <string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Delete(); // Assert Assert.IsFalse(file.Exists); }
public void CopyFrom() { // Setup var pathTree = new PathTree <string>(); var source = pathTree.CreateFile(@"x:\directory\File.bmp", "Value"); var file = new PathFile <string>(pathTree, @"x:\directory\file2.bmp"); // Execute file.CopyFrom(source); // Assert Assert.IsTrue(file.Exists); Assert.AreEqual("Value", file.Value); }
public void CallExistsWithExistingFile() { // Setup var path = "\\file\\does\\exist.dat"; var pathTree = new PathTree<string>(); pathTree.CreateFile(path, "Value"); var file = new PathFile<string>(pathTree, path); // Execute var result = file.Exists; // Assert Assert.IsTrue(result); }
static void ReadLinePathAndFile(Dictionary <string, List <PathFile> > path, int n) { while (n > 0) { string[] pathFileSize = Console.ReadLine() .Split(new[] { '\\', ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .ToArray(); string rootPath = pathFileSize[0]; string filename = pathFileSize[pathFileSize.Length - 2]; string[] extensionSplit = Regex.Split(filename, @".*[.](.+)") .Where(x => x.Length > 0) .Select(x => x.Trim()) .ToArray(); string extension = extensionSplit[0]; long fileSize = long.Parse(pathFileSize[pathFileSize.Length - 1]); PathFile newRootFile = new PathFile(filename, extension, fileSize); if (!path.ContainsKey(rootPath)) { path.Add(rootPath, new List <PathFile>()); } bool hasNewFileSize = true; foreach (var p in path) { if (p.Key == rootPath) { foreach (var f in p.Value) { if (f.FileName == filename) { f.SizeFile = fileSize; hasNewFileSize = false; } } } } if (hasNewFileSize) { path[rootPath].Add(newRootFile); } n--; } }
public void CallExistsWithExistingFile() { // Setup var path = "\\file\\does\\exist.dat"; var pathTree = new PathTree <string>(); pathTree.CreateFile(path, "Value"); var file = new PathFile <string>(pathTree, path); // Execute var result = file.Exists; // Assert Assert.IsTrue(result); }
public string returnData(PathFile pathFile) { DataTable dt = new DataTable(); List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; FileInfo fileInfo = new FileInfo(pathFile.path); using (var stream = File.Open(pathFile.path, FileMode.Open, FileAccess.Read)) { IExcelDataReader reader; reader = ExcelReaderFactory.CreateReader(stream); var conf = new ExcelDataSetConfiguration { ConfigureDataTable = _ => new ExcelDataTableConfiguration { UseHeaderRow = true } }; var dataSet = reader.AsDataSet(conf); dt = dataSet.Tables[0]; } foreach (DataRow row in dt.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in dt.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } string result = JsonConvert.SerializeObject(parentRow); if (fileInfo.Exists) { fileInfo.Delete(); } return(result); }
//[TestMethod] public void Temp() { var fileSystem = new TestFileSystem(); var pathTree = new PathTree <IFile>(); pathTree.CreateDirectory(@"urban stuff"); pathTree.CreateFile(@"urban stuff\urban1.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban1.hsf")); pathTree.CreateFile(@"urban stuff\urban1.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban1.jpg")); pathTree.CreateFile(@"urban stuff\urban2.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban2.hsf")); pathTree.CreateFile(@"urban stuff\urban2.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban2.jpg")); pathTree.CreateFile(@"urban stuff\urban3.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban3.hsf")); pathTree.CreateFile(@"urban stuff\urban3.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban3.jpg")); pathTree.CreateDirectory(@"curved case stuff"); pathTree.CreateFile(@"curved case stuff\curved1.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved1.hsf")); pathTree.CreateFile(@"curved case stuff\curved1.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved1.jpg")); pathTree.CreateFile(@"curved case stuff\curved2.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved2.hsf")); pathTree.CreateFile(@"curved case stuff\curved2.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved2.jpg")); pathTree.CreateFile(@"curved case stuff\curved3.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved3.hsf")); pathTree.CreateFile(@"curved case stuff\curved3.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved3.jpg")); IFile file = new PathFile <IFile>(pathTree, @"urban stuff\urban1.hsf"); IFile destination = new PathFile <IFile>(pathTree, @"curved case stuff\carved urban1.esa"); if (file.Exists) { file.CopyTo(destination); } file = file.ChangeExtension(".jpg"); destination = destination.ChangeExtension(".jpg"); if (file.Exists) { file.CopyTo(destination); } Assert.IsFalse(pathTree.FileExists(@"urban stuff\urban1.hsf")); Assert.IsTrue(pathTree.FileExists(@"curved case stuff\carved urban1.esa")); }
/// <summary> /// Constructor. This will try to have the requested .pat file parsed for its metadata /// </summary> /// <param name="filePath">The full name of the .pat file</param> internal Path(string filePath) { if (File.Exists(filePath)) { try { PathFile patFile = new PathFile(filePath); IsPlayerPath = patFile.IsPlayerPath; Name = patFile.Name; Start = patFile.Start; End = patFile.End; } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 // Do not catch general exception types { Name = $"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } if (string.IsNullOrEmpty(Name)) { Name = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } if (string.IsNullOrEmpty(Start)) { Start = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } if (string.IsNullOrEmpty(End)) { End = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } } else { Name = Start = End = $"<{catalog.GetString("missing:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>"; } FilePath = filePath; }
public void CopyToWithNotExistingSource() { // Setup var pathTree = new PathTree<string>(); pathTree.CreateDirectory(@"x:\directory"); var file = new PathFile<string>(pathTree, @"x:\directory\File.bmp"); var dest = new PathFile<string>(pathTree, @"x:\directory\file2.bmp"); // Execute file.CopyTo(dest); }
public void CopyTo() { // Setup var pathTree = new PathTree<string>(); var file = pathTree.CreateFile(@"x:\directory\File.bmp", "Value"); var dest = new PathFile<string>(pathTree, @"x:\directory\file2.bmp"); // Execute file.CopyTo(dest); // Assert Assert.IsTrue(dest.Exists); Assert.AreEqual("Value", dest.Value); }
public void CreateFileWithNullValue() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Create(a_value: null); }
public void CreateFile() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Create("Value"); // Assert Assert.IsTrue(file.Exists); Assert.AreEqual("Value", file.Value); }
public void CopyInWithNotExistingDirectory() { // Setup var fileSystem = new PathTree<string>(); var directory = fileSystem.CreateDirectory(@"\directory"); var file = new PathFile<string>(fileSystem, @"\noexisty\file1.dat"); // Execute directory.CopyIn(file); }
public void DeleteFile() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); file.Create("Value"); // Execute file.Delete(); // Assert Assert.IsFalse(file.Exists); }
public void GetDirectory() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute var result = file.Directory; // Assert Assert.IsNotNull(result); Assert.AreEqual("a", result.Name); }
//..................................................................... /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonCopying_Click(object sender, EventArgs e) { string srcpath = this.TextGithub.Text; string dstpath = this.TextApache.Text; if (string.IsNullOrEmpty(srcpath)) { return; } if (string.IsNullOrEmpty(dstpath)) { return; } this.AppINI.Plus(this.CONST_HANS_GITHUB, srcpath); this.AppINI.Plus(this.CONST_APACHE_ROOT, dstpath); this.AppINI.Save( ); PathFile pathfile = new PathFile( ); pathfile.SeekingPath(srcpath); List <DirectoryInfo> listpath = pathfile.Paths; var listname = from lst in listpath orderby lst.FullName select lst.FullName; foreach (var code in listname) { string newPath = dstpath + code.Substring(srcpath.Length); if (Directory.Exists(newPath)) { continue; } if (newPath.ToLower( ).Contains(".git")) { continue; } Directory.CreateDirectory(newPath); } List <FileInfo> listing = pathfile.SeekingFiles( ); foreach (FileInfo fileinfo in listing) { if (fileinfo.FullName.ToLower( ).Contains("\\.git\\")) { continue; } string newName = fileinfo.FullName .Substring(srcpath.Length); fileinfo.CopyTo(dstpath + newName, true); } Process.Start("explorer.exe", dstpath); return; }
//[TestMethod] public void Temp() { var fileSystem = new TestFileSystem(); var pathTree = new PathTree<IFile>(); pathTree.CreateDirectory(@"urban stuff"); pathTree.CreateFile(@"urban stuff\urban1.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban1.hsf")); pathTree.CreateFile(@"urban stuff\urban1.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban1.jpg")); pathTree.CreateFile(@"urban stuff\urban2.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban2.hsf")); pathTree.CreateFile(@"urban stuff\urban2.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban2.jpg")); pathTree.CreateFile(@"urban stuff\urban3.hsf", fileSystem.StageFile(@"x:\root\urban stuff\urban3.hsf")); pathTree.CreateFile(@"urban stuff\urban3.jpg", fileSystem.StageFile(@"x:\root\urban stuff\urban3.jpg")); pathTree.CreateDirectory(@"curved case stuff"); pathTree.CreateFile(@"curved case stuff\curved1.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved1.hsf")); pathTree.CreateFile(@"curved case stuff\curved1.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved1.jpg")); pathTree.CreateFile(@"curved case stuff\curved2.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved2.hsf")); pathTree.CreateFile(@"curved case stuff\curved2.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved2.jpg")); pathTree.CreateFile(@"curved case stuff\curved3.hsf", fileSystem.StageFile(@"x:\root\curved case stuff\curved3.hsf")); pathTree.CreateFile(@"curved case stuff\curved3.jpg", fileSystem.StageFile(@"x:\root\curved case stuff\curved3.jpg")); IFile file = new PathFile<IFile>(pathTree, @"urban stuff\urban1.hsf"); IFile destination = new PathFile<IFile>(pathTree, @"curved case stuff\carved urban1.esa"); if (file.Exists) file.CopyTo(destination); file = file.ChangeExtension(".jpg"); destination = destination.ChangeExtension(".jpg"); if (file.Exists) file.CopyTo(destination); Assert.IsFalse(pathTree.FileExists(@"urban stuff\urban1.hsf")); Assert.IsTrue(pathTree.FileExists(@"curved case stuff\carved urban1.esa")); }
public void GetName() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute var result = file.Name; // Assert Assert.AreEqual("file.txt", result); }
/// <summary> /// Constructor /// </summary> /// <param name="path">Contains the information (mainly filepath) needed for loading the .pat file</param> public DrawPATfile(ORTS.Menu.Path path) { FileName = path.FilePath.Split('\\').Last(); patFile = new PathFile(path.FilePath); }
public ValoresController() { jsString = new ReturnJsString(); pathFile = new PathFile(); }
/// <summary> /// Try to load the file. /// Possibly this might raise an exception. That exception is not caught here /// </summary> /// <param name="file">The file that needs to be loaded</param> public override void TryLoading(string file) { _ = new PathFile(file); }
public void CopyFromWithNullDest() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, @"x:\directory\file2.bmp"); // Execute file.CopyFrom(a_source: null); }
public void DeleteNotExistingFile() { // Setup var pathTree = new PathTree<string>(); pathTree.CreateDirectory("\\this\\is\\a"); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Delete(); // Assert Assert.IsFalse(file.Exists); }
public void ConstructPathFileWithNullPathTree() { // Execute var file = new PathFile<string>(a_pathTree: null, a_path: "\\file.dat"); // Assert Assert.AreEqual("\\file.dat", file.Path); Assert.IsNotNull(file.FileSystem); }
public void DeleteFromNotExistingFile() { // Setup var pathTree = new PathTree<string>(); var file = new PathFile<string>(pathTree, "\\this\\is\\a\\file.txt"); // Execute file.Delete(); }
public string pathName; //name of the path to be able to print it. /// <summary> /// Creates an AIPath from PAT file information. /// First creates all the nodes and then links them together into a main list /// with optional parallel siding list. /// </summary> public AIPath(TrackDatabaseFile TDB, TrackSectionsFile tsectiondat, string filePath, bool isTimetableMode) { PathFile patFile = new PathFile(filePath); pathName = patFile.Name; TrackDB = TDB.TrackDB; TSectionDat = tsectiondat; bool fatalerror = false; if (patFile.PathNodes.Count <= 0) { fatalerror = true; Nodes = null; return; } foreach (PathNode tpn in patFile.PathNodes) { Nodes.Add(new AIPathNode(tpn, patFile.DataPoints[(int)tpn.PathDataPoint], TrackDB, isTimetableMode)); } FirstNode = Nodes[0]; //LastVisitedNode = FirstNode; // Connect the various nodes to each other for (int i = 0; i < Nodes.Count; i++) { AIPathNode node = Nodes[i]; node.Index = i; PathNode tpn = patFile.PathNodes[i]; // find TVNindex to next main node. if (tpn.HasNextMainNode) { node.NextMainNode = Nodes[(int)tpn.NextMainNode]; node.NextMainTVNIndex = node.FindTVNIndex(node.NextMainNode, TDB, tsectiondat, i == 0 ? -1 : Nodes[i - 1].NextMainTVNIndex); if (node.JunctionIndex >= 0) { node.IsFacingPoint = TestFacingPoint(node.JunctionIndex, node.NextMainTVNIndex); } if (node.NextMainTVNIndex < 0) { node.NextMainNode = null; Trace.TraceWarning("Cannot find main track for node {1} in path {0}", filePath, i); fatalerror = true; } } // find TVNindex to next siding node if (tpn.HasNextSidingNode) { node.NextSidingNode = Nodes[(int)tpn.NextSidingNode]; node.NextSidingTVNIndex = node.FindTVNIndex(node.NextSidingNode, TDB, tsectiondat, i == 0 ? -1 : Nodes[i - 1].NextMainTVNIndex); if (node.JunctionIndex >= 0) { node.IsFacingPoint = TestFacingPoint(node.JunctionIndex, node.NextSidingTVNIndex); } if (node.NextSidingTVNIndex < 0) { node.NextSidingNode = null; Trace.TraceWarning("Cannot find siding track for node {1} in path {0}", filePath, i); fatalerror = true; } } if (node.NextMainNode != null && node.NextSidingNode != null) { node.Type = AIPathNodeType.SidingStart; } } FindSidingEnds(); if (fatalerror) { Nodes = null; // invalid path - do not return any nodes } }
public void ConstructPathFile() { // Setup var pathTree = new PathTree<string>(); // Execute var file = new PathFile<string>(pathTree, "\\file.dat"); // Assert Assert.AreEqual("\\file.dat", file.Path); Assert.AreSame(pathTree, file.FileSystem); }