private void UpdateListViewGraph() { try { listViewGraph.Items.Clear(); var graphs = new List <string>(); graphs.Add("default"); graphs.AddRange(fuseki.ListGraphs().Select(uri => uri.ToString()).OrderBy(ee => ee)); foreach (var uri in graphs) { var graphBase64 = GraphEditor.Base64Encode(uri); var filePath = string.Format(@"{0}\{1}.txt", DocumentRoot, graphBase64); var updateDate = ""; if (File.Exists(filePath)) { var info = new FileInfo(filePath); updateDate = info.LastWriteTime.ToShortDateString(); } var item = new ListViewItem(new[] { uri, updateDate }) { Tag = uri }; listViewGraph.Items.Add(item); } UpdateListViewGraphColor(""); } catch (Exception ex) { MessageBox.Show("error during UpdateListViewGraph. " + ex); } }
private void truncateToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewGraph.SelectedItems.Count != 1) { MessageBox.Show("no graph is selected"); return; } var graphUri = (string)listViewGraph.SelectedItems[0].Tag; if ( MessageBox.Show(string.Format("are you want to truncate {0}", graphUri), "Warning", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } var tabPage = GetTabPage(graphUri); if (tabPage != null) { tabControlGraph.TabPages.Remove(tabPage); } var loadUri = graphUri; if (graphUri == "default") { loadUri = ""; } var g = new Graph(); fuseki.LoadGraph(g, loadUri); g.Clear(); if (graphUri != "default") { SetNewGraphTriple(g, graphUri); } fuseki.SaveGraph(g); var graphBase64 = GraphEditor.Base64Encode(graphUri); var filePath = string.Format(@"{0}\{1}.txt", DocumentRoot, graphBase64); File.WriteAllText(filePath, ""); }
private void duplicateToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewGraph.SelectedItems.Count != 1) { MessageBox.Show("no graph is selected"); return; } var graphUri = (string)listViewGraph.SelectedItems[0].Tag; var g = new Graph(); fuseki.LoadGraph(g, graphUri); var form = new SingleForm { Title = "Set New Graph URI", Label = "URI", Content = graphUri }; if (form.ShowDialog() != DialogResult.OK) { return; } var srcUri = graphUri; var srcGraphBase64 = GraphEditor.Base64Encode(srcUri); var dstUri = form.Content; var dstGraphLabel = dstUri.Split(new[] { '/', '#' }).Last(); var dstGraphBase64 = GraphEditor.Base64Encode(dstUri); var newg = new Graph { BaseUri = new Uri(dstUri) }; var nLabel = newg.CreateUriNode(UriFactory.Create("http://www.w3.org/2000/01/rdf-schema#label")); newg.Assert(new Triple(newg.CreateUriNode(UriFactory.Create(dstUri)), nLabel, newg.CreateLiteralNode(dstGraphLabel))); var cnt = 0; foreach (var triple in g.Triples) { INode news = newg.CreateUriNode(UriFactory.Create(triple.Subject.ToString().Replace(srcUri, dstUri))); INode newp = newg.CreateUriNode(UriFactory.Create(triple.Predicate.ToString().Replace(srcUri, dstUri))); INode newo = null; if (triple.Object.NodeType == NodeType.Uri) { newo = newg.CreateUriNode(UriFactory.Create(triple.Object.ToString().Replace(srcUri, dstUri))); } else if (triple.Object.NodeType == NodeType.Literal) { newo = newg.CreateLiteralNode(triple.Object.ToString().Replace(srcUri, dstUri)); } var asserted = newg.Assert(new Triple(news, newp, newo)); if (asserted) { cnt++; } } var srcPath = string.Format(@"{0}\{1}.txt", DocumentRoot, srcGraphBase64); var dstPath = string.Format(@"{0}\{1}.txt", DocumentRoot, dstGraphBase64); File.Copy(srcPath, dstPath); fuseki.SaveGraph(newg); UpdateListViewGraph(); MessageBox.Show(string.Format("total {0} triples cloned", cnt)); }