private void CreateBraidData() { BraidData b = new BraidData(); b.Repeats = 4; Permutation p = new Permutation(); p.SetPermOf(0, 1); p.SetPermOf(1, 0); b.Add(p); p = new Permutation(); b.Add(p); p = new Permutation(); p.SetPermOf(0, 1); p.SetPermOf(1, 0); b.Add(p); BraidPatterns.Add(b); b.PropertyChanged += b_PropertyChanged; }
public async void ImportPattern(PatternType typ) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; if (typ == PatternType.wheels) { openPicker.FileTypeFilter.Add(".wheel"); } else if (typ == PatternType.ross) { openPicker.FileTypeFilter.Add(".ross"); } else if (typ == PatternType.bazley) { openPicker.FileTypeFilter.Add(".baz"); } else if (typ == PatternType.barrel) { openPicker.FileTypeFilter.Add(".bar"); } else if (typ == PatternType.latticeRim) { openPicker.FileTypeFilter.Add(".lattice"); } else if (typ == PatternType.braid) { openPicker.FileTypeFilter.Add(".braid"); } openPicker.FileTypeFilter.Add(".xml"); StorageFile file = await openPicker.PickSingleFileAsync(); XmlSerializer ser; if (file != null) { var stream = await file.OpenStreamForReadAsync(); if (typ == PatternType.wheels) { ser = new XmlSerializer(typeof(WheelsData)); WheelsData wd = (WheelsData)ser.Deserialize(stream); wd.PatternIndex = WheelsPatterns.Count; wd.FixUp(); WheelsPatterns.Add(wd); SelectedPathIndex = wd.PatternIndex; } else if (typ == PatternType.ross) { ser = new XmlSerializer(typeof(RossData)); RossData rd = (RossData)ser.Deserialize(stream); rd.PatternIndex = RossPatterns.Count; RossPatterns.Add(rd); SelectedPathIndex = rd.PatternIndex; } else if (typ == PatternType.bazley) { ser = new XmlSerializer(typeof(BazelyChuck)); BazelyChuck bd = (BazelyChuck)ser.Deserialize(stream); bd.PatternIndex = BazeleyPatterns.Count; BazeleyPatterns.Add(bd); SelectedPathIndex = bd.PatternIndex; } else if (typ == PatternType.barrel) { ser = new XmlSerializer(typeof(Barrel)); Barrel bd = (Barrel)ser.Deserialize(stream); bd.PatternIndex = BarrelPatterns.Count; BarrelPatterns.Add(bd); SelectedPathIndex = bd.PatternIndex; } else if (typ == PatternType.latticeRim) { ser = new XmlSerializer(typeof(LatticeData)); LatticeData bd = (LatticeData)ser.Deserialize(stream); if (LatticePatterns.Select(p => p.PatternIndex == bd.PatternIndex).Count() > 0) { bd.PatternIndex = LatticePatterns.Count + 1; } LatticePatterns.Add(bd); SelectedPathIndex = bd.PatternIndex; } else if (typ == PatternType.braid) { ser = new XmlSerializer(typeof(BraidData)); BraidData bd = (BraidData)ser.Deserialize(stream); bd.PatternIndex = BraidPatterns.Count; BraidPatterns.Add(bd); SelectedPathIndex = bd.PatternIndex; } } else { } }