/// <summary> /// Sets the starting point. /// </summary> /// <param name="folderId">The folder id.</param> /// <remarks>If the specified folder does not exist, it will fallback to Library://</remarks> public void SetStartingPoint(string folderId) { if (string.IsNullOrEmpty(folderId)) { return; } if (!ResourceIdentifier.IsFolderResource(folderId)) { throw new ArgumentException(string.Format(Strings.NotAFolder, folderId)); } // Library:// will *always* exist, so fallback to this if given folder doesn't check out if (!_conn.ResourceService.ResourceExists(folderId)) { folderId = StringConstants.RootIdentifier; } this.ActiveControl = repoView; repoView.NavigateTo(folderId); this.SelectedFolder = folderId; //HACK: Navigating to the specified folder takes away the focus to the //name field this.ActiveControl = txtName; }
internal TreePath GetPathFromResourceId(string connectionName, string resId) { var rootNode = _rootNodes[connectionName]; if (StringConstants.RootIdentifier.Equals(resId)) { return(GetPath(rootNode)); } string[] components = ResourceIdentifier.GetPath(resId).Split('/'); //NOXLATE if (!ResourceIdentifier.IsFolderResource(resId)) { //Fix extension to last component components[components.Length - 1] = components[components.Length - 1] + "." + ResourceIdentifier.GetResourceTypeAsString(resId); } RepositoryItem current = rootNode; for (int i = 0; i < components.Length; i++) { if (current.Contains(components[i])) { current = current[components[i]]; } else { return(null); } } return(GetPath(current)); }
/// <summary> /// Initializes a new instance of the <see cref="RebaseOptions"/> class. /// </summary> /// <param name="sourceFolder">The source folder.</param> /// <param name="targetFolder">The target folder.</param> public RebaseOptions(string sourceFolder, string targetFolder) { Check.ThatPreconditionIsMet(ResourceIdentifier.IsFolderResource(sourceFolder), $"{nameof(ResourceIdentifier)}.{nameof(ResourceIdentifier.IsFolderResource)}({nameof(sourceFolder)})"); Check.ThatPreconditionIsMet(ResourceIdentifier.IsFolderResource(targetFolder), $"{nameof(ResourceIdentifier)}.{nameof(ResourceIdentifier.IsFolderResource)}({nameof(targetFolder)})"); this.SourceFolder = sourceFolder; this.TargetFolder = targetFolder; }
private static bool IsChild(Dictionary <string, string> resIds, string resId) { foreach (var r in resIds.Keys) { if (ResourceIdentifier.IsFolderResource(r) && resId.StartsWith(r)) { return(true); } } return(false); }
private void btnOpen_Click(object sender, EventArgs e) { lblMessage.Text = string.Empty; if (ResourceIdentifier.Validate(txtResourceId.Text) && !ResourceIdentifier.IsFolderResource(txtResourceId.Text)) { this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { lblMessage.Text = Strings.InvalidResourceId; } }
private void btnOK_Click(object sender, EventArgs e) { if (_mode == ResourcePickerMode.OpenResource) { if (!_conn.ResourceService.ResourceExists(txtResourceId.Text)) { MessageBox.Show(Strings.ResourceDoesntExist); return; } } else if (_mode == ResourcePickerMode.SaveResource) { if (ResourceIdentifier.IsFolderResource(txtResourceId.Text)) { MessageBox.Show(Strings.InvalidResourceIdFolder); return; } else { if (!ResourceIdentifier.Validate(txtResourceId.Text)) { MessageBox.Show(Strings.InvalidResourceId); return; } else { if (ResourceIdentifier.GetResourceTypeAsString(txtResourceId.Text) != cmbResourceFilter.SelectedItem.ToString()) { MessageBox.Show(Strings.InvalidResourceIdNotSpecifiedType); return; } } if (_conn.ResourceService.ResourceExists(txtResourceId.Text)) { if (MessageBox.Show(Strings.OverwriteResource, Strings.SaveResource, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } } } if (ResourceIdentifier.IsFolderResource(txtResourceId.Text)) { LastSelectedFolder.FolderId = txtResourceId.Text; } else { LastSelectedFolder.FolderId = (txtResourceId.Text != StringConstants.RootIdentifier) ? ResourceIdentifier.GetParentFolder(txtResourceId.Text) : StringConstants.RootIdentifier; } this.DialogResult = DialogResult.OK; }
/// <summary> /// Refreshes the model of the repostiory from the specified folder id /// </summary> /// <param name="folderId"></param> public void RefreshModel(string folderId) { if (_model != null) { if (string.IsNullOrEmpty(folderId)) { _model.Refresh(null); } else { if (!ResourceIdentifier.IsFolderResource(folderId)) { throw new ArgumentException(Strings.ErrNotAFolder); } _model.Refresh(folderId); } } }
public override IResource CreateItem(string startPoint, IServerConnection conn) { using (var dlg = DialogFactory.OpenFile()) { dlg.Multiselect = true; dlg.Filter = string.Format(OSGeo.MapGuide.MaestroAPI.Strings.GenericFilter, OSGeo.MapGuide.MaestroAPI.Strings.PickDwf, "dwf"); //NOXLATE if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var proc = ObjectFactory.CreateLoadProcedure(LoadType.Dwf, dlg.FileNames); if (!string.IsNullOrEmpty(startPoint) && ResourceIdentifier.IsFolderResource(startPoint)) { proc.SubType.RootPath = startPoint; proc.SubType.SpatialDataSourcesPath = startPoint; proc.SubType.LayersPath = startPoint; } return(proc); } return(null); } }
private void UpdateResourceId() { btnOK.Enabled = false; this.SelectedFolder = txtFolder.Text; if (this.SelectFoldersOnly) { txtResourceId.Text = txtFolder.Text; if (!string.IsNullOrEmpty(txtFolder.Text) && ResourceIdentifier.IsFolderResource(txtResourceId.Text)) { btnOK.Enabled = true; } } else { txtResourceId.Text = txtFolder.Text + txtName.Text + "." + cmbResourceFilter.SelectedItem.ToString(); if (!ResourceIdentifier.IsFolderResource(txtResourceId.Text) && !string.IsNullOrEmpty(txtName.Text)) { btnOK.Enabled = true; } } }
/// <summary> /// Creates an image-based Symbol Definition in the specified folder for each image symbol in the Symbol Library. /// /// Any existing resource names are overwritten /// </summary> /// <param name="targetFolder"></param> public void ExtractSymbols(string targetFolder) { Check.ArgumentNotEmpty(targetFolder, nameof(targetFolder)); Check.ThatPreconditionIsMet(ResourceIdentifier.IsFolderResource(targetFolder), $"{nameof(ResourceIdentifier)}.{nameof(ResourceIdentifier.IsFolderResource)}({nameof(targetFolder)})"); IDrawingService drawSvc = (IDrawingService)_conn.GetService((int)ServiceType.Drawing); IDrawingSource ds = PrepareSymbolDrawingSource(_conn, _symbolLibId); //Each section in the symbols.dwf represents a symbol var sectionList = drawSvc.EnumerateDrawingSections(ds.ResourceID); foreach (var sect in sectionList.Section) { var sectResources = drawSvc.EnumerateDrawingSectionResources(ds.ResourceID, sect.Name); foreach (var res in sectResources.SectionResource) { if (res.Role.ToUpper() == StringConstants.Thumbnail.ToUpper()) { ExtractSymbol(targetFolder, drawSvc, ds, sect, res); } } } }
private string[] MoveResourcesWithinConnection(string connectionName, ICollection <string> resIds, string folderId) { var wb = Workbench.Instance; var notMovedToTarget = new List <string>(); var notMovedFromSource = new List <string>(); var omgr = ServiceRegistry.GetService <OpenResourceManager>(); var conn = _connManager.GetConnection(connectionName); var dlg = new ProgressDialog(); var worker = new ProgressDialog.DoBackgroundWork((w, e, args) => { LengthyOperationProgressCallBack cb = (sender, cbe) => { w.ReportProgress(cbe.Progress, cbe.StatusMessage); }; var f = (string)args[0]; var resourceIds = (ICollection <string>)args[1]; foreach (var r in resourceIds) { if (ResourceIdentifier.IsFolderResource(r)) { //IMPORTANT: We need to tweak the target resource id //otherwise the content *inside* the source folder is //moved instead of the folder itself! var rid = new ResourceIdentifier(r); var target = $"{folderId + rid.Name}/"; //NOXLATE conn.ResourceService.MoveResourceWithReferences(r, target, null, cb); } else { var rid = new ResourceIdentifier(r); var target = $"{folderId + rid.Name}.{rid.Extension}"; //NOXLATE if (omgr.IsOpen(r, conn)) { notMovedFromSource.Add(r); continue; } if (!omgr.IsOpen(target, conn)) { conn.ResourceService.MoveResourceWithReferences(r, target, null, cb); } else { notMovedToTarget.Add(r); } } } //Collect affected folders and refresh them Dictionary <string, string> folders = new Dictionary <string, string>(); folders.Add(folderId, folderId); foreach (var n in resourceIds) { var ri = new ResourceIdentifier(n); var parent = ri.ParentFolder; if (parent != null && !folders.ContainsKey(parent)) { folders.Add(parent, parent); } } return(folders.Keys); }); var affectedFolders = (IEnumerable <string>)dlg.RunOperationAsync(wb, worker, folderId, resIds); if (notMovedToTarget.Count > 0 || notMovedFromSource.Count > 0) { MessageService.ShowMessage(string.Format( Strings.NotCopiedOrMovedDueToOpenEditors, Environment.NewLine + string.Join(Environment.NewLine, notMovedToTarget.ToArray()) + Environment.NewLine, Environment.NewLine + string.Join(Environment.NewLine, notMovedFromSource.ToArray()) + Environment.NewLine)); } return(new List <string>(affectedFolders).ToArray()); }
internal string[] CopyResourcesToFolder(RepositoryHandle[] data, string targetConnectionName, string folderId) { string rootSourceParent = GetCommonParent(data); //There is an implicit assumption here that all items dropped come from the same connection var sourceConn = data.First().Connection; var targetConn = _connManager.GetConnection(targetConnectionName); var migrator = new ResourceMigrator(sourceConn, targetConn); //Collect all source ids var sourceIds = new List <string>(); foreach (var resId in data.Select(x => x.ResourceId.ToString())) { if (ResourceIdentifier.IsFolderResource(resId)) { sourceIds.AddRange(GetFullResourceList(sourceConn, resId)); } else { sourceIds.Add(resId); } } var targets = new List <string>(); foreach (var resId in sourceIds) { var dstId = resId.Replace(rootSourceParent, folderId); System.Diagnostics.Trace.TraceInformation($"{resId} => {dstId}"); //NOXLATE targets.Add(dstId); } bool overwrite = true; var existing = new List <string>(); foreach (var resId in targets) { if (targetConn.ResourceService.ResourceExists(resId)) { existing.Add(resId); } } if (existing.Count > 0) { overwrite = MessageService.AskQuestion(string.Format(Strings.PromptOverwriteOnTargetConnection, existing.Count)); } var wb = Workbench.Instance; var dlg = new ProgressDialog(); var worker = new ProgressDialog.DoBackgroundWork((w, evt, args) => { LengthyOperationProgressCallBack cb = (s, cbe) => { w.ReportProgress(cbe.Progress, cbe.StatusMessage); }; return(migrator.CopyResources(sourceIds.ToArray(), targets.ToArray(), overwrite, new RebaseOptions(rootSourceParent, folderId), cb)); }); var result = (string[])dlg.RunOperationAsync(wb, worker); RefreshModel(targetConn.DisplayName, folderId); ExpandNode(targetConn.DisplayName, folderId); return(result); }
private bool EvaluateStates() { btnCreate.Enabled = IsValidToPreview() && ResourceIdentifier.IsFolderResource(txtFolder.Text); return(btnCreate.Enabled); }
private void UpdateNavigationState() { _btnGo.Enabled = _btnOpenAsXml.Enabled = ResourceIdentifier.Validate(_cmbResourceId.Text) && !ResourceIdentifier.IsFolderResource(_cmbResourceId.Text); }