void AddDirectory() { TreeNode s = selected; if (s == null) { return; } ILogDirectory d = s.Tag as ILogDirectory; try { List <string> l = d.GetDirectoryNames(); for (int i = 1; ; i++) { string n = "New folder" + i; if (!l.Contains(n)) { ILogDirectory ld = d.Create(n, ""); TreeNode nd = ld.CreateNode(true); s.Nodes.Add(nd); return; } } } catch (Exception exception) { exception.ShowError(); } }
private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = dataGridViewFiles.Rows[e.RowIndex]; ILogData d = row.Tag as ILogData; int ri = e.ColumnIndex; string text = row.Cells[ri].Value + ""; if (ri == 1) { if (d.Comment.Equals(text)) { return; } d.Comment = text; return; } if (ri == 0) { if (d.Name.Equals(text)) { return; } ILogDirectory dir = d.Parent as ILogDirectory; List <string> l = dir.GetDirectoryNames(); string name = d.Name; l.Remove(name); if (l.Contains(text)) { MessageBox.Show(this, "Name already exist"); row.Cells[ri].Value = name; return; } d.Name = text; } }
void ShowIntervalTable(ILogDirectory dir, bool isFile) { Dictionary <string, ILogData> d = new Dictionary <string, ILogData>(); foreach (object o in current.Children) { if (o is ILogData) { ILogData ld = o as ILogData; d[ld.Name] = ld; } } List <string> lt = new List <string>(d.Keys); lt.Sort(); bool isRoot = IsRoot; dataGridViewIntervals.Rows.Clear(); foreach (string key in lt) { DataGridViewRow row = new DataGridViewRow(); ILogData data = d[key]; ILogInterval i = data as ILogInterval; row.Tag = d[key]; row.CreateCells(dataGridViewIntervals, new object[] { data.Name, data.Comment, i.Begin, i.End, data.FileName }); dataGridViewIntervals.Rows.Add(row); } toolStripLabelDrag.Visible = false; newToolStripButton.Visible = !isRoot; dataGridViewFiles.Visible = false; dataGridViewIntervals.Visible = true; }
void AddInterval(ILogData data) { TreeNode s = selected; if (s == null) { return; } ILogDirectory d = s.Tag as ILogDirectory; if ((d == null) | (data == null)) { return; } try { List <string> l = d.GetDirectoryNames(); for (int i = 1; ; i++) { string n = "New interval" + i; if (!l.Contains(n)) { ILogInterval ld = d.CreateIntrerval(data, n, "", 0, (uint)data.Length); ShowIntervalTable(d, false); return; } } } catch (Exception exception) { exception.ShowError(); } }
private void dataGridViewIntervals_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = dataGridViewIntervals.Rows[e.RowIndex]; ILogData d = row.Tag as ILogData; int ri = e.ColumnIndex; string text = row.Cells[ri].Value + ""; if (ri == 1) { if (d.Comment.Equals(text)) { return; } d.Comment = text; return; } if (ri == 0) { if (d.Name.Equals(text)) { return; } ILogDirectory dir = d.Parent as ILogDirectory; List <string> l = dir.GetDirectoryNames(); string name = d.Name; l.Remove(name); if (l.Contains(text)) { MessageBox.Show(this, "Name already exist"); row.Cells[ri].Value = name; return; } d.Name = text; return; } ILogInterval interval = d as ILogInterval; try { uint number = uint.Parse(text); if (number == 1) { number = 0; } if (ri == 2) { interval.Begin = number; } if (ri == 3) { interval.End = number; } } catch (Exception exception) { exception.ShowError(); } }
/// <summary> /// Creates a tree /// </summary> /// <param name="data">Database interface</param> /// <returns>roots of trees</returns> static ILogDirectory[] CreateTree(this IDatabaseInterface data) { Dictionary <object, IParentSet> dictionary = new Dictionary <object, IParentSet>(); IEnumerable <object> list = data.Elements; List <ILogDirectory> directories = new List <ILogDirectory>(); foreach (object o in list) { ILogItem item = data[o]; IParentSet ps = null; if (item is ILogInterval) { ps = new LogIntervalWrapper(item as ILogInterval); } else if (item is ILogData) { ps = new LogItemWrapper(item as ILogData); } else { ps = new LogDirectoryWrapper(item); } dictionary[o] = ps; } foreach (IParentSet ps in dictionary.Values) { ILogItem it = (ps as ILogItem); object o = it.ParentId; if (!o.Equals(it.Id)) { if (dictionary.ContainsKey(o)) { ps.Parent = dictionary[o] as ILogItem; } } if (it is ILogInterval) { ILogInterval interval = it as ILogInterval; ILogData d = dictionary[interval.DataId] as ILogData; (interval as LogIntervalWrapper).DataSet = d; } } List <ILogDirectory> l = new List <ILogDirectory>(); foreach (IParentSet ps in dictionary.Values) { if (ps is ILogDirectory) { ILogDirectory item = (ps as ILogDirectory); if (item.Parent == null) { l.Add(item); } } } return(l.ToArray()); }
/// <summary> /// Creates a directory /// </summary> /// <param name="parent">Parent</param> /// <param name="name">Name</param> /// <param name="comment">Comment</param> /// <returns>Rhe directory</returns> static public ILogDirectory Create(this ILogDirectory parent, string name, string comment) { if (parent.GetDirectoryNames().Contains(name)) { throw new Exception(name + " already exists"); } return(new LogDirectoryWrapper(parent as LogDirectoryWrapper, data.Create(parent.Id, name, comment))); }
/// <summary> /// Names of directory children /// </summary> /// <param name="directory"></param> /// <returns></returns> static public List <string> GetDirectoryNames(this ILogDirectory directory) { List <string> list = new List <string>(); foreach (ILogItem it in directory.Children) { list.Add(it.Name); } return(list); }
/// <summary> /// Creates data /// </summary> /// <param name="directory">Directory</param> /// <param name="data">Data</param> /// <param name="name"></param> /// <param name="fileName">File name</param> /// <param name="comment">Comment</param> /// <returns>The data</returns> public static ILogInterval CreateIntrerval(this ILogDirectory directory, ILogData data, string name, string comment, uint begin, uint end) { IDatabaseInterface d = StaticExtensionEventLogDatabase.data; if (directory.GetDirectoryNames().Contains(name)) { throw new Exception(name + " already exists"); } ILogInterval interval = d.CreateInterval(directory.Id, name, comment, data, begin, end); return(new LogIntervalWrapper(directory as LogDirectoryWrapper, interval, data)); }
void ShowContent(ILogDirectory dir) { if (dir == current) { return; } current = dir; bool isFile = IsFile; Dictionary <string, ILogData> d = new Dictionary <string, ILogData>(); foreach (object o in current.Children) { if (o is ILogData) { ILogData ld = o as ILogData; d[ld.Name] = ld; } } List <string> lt = new List <string>(d.Keys); lt.Sort(); bool isRoot = IsRoot; if (isFile) { dataGridViewFiles.Rows.Clear(); foreach (string key in lt) { DataGridViewRow row = new DataGridViewRow(); ILogData data = d[key]; row.Tag = d[key]; row.CreateCells(dataGridViewFiles, new object[] { data.Name, data.Comment, data.Length, data.FileName }); dataGridViewFiles.Rows.Add(row); } toolStripLabelDrag.Visible = !isRoot; newToolStripButton.Visible = false; dataGridViewFiles.Visible = true; dataGridViewIntervals.Visible = false; } else { ShowIntervalTable(dir, isFile); } }
/// <summary> /// Creates data /// </summary> /// <param name="directory">Directory</param> /// <param name="data">Data</param> /// <param name="name"></param> /// <param name="fileName">File name</param> /// <param name="comment">Comment</param> /// <returns>The data</returns> public static ILogData CreateData(this ILogDirectory directory, IEnumerable <byte[]> data, string name, string fileName, string comment) { IDatabaseInterface d = StaticExtensionEventLogDatabase.data; if (d.Filenames.Contains(fileName)) { throw new Exception("File " + fileName + " already exists"); } if (directory.GetDirectoryNames().Contains(name)) { throw new Exception(name + " already exists"); } ILogData ld = d.Create(data, directory.Id, name, fileName, comment); d.Filenames.Add(fileName); return(new LogItemWrapper(directory as LogDirectoryWrapper, ld)); }
static internal TreeNode CreateNode(this ILogItem item, bool openedDir = false) { int n2 = 0; int n3 = 1; int n4 = 2; if (openedDir) { ++n2; ++n3; ++n4; } TreeNode n = null; if (item is ILogDirectory) { ILogDirectory d = item as ILogDirectory; List <TreeNode> l = new List <TreeNode>(); foreach (ILogItem it in d.Children) { TreeNode tn = it.CreateNode(openedDir); if (tn != null) { l.Add(it.CreateNode(openedDir)); } } l.Sort(TreeNodeComparer.Singleton); n = new TreeNode(item.Name, 0, 1, l.ToArray()); } else { if (!openedDir) { n = new TreeNode(item.Name, 2, 3); } else { return(null); } } n.Tag = item; return(n); }
private void treeViewDir_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { TreeNode s = e.Node; if (s == null) { return; } object o = s.Tag; if (o == null) { return; } if (o is ILogItem) { ILogItem item = o as ILogItem; ILogItem p = item.Parent; if (p == null | !(p is ILogDirectory)) { MessageBox.Show("Prohibited"); return; } ILogDirectory d = p as ILogDirectory; List <string> names = d.GetDirectoryNames(); string name = e.Label; if (names.Contains(name)) { MessageBox.Show("Name alredy exists"); return; } try { item.Name = name; } catch (Exception exception) { exception.ShowError(); } } }
/// <summary> /// Full directory /// </summary> /// <param name="item">Item</param> /// <param name="action">Action</param> /// <returns>Full directory</returns> public static IEnumerable <ILogItem> FullDirectory(this ILogItem item, Action <ILogItem> action = null) { if (action != null) { action(item); } yield return(item); if (item is ILogDirectory) { ILogDirectory ld = item as ILogDirectory; IEnumerable <ILogItem> enu = ld.Children; foreach (ILogItem it in enu) { IEnumerable <ILogItem> enn = it.FullDirectory(action); foreach (ILogItem itt in enn) { yield return(itt); } } } }
ILogItem SaveFile(string filename) { IDatabaseInterface d = StaticExtensionEventLogDatabase.Data; string fn = Path.GetFileNameWithoutExtension(filename).ToLower(); if (d.Filenames.Contains(fn)) { MessageBox.Show("File already exists"); return(null); } using (Stream stream = File.OpenRead(filename)) { ILogDirectory dir = selected.Tag as ILogDirectory; IEnumerable <byte[]> data = stream.ToObjectEnumerable().ToByteEnumerable(); ILogItem it = dir.CreateData(data, fn, fn, ""); DataGridViewRow row = new DataGridViewRow(); ILogData ld = it as ILogData; row.Tag = it; row.CreateCells(dataGridViewFiles, new object[] { ld.Name, ld.Comment, ld.Length, ld.FileName }); dataGridViewFiles.Rows.Add(row); return(it); } }
internal DatabaseDirectoryLogReader(ILogDirectory directory) { this.directory = directory; }