/// <summary> /// Run all child simulations with the given optimal values, /// and store the results in the given checkpoint name. /// </summary> /// <param name="checkpointName">Name of the checkpoint.</param> /// <param name="optimalValues">Changes to be applied to the models.</param> /// <param name="fileName">Name of the apsimx file run by the optimiser.</param> private void RunSimsWithOptimalValues(string fileName, string checkpointName, IEnumerable <CompositeFactor> optimalValues) { IDataStore storage = FindInScope <IDataStore>(); // First, clone the simulations (we don't want to change the values // of the parameters in the original file). Simulations clonedSims = FileFormat.ReadFromFile <Simulations>(fileName, out List <Exception> errors); if (errors != null && errors.Count > 0) { throw errors[0]; } // Apply the optimal values to the cloned simulations. clonedSims = EditFile.ApplyChanges(clonedSims, optimalValues); DataStore clonedStorage = clonedSims.FindChild <DataStore>(); clonedStorage.Close(); clonedStorage.CustomFileName = storage.FileName; clonedStorage.Open(); // Run the child models of the cloned CroptimizR. Runner runner = new Runner(clonedSims); errors = runner.Run(); if (errors != null && errors.Count > 0) { throw errors[0]; } storage.Writer.AddCheckpoint(checkpointName); storage.Writer.SetCheckpointShowGraphs(checkpointName, true); }
private void saveItem_Click(object sender, System.EventArgs evtargs) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { Globals.GetFrame(_appliance).AddLogLine("Saving state in " + dlg.FileName + "..."); try { DataStore saveFile = new DataStore(dlg.FileName); IEnumerator e = _appliance.VariableTable.GetObjectEnumerator(); while (e.MoveNext()) { if (((ApplianceObject)e.Current).State) { ApplianceState state = (ApplianceState)e.Current; if (state.Defined) { saveFile.Set(state.FullName, state.Value.ToString()); } } } saveFile.Close(); } catch (Exception) { Globals.GetFrame(_appliance).AddLogLine("File not found."); } } }
public void ForeignCharacterTest() { string path = Path.Combine(Path.GetTempPath(), "文档.db"); DataStore storage = new DataStore(); storage.FileName = path; Assert.DoesNotThrow(() => storage.Open(false)); try { storage.Close(); File.Delete(path); } catch { } }
/// <summary>Look through all models. For each simulation found set the filename.</summary> private void SetFileNameInAllSimulations() { foreach (Model child in Apsim.ChildrenRecursively(this)) { if (child is Simulation) { (child as Simulation).FileName = FileName; } else if (child is DataStore) { DataStore storage = child as DataStore; storage.Close(); storage.UpdateFileName(); storage.Open(); } } }
/// <summary>Look through all models. For each simulation found set the filename.</summary> private void SetFileNameInAllSimulations() { foreach (Model child in this.FindAllDescendants().ToList()) { if (child is Simulation) { (child as Simulation).FileName = FileName; } else if (child is DataStore) { DataStore storage = child as DataStore; storage.Close(); storage.UpdateFileName(); storage.Open(); } } }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { base.OnClosing(e); DataStore.AppPrefs.RoiFilePath = _txtRegionFile.Text; DataStore.AppPrefs.SubjectfilePath = _txtSubjectFile.Text; DataStore.AppPrefs.DataFileDir = _txtDataFolder.Text; DataStore.AppPrefs.OutputDir = _txtOutputFolder.Text; DataStore.AppPrefs.WindowLocation.X = this.Left; DataStore.AppPrefs.WindowLocation.Y = this.Top; DataStore.AppPrefs.WindowLocation.Width = this.Width; DataStore.AppPrefs.WindowLocation.Height = this.Height; DataStore.Save(); DataStore.Close(); }
private void restoreItem_Click(object sender, System.EventArgs evtargs) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { Globals.GetFrame(_appliance).AddLogLine("Restoring state from " + dlg.FileName + "..."); try { DataStore loadFile = new DataStore(dlg.FileName); IEnumerator e = _appliance.VariableTable.GetObjectEnumerator(); while (e.MoveNext()) { if (((ApplianceObject)e.Current).State) { ApplianceState state = (ApplianceState)e.Current; if (loadFile.IsKeyValid(state.Name)) { _debugConnection.Send( new StateChangeNotification(state.FullName, loadFile.GetStringData(state.FullName))); } } } loadFile.Close(); } catch (Exception) { Globals.GetFrame(_appliance).AddLogLine("File not found."); } } }