protected static void ResetItem(OpenResourceManager omgr, RepositoryItem ri, IServerConnection conn) { ri.Reset(); if (omgr.IsOpen(ri.ResourceId, conn)) { ri.IsOpen = true; var ed = omgr.GetOpenEditor(ri.ResourceId, conn); if (ed.IsDirty) ri.IsDirty = true; } }
private Maestro.Editors.RepositoryHandle[] CollectDependentResources(RepositoryItem[] items, ServerConnectionManager connMgr) { var ids = new List<Maestro.Editors.RepositoryHandle>(); foreach (var it in items) { var conn = connMgr.GetConnection(it.ConnectionName); if (it.IsFolder) { ids.Add(new Editors.RepositoryHandle(new ResourceIdentifier(it.ResourceId), conn)); break; } try { var references = conn.ResourceService.EnumerateResourceReferences(it.ResourceId); ids.AddRange(references.ResourceId.Select(x => new Maestro.Editors.RepositoryHandle(new ResourceIdentifier(x), conn))); } catch //Back-referencing may not be supported { } } return ids.ToArray(); }
void OnSiteExplorerItemsSelected(object sender, RepositoryItem[] items) { if (items == null) return; if (items.Length != 1) return; var idx = _cmbActiveConnections.Items.IndexOf(items[0].ConnectionName); if (idx >= 0) { _cmbResourceId.Text = items[0].ResourceId; _cmbActiveConnections.SelectedIndex = idx; } }
private System.Collections.IEnumerable GetSorted(string connectionName, ResourceList list) { //Sort them before returning them SortedList<string, RepositoryItem> folders = new SortedList<string, RepositoryItem>(); SortedList<string, RepositoryItem> docs = new SortedList<string, RepositoryItem>(); foreach (var item in list.Children) { var it = new RepositoryItem(connectionName, item); it.Model = this; if (it.IsFolder) folders.Add(it.ResourceId, it); else docs.Add(it.ResourceId, it); } foreach (var folder in folders.Values) { yield return folder; } foreach (var doc in docs.Values) { yield return doc; } }
/// <summary> /// Restores node ui state from before refresh /// </summary> /// <param name="item"></param> private void ApplyCurrentItemState(RepositoryItem item) { var conn = _connManager.GetConnection(item.ConnectionName); if (_openResMgr.IsOpen(item.ResourceId, conn)) { item.IsOpen = true; var ed = _openResMgr.GetOpenEditor(item.ResourceId, conn); if (ed.IsDirty) item.IsDirty = true; } item.ClipboardState = _clip.GetClipboardState(item.ResourceId); }
internal TreePath GetPath(RepositoryItem node) { if (node.IsRoot) { return new TreePath(node); } else { Stack<object> stack = new Stack<object>(); while (!node.IsRoot) { stack.Push(node); node = node.Parent; } stack.Push(node); return new TreePath(stack.ToArray()); } }
void OnItemsSelected(object sender, RepositoryItem[] items) { CheckButtonState(items); }
internal static string GetCommonParent(RepositoryItem[] data) { if (data.Length > 0) { if (data.Length == 1) { if (data[0].IsFolder) return data[0].ResourceId.ToString(); else return data[0].Parent.ResourceId; } else { int matches = 0; string[] parts = data.First().ResourceId.ToString() .Substring(StringConstants.RootIdentifier.Length) .Split('/'); //NOXLATE string test = StringConstants.RootIdentifier; string parent = test; int partIndex = 0; //Use first one as a sample to see how far we can go. Keep going until we have //a parent that doesn't match all of them. The one we recorded before then will //be the common parent while (matches == data.Length) { parent = test; partIndex++; if (partIndex < parts.Length) //Shouldn't happen, but just in case break; test = test + parts[partIndex]; matches = data.Where(x => x.ResourceId.StartsWith(test)).Count(); } return parent; } } else { return StringConstants.RootIdentifier; } }
private void NotifyStructureChanged(RepositoryItem repositoryItem) { if (!_notify) return; var model = FindModel(); if (model != null && this.Parent != null) { TreePath path = model.GetPath(repositoryItem); if (path != null) { var args = new TreePathEventArgs(path); model.RaiseStructureChanged(args); } } }
internal void RemoveChildWithoutNotification(RepositoryItem item) { if (_children.ContainsKey(item.NameQualified) && item.Parent == this) { if (_children.Remove(item.NameQualified)) { item.Parent = null; } } }
internal void AddChildWithoutNotification(RepositoryItem item) { item.Parent = this; if (!_children.ContainsKey(item.NameQualified)) _children.Add(item.NameQualified, item); }
/// <summary> /// Removes the child item /// </summary> /// <param name="item"></param> public void RemoveChild(RepositoryItem item) { if (_children.ContainsKey(item.NameQualified) && item.Parent == this) { if (_children.Remove(item.NameQualified)) { item.Parent = null; NotifyStructureChanged(this); } } }
/// <summary> /// Adds the specified item as a child item /// </summary> /// <param name="item"></param> public void AddChild(RepositoryItem item) { item.Parent = this; _children.Add(item.NameQualified, item); NotifyStructureChanged(this); }
/// <summary> /// Gets the child nodes in the given tree path /// </summary> /// <param name="treePath"></param> /// <returns></returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { if (treePath.IsEmpty()) { _rootNodes.Clear(); var roots = new List <RepositoryItem>(); foreach (var connName in _connManager.GetConnectionNames()) { if (_rootNodes.ContainsKey(connName)) { continue; } var conn = _connManager.GetConnection(connName); var list = conn.ResourceService.GetRepositoryResources(StringConstants.RootIdentifier, 0); //NOXLATE if (list.Items.Count != 1) { throw new InvalidOperationException(); //Huh? } var connNode = new RepositoryItem(connName, (IRepositoryItem)list.Items[0]); Debug.Assert(connNode.Parent == null); Debug.Assert(connNode.IsRoot); connNode.Name = connName; connNode.Model = this; if (!_rootNodes.ContainsKey(connName)) { _rootNodes[connName] = connNode; roots.Add(connNode); } } foreach (var r in roots) { yield return(r); } } else { var node = treePath.LastNode as RepositoryItem; if (node != null && node.IsFolder) //Can't enumerate children of documents { string connName = GetParentConnectionName(node); var conn = _connManager.GetConnection(connName); node.ClearChildrenWithoutNotification(); var list = conn.ResourceService.GetRepositoryResources(node.ResourceId, string.Empty, 1, false); //NOXLATE foreach (RepositoryItem item in GetSorted(connName, list)) { node.AddChildWithoutNotification(item); ApplyCurrentItemState(item); Debug.Assert(item.Parent != null); Debug.Assert(!item.IsRoot); yield return(item); } } else { yield break; } } }
private void DoDelete(Workbench wb, OSGeo.MapGuide.MaestroAPI.Services.IResourceService resSvc, RepositoryItem[] items) { var pdlg = new ProgressDialog(); pdlg.CancelAbortsThread = true; string[] args = new string[items.Length]; for (int i = 0; i < items.Length; i++) { args[i] = items[i].ResourceId; } var work = new Maestro.Shared.UI.ProgressDialog.DoBackgroundWork((worker, e, target) => { int deleted = 0; if (target == null || target.Length == 0) return deleted; int step = 100 / target.Length; int current = 0; foreach (RepositoryItem item in target) { if (worker.CancellationPending || e.Cancel) return deleted; current += step; if (item.IsRoot) //Wait a minute...! { continue; } else { resSvc.DeleteResource(item.ResourceId); deleted++; worker.ReportProgress(current, item.ResourceId); } } //collect affected parents and update the model foreach (RepositoryItem item in target) { var parent = item.Parent; if (parent != null) { parent.RemoveChild(item); } } return deleted; }); pdlg.RunOperationAsync(wb, work, items); }
private static bool ConfirmDeleteOpenResources(RepositoryItem[] items, Maestro.Base.Editor.IEditorViewContent[] editors) { Check.NotNull(items, "items"); //NOXLATE Check.NotNull(editors, "editors"); //NOXLATE Dictionary<string, string> resIds = new Dictionary<string, string>(); foreach (var item in items) { resIds.Add(item.ResourceId, item.ResourceId); } bool isDeletingOpenResource = false; foreach (var ed in editors) { string resId = ed.EditorService.ResourceID; if (resIds.ContainsKey(resId) || IsChild(resIds, resId)) { isDeletingOpenResource = true; break; } } if (isDeletingOpenResource && !MessageService.AskQuestion(Strings.ConfirmDeleteOpenResource)) return false; return true; }
/// <summary> /// Gets the child nodes in the given tree path /// </summary> /// <param name="treePath"></param> /// <returns></returns> public override System.Collections.IEnumerable GetChildren(TreePath treePath) { if (treePath.IsEmpty()) { _rootNodes.Clear(); var roots = new List<RepositoryItem>(); foreach (var connName in _connManager.GetConnectionNames()) { if (_rootNodes.ContainsKey(connName)) continue; var conn = _connManager.GetConnection(connName); var list = conn.ResourceService.GetRepositoryResources(StringConstants.RootIdentifier, 0); //NOXLATE if (list.Items.Count != 1) { throw new InvalidOperationException(); //Huh? } var connNode = new RepositoryItem(connName, (IRepositoryItem)list.Items[0]); Debug.Assert(connNode.Parent == null); Debug.Assert(connNode.IsRoot); connNode.Name = connName; connNode.Model = this; if (!_rootNodes.ContainsKey(connName)) { _rootNodes[connName] = connNode; roots.Add(connNode); } } foreach (var r in roots) { yield return r; } } else { var node = treePath.LastNode as RepositoryItem; if (node != null && node.IsFolder) //Can't enumerate children of documents { string connName = GetParentConnectionName(node); var conn = _connManager.GetConnection(connName); node.ClearChildrenWithoutNotification(); var list = conn.ResourceService.GetRepositoryResources(node.ResourceId, string.Empty, 1, false); //NOXLATE foreach (RepositoryItem item in GetSorted(connName, list)) { node.AddChildWithoutNotification(item); ApplyCurrentItemState(item); Debug.Assert(item.Parent != null); Debug.Assert(!item.IsRoot); yield return item; } } else { yield break; } } }
internal static string GetParentConnectionName(RepositoryItem item) { if (!string.IsNullOrEmpty(item.ConnectionName)) return item.ConnectionName; var current = item.Parent; if (current != null) { current = item.Parent; while (current != null) { current = current.Parent; } Debug.Assert(!string.IsNullOrEmpty(current.ConnectionName)); return current.ConnectionName; } else { Debug.Assert(!string.IsNullOrEmpty(item.ConnectionName)); return item.ConnectionName; } }
private void CheckButtonState(RepositoryItem[] items) { btnOpenEditor.Enabled = false; btnValidate.Enabled = false; if (items.Length == 1) { btnOpenEditor.Enabled = (!items[0].IsFolder); btnValidate.Enabled = true; } }