Esempio n. 1
0
        private void addLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var map = this.Viewer.GetMap();

            if (map != null)
            {
                var node = legendCtrl.SelectedNode;
                if (node != null)
                {
                    var grp = node.Tag as GroupNodeMetadata;
                    if (grp != null)
                    {
                        using (var picker = new ResourcePicker(map.CurrentConnection, ResourceTypes.LayerDefinition.ToString(), ResourcePickerMode.OpenResource))
                        {
                            if (picker.ShowDialog() == DialogResult.OK)
                            {
                                var mapSvc = (IMappingService)map.CurrentConnection.GetService((int)ServiceType.Mapping);
                                var layer  = mapSvc.CreateMapLayer(map, ((ILayerDefinition)map.CurrentConnection.ResourceService.GetResource(picker.ResourceID)));
                                layer.Name         = GenerateUniqueName(ResourceIdentifier.GetName(picker.ResourceID), map.Layers);
                                layer.LegendLabel  = ResourceIdentifier.GetName(picker.ResourceID);
                                layer.Group        = grp.Name;
                                layer.Visible      = true;
                                layer.ShowInLegend = true;
                                map.Layers.Insert(0, layer);
                                legendCtrl.Viewer.RefreshMap();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public ExplodeThemeDialog(IEditorService editor, IVectorScaleRange parentRange, IVectorStyle style, ILayerDefinition parentLayer)
            : this()
        {
            if (style.StyleType == StyleType.Composite)
            {
                throw new NotSupportedException(Strings.ErrorExplodingCompositeStyleNotSupported);
            }

            _editor      = editor;
            _style       = style;
            _parentRange = parentRange;
            _parentLayer = parentLayer;

            txtLayersCreate.Text    = style.RuleCount.ToString(CultureInfo.InvariantCulture);
            txtLayerNameFormat.Text = "{0} - {1} - {2}"; //NOXLATE
            EvaluateStates();

            if (!_editor.IsNew)
            {
                txtLayerPrefix.Text = ResourceIdentifier.GetName(_editor.ResourceID);
            }
            else
            {
                txtLayerPrefix.Text = "Theme"; //NOXLATE
            }
        }
Esempio n. 3
0
        public static IWatermark AddWatermark <T>(IList <T> collection, IWatermarkDefinition watermark) where T : class, IWatermark, new()
        {
            Check.NotNull(watermark, "watermark");
            T impl = new T();

            impl.ResourceId = watermark.ResourceID;
            impl.Name       = ResourceIdentifier.GetName(impl.ResourceId);
            impl.Usage      = UsageType.All;
            collection.Add(impl);
            return(impl);
        }
 private void btnAddMap_Click(object sender, EventArgs e)
 {
     using (var picker = new ResourcePicker(_edsvc.CurrentConnection, ResourceTypes.MapDefinition.ToString(), ResourcePickerMode.OpenResource))
     {
         if (picker.ShowDialog() == DialogResult.OK)
         {
             LastSelectedFolder.FolderId = picker.SelectedFolder;
             string resId = picker.ResourceID;
             AddMapDefinition(resId, ResourceIdentifier.GetName(resId));
         }
     }
 }
        /// <summary>
        /// Binds the specified resource to this control. This effectively initializes
        /// all the fields in this control and sets up databinding on all fields. All
        /// subclasses *must* override this method.
        ///
        /// Also note that this method may be called more than once (e.g. Returning from
        /// and XML edit of this resource). Thus subclasses must take this scenario into
        /// account when implementing
        /// </summary>
        /// <param name="service">The editor service</param>
        protected override void Bind(IEditorService service)
        {
            //NOTE: This is exempt from #1656 requirements because this will never be called when returing
            //from an XML editor because IT IS the xml editor!

            _edSvc = service;
            _edSvc.RegisterCustomNotifier(editor);
            var path = Path.Combine(this.XsdPath, _edSvc.GetEditedResource().ValidatingSchema);

            editor.LoadAutoCompletionData(path);
            editor.Bind(_edSvc);
            editor.ReadyForEditing();                                                                        //This turns on event broadcasting
            this.Title = $"{Strings.XmlEditor} {ResourceIdentifier.GetName(this.EditorService.ResourceID)}"; //NOXLATE
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes this instances from the specified Layer Definition
        /// </summary>
        /// <param name="ldf"></param>
        /// <param name="suppressErrors"></param>
        protected void Initialize(ILayerDefinition ldf, bool suppressErrors)
        {
            Check.ArgumentNotNull(ldf, nameof(ldf));
            this.LayerDefinitionID = ldf.ResourceID;
            switch (ldf.SubLayer.LayerType)
            {
            case LayerType.Vector:
            {
                var vl = ((IVectorLayerDefinition)ldf.SubLayer);
                _qualifiedClassName   = vl.FeatureName;
                _geometryPropertyName = vl.Geometry;
                _featureSourceId      = vl.ResourceId;
                _filter = vl.Filter;
                InitIdentityProperties(vl, suppressErrors);
                InitScaleRanges(vl);
                _hasTooltips = !string.IsNullOrEmpty(vl.ToolTip);
            }
            break;

            case LayerType.Raster:
            {
                var rl = ((IRasterLayerDefinition)ldf.SubLayer);
                _qualifiedClassName   = rl.FeatureName;
                _geometryPropertyName = rl.Geometry;
                _featureSourceId      = rl.ResourceId;
                InitScaleRanges(rl);
            }
            break;

            case LayerType.Drawing:
            {
                _featureSourceId = ldf.SubLayer.ResourceId;
                var dl = ((IDrawingLayerDefinition)ldf.SubLayer);
                _scaleRanges = new double[]
                {
                    dl.MinScale,
                    dl.MaxScale
                };
                EnsureOrderedMinMaxScales();
            }
            break;
            }

            _expandInLegend = false;
            this.Name       = ResourceIdentifier.GetName(ldf.ResourceID);
            _legendLabel    = this.Name;
            _selectable     = true;
            _showInLegend   = true;
            _visible        = true;
        }
        private void lstResources_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var item = lstResources.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                var doc = item.Tag as ResourceListResourceDocument;
                if (doc != null)
                {
                    txtName.Text = ResourceIdentifier.GetName(doc.ResourceId);
                    btnOK.PerformClick();
                }
            }
        }
        private void repoView_RequestAddToMap(object sender, EventArgs e)
        {
            var item = repoView.SelectedItem;

            if (item != null && item.ResourceType == ResourceTypes.LayerDefinition.ToString())
            {
                var layer = _mapSvc.CreateMapLayer(_rtMap, ((ILayerDefinition)this.EditorService.CurrentConnection.ResourceService.GetResource(item.ResourceId)));
                layer.Name         = LiveMapEditorLegend.GenerateUniqueName(ResourceIdentifier.GetName(item.ResourceId), _rtMap.Layers);
                layer.LegendLabel  = ResourceIdentifier.GetName(item.ResourceId);
                layer.Visible      = true;
                layer.ShowInLegend = true;
                _rtMap.Layers.Insert(0, layer);
                viewer.RefreshMap();
            }
        }
 private void lstResources_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lstResources.SelectedItems.Count == 1)
     {
         var item = lstResources.SelectedItems[0];
         var doc  = item.Tag as ResourceListResourceDocument;
         if (doc != null)
         {
             txtName.Text = ResourceIdentifier.GetName(doc.ResourceId);
         }
         bool bPreviewable = IsPreviewable(doc);
         btnPreview.Enabled             = bPreviewable;
         lblPreviewNotAvailable.Visible = !bPreviewable;
         if (picPreview.Image != null)
         {
             picPreview.Image.Dispose();
             picPreview.Image = null;
         }
     }
 }
        private static string GenerateBaseLayerName(string layerId, ITileSetDefinition tileSet)
        {
            Check.ArgumentNotNull(tileSet, nameof(tileSet));
            Check.ArgumentNotEmpty(layerId, nameof(layerId));

            int    counter = 0;
            string prefix  = ResourceIdentifier.GetName(layerId);
            string name    = prefix;

            if (tileSet.LayerExists(name))
            {
                name = prefix + counter;
            }
            while (tileSet.LayerExists(name))
            {
                counter++;
                name = prefix + counter;
            }

            return(name);
        }
        protected override string GenerateLayerPreviewUrl(IResource res, string locale, bool isNew, string sessionID)
        {
            string url = GetRootUrl();

            var ldf = (ILayerDefinition)res;

            //Use feature source as name/label
            string layerName = ResourceIdentifier.GetName(ldf.SubLayer.ResourceId);

            var mdf = CreateLayerPreviewMapDefinition(ldf, sessionID, layerName, _conn);

            //if (PropertyService.Get(ConfigProperties.PreviewViewerType, "AJAX").Equals("AJAX")) //NOXLATE
            if (this.UseAjaxViewer)
            {
                //Create temp web layout to house this map
                var wl = ObjectFactory.CreateWebLayout(new Version(1, 0, 0), mdf.ResourceID);

                //Add a custom zoom command (to assist previews of layers that aren't [0, infinity] scale)
                AttachPreviewCommands(wl);

                var resId = $"Session:{sessionID}//{Guid.NewGuid()}.WebLayout"; //NOXLATE

                _conn.ResourceService.SaveResourceAs(wl, resId);
                url += $"mapviewerajax/?WEBLAYOUT={resId}&SESSION={sessionID}&LOCALE={GetLocale(locale)}"; //NOXLATE
            }
            else
            {
                throw new NotImplementedException();
                ////Create temp flex layout
                //var appDef = ObjectFactory.CreatePreviewFlexLayout(conn);
                //var resId = "Session:" + sessionId + "//" + Guid.NewGuid() + ".ApplicationDefinition"; //NOXLATE
                //appDef.AddMapGroup("previewmap", true, mdfId); //NOXLATE

                //conn.ResourceService.SaveResourceAs(appDef, resId);
                //url += "fusion/templates/mapguide/preview/index.html?Session=" + sessionId + "&ApplicationDefinition=" + resId; //NOXLATE
            }

            return(url);
        }
Esempio n. 12
0
        /// <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);
        }
Esempio n. 13
0
 private void UpdateTitle()
 {
     this.Title       = this.IsNew ? Strings.NewResource : ResourceIdentifier.GetName(_svc.ResourceID);
     this.Description = GetTooltip(this.IsNew ? Strings.NewResource : _svc.ResourceID);
 }
Esempio n. 14
0
        /// <summary>
        /// Previews the given resource
        /// </summary>
        /// <param name="res"></param>
        /// <param name="edSvc"></param>
        /// <param name="locale"></param>
        public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            IServerConnection conn = edSvc.CurrentConnection;

            if (this.UseLocal && IsLocalPreviewableType(res) && SupportsMappingService(conn))
            {
                BusyWaitDelegate worker = () =>
                {
                    IMappingService mapSvc     = (IMappingService)conn.GetService((int)ServiceType.Mapping);
                    IMapDefinition  previewMdf = null;
                    switch (res.ResourceType)
                    {
                    case "LayerDefinition":
                    {
                        ILayerDefinition ldf       = (ILayerDefinition)res;
                        string           layerName = string.Empty;
                        if (edSvc.IsNew)
                        {
                            layerName = ResourceIdentifier.GetName(ldf.SubLayer.ResourceId);
                        }
                        else
                        {
                            layerName = ResourceIdentifier.GetName(edSvc.ResourceID);
                        }
                        previewMdf = ResourcePreviewEngine.CreateLayerPreviewMapDefinition(ldf, edSvc.SessionID, layerName, conn);
                    }
                    break;

                    case "WatermarkDefinition":
                    {
                        previewMdf = Utility.CreateWatermarkPreviewMapDefinition((IWatermarkDefinition)res);
                    }
                    break;

                    case "MapDefinition":
                    {
                        previewMdf = (IMapDefinition)res;
                    }
                    break;
                    }

                    if (string.IsNullOrEmpty(previewMdf.ResourceID))
                    {
                        var sessionId = edSvc.SessionID;
                        var mdfId     = "Session:" + sessionId + "//" + Guid.NewGuid() + ".MapDefinition"; //NOXLATE

                        conn.ResourceService.SaveResourceAs(previewMdf, mdfId);
                        previewMdf.ResourceID = mdfId;
                    }

                    if (previewMdf != null)
                    {
                        return(mapSvc.CreateMap(previewMdf, false));
                    }
                    else
                    {
                        return(null);
                    }
                };
                Action <object, Exception> onComplete = (obj, ex) =>
                {
                    if (ex != null)
                    {
                        throw ex;
                    }

                    if (obj != null)
                    {
                        var rtMap = (RuntimeMap)obj;
                        if (_viewManager != null)
                        {
                            _viewManager.OpenContent(ViewRegion.Document, () => new MapPreviewViewContent(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID));
                        }
                        else
                        {
                            var diag = new MapPreviewDialog(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID);
                            diag.Show(null);
                        }
                    }
                    else //Fallback, shouldn't happen
                    {
                        _inner.Preview(res, edSvc, locale);
                    }
                };
                BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete);
            }
            else
            {
                _inner.Preview(res, edSvc, locale);
            }
        }