private void DisplayFragment(Fragment f) { if(f != null) { MessageBox.Show(f.ToMultiLineString()); } else { MessageBox.Show("fragment null"); } }
private void DemoFragments() { List<Core.Fragment> lst = new List<Core.Fragment>(); for (int i = 1; i < 10; i++) { Core.Fragment f = new Core.Fragment("frg" + i); f.SetMeta("DemoKey", "demo value for frg" + i); if(i % 2 == 0) { f.SetMeta("ConditionalMetaKey", "example " + i); } lst.Add(f); } fmw.Receive(lst); }
public Fragment DeepCopy() { Fragment f = null; foreach (KeyValuePair<string, string> kv in _meta) { if (f == null) { f = new Fragment(kv.Key, kv.Value); } f.SetMeta(kv.Key, kv.Value); } f.DisplayKey = this.DisplayKey; return f; }
public void Merge(Fragment f, ConflictMergeAction cma) { foreach (KeyValuePair<string, string> kv in f.Meta) { if (_meta.ContainsKey(kv.Key)) { switch (cma) { case ConflictMergeAction.OverwriteConflicts: //overwrite current value SetMeta(kv.Key, kv.Value); break; case ConflictMergeAction.SkipConflicts: //skip value (leave alone) break; case ConflictMergeAction.ThrowErrorOnConflicts: throw new FragmentMergeException("Merge Conflict for Fragment Key: " + kv.Key); } } else { //no conflicts, just copy regardless of ConflictMergeAction SetMeta(kv.Key, kv.Value); } } DisplayKey = f.DisplayKey; }
public ProcessableFragment(Fragment f, string processedKey) : base("FragmentType", "Processable") { this.processedKey = processedKey; Merge(f, ConflictMergeAction.OverwriteConflicts); }
private void ExtractByKeys(object sender, RoutedEventArgs e) { List<string> keys = new List<string>(); List<Fragment> fragments = new List<Fragment>(); string key = ""; do { key = UI.Prompt.Input("Enter key to extract, or press enter to continue"); if (!string.IsNullOrWhiteSpace(key)) { keys.Add(key); } } while (!string.IsNullOrWhiteSpace(key)); bool keysVerified = true; foreach(Fragment f in window.GetFragments()) { //break nested loop if key verification fails if (!keysVerified) { break; } Fragment newFragment = null; foreach(string k in keys) { string v = f.GetMeta(k); if(v != null) { if(newFragment == null) { newFragment = new Fragment(k, v); } else { newFragment.SetMeta(k, v); } }else { keysVerified = false; break; } } fragments.Add(newFragment); } if (keysVerified) { window.Receive(fragments); } else { MessageBox.Show("keys could not be verified, one or more fragments missing specified keys"); } }