private static void LoadDataSteps(IStepsContainer data, MachineStepsDocument doc) { data.Steps.Clear(); data.Steps.Add(new StepViewModel(-1, "Start", "Initial condition")); for (int i = 0; i < doc.Steps.Count; i++) { data.Steps.Add(new StepViewModel(doc.Steps[i], i + 1)); } }
public static MachineStepsDocument Parse(string fileName, bool traceOut = false, Func <int, Tuple <double, double> > getLinkLimits = null, Func <int> getLinearLinksCount = null, Func <IList <int> > getLinearLinksIds = null) { MachineStepsDocument msd = null; var parser = new IsoTextParser(); using (var stream = File.OpenText(fileName)) { var lineNumber = 1; while (true) { var line = stream.ReadLine(); if (line == null) { break; } if (!string.IsNullOrWhiteSpace(line)) { parser.ParseLine(line, lineNumber++); } } } if (parser.Istructions != null && parser.Istructions.Count > 0) { StateInfoServices.GetLinkLimits = getLinkLimits; StateInfoServices.GetLinearLinksCount = getLinearLinksCount; StateInfoServices.GetLinearLinksIds = getLinearLinksIds; msd = IstructionToActionConverter.Convert(parser.Istructions); if ((msd != null) && traceOut) { var dir = System.IO.Path.GetDirectoryName(fileName); var name = System.IO.Path.GetFileNameWithoutExtension(fileName); var mfile = $"{dir}\\{name}.msteps"; var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MachineStepsDocument)); using (var writer = new System.IO.StreamWriter(mfile)) { serializer.Serialize(writer, msd); } } } return(msd); }
public static MachineStepsDocument Convert(List <BaseIstruction> Istructions) { var converter = new IstructionToActionConverter(); MachineStepsDocument msd = null; BaseIstructionConverter.ResetStepId(); if (converter.ConvertImplementation(Istructions)) { msd = new MachineStepsDocument() { Steps = converter._machineSteps }; } return(msd); }
private void FileSaveCommandImpl() { var dlg = new Microsoft.Win32.SaveFileDialog() { DefaultExt = "msteps", AddExtension = true, Filter = "Machine steps |*.msteps" }; var b = dlg.ShowDialog(); if (b.HasValue && b.Value) { var doc = new MachineStepsDocument() { Steps = Steps.ToList() }; var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MachineStepsDocument)); using (var writer = new System.IO.StreamWriter(dlg.FileName)) { serializer.Serialize(writer, doc); } } }