/// <summary> /// Runs the Macro at the given location. /// </summary> /// <param name="macroFile">The file path to the macro.</param> public void RunMacro(FileSystem.File macroFile) { PMMacro macro = null; macro = LoadMacro(macroFile); macro.Run(); }
/// <summary> /// gets a specific file by virtual path /// </summary> /// <param name="VirtualPath">the virtual path of the file</param> /// <returns></returns> public override FileSystem.File GetFile(string VirtualPath) { VirtualPath = CleanVirtualPath(VirtualPath); var aPath = VirtualPathToUNCPath(VirtualPath); var sysFile = new FileInfo(aPath); if (!sysFile.Exists) { throw new FileNotFoundException("The file at " + VirtualPath + " was not found."); } var file = new FileSystem.File { FullPath = VirtualPath, Name = sysFile.Name, DateModified = sysFile.LastWriteTime, DateCreated = sysFile.CreationTime, Id = Guid.NewGuid().ToString(), LastAccessTime = sysFile.LastAccessTime, ParentDirectory = GetDirectory(VirtualPath.Substring(0, VirtualPath.LastIndexOf("/"))), FilePath = VirtualPath, FileSize = sysFile.Length, }; return(file); }
/// <summary> /// gets the file contents via Lazy load, however in the DbProvider the Contents are loaded when the initial object is created to cut down on DbReads /// </summary> /// <param name="BaseFile">the baseFile object to fill</param> /// <returns>the original file object</returns> internal override FileSystem.File GetFileContents(FileSystem.File BaseFile) { var aPath = VirtualPathToUNCPath(BaseFile.FullPath); BaseFile.FileContents = FileToByteArray(aPath); return(BaseFile); }
/// <summary> /// gets a specific file by virtual path /// </summary> /// <param name="VirtualPath">the virtual path of the file</param> /// <returns></returns> public override FileSystem.File GetFile(string VirtualPath) { VirtualPath = RelativeFilePath(VirtualPath); var aPath = BlogAbsolutePath(VirtualPath); var sysFile = new FileInfo(aPath); if (!sysFile.Exists) { throw new FileNotFoundException("The file at " + VirtualPath + " was not found."); } var file = new FileSystem.File { FullPath = VirtualPath, Name = sysFile.Name, DateModified = sysFile.LastWriteTime, DateCreated = sysFile.CreationTime, Id = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), LastAccessTime = sysFile.LastAccessTime, ParentDirectory = GetDirectory(VirtualPath.Substring(0, VirtualPath.LastIndexOf("/"))), FilePath = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), FileSize = sysFile.Length, }; return(file); }
public static NARC_new FromFileSystem(NARCFileSystem fileSystem) { NARC_new narcNew = new NARC_new(); narcNew.FATB.numFiles = (ushort)fileSystem.Root.TotalNrSubFiles; List <byte> byteList = new List <byte>(); for (ushort index = 0; (int)index < (int)narcNew.FATB.numFiles; ++index) { FileSystem.File fileById = fileSystem.Root.GetFileByID((int)index); narcNew.FATB.allocationTable.Add(new FileAllocationEntry((uint)byteList.Count, (uint)fileById.Data.Length)); byteList.AddRange((IEnumerable <byte>)fileById.Data); while (byteList.Count % 4 != 0) { byteList.Add(byte.MaxValue); } } narcNew.FIMG.fileImage = byteList.ToArray(); NARC_new.GenerateDirectoryTable(narcNew.FNTB.directoryTable, fileSystem.Root); uint dirEntryStart = narcNew.FNTB.directoryTable[0].dirEntryStart; ushort FileId = 0; NARC_new.GenerateEntryNameTable(narcNew.FNTB.directoryTable, narcNew.FNTB.entryNameTable, fileSystem.Root, ref dirEntryStart, ref FileId); return(narcNew); }
/// <summary> /// gets the file contents via Lazy load, however in the DbProvider the Contents are loaded when the initial object is created to cut down on DbReads /// </summary> /// <param name="BaseFile">the baseFile object to fill</param> /// <returns>the original file object</returns> internal override FileSystem.File GetFileContents(FileSystem.File BaseFile) { var aPath = BlogAbsolutePath(BaseFile.FullPath); BaseFile.FileContents = FileToByteArray(aPath); return(BaseFile); }
/// <summary> /// Creates a single polyline from a generic curve. /// </summary> public Polyline ToPolyline() { // Select the curve AddToSelection(true); // Write to a pic file FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("pic"); PSAutomation.ActiveModel.Export(tempFile, ExportItemsOptions.Selected); // Geth the data from the pic file List <Polyline> polyLineList = Polyline.ReadFromDUCTPictureFile(tempFile); // create a single spline from the data Polyline myPolyLine = new Polyline(); foreach (Polyline s in polyLineList) { foreach (Point sp in s) { myPolyLine.Add(sp); } } // Delete the file tempFile.Delete(); // Return the model return(myPolyLine); }
public void WriteClosedPolylineTest() { FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("pic"); List <Point> points = new List <Point>(); points.Add(new Point(0, 0, 0)); points.Add(new Point(10, 5, 2)); points.Add(new Point(20, 9, 5)); Polyline line = new Polyline(points); line.WriteToDUCTPictureFile(tempFile); Polyline newline = Polyline.ReadFromDUCTPictureFile(tempFile).Single(); // Assert that the polyline read from the file is open Assert.IsFalse(newline.IsClosed); // Close the polyline and write again line.IsClosed = true; line.WriteToDUCTPictureFile(tempFile); newline = Polyline.ReadFromDUCTPictureFile(tempFile).Single(); // Assert that the polyline read from the file is closed Assert.IsTrue(newline.IsClosed); tempFile.Delete(); }
/// <summary> /// A test for Item /// </summary> public void ItemTest(FileSystem.File entityFile) { // Get entities T entity = (T)ImportAndGetEntity(entityFile); // Check item Assert.AreEqual(entity, _powerSHAPECollection[0], "Did not return entity"); }
protected List <PSEntity> ImportAndGetEntities(FileSystem.File fileToImport) { // Import entities _powerSHAPE.ActiveModel.Import(fileToImport); // Get entities return(_powerSHAPE.ActiveModel.SelectedItems.ToList()); }
/// <summary> /// A test for LastItem /// </summary> public void LastItemTest(FileSystem.File multipleEntitiesFile) { // Get entities List <PSEntity> entities = ImportAndGetEntities(multipleEntitiesFile); // Check item Assert.AreEqual((T)entities.Last(), _powerSHAPECollection.Last(), "Returned the incorrect entity"); }
private static void AssertValidTextFile(FileSystem.File file, string path, string name, string content) { Assert.NotNull(file); Assert.AreEqual(path, file.Path); Assert.AreEqual(name, file.Name); Assert.NotNull(file.Content); Assert.NotNull(file.Content.Data); Assert.AreEqual(content, Encoding.UTF8.GetString(file.Content.Data)); }
/// <summary> /// A test for Contains /// </summary> public void ContainsTest(FileSystem.File entityToAddFile) { // Import entity T entityToAdd = (T)ImportAndGetEntity(entityToAddFile); // Check collection Assert.IsTrue(_powerSHAPECollection.Contains(entityToAdd), "Incorrectly returned that collection does not contain entity"); }
/// <summary> /// Creates a new macro and reads the Macro File in. /// </summary> /// <param name="powerMILL">The base instance to interact with PowerMILL.</param> /// <param name="macroFile">The file with the macro to be loaded.</param> protected internal PMMacro(PMAutomation powerMILL, FileSystem.File macroFile) { _lines = new List <string>(); if (macroFile != null) { // Break the file down into lines _lines = macroFile.ReadTextLines(); } ConfigureMacro(powerMILL); }
private static IFileSystemItem CreateFile(IList <string> items) { var file = new FileSystem.File { Name = items[8], Size = double.Parse(items[4]) }; return(file); }
/// <summary> /// A test for Count /// </summary> public override void CountTest(FileSystem.File entityToAddFile) { base.CountTest(entityToAddFile); // Import entity ImportAndGetEntity(entityToAddFile); // Check collection Assert.AreEqual(1, _powerSHAPECollection.Count, "Collection count is incorrect"); }
/// <summary> /// Reimports a file into PowerMill. /// </summary> /// <param name="file">The file to import.</param> public void Reimport(FileSystem.File file) { var arrayToCheck = new[] { "dmt", "dgk", "ddx", "ddz", "psmodel", "doc", "det", "pic" }; if (!arrayToCheck.Contains(file.Extension)) { throw new Exception("File extension must be dgk, ddx, ddz, psmodel, doc, det or pic"); } PowerMill.DoCommand(string.Format("EDIT MODEL '{0}' REIMPORT '{1}'", Name, file.Path)); }
/// <summary> /// Exports the model to the specified file. /// </summary> /// <param name="file">The file to which the model will be exported.</param> public void ExportModel(FileSystem.File file, bool exportInActiveWorkplane = true) { // Delete the file if it already exists file.Delete(); if (exportInActiveWorkplane == false) { PowerMill.DoCommand("DEACTIVATE WORKPLANE"); } PowerMill.DoCommand("EXPORT MODEL '" + Name + "' '" + file.Path + "'"); }
protected PSEntity ImportAndGetEntity(FileSystem.File fileToImport) { // Import entity _powerSHAPE.ActiveModel.Import(fileToImport); // Get entity if (_powerSHAPE.ActiveModel.SelectedItems.Count > 0) { return(_powerSHAPE.ActiveModel.SelectedItems[0]); } return(_powerSHAPE.ActiveModel.CreatedItems[0]); }
/// <summary> /// This test checks that the Entity's Identifier is as expected /// </summary> public override void IdentifierTest(FileSystem.File fileToImport, string expectedIdentifier) { // Get entity PSEntity importedEntity = ImportAndGetEntity(fileToImport); // Check that the collection Identifier matches the entity type string actualIdentifier = (string)importedEntity .GetType().GetProperty("Identifier", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(importedEntity, null); Assert.AreEqual(expectedIdentifier, actualIdentifier); }
/// <summary> /// Exports the mesh to the selected DMT file /// </summary> /// <param name="file">The DMT file name to export to</param> public void WriteToDMTFile(FileSystem.File file) { if (file.Extension.ToLower() == "dmt") { file.Delete(); AddToSelection(true); _powerSHAPE.ActiveModel.Export(file, ExportItemsOptions.Selected, ExportWorkplanes.Active); } else { throw new Exception("The selected file name is not a valid DMT file name"); } }
/// <summary> /// Exports the mesh to the selected DMT file /// </summary> /// <param name="file">The DMT file name to export to</param> public void WriteToDMTFile(FileSystem.File file) { if (file.Extension.ToLower() == "dmt") { file.Delete(); AddToSelection(true); _powerSHAPE.DoCommand("FILE EXPORT '" + file.Path + "'"); } else { throw new Exception("The selected file name is not a valid DMT file name"); } }
/// <summary> /// Constructor reads the Macro File in. /// </summary> /// <param name="powerSHAPE">The base instance to interact with PowerShape.</param> /// <param name="macroFile">The file path to the macro.</param> /// <remarks></remarks> protected internal PSMacro(PSAutomation powerSHAPE, FileSystem.File macroFile) { if (macroFile != null) { // Break the file down into lines _lines = macroFile.ReadTextLines(); } else { _lines = new List <string>(); } ConfigureMacro(powerSHAPE); }
/// <summary> /// gets the file contents via Lazy load, however in the DbProvider the Contents are loaded when the initial object is created to cut down on DbReads /// </summary> /// <param name="BaseFile">the baseFile object to fill</param> /// <returns>the original file object</returns> internal override FileSystem.File GetFileContents(FileSystem.File BaseFile) { var db = new FileSystem.FileStoreDb(this.connectionString); var file = db.FileStoreFiles.FirstOrDefault(x => x.FileID == Guid.Parse(BaseFile.Id)); if (file == null) { throw new ArgumentException("File not found in dataset"); } BaseFile.FileContents = file.Contents.ToArray(); db.Dispose(); return(BaseFile); }
/// <summary> /// Executes the macro in one go rather than line by line. /// </summary> public override void RunComplete() { // Replace substitution tokens List <string> linesToExecute = new List <string>(); foreach (string lineToParse in _lines) { linesToExecute.AddRange(ReplaceTokens(lineToParse)); } FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("mac"); tempFile.WriteTextLines(linesToExecute); _powerMILL.DoCommand("MACRO \"" + tempFile.Path + "\""); tempFile.Delete(); }
/// <summary> /// Imports a file as a Boundary into PowerMill and adds it to the boundaries collection. /// </summary> /// <param name="file">The file path of the boundary to import.</param> /// <returns>The new PMBoundary.</returns> public PMBoundary CreateBoundary(FileSystem.File file) { PMBoundary newBoundary = null; if (file.Exists) { _powerMILL.DoCommand(CREATE_BOUNDARY); // Get the name PowerMILL gave to the last boundary newBoundary = (PMBoundary)_powerMILL.ActiveProject.CreatedItems(typeof(PMBoundary)).Last(); Add(newBoundary); _powerMILL.DoCommand("EDIT BOUNDARY '" + newBoundary.Name + "' INSERT FILE '" + file.Path + "'"); } return(newBoundary); }
/// <summary> /// Imports the DUCT Picture file into PowerMILL as a Pattern and adds it to the collection. /// </summary> /// <param name="file">the DUCT Picture file to import.</param> public PMPattern CreatePattern(FileSystem.File file) { PMPattern newPattern = null; if (file.Exists) { _powerMILL.DoCommand("CREATE PATTERN ;"); // Get the name PowerMILL gave to the last pattern newPattern = (PMPattern)_powerMILL.ActiveProject.CreatedItems(typeof(PMPattern)).Last(); Add(newPattern); _powerMILL.DoCommand("EDIT PATTERN '" + newPattern.Name + "' INSERT FILE '" + file.Path + "'"); } return(newPattern); }
public void ExportBlockTest() { _powerMILL.ActiveProject.Boundaries.CreateBoundary(TestFiles.CurvesFiles); _powerMILL.ActiveProject.Refresh(); PMBoundary boundary = _powerMILL.ActiveProject.Boundaries.ActiveItem; var boundingBox = _powerMILL.ActiveProject.CreateBlockFromBoundaryWithLimits(boundary, 0, 100); FileSystem.File file = FileSystem.File.CreateTemporaryFile("dmt", false); _powerMILL.ActiveProject.ExportBlock(file); Assert.That(file.Exists); file.Delete(); file = FileSystem.File.CreateTemporaryFile("stl", false); _powerMILL.ActiveProject.ExportBlock(file); Assert.That(file.Exists); file.Delete(); }
/// <summary> /// Executes the macro in one go rather than line by line. /// </summary> public override void RunComplete() { FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("mac"); tempFile.WriteTextLines(_lines); _powerSHAPE.DoCommand("MACRO RUN \"" + tempFile.Path + "\""); // Wait for the macro to finish System.Threading.Thread.Sleep(1000); while (_powerSHAPE.IsBusy()) { System.Threading.Thread.Sleep(1000); } tempFile.Delete(); }
/// <summary> /// Creates a new Mesh from a DMT Model. /// </summary> /// <param name="powerSHAPE">This is the PowerSHAPE Automation object.</param> /// <param name="model">The DMT model from which to create the model.</param> internal PSMesh(PSAutomation powerSHAPE, DMTModel model) : base(powerSHAPE) { // Write the DMT to a temporary file FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("dmt"); DMTModelWriter.WriteFile(model, tempFile); // Import the DMT into PowerSHAPE _powerSHAPE.DoCommand("FILE IMPORT '" + tempFile.Path + "'"); // Delete the temporary file tempFile.Delete(); PSMesh newMesh = (PSMesh)_powerSHAPE.ActiveModel.CreatedItems[0]; // Set the Id _id = newMesh.Id; }
/// <summary> /// gets a specific file by virtual path /// </summary> /// <param name="VirtualPath">the virtual path of the file</param> /// <returns></returns> public override FileSystem.File GetFile(string VirtualPath) { VirtualPath = CleanVirtualPath(VirtualPath); var aPath = VirtualPathToUNCPath(VirtualPath); var sysFile = new FileInfo(aPath); if (!sysFile.Exists) throw new FileNotFoundException("The file at " + VirtualPath + " was not found."); var file = new FileSystem.File { FullPath = VirtualPath, Name = sysFile.Name, DateModified = sysFile.LastWriteTime, DateCreated = sysFile.CreationTime, Id = Guid.NewGuid().ToString(), LastAccessTime = sysFile.LastAccessTime, ParentDirectory = GetDirectory(VirtualPath.Substring(0, VirtualPath.LastIndexOf("/"))), FilePath = VirtualPath, FileSize = sysFile.Length, }; return file; }
/// <summary> /// gets a specific file by virtual path /// </summary> /// <param name="VirtualPath">the virtual path of the file</param> /// <returns></returns> public override FileSystem.File GetFile(string VirtualPath) { try { VirtualPath = RelativeFilePath(VirtualPath); var aPath = BlogAbsolutePath(VirtualPath); var sysFile = new FileInfo(aPath); if (!sysFile.Exists) { VirtualPath = "~/App_Data/files/2014/02/26/Rollin News RN Icon.jpg"; VirtualPath = RelativeFilePath(VirtualPath); aPath = BlogAbsolutePath(VirtualPath); sysFile = new FileInfo(aPath); } var file = new FileSystem.File { FullPath = VirtualPath, Name = sysFile.Name, DateModified = sysFile.LastWriteTime, DateCreated = sysFile.CreationTime, Id = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), LastAccessTime = sysFile.LastAccessTime, ParentDirectory = GetDirectory(VirtualPath.Substring(0, VirtualPath.LastIndexOf("/"))), FilePath = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), FileSize = sysFile.Length, }; return file; } catch (Exception exception) { RDN.Library.Classes.Error.ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: VirtualPath); } return null; }
/// <summary> /// gets a specific file by virtual path /// </summary> /// <param name="VirtualPath">the virtual path of the file</param> /// <returns></returns> public override FileSystem.File GetFile(string VirtualPath) { VirtualPath = RelativeFilePath(VirtualPath); var aPath = BlogAbsolutePath(VirtualPath); var sysFile = new FileInfo(aPath); if (!sysFile.Exists) throw new FileNotFoundException("The file at " + VirtualPath + " was not found."); var file = new FileSystem.File { FullPath = VirtualPath, Name = sysFile.Name, DateModified = sysFile.LastWriteTime, DateCreated = sysFile.CreationTime, Id = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), LastAccessTime = sysFile.LastAccessTime, ParentDirectory = GetDirectory(VirtualPath.Substring(0, VirtualPath.LastIndexOf("/"))), FilePath = VirtualPath.Replace(Blog.CurrentInstance.RootFileStore.FullPath, ""), FileSize = sysFile.Length, }; return file; }