/// <summary> /// Event handler invoked when user clicks on 'Import' /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void OnImport(object sender, EventArgs e) { string fileName = this.view.AskUserForOpenFileName("*.apsim|*.apsim"); APSIMImporter importer = new APSIMImporter(); try { this.view.ShowWaitCursor(true); try { importer.ProcessFile(fileName); string newFileName = Path.ChangeExtension(fileName, ".apsimx"); bool onLeftTabControl = this.view.IsControlOnLeft(sender); this.OpenApsimXFileInTab(newFileName, onLeftTabControl); } finally { this.view.ShowWaitCursor(false); } } catch (Exception exp) { throw new Exception("Failed import: " + exp.Message); } }
/// <summary> /// Event handler invoked when user clicks on 'Import' /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private void OnImport(object sender, EventArgs e) { string fileName = this.view.AskUserForFileName(string.Empty, "*.apsim|*.apsim"); APSIMImporter importer = new APSIMImporter(); try { this.view.WaitCursor = true; try { importer.ProcessFile(fileName); string newFileName = Path.ChangeExtension(fileName, ".apsimx"); this.OpenApsimXFileInTab(newFileName); } finally { this.view.WaitCursor = false; } } catch (Exception exp) { throw new Exception("Failed import: " + exp.Message); } }
/// <summary> /// Runs the importer on a file, then opens it in a new tab. /// </summary> /// <param name="fileName">Path to the file to be imported.</param> /// <param name="leftTab">Should the file be opened in the left tabset?</param> public void Import(string fileName) { try { APSIMImporter importer = new APSIMImporter(); importer.ProcessFile(fileName); } catch (Exception err) { ShowError(err); } }
public void ImportOldAPSIM() { // test the importing of an example simulation from APSIM 7.6 APSIMImporter importer = new APSIMImporter(); importer.ProcessFile("Continuous_Wheat.apsim"); Simulations testrunSimulations = Simulations.Read("Continuous_Wheat.apsimx"); Assert.IsNotNull(Apsim.Find(testrunSimulations, "wheat")); Assert.IsNotNull(Apsim.Find(testrunSimulations, "clock")); Assert.IsNotNull(Apsim.Find(testrunSimulations, "SoilNitrogen")); Assert.IsNotNull(Apsim.Find(testrunSimulations, "SoilWater")); }
static void Main(string[] args) { APSIMImporter importer = new APSIMImporter(); string apsimPath = ""; if ((args.Length > 0) && (args[0].Length > 0)) { for (int i = 0; i < args.Length; i++) { String filename = args[i]; if (filename[0] == '-') // if this is a parameter { if (filename[1] == 'a') // apsim path macro replacement { apsimPath = filename.Substring(2, filename.Length - 2); } } else { // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(filename); importer.ApsimPath = apsimPath; //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { importer.ProcessDir(filename); } else { importer.ProcessFile(filename); } } } } else { Console.WriteLine("Useage: Importer [options] file.apsim [file2.apsim ....]\n Or: Importer [options] directoryname [dir2 ...]\n"); Console.Write("Where options are\n\t-a to set the base apsim path. e.g. -aC:\\apsim \n"); } }