void LoadSchemas() { if (this.cache == null) { if (this.Site != null) { this.cache = (SchemaCache)this.Site.GetService(typeof(SchemaCache)); } } items.Clear(); DataGridViewRowCollection col = this.dataGridView1.Rows; col.Clear(); if (this.cache != null) { foreach (CacheEntry e in this.cache.GetSchemas()) { Uri uri = e.Location; string filename = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri; SchemaItem item = new SchemaItem(e.Disabled, e.TargetNamespace, filename); items.Add(item); int i = col.Add(item.Values); col[i].Tag = item; } } }
public override void Do() { SchemaItem item = row.Tag as SchemaItem; if (row.Index == this.View.Rows.Count - 1) { isNewRow = true; } this.View.CurrentCell = row.Cells[2]; this.View.NotifyCurrentCellDirty(true); row.Cells[1].Value = newNamespace; if (item == null) // then it was a new row { item = new SchemaItem(false, newNamespace, newSchema); item.Schema = schema; AttachItem(row, item); } else { item.TargetNamespace = newNamespace; item.Filename = newSchema; } InvalidateRow(row); this.View.NotifyCurrentCellDirty(false); Verify(); }
public int InsertRow(bool disabled, string targetNamespace, string filename) { SchemaItem item = new SchemaItem(disabled, targetNamespace, filename); int i = this.view.Rows.Add(item.Values); DataGridViewRow row = this.view.Rows[i]; AttachItem(row, item); return(i); }
public bool Commit() { IList <CacheEntry> oldList = _cache.GetSchemas(); XmlResolver resolver = this._cache.Resolver; foreach (DataGridViewRow row in this.dataGridView1.Rows) { string filename = row.Cells[2].Value as string; SchemaItem item = (SchemaItem)row.Tag; if (!string.IsNullOrEmpty(filename)) { CacheEntry ce = this._cache.FindSchemaByUri(filename); bool isNew = (ce == null); if (ce == null || ce.Schema == null) { try { XmlSchema s = resolver.GetEntity(new Uri(filename), "", typeof(XmlSchema)) as XmlSchema; if (ce == null) { ce = this._cache.Add(s); } else { ce.Schema = s; } } catch (Exception e) { DialogResult rc = MessageBox.Show(this, string.Format(SR.SchemaLoadError, filename, e.Message), SR.SchemaError, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (rc == DialogResult.Cancel) { row.Selected = true; return(false); } } } if (!isNew) { oldList.Remove(ce); } if (row.Cells[0].Value != null) { ce.Disabled = (bool)row.Cells[0].Value; } } } // Remove schemas from the cache that have been removed from the grid view. foreach (CacheEntry toRemove in oldList) { _cache.Remove(toRemove); } this._undoManager.Clear(); return(true); }
public DataGridViewRow RemoveRow(DataGridViewRow row) { if (row.Index != -1) { this.view.Rows.Remove(row); } SchemaItem item = row.Tag as SchemaItem; if (item != null) { this.items.Remove(item); } return(row); }
public override void Do() { List <DataGridViewRow> list = new List <DataGridViewRow>(); foreach (string file in this.files) { try { Uri uri = new Uri(file); string path = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri; DataGridViewRow row = FindExistingRow(path); if (row != null) { XmlSchema s = LoadSchema(path); if (s != null) { SchemaItem item = row.Tag as SchemaItem; if (item == null) { item = new SchemaItem(false, s.TargetNamespace, path); AttachItem(row, item); } row.Cells[1].Value = s.TargetNamespace; item.TargetNamespace = s.TargetNamespace; row.Cells[2].Value = path; item.Filename = path; } } else { row = InsertRow(path); if (row != null) { newRows.Add(row); list.Add(row); } } list.Add(row); } catch { #if DEBUG Trace.WriteLine("Bad file name:" + file); #endif } } SelectRows(list); Verify(); }
public IList <DataGridViewRow> RemoveRows(IList <DataGridViewRow> rows) { DataGridViewRowCollection col = this.view.Rows; foreach (DataGridViewRow row in rows) { col.Remove(row); SchemaItem item = row.Tag as SchemaItem; if (item != null) { this.items.Remove(item); } } return(rows); }
public void AddRows(IList <DataGridViewRow> rows) { DataGridViewRowCollection col = this.view.Rows; foreach (DataGridViewRow row in rows) { int i = col.Add(row); SchemaItem item = row.Tag as SchemaItem; if (item != null) { items.Insert(i, item); } } SelectRows(rows); }
public SchemaDialogEditCommand(DataGridView view, List <SchemaItem> items, DataGridViewRow row, string newSchema) : base(view, items) { this.newSchema = newSchema; this.row = row; SchemaItem item = row.Tag as SchemaItem; if (item != null) { oldSchema = item.Filename; oldNamespace = item.TargetNamespace; schema = item.Schema; } // should succeed because previous code already validated the filename. schema = SchemaDialogCommand.LoadSchema(newSchema); newNamespace = schema == null ? "" : schema.TargetNamespace; index = row.Index; }
public override void Undo() { if (IsNewRow) { row = RemoveRow(row); } else { row.Cells[2].Value = oldSchema; row.Cells[1].Value = oldNamespace; SchemaItem item = row.Tag as SchemaItem; if (item != null) { item.Filename = oldSchema; item.TargetNamespace = oldNamespace; } InvalidateRow(row); } Verify(); }
protected void Verify() { foreach (DataGridViewRow row in this.view.Rows) { string matches = "null"; if (row.Tag != null) { SchemaItem item = (SchemaItem)row.Tag; if (item != items[row.Index]) { matches = "false"; } else { matches = "true"; } } string name = row.Cells[2].Value as string; Trace.WriteLine("row[" + name + "]=" + matches); } }
public override void Do() { SchemaItem item = row.Tag as SchemaItem; if (row.Index == this.View.Rows.Count - 1) { isNewRow = true; } this.View.CurrentCell = row.Cells[2]; this.View.NotifyCurrentCellDirty(true); row.Cells[1].Value = newNamespace; if (item == null) { // then it was a new row item = new SchemaItem(false, newNamespace, newSchema); item.Schema = schema; AttachItem(row, item); } else { item.TargetNamespace = newNamespace; item.Filename = newSchema; } InvalidateRow(row); this.View.NotifyCurrentCellDirty(false); Verify(); }
public int InsertRow(bool disabled, string targetNamespace, string filename) { SchemaItem item = new SchemaItem(disabled, targetNamespace, filename); int i = this.view.Rows.Add(item.Values); DataGridViewRow row = this.view.Rows[i]; AttachItem(row, item); return i; }
public void AttachItem(DataGridViewRow row, SchemaItem item) { row.Tag = item; this.items.Insert(row.Index, item); }
public override void Do() { List<DataGridViewRow> list = new List<DataGridViewRow>(); foreach (string file in this.files) { try { Uri uri = new Uri(file); string path = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri; DataGridViewRow row = FindExistingRow(path); if (row != null) { XmlSchema s = LoadSchema(path); if (s != null) { SchemaItem item = row.Tag as SchemaItem; if (item == null) { item = new SchemaItem(false, s.TargetNamespace, path); AttachItem(row, item); } row.Cells[1].Value = s.TargetNamespace; item.TargetNamespace = s.TargetNamespace; row.Cells[2].Value = path; item.Filename = path; } } else { row = InsertRow(path); if (row != null) { newRows.Add(row); list.Add(row); } } list.Add(row); } catch { #if DEBUG Trace.WriteLine("Bad file name:" + file); #endif } } SelectRows(list); Verify(); }