private void AddLayerDefinition(ResourceDragMessage message, GroupNodeMetadata groupMeta) { if (ResourceIdentifier.GetResourceTypeAsString(message.ResourceID) == ResourceTypes.LayerDefinition.ToString()) { var map = this.Viewer.GetMap(); var conn = map.CurrentConnection; var mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); var ldf = (ILayerDefinition)conn.ResourceService.GetResource(message.ResourceID); var rtLayer = mapSvc.CreateMapLayer(map, ldf); //Set some desired properties if not already set if (string.IsNullOrEmpty(rtLayer.LegendLabel)) { rtLayer.LegendLabel = rtLayer.Name; } rtLayer.ShowInLegend = true; rtLayer.ExpandInLegend = true; rtLayer.Selectable = true; if (groupMeta != null) { rtLayer.Group = groupMeta.Name; } map.Layers.Insert(0, rtLayer); this.Viewer.RefreshMap(); } }
private void PopulateDocumentList(ResourceList list) { lstResources.Clear(); SortedList <string, ResourceListResourceDocument> items = new SortedList <string, ResourceListResourceDocument>(); foreach (var item in list.Items) { var doc = item as ResourceListResourceDocument; if (doc != null) { string sortKey = doc.Name + "." + doc.ResourceType; items.Add(sortKey, doc); } } foreach (var doc in items.Values) { var li = new ListViewItem(doc.Name); li.Tag = doc; try { var rt = ResourceIdentifier.GetResourceTypeAsString(doc.ResourceId); li.ImageIndex = RepositoryIcons.GetImageIndexForResourceType(rt); } catch { li.ImageIndex = RepositoryIcons.RES_UNKNOWN; } lstResources.Items.Add(li); } }
/// <summary> /// Initiates the editing process. The resource to be edited is copied to the session repository and /// a deserialized version is returned from this copy. Subsequent calls will return the same reference /// to this resource object. /// </summary> /// <returns> /// A deserialized version of a session-copy of the resource to be edited /// </returns> public IResource GetEditedResource() { if (_causeForInvalidation != null) { return(null); } if (_editCopy == null) { try { string copy = _conn.GenerateSessionResourceId(ResourceIdentifier.GetResourceTypeAsString(this.ResourceID)); _conn.ResourceService.CopyResource(this.ResourceID, copy, true); _editCopy = _conn.ResourceService.GetResource(copy); _editCopy.PropertyChanged += WeakEventHandler.Wrap <PropertyChangedEventHandler>(OnResourcePropertyChanged, (eh) => _editCopy.PropertyChanged -= eh); } catch (Exception ex) { _causeForInvalidation = ex; } } return(_editCopy); }
public IMapLayer InsertLayer(int index, string groupName, string layerName, string layerDefinitionId) { Check.ThatArgumentIsBetweenRange(index, 0, this.MapLayer.Count, true, nameof(index) + " (" + index + ") between [" + 0 + "," + this.MapLayer.Count + "]"); Check.ArgumentNotEmpty(layerName, nameof(layerName)); Check.ArgumentNotEmpty(layerDefinitionId, nameof(layerDefinitionId)); Check.ThatPreconditionIsMet(ResourceIdentifier.Validate(layerDefinitionId), $"ResourceIdentifier.Validate({nameof(layerDefinitionId)})"); Check.ThatPreconditionIsMet(ResourceIdentifier.GetResourceTypeAsString(layerDefinitionId) == ResourceTypes.LayerDefinition.ToString(), $"ResourceIdentifier.GetResourceTypeAsString({nameof(layerDefinitionId)}) == ResourceTypes.LayerDefinition.ToString()"); if (!string.IsNullOrEmpty(groupName)) { Check.ArgumentNotNull(this.GetGroupByName(groupName), $"Group for <{nameof(groupName)}>"); } var layer = new MapLayerType() { Parent = this, ExpandInLegend = true, LegendLabel = layerName, Name = layerName, ResourceId = layerDefinitionId, ShowInLegend = true, Visible = true, Selectable = true }; layer.Group = string.IsNullOrEmpty(groupName) ? string.Empty : groupName; this.MapLayer.Insert(index, layer); return(layer); }
public IMapLayer AddLayer(string groupName, string layerName, string layerDefinitionId) { Check.ArgumentNotEmpty(layerName, nameof(layerName)); Check.ArgumentNotEmpty(layerDefinitionId, nameof(layerDefinitionId)); Check.ThatPreconditionIsMet(ResourceIdentifier.Validate(layerDefinitionId), $"ResourceIdentifier.Validate({nameof(layerDefinitionId)})"); Check.ThatPreconditionIsMet(ResourceIdentifier.GetResourceTypeAsString(layerDefinitionId) == ResourceTypes.LayerDefinition.ToString(), $"ResourceIdentifier.GetResourceTypeAsString({nameof(layerDefinitionId)}) == ResourceTypes.LayerDefinition.ToString()"); if (!string.IsNullOrEmpty(groupName)) { Check.ThatPreconditionIsMet(this.GetGroupByName(groupName) != null, $"There should be an existing group for <{nameof(groupName)}>"); } var layer = new MapLayerType() { Parent = this, ExpandInLegend = true, LegendLabel = layerName, Name = layerName, ResourceId = layerDefinitionId, ShowInLegend = true, Visible = true, Selectable = true }; layer.Group = string.IsNullOrEmpty(groupName) ? string.Empty : groupName; this.MapLayer.Insert(0, layer); OnPropertyChanged(nameof(MapLayer)); this.AutoSetExtentsFromLayer(layer.ResourceId); return(layer); }
/// <summary> /// Initializes a new instance of the <see cref="SymbolPicker"/> class. /// </summary> /// <param name="symbolLibrary">The symbol library.</param> /// <param name="conn">The conn.</param> public SymbolPicker(string symbolLibrary, IServerConnection conn) : this(conn) { if (ResourceIdentifier.GetResourceTypeAsString(symbolLibrary) != ResourceTypes.SymbolLibrary.ToString()) { throw new ArgumentException(string.Format(Strings.ErrorInvalidSymbolLibraryResourceId, symbolLibrary)); } txtSymbolLibrary.Text = symbolLibrary; }
public IMapLayer AddLayer(IMapLayer layerToInsertAbove, string groupName, string layerName, string layerDefinitionId) { Check.ArgumentNotEmpty(layerName, nameof(layerName)); Check.ArgumentNotEmpty(layerDefinitionId, nameof(layerDefinitionId)); Check.ThatPreconditionIsMet(ResourceIdentifier.Validate(layerDefinitionId), $"ResourceIdentifier.Validate({nameof(layerDefinitionId)})"); Check.ThatPreconditionIsMet(ResourceIdentifier.GetResourceTypeAsString(layerDefinitionId) == ResourceTypes.LayerDefinition.ToString(), $"ResourceIdentifier.GetResourceTypeAsString({nameof(layerDefinitionId)}) == ResourceTypes.LayerDefinition.ToString()"); if (!string.IsNullOrEmpty(groupName)) { Check.ArgumentNotNull(this.GetGroupByName(groupName), $"Group for <{nameof(groupName)}>"); } var layer = new MapLayerType() { Parent = this, ExpandInLegend = true, LegendLabel = layerName, Name = layerName, ResourceId = layerDefinitionId, ShowInLegend = true, Visible = true, Selectable = true }; layer.Group = string.IsNullOrEmpty(groupName) ? string.Empty : groupName; if (layerToInsertAbove != null) { var clayerToInsertAbove = layerToInsertAbove as MapLayerType; if (clayerToInsertAbove != null) { var idx = this.MapLayer.IndexOf(clayerToInsertAbove); if (idx >= 0) { this.MapLayer.Insert(idx, layer); } else { this.MapLayer.Add(layer); } } else { this.MapLayer.Add(layer); } } else { this.MapLayer.Add(layer); } OnPropertyChanged(nameof(MapLayer)); this.AutoSetExtentsFromLayer(layer.ResourceId); return(layer); }
/// <summary> /// Gets the specified image list index for the given resource /// </summary> /// <param name="resourceId"></param> /// <returns></returns> public int GetImageIndexFromResourceID(string resourceId) { int idx = _small.Images.IndexOfKey(ResourceIdentifier.GetResourceTypeAsString(resourceId)); if (idx < 0) { return(_small.Images.IndexOfKey(UNKNOWN)); } return(idx); }
/// <summary> /// Initializes a new instance of the ImageSymbolConverter class /// </summary> /// <param name="conn"></param> /// <param name="symbolLibId"></param> public ImageSymbolConverter(IServerConnection conn, string symbolLibId) { Check.ArgumentNotNull(conn, nameof(conn)); Check.ArgumentNotEmpty(symbolLibId, nameof(symbolLibId)); Check.ThatPreconditionIsMet(ResourceIdentifier.GetResourceTypeAsString(symbolLibId) == ResourceTypes.SymbolLibrary.ToString(), "ResourceIdentifier.GetResourceTypeAsString(symbolLibId) == ResourceTypes.SymbolLibrary.ToString()"); //NOXLATE Check.ThatPreconditionIsMet(Array.IndexOf(conn.Capabilities.SupportedServices, (int)ServiceType.Drawing) >= 0, "Array.IndexOf(conn.Capabilities.SupportedServices, (int)ServiceType.Drawing) >= 0"); //NOXLATE _symbolLibId = symbolLibId; _conn = conn; }
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> /// Initiates the editing process. The resource to be edited is copied to the session repository and /// a deserialized version is returned from this copy. Subsequent calls will return the same reference /// to this resource object. /// </summary> /// <returns> /// A deserialized version of a session-copy of the resource to be edited /// </returns> public IResource GetEditedResource() { if (_editCopy == null) { string copy = _conn.GenerateSessionResourceId(ResourceIdentifier.GetResourceTypeAsString(this.ResourceID)); _conn.ResourceService.CopyResource(this.ResourceID, copy, true); _editCopy = _conn.ResourceService.GetResource(copy); _editCopy.PropertyChanged += WeakEventHandler.Wrap <PropertyChangedEventHandler>(OnResourcePropertyChanged, (eh) => _editCopy.PropertyChanged -= eh); } return(_editCopy); }
private void lstDrawOrder_DragOver(object sender, DragEventArgs e) { var res = e.Data.GetData(typeof(ResourceDragMessage)) as ResourceDragMessage; var layer = e.Data.GetData(typeof(RuntimeMapLayer)) as RuntimeMapLayer; if (layer != null) { e.Effect = DragDropEffects.Move; } else if (res != null && ResourceIdentifier.GetResourceTypeAsString(res.ResourceID) == ResourceTypes.LayerDefinition.ToString()) { e.Effect = DragDropEffects.Copy; } }
/// <summary> /// Initializes a new instance of the EditorWindow class /// </summary> /// <param name="conn"></param> /// <param name="resourceId"></param> public EditorWindow(IServerConnection conn, string resourceId) : this() { _conn = conn; this.Text = this.Text + " - " + resourceId; _svc = new DefaultResourceEditorService(resourceId, conn); _svc.DirtyStateChanged += OnDirtyStateChanged; _ed.Dock = DockStyle.Fill; var previewer = conn.GetPreviewUrlGenerator(); btnPreview.Enabled = (previewer != null && previewer.IsPreviewableType(ResourceIdentifier.GetResourceTypeAsString(resourceId))); this.Controls.Add(_ed); _ed.Bind(_svc); _ed.ReadyForEditing(); _ed.TextChanged += OnXmlContentChanged; }
/// <summary> /// Executes the specified load procedure. /// </summary> /// <param name="resourceID">The resource ID of the load procedure.</param> /// <param name="callback">The callback.</param> /// <returns></returns> public string[] Execute(string resourceID, OSGeo.MapGuide.MaestroAPI.LengthyOperationProgressCallBack callback) { if (!ResourceIdentifier.Validate(this.ResourceID)) { throw new ArgumentException("Invalid resource id: " + this.ResourceID); } if (ResourceIdentifier.GetResourceTypeAsString(this.ResourceID) != ResourceTypes.LoadProcedure.ToString()) { throw new ArgumentException("Not a load procedure resource id: " + this.ResourceID); } ILoadProcedure proc = (ILoadProcedure)this.Parent.ResourceService.GetResource(resourceID); return(Execute(proc, callback)); }
Dictionary <string, IResource> IGetResourceContents.Execute(IEnumerable <string> resourceIds) { //There is an implicit assumption here that all resource ids check out and that //there is no duplicates var resources = new Dictionary <string, IResource>(); if (this.Parent.SiteVersion >= new Version(2, 2)) { Trace.TraceInformation("[GetResources]: Using optimal code path provided by 2.2 Resource Service APIs"); MgStringCollection ids = new MgStringCollection(); foreach (var rid in resourceIds) { ids.Add(rid); } //Use the magic of reflection to call newer APIs even though we're referencing //and older assembly System.Reflection.MethodInfo mi = _resSvc.GetType().GetMethod("GetResourceContents"); MgStringCollection result = (MgStringCollection)mi.Invoke(_resSvc, new object[] { ids, null }); int rcount = ids.GetCount(); for (int i = 0; i < rcount; i++) { var resId = ids.GetItem(i); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(result.GetItem(i)))) { var resType = ResourceIdentifier.GetResourceTypeAsString(resId); IResource r = ObjectFactory.Deserialize(resType, ms); r.ResourceID = resId; resources.Add(resId, r); } } } else { //TODO: Maybe use a ThreadPool in conjunction with cloned connections? Trace.TraceInformation("[GetResources]: Using non-optimal code path provided by pre-2.2 Resource Service APIs"); foreach (var rid in resourceIds) { resources.Add(rid, this.Parent.ResourceService.GetResource(rid)); } } return(resources); }
private void btnTarget_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Source)) { MessageBox.Show(Strings.SelectSourceResource); return; } var resType = ResourceIdentifier.GetResourceTypeAsString(this.Source); using (var picker = new ResourcePicker(_conn, resType, ResourcePickerMode.OpenResource)) { picker.SetStartingPoint(ResourceIdentifier.GetParentFolder(this.Source)); if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtTarget.Text = picker.ResourceID; } } }
private void lstDrawOrder_DragDrop(object sender, DragEventArgs e) { var pt = lstDrawOrder.PointToClient(new Point(e.X, e.Y)); var index = lstDrawOrder.IndexFromPoint(pt); if (index < 0) { index = lstDrawOrder.Items.Count - 1; } var res = e.Data.GetData(typeof(ResourceDragMessage)) as ResourceDragMessage; var layer = e.Data.GetData(typeof(RuntimeMapLayer)) as RuntimeMapLayer; if (layer != null) { _map.Layers.SetNewIndex(index, layer); if (lstDrawOrder.SelectedIndex != index) { lstDrawOrder.SelectedIndex = index; } else { OnLayerSelected(layer); } this.Viewer.RefreshMap(); } else if (res != null && ResourceIdentifier.GetResourceTypeAsString(res.ResourceID) == ResourceTypes.LayerDefinition.ToString()) { var conn = _map.CurrentConnection; var mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); layer = mapSvc.CreateMapLayer(_map, (ILayerDefinition)conn.ResourceService.GetResource(res.ResourceID)); _map.Layers.Insert(0, layer); if (lstDrawOrder.SelectedIndex != 0) { lstDrawOrder.SelectedIndex = 0; } else { OnLayerSelected(layer); } this.Viewer.RefreshMap(); } }
/// <summary> /// Gets the specified image list key for the given resource /// </summary> /// <param name="resourceId"></param> /// <returns></returns> public string GetImageKeyFromResourceID(string resourceId) { var rt = ResourceIdentifier.GetResourceTypeAsString(resourceId); switch (rt) { case "DrawingSource": case "FeatureSource": case "Folder": case "LayerDefinition": case "MapDefinition": case "WebLayout": case "ApplicationDefinition": case "SymbolLibrary": case "PrintLayout": case "TileSetDefinition": return(rt.ToString()); default: return(UNKNOWN); } }
private void RebuildTree() { ResourceTree.Nodes.Clear(); TreeNode root = ResourceTree.Nodes.Add("Library://"); root.ImageIndex = root.SelectedImageIndex = RepositoryIcons.RES_ROOT; foreach (ResourceItem ri in m_resources.Values) { string partial = ri.ResourcePath.Substring(root.Text.Length); string[] parts = partial.Split('/'); TreeNode cur = root; root.Expand(); for (int i = 0; i < parts.Length - 1; i++) { TreeNode next = null; foreach (TreeNode n in cur.Nodes) { if (n.Text == parts[i]) { next = n; break; } } if (next == null) { cur = cur.Nodes.Add(parts[i]); cur.ImageIndex = cur.SelectedImageIndex = RepositoryIcons.RES_FOLDER; } else { cur = next; } cur.Expand(); } if (parts[parts.Length - 1].Trim().Length > 0) { TreeNode n = cur.Nodes.Add(parts[parts.Length - 1]); n.Tag = ri; n.ImageIndex = n.SelectedImageIndex = RepositoryIcons.GetImageIndexForResourceType(ResourceIdentifier.GetResourceTypeAsString(ri.ResourcePath)); } else { cur.Tag = ri; } } }
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> /// Moves resources from the source connection to the specified folder on the target connection. Folder structure of the source is discarded /// </summary> /// <param name="resourceIds"></param> /// <param name="folderId"></param> /// <param name="overwrite"></param> /// <param name="callback"></param> /// <returns></returns> public int MoveResources(string[] resourceIds, string folderId, bool overwrite, LengthyOperationProgressCallBack callback) { Check.ArgumentNotNull(resourceIds, nameof(resourceIds)); Check.ArgumentNotEmpty(folderId, nameof(folderId)); var cb = callback; if (cb == null) { cb = new LengthyOperationProgressCallBack((s, e) => { //Do nothing }); } var targetCaps = _target.Capabilities; int moved = 0; int unit = 100 / resourceIds.Length; int progress = 0; foreach (var resId in resourceIds) { string targetId = folderId + ResourceIdentifier.GetName(resId) + "." + ResourceIdentifier.GetResourceTypeAsString(resId); //NOXLATE string message = string.Empty; //Skip if target exists and overwrite is not specified if (!overwrite && _target.ResourceService.ResourceExists(targetId)) { progress += unit; continue; } else { IResource res = _source.ResourceService.GetResource(resId); //Check if downgrading is required var maxVer = targetCaps.GetMaxSupportedResourceVersion(res.ResourceType); if (res.ResourceVersion > maxVer) { res = _converter.Convert(res, maxVer); cb(this, new LengthyOperationProgressArgs(string.Format(Strings.DowngradedResource, resId, maxVer), progress)); } //Save resource _target.ResourceService.SaveResourceAs(res, targetId); //Copy resource data var resData = _source.ResourceService.EnumerateResourceData(res.ResourceID); foreach (var data in resData.ResourceData) { using (var stream = _source.ResourceService.GetResourceData(res.ResourceID, data.Name)) { if (!stream.CanSeek) { using (var ms = MemoryStreamPool.GetStream()) { Utility.CopyStream(stream, ms, false); ms.Position = 0L; _target.ResourceService.SetResourceData(targetId, data.Name, data.Type, ms); } } else { stream.Position = 0L; _target.ResourceService.SetResourceData(targetId, data.Name, data.Type, stream); } } } moved++; _source.ResourceService.DeleteResource(resId); message = string.Format(Strings.CopiedResource, resId); } progress += unit; cb(this, new LengthyOperationProgressArgs(message, progress)); } return(moved); }