private void Button_Click(object sender, RoutedEventArgs e) { var dlg = new OpenFileDialog() { DefaultExt = "iso", Filter = "Cnc iso file |*.iso" }; var b = dlg.ShowDialog(); if (b.HasValue && b.Value) { IsoParser.Parse(dlg.FileName, true); } }
private void LoadStepsCommandImplementation() { var dlg = MVMIoc.SimpleIoc <IFileDialog> .GetInstance("OpenFile"); var data = MVMIoc.SimpleIoc <IStepsContainer> .GetInstance(); dlg.AddExtension = true; dlg.DefaultExt = "msteps"; dlg.Filter = "Machine steps |*.msteps|Cnc iso file |*.iso|Cnc iso file |*.i"; var b = dlg.ShowDialog(); if (b.HasValue && b.Value) { var extension = System.IO.Path.GetExtension(dlg.FileName).Replace(".", ""); if (string.Compare(extension, "msteps", true) == 0) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(MachineStepsDocument)); using (var reader = new System.IO.StreamReader(dlg.FileName)) { var doc = (MachineStepsDocument)serializer.Deserialize(reader); if (doc != null) { LoadDataSteps(data, doc); data.SourceName = dlg.FileName; } } } else if ((string.Compare(extension, "iso", true) == 0) || (string.Compare(extension, "i", true) == 0)) { var doc = IsoParser.Parse(dlg.FileName, true, GetLinkLimits, GetLinearLinkCount, GetLinearLinksIds); if (doc != null) { LoadDataSteps(data, doc); data.SourceName = dlg.FileName; } } } }
public static MachineStepsDocument LoadAndParse(string fileName, bool traceOut = false, Func<int, Tuple<double, double>> getLinkLimits = null, Func<int> getLinearLinksCount = null) { return IsoParser.Parse(fileName, traceOut, getLinkLimits, getLinearLinksCount); }
public static Duration fromIso(string s, bool check) { try { long ticks = 0; bool neg = false; IsoParser p = new IsoParser(s); // check for negative if (p.cur == '-') { neg = true; p.consume(); } else if (p.cur == '+') { p.consume(); } // next char must be P p.consume('P'); if (p.cur == -1) { throw new System.Exception(); } // D int num = 0; if (p.cur != 'T') { num = p.num(); p.consume('D'); ticks += num * nsPerDay; if (p.cur == -1) { return(new Duration(ticks)); } } // next char must be T p.consume('T'); if (p.cur == -1) { throw new System.Exception(); } num = p.num(); // H if (num >= 0 && p.cur == 'H') { p.consume(); ticks += num * nsPerHr; num = p.num(); } // M if (num >= 0 && p.cur == 'M') { p.consume(); ticks += num * nsPerMin; num = p.num(); } // S if (num >= 0 && p.cur == 'S' || p.cur == '.') { ticks += num * nsPerSec; if (p.cur == '.') { p.consume(); ticks += p.frac(); } p.consume('S'); } // verify we parsed everything if (p.cur != -1) { throw new System.Exception(); } // negate if necessary and return result if (neg) { ticks = -ticks; } return(new Duration(ticks)); } catch (System.Exception) { if (!check) { return(null); } throw ParseErr.make("ISO 8601 Duration", s).val; } }
public static Duration fromIso(string s, bool check) { try { long ticks = 0; bool neg = false; IsoParser p = new IsoParser(s); // check for negative if (p.cur == '-') { neg = true; p.consume(); } else if (p.cur == '+') { p.consume(); } // next char must be P p.consume('P'); if (p.cur == -1) throw new System.Exception(); // D int num = 0; if (p.cur != 'T') { num = p.num(); p.consume('D'); ticks += num * nsPerDay; if (p.cur == -1) return new Duration(ticks); } // next char must be T p.consume('T'); if (p.cur == -1) throw new System.Exception(); num = p.num(); // H if (num >= 0 && p.cur == 'H') { p.consume(); ticks += num * nsPerHr; num = p.num(); } // M if (num >= 0 && p.cur == 'M') { p.consume(); ticks += num * nsPerMin; num = p.num(); } // S if (num >= 0 && p.cur == 'S' || p.cur == '.') { ticks += num * nsPerSec; if (p.cur == '.') { p.consume(); ticks += p.frac(); } p.consume('S'); } // verify we parsed everything if (p.cur != -1) throw new System.Exception(); // negate if necessary and return result if (neg) ticks = -ticks; return new Duration(ticks); } catch(System.Exception) { if (!check) return null; throw ParseErr.make("ISO 8601 Duration", s).val; } }