private void ProcessObjectClass(WorkspaceInfo wsInfo, IObjectClass objClass) { IJTXGDBHistoryChanges gdbHistoryChanges = new JTXGDBHistoryChangesClass(); DateTime now = (DateTime)((IDatabaseConnectionInfo2) wsInfo.workspace).ConnectionCurrentDateTime; IJTXChangeSet changeSet = gdbHistoryChanges.GetChanges(m_database, wsInfo.workspaceID, objClass, wsInfo.lastProcessed, now); wsInfo.lastProcessed = now; if(changeSet.Count > 0) { m_database.LogMessage(5, 2000, "Changes found"); } IJTXSpatialNotificationManager snMan = m_database.SpatialNotificationManager; bool bHasMatches; IJTXChangeRuleMatchSet matches = snMan.EvaluateSet(null, changeSet, out bHasMatches); if (bHasMatches) { m_database.LogMessage(5, 2000, "Matches found"); snMan.Notify(matches); } }
List <string> IPlasticAPI.UndoUnchanged(WorkspaceInfo wkInfo, IList paths) { throw new NotImplementedException(); }
void IPlasticAPI.UndoCheckout(WorkspaceInfo wkInfo, IList <string> paths, IList <string> skippedLocks, bool bHandleDeletedChangeset) { throw new NotImplementedException(); }
string IPlasticAPI.SwitchWorkspaceSelector(WorkspaceInfo wkInfo, SwitchToSelectorEntry[] entries) { throw new NotImplementedException(); }
IUpdateResult IPlasticAPI.SwitchToChangeset(WorkspaceInfo wkInfo, RepositorySpec repSpec, BranchInfo brInfo, ChangesetInfo csInfo, IContinueWithPendingChangesQuestioner questioner, ICmdNotifier notifier) { throw new NotImplementedException(); }
DiffInfo IPlasticAPI.BuildDiffInfoForDiffWithPrevious(string revspec2, string symbolicName2, string defaultPath2, string fileExt, WorkspaceInfo currentWk) { throw new NotImplementedException(); }
/// <summary> /// Creates a new Custom Node in the manager. /// </summary> /// <param name="name">Name of the custom node.</param> /// <param name="category">Category for the custom node.</param> /// <param name="description">Description of the custom node.</param> /// <param name="functionId"> /// Optional identifier to be used for the custom node. By default, will make a new unique one. /// </param> /// <returns>Newly created Custom Node Workspace.</returns> public WorkspaceModel CreateCustomNode(string name, string category, string description, Guid? functionId = null) { var newId = functionId ?? Guid.NewGuid(); var info = new WorkspaceInfo() { Name = name, Category = category, Description = description, X = 0, Y = 0, ID = newId.ToString(), FileName = string.Empty, IsVisibleInDynamoLibrary = true }; var workspace = new CustomNodeWorkspaceModel(info, nodeFactory); RegisterCustomNodeWorkspace(workspace); return workspace; }
private async Task<ArcGISDynamicMapServiceLayer> AddFileDatasetToDynamicMapServiceLayer(WorkspaceFactoryType workspaceType, string directoryPath, List<string> fileNames) { try { // Create a new WorkspaceInfo object with a unique ID. string uniqueId = Guid.NewGuid().ToString(); WorkspaceInfo workspaceInfo = new WorkspaceInfo(uniqueId, workspaceType, "DATABASE=" + directoryPath); // Create and initialize a new LocalMapService instance. LocalMapService localMapService = new LocalMapService(_emptyMapPackage) { EnableDynamicLayers = true }; localMapService.DynamicWorkspaces.Add(workspaceInfo); await localMapService.StartAsync(); // Create and initialize new ArcGISLocalDynamicMapServiceLayer over the local service. var dynLayer = new ArcGISDynamicMapServiceLayer() { ID = "Workspace: " + (new DirectoryInfo(directoryPath)).Name, ServiceUri = localMapService.UrlMapService }; await dynLayer.InitializeAsync(); // Create a DynamicLayerInfoCollection to hold the new datasets as "dynamic layers". DynamicLayerInfoCollection dynamicLayerInfoCollection = new DynamicLayerInfoCollection(); dynLayer.DynamicLayerInfos = dynamicLayerInfoCollection; // Create a LayerDrawingOptionsCollection to specify the symbology for each layer. LayerDrawingOptionCollection layerDrawingOptionsCollection = new LayerDrawingOptionCollection(); dynLayer.LayerDrawingOptions = layerDrawingOptionsCollection; // Iterate over each of the selected files in the workspace. int counter = 0; foreach (string fileName in fileNames) { // Create a new DynamicLayerInfo (to make changes to existing map service layers use the CreateDynamicLayerInfosFromLayerInfos() method. DynamicLayerInfo dynamicLayerInfo = new DynamicLayerInfo { ID = counter, Name = "Dataset: " + fileName }; // Create a DataSource object to represent the physical datasource implementation (table or raster) which will become the DataSource // property of a new LayerDataSource in the map service. Other supported datasource types are JoinDataSource and QueryDataSource. DataSource dataSource = null; // If the workspace type is Raster create a new RasterDataSource. if (workspaceInfo.FactoryType == WorkspaceFactoryType.Raster) { // Create a new RasterDataSource object dataSource = new RasterDataSource { // Match the DataSourceName to the physical filename on disk (including extension). DataSourceName = fileName, // Provide the WorkspaceID (the unique workspace identifier created earlier). A LocalMapService may have multiple dynamic workspaces. WorkspaceID = workspaceInfo.Id }; } else { // Else if the workspace is not Raster create a new TableDataSource dataSource = new TableDataSource { // Match the DataSourceName to the physical filename on disk (excluding extension). DataSourceName = fileName, // Provide the WorkspaceID (the unique workspace identifier created earlier). A LocalMapService may have multiple dynamic workspaces. WorkspaceID = workspaceInfo.Id }; } // Set the Source property of the DynamicLayerInfo object. dynamicLayerInfo.Source = new LayerDataSource { DataSource = dataSource }; // Add the new DynamicLayerInfo object to the collection. dynamicLayerInfoCollection.Add(dynamicLayerInfo); // Create a new LayerDrawingOptions object to hold the renderer information. var layerDrawOpt = new LayerDrawingOptions() { // Match up the LayerID to the ID of the layer within the service. LayerID = counter, }; // Use the GetDetails method which now supports dynamic data sources to determine the geometry type of the new datasource. var featureLayerInfo = await dynLayer.GetDetailsAsync(dynamicLayerInfo.ID); switch (featureLayerInfo.GeometryType) { case GeometryType.Envelope: layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleFillSymbol() { Color = GetRandomColor(), Outline = new SimpleLineSymbol() { Color = GetRandomColor() } } }; break; case GeometryType.MultiPoint: layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = GetRandomColor(), Size = 8 } }; break; case GeometryType.Point: layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = GetRandomColor(), Size = 8 } }; break; case GeometryType.Polygon: layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleFillSymbol() { Color = GetRandomColor(), Outline = new SimpleLineSymbol() { Color = GetRandomColor() } } }; break; case GeometryType.Polyline: layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleLineSymbol() { Color = GetRandomColor() } }; break; default: break; } // Set the LayerDrawingOptions property on the local dynamic map service layer (the LayerID property ties this to the DynamicLayerInfo object). layerDrawingOptionsCollection.Add(layerDrawOpt); counter++; } return dynLayer; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return null; } }
bool IPlasticAPI.IsIncomingChangesInProgress(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
bool IPlasticAPI.IsFsReaderWatchLimitReached(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
bool IPlasticAPI.HasWorkspaceMergeChanges(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
OutOfDateItems IPlasticAPI.CalculateOutOfDateItems(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
WorkspaceTreeNode IPlasticAPI.GetWorkspaceTree(WorkspaceInfo wkInfo, string path) { throw new NotImplementedException(); }
long IPlasticAPI.GetWorkingChangeset(RepositorySpec repSpec, WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
BranchInfo IPlasticAPI.GetCheckoutBranch(WorkspaceInfo wkInfo) { return(mWorkingBranch); }
bool IPlasticAPI.IsOnChangedTree(WorkspaceInfo wkInfo, string path) { throw new NotImplementedException(); }
internal static bool FromXmlDocument( XmlDocument xmlDoc, string path, bool isTestMode, bool forceManualExecutionMode, ILogger logger, out WorkspaceInfo workspaceInfo) { try { string funName = null; double cx = 0; double cy = 0; double zoom = 1.0; string id = ""; string category = ""; string description = ""; string version = ""; var runType = RunType.Manual; int runPeriod = RunSettings.DefaultRunPeriod; bool hasRunWithoutCrash = false; bool isVisibleInDynamoLibrary = true; var topNode = xmlDoc.GetElementsByTagName("Workspace"); // legacy support if (topNode.Count == 0) { topNode = xmlDoc.GetElementsByTagName("dynWorkspace"); } // load the header foreach (XmlNode node in topNode) { foreach (XmlAttribute att in node.Attributes) { if (att.Name.Equals("X")) cx = double.Parse(att.Value, CultureInfo.InvariantCulture); else if (att.Name.Equals("Y")) cy = double.Parse(att.Value, CultureInfo.InvariantCulture); else if (att.Name.Equals("zoom")) zoom = double.Parse(att.Value, CultureInfo.InvariantCulture); else if (att.Name.Equals("Name")) funName = att.Value; else if (att.Name.Equals("ID")) id = att.Value; else if (att.Name.Equals("Category")) category = att.Value; else if (att.Name.Equals("Description")) description = att.Value; else if (att.Name.Equals("HasRunWithoutCrash")) hasRunWithoutCrash = bool.Parse(att.Value); else if (att.Name.Equals("IsVisibleInDynamoLibrary")) isVisibleInDynamoLibrary = bool.Parse(att.Value); else if (att.Name.Equals("Version")) version = att.Value; else if (att.Name.Equals("RunType")) { if (forceManualExecutionMode || !Enum.TryParse(att.Value, false, out runType)) { runType = RunType.Manual; } } else if (att.Name.Equals("RunPeriod")) runPeriod = Int32.Parse(att.Value); } } // we have a dyf and it lacks an ID field, we need to assign it // a deterministic guid based on its name. By doing it deterministically, // files remain compatible if (string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(funName) && funName != "Home") { id = GuidUtility.Create(GuidUtility.UrlNamespace, funName).ToString(); } workspaceInfo = new WorkspaceInfo { ID = id, Name = funName, X = cx, Y = cy, Zoom = zoom, FileName = path, Category = category, Description = description, Version = version, RunType = runType, RunPeriod = runPeriod, HasRunWithoutCrash = hasRunWithoutCrash, IsVisibleInDynamoLibrary = isVisibleInDynamoLibrary }; return true; } catch (Exception ex) { logger.Log(Properties.Resources.OpenWorkbenchError); logger.Log(ex); Debug.WriteLine(ex.Message + ":" + ex.StackTrace); //TODO(Steve): Need a better way to handle this kind of thing. -- MAGN-5712 if (isTestMode) throw; // Rethrow for NUnit. workspaceInfo = null; return false; } }
bool IPlasticAPI.IsWorkingChangesetDeleted(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
/// <summary> /// Opens a Custom Node workspace from an XmlDocument, given a pre-constructed WorkspaceInfo. /// </summary> /// <param name="xmlDoc">XmlDocument representing the parsed custom node file.</param> /// <param name="workspaceInfo">Workspace header describing the custom node file.</param> /// <param name="isTestMode"> /// Flag specifying whether or not this should operate in "test mode". /// </param> /// <param name="workspace"></param> /// <returns></returns> public bool OpenCustomNodeWorkspace( XmlDocument xmlDoc, WorkspaceInfo workspaceInfo, bool isTestMode, out WorkspaceModel workspace) { CustomNodeWorkspaceModel customNodeWorkspace; if (InitializeCustomNode( workspaceInfo, xmlDoc, out customNodeWorkspace)) { workspace = customNodeWorkspace; return true; } workspace = null; return false; }
List <ErrorMessage> IPlasticAPI.PartialUpdate(WorkspaceInfo wkInfo, List <string> paths) { throw new NotImplementedException(); }
private bool OpenFile(WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, out WorkspaceModel workspace) { CustomNodeManager.AddUninitializedCustomNodesInPath( Path.GetDirectoryName(workspaceInfo.FileName), IsTestMode); var result = workspaceInfo.IsCustomNodeWorkspace ? CustomNodeManager.OpenCustomNodeWorkspace(xmlDoc, workspaceInfo, IsTestMode, out workspace) : OpenHomeWorkspace(xmlDoc, workspaceInfo, out workspace); workspace.OnCurrentOffsetChanged( this, new PointEventArgs(new Point2D(workspaceInfo.X, workspaceInfo.Y))); return result; }
void IPlasticAPI.PerformUpdateMerge(WorkspaceInfo wkInfo, MergeSource mergeSource, MergeResult mergeResult, ICmdNotifier notifier) { throw new NotImplementedException(); }
void IPlasticAPI.SwitchToBranch(WorkspaceInfo wkInfo, BranchInfo branchInfo) { throw new NotImplementedException(); }
void IPlasticAPI.RemoveWorkspace(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
IUpdateResult IPlasticAPI.SwitchToLabel(WorkspaceInfo wkInfo, RepositorySpec repSpec, MarkerInfo labelInfo, IContinueWithPendingChangesQuestioner questioner, ICmdNotifier notifier) { throw new NotImplementedException(); }
BranchInfo IPlasticAPI.RenameBranch(WorkspaceInfo wkInfo, RepositorySpec repSpec, BranchInfo branchInfo, string newName) { throw new NotImplementedException(); }
void IPlasticAPI.UndoCheckout(WorkspaceInfo wkInfo, string[] paths, ICmdNotifier notifier) { throw new NotImplementedException(); }
MarkerInfo IPlasticAPI.RenameLabel(WorkspaceInfo wkInfo, RepositorySpec repSpec, MarkerInfo labelInfo, string newName) { throw new NotImplementedException(); }
void IPlasticAPI.UndoShelvedChanges(WorkspaceInfo wkInfo, string[] paths) { throw new NotImplementedException(); }
WorkspaceInfo IPlasticAPI.RenameWorkspace(WorkspaceInfo wkInfo, string newName) { throw new NotImplementedException(); }
public HomeWorkspaceModel(Guid guid, EngineController engine, DynamoScheduler scheduler, NodeFactory factory, IEnumerable<KeyValuePair<Guid, List<CallSite.RawTraceData>>> traceData, IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes, IEnumerable<AnnotationModel> annotations, IEnumerable<PresetModel> presets, ElementResolver resolver, WorkspaceInfo info, bool verboseLogging, bool isTestMode):this(engine, scheduler, factory, traceData, nodes, notes, annotations, presets, resolver, info, verboseLogging, isTestMode) { Guid = guid; }
void IPlasticAPI.RevertToClientDiffRevisions(WorkspaceInfo wkInfo, ClientDiffInfo clientDiff, WorkspaceTreeNode wkNode, string workspacePath) { throw new NotImplementedException(); }
/// <summary> /// Attempts to migrate a workspace to the current version of Dynamo. /// </summary> /// <param name="workspaceInfo">Information about workspace to migrate</param> /// <param name="xmlDoc">Xml data about workspace to migrate</param> /// <param name="isTestMode">Indicates if current code is running in tests</param> /// <param name="factory">Factory to create nodes</param> /// <returns>True if the workspace is migrated successfully</returns> public bool ProcessWorkspace(WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, bool isTestMode, NodeFactory factory) { Version fileVersion = VersionFromString(workspaceInfo.Version); var currentVersion = AssemblyHelper.GetDynamoVersion(includeRevisionNumber: false); // Only compare for major version difference. // For minor versions and build versions, we ignore the differences if (fileVersion.Major > currentVersion.Major) { bool resume = displayFutureFileMessage( workspaceInfo.FileName, fileVersion, currentVersion); if (!resume) return false; } var decision = ProcessWorkspace( xmlDoc, fileVersion, currentVersion, workspaceInfo.FileName, isTestMode, factory); if (decision != Decision.Abort) return true; displayObsoleteFileMessage(workspaceInfo.FileName, fileVersion, currentVersion); return false; }
void IPlasticAPI.RevertToThisRevision(WorkspaceInfo wkInfo, RepositorySpec repSpec, HistoryRevision revision, string path) { throw new NotImplementedException(); }
/// <summary> /// Attempts to migrate a workspace to the current version of Dynamo. /// </summary> /// <param name="workspaceInfo">Information about workspace to migrate</param> /// <param name="xmlDoc">Xml data about workspace to migrate</param> /// <param name="isTestMode">Indicates if current code is running in tests</param> /// <param name="factory">Factory to create nodes</param> /// <returns>True if the workspace is migrated successfully</returns> public bool ProcessWorkspace(WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, bool isTestMode, NodeFactory factory) { Version fileVersion = VersionFromString(workspaceInfo.Version); var currentVersion = AssemblyHelper.GetDynamoVersion(includeRevisionNumber: false); if (fileVersion > currentVersion) { bool resume = displayFutureFileMessage( workspaceInfo.FileName, fileVersion, currentVersion); if (!resume) return false; } var decision = ProcessWorkspace( xmlDoc, fileVersion, currentVersion, workspaceInfo.FileName, isTestMode, factory); if (decision != Decision.Abort) return true; displayObsoleteFileMessage(workspaceInfo.FileName, fileVersion, currentVersion); return false; }
List <ChangeInfo> IPlasticAPI.SearchMatches(WorkspaceInfo wkInfo, string path, double allowedChangesPerUnit) { throw new NotImplementedException(); }
public HomeWorkspaceModel( EngineController engine, DynamoScheduler scheduler, NodeFactory factory, IEnumerable<KeyValuePair<Guid, List<string>>> traceData, IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes, IEnumerable<AnnotationModel> annotations, IEnumerable<PresetModel> presets, ElementResolver resolver, WorkspaceInfo info, bool verboseLogging, bool isTestMode) : base(nodes, notes,annotations, info, factory,presets, resolver) { EvaluationCount = 0; // This protects the user from a file that might have crashed during // its last run. As a side effect, this also causes all files set to // run auto but lacking the HasRunWithoutCrash flag to run manually. if (info.RunType == RunType.Automatic && !info.HasRunWithoutCrash) { info.RunType = RunType.Manual; } RunSettings = new RunSettings(info.RunType, info.RunPeriod); PreloadedTraceData = traceData; this.scheduler = scheduler; this.verboseLogging = verboseLogging; IsTestMode = isTestMode; EngineController = engine; // The first time the preloaded trace data is set, we cache // the data as historical. This will be used after the initial // run of this workspace, when the PreloadedTraceData has been // nulled, to check for node deletions and reconcile the trace data. // We do a deep copy of this data because the PreloadedTraceData is // later set to null before the graph update. var copiedData = new List<KeyValuePair<Guid, List<string>>>(); foreach (var kvp in PreloadedTraceData) { var strings = kvp.Value.Select(string.Copy).ToList(); copiedData.Add(new KeyValuePair<Guid, List<string>>(kvp.Key, strings)); } historicalTraceData = copiedData; }
IList IPlasticAPI.SelectiveUpdate(WorkspaceInfo wkInfo, UpdateFlags flags, IList dirs, IList files) { throw new NotImplementedException(); }
private bool InitializeCustomNode( WorkspaceInfo workspaceInfo, XmlDocument xmlDoc, out CustomNodeWorkspaceModel workspace) { // Add custom node definition firstly so that a recursive // custom node won't recursively load itself. SetPreloadFunctionDefinition(Guid.Parse(workspaceInfo.ID)); var nodeGraph = NodeGraph.LoadGraphFromXml(xmlDoc, nodeFactory); var newWorkspace = new CustomNodeWorkspaceModel( nodeFactory, nodeGraph.Nodes, nodeGraph.Notes, nodeGraph.Annotations, nodeGraph.Presets, nodeGraph.ElementResolver, workspaceInfo); RegisterCustomNodeWorkspace(newWorkspace); workspace = newWorkspace; return true; }
void IPlasticAPI.SetAsGluonWorkspace(WorkspaceInfo wkInfo) { throw new NotImplementedException(); }
protected WorkspaceModel( IEnumerable<NodeModel> nodes, IEnumerable<NoteModel> notes, IEnumerable<AnnotationModel> annotations, WorkspaceInfo info, NodeFactory factory, IEnumerable<PresetModel> presets, ElementResolver resolver) { guid = Guid.NewGuid(); this.nodes = new List<NodeModel>(nodes); this.notes = new List<NoteModel>(notes); this.annotations = new List<AnnotationModel>(annotations); // Set workspace info from WorkspaceInfo object Name = info.Name; Description = info.Description; X = info.X; Y = info.Y; FileName = info.FileName; Zoom = info.Zoom; HasUnsavedChanges = false; LastSaved = DateTime.Now; WorkspaceVersion = AssemblyHelper.GetDynamoVersion(); undoRecorder = new UndoRedoRecorder(this); NodeFactory = factory; this.presets = new List<PresetModel>(presets); ElementResolver = resolver; foreach (var node in this.nodes) RegisterNode(node); foreach (var connector in Connectors) RegisterConnector(connector); SetModelEventOnAnnotation(); }
void IPlasticAPI.SetSelector(WorkspaceInfo wkInfo, string selector, SetSelectorFlags flags) { throw new NotImplementedException(); }
private bool OpenHomeWorkspace( XmlDocument xmlDoc, WorkspaceInfo workspaceInfo, out WorkspaceModel workspace) { var nodeGraph = NodeGraph.LoadGraphFromXml(xmlDoc, NodeFactory); var newWorkspace = new HomeWorkspaceModel( EngineController, Scheduler, NodeFactory, Utils.LoadTraceDataFromXmlDocument(xmlDoc), nodeGraph.Nodes, nodeGraph.Notes, nodeGraph.Annotations, nodeGraph.Presets, nodeGraph.ElementResolver, workspaceInfo, DebugSettings.VerboseLogging, IsTestMode ); RegisterHomeWorkspace(newWorkspace); workspace = newWorkspace; return true; }
/// <summary> /// Adds a file dataset (Shapefile or raster) to a new local dynamic map service layer. /// </summary> /// <param name="workspaceType">The workspace type (FileGDB, Raster, SDE, Shapefile) <see cref="http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client.Local~ESRI.ArcGIS.Client.Local.WorkspaceFactoryType.html"/>.</param> /// <param name="directoryPath">A <see cref="System.String"/> representing the directory path.</param> /// <param name="fileNames">A <see cref="System.Collections.Generic.List{System.String}"/> representing the name of the file (for raster datasets this must include the extension).</param> /// <param name="callback">The Action delegate to call back on once the dynamic layer work is complete.</param> public void AddFileDatasetToDynamicMapServiceLayer(WorkspaceFactoryType workspaceType, string directoryPath, List<string> fileNames, Action<ArcGISLocalDynamicMapServiceLayer> callback) { try { // Generate a unique workspace ID (any unique string). string uniqueId = Guid.NewGuid().ToString(); // Create a new WorkspaceInfo object with a unique ID. WorkspaceInfo workspaceInfo = new WorkspaceInfo(uniqueId, workspaceType, "DATABASE=" + directoryPath); // Create a new LocalMapService instance. LocalMapService localMapService = new LocalMapService { // Set the path property. Path = _emptyMpkPath, // Enable the dynamic layers capability. EnableDynamicLayers = true }; // Register the workspace to be used with this service. localMapService.DynamicWorkspaces.Add(workspaceInfo); // Asynchronously start the local map service. localMapService.StartAsync(x => { // Create the local dynamic map service layer. ArcGISLocalDynamicMapServiceLayer arcGisLocalDynamicMapServiceLayer = null; // Create a new ArcGISLocalDynamicMapServiceLayer passing in the newly started local service. arcGisLocalDynamicMapServiceLayer = new ArcGISLocalDynamicMapServiceLayer(localMapService) { // Assign the filename as the map layer ID. ID = "Workspace: " + (new DirectoryInfo(directoryPath)).Name, // Enable the dynamic layers capability. EnableDynamicLayers = true, }; // Handle the layer initialized event inline to perform the layer dynamic layer management. arcGisLocalDynamicMapServiceLayer.Initialized += (s, e) => { // Create a DynamicLayerInfoCollection to hold the new datasets as "dynamic layers". DynamicLayerInfoCollection dynamicLayerInfoCollection = new DynamicLayerInfoCollection(); // Create a LayerDrawingOptionsCollection to specify the symbology for each layer. LayerDrawingOptionsCollection layerDrawingOptionsCollection = new LayerDrawingOptionsCollection(); // Iterate over each of the selected files in the workspace. int counter = 0; foreach (string fileName in fileNames) { // Create a new DynamicLayerInfo (to make changes to existing map service layers use the CreateDynamicLayerInfosFromLayerInfos() method. DynamicLayerInfo dynamicLayerInfo = new DynamicLayerInfo { // Assign a layer ID. ID = counter, // Specify a friendly name. Name = "Dataset: " + fileName }; // Create a DataSource object to represent the physical datasource implementation (table or raster) which will become the DataSource // property of a new LayerDataSource in the map service. Other supported datasource types are JoinDataSource and QueryDataSource. DataSource dataSource = null; // If the workspace type is Raster create a new RasterDataSource. if (workspaceInfo.FactoryType == WorkspaceFactoryType.Raster) { // Create a new RasterDataSource object dataSource = new RasterDataSource { // Match the DataSourceName to the physical filename on disk (including extension). DataSourceName = fileName, // Provide the WorkspaceID (the unique workspace identifier created earlier). A LocalMapService may have multiple dynamic workspaces. WorkspaceID = workspaceInfo.Id }; } else { // Else if the workspace is not Raster create a new TableDataSource dataSource = new TableDataSource { // Match the DataSourceName to the physical filename on disk (excluding extension). DataSourceName = fileName, // Provide the WorkspaceID (the unique workspace identifier created earlier). A LocalMapService may have multiple dynamic workspaces. WorkspaceID = workspaceInfo.Id }; /* * Apply a renderer for vector layers. * Note: It is always necessary to provide a renderer when the layer being added (represented by a DynamicLayerInfo) is part of a new * DynamicLayerInfoCollection as opposed to using the CreateDynamicLayerInfosFromLayerInfos() method which creates a DynamicLayerInfoCollection * containing the existing layers in the map service. */ // Create a new LayerDrawingOptions object to hold the renderer information. var layerDrawOpt = new LayerDrawingOptions() { // Match up the LayerID to the ID of the layer within the service. LayerID = counter, }; // We need to determine the geometry type of the new feature class. // To do this, we will submit a request to the ..\MapServer\dynamicLayer?.. endpoint which will return the service level metadata, // allowing us to identify the geometry type and create an appropriate renderer. // Note:- This is a workaround until the next release where GetAllDetails will honor the DynamicLayerInfoCollection. // Create a new WebClient instance to make the request and download the response. WebClient webClient = new WebClient(); // Register an asynchronous handler in which to create the renderers and apply the to the dynamic map service layer. webClient.DownloadDataCompleted += (client, downloadDataEventArgs) => { // Read the JSON response as XML XmlReader reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(downloadDataEventArgs.Result, new XmlDictionaryReaderQuotas()); // Get the root XML element XElement root = XElement.Load(reader); // Query for the "geometryType" element XElement geometryType = root.XPathSelectElement("//geometryType"); // Create the render based on the geometry type switch (geometryType.Value) { case "esriGeometryPoint": layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = new SolidColorBrush(GetRandomColor()), Size = 8 } }; break; case "esriGeometryPolyline": layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleLineSymbol() { Color = new SolidColorBrush(GetRandomColor()) } }; break; case "esriGeometryPolygon": layerDrawOpt.Renderer = new SimpleRenderer() { Symbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(GetRandomColor()), BorderBrush = new SolidColorBrush(GetRandomColor()) } }; break; } // Set the LayerDrawingOptions property on the local dynamic map service layer (the LayerID property ties this to the DynamicLayerInfo object). layerDrawingOptionsCollection.Add(layerDrawOpt); // Update the layer drawing options property on the dynamic map service layer. arcGisLocalDynamicMapServiceLayer.LayerDrawingOptions = layerDrawingOptionsCollection; // Need to refresh the layer after the renderer(s) have been applied. arcGisLocalDynamicMapServiceLayer.Refresh(); }; // Make the request for the service metadata // e.g. http://127.0.0.1:<PORT>/arcgis/rest/services/<MPK_NAME>/MapServer/dynamicLayer?layer={"id":0,"source":{"type":"dataLayer","dataSource":{"type":"table","workspaceId":"MyWorkspace","dataSourceName":"MyFeatureClassName"}}} webClient.DownloadDataAsync(new Uri(arcGisLocalDynamicMapServiceLayer.Url + "/dynamicLayer?layer={'id':" + counter.ToString() + "," + "'source':{'type':'dataLayer','dataSource':{" + "'type':'table'," + "'workspaceId':'" + workspaceInfo.Id + "'," + "'dataSourceName':'" + fileName + "'" + "}}}")); } // Set the Source property of the DynamicLayerInfo object. dynamicLayerInfo.Source = new LayerDataSource { DataSource = dataSource }; // Add the new DynamicLayerInfo object to the collection. dynamicLayerInfoCollection.Add(dynamicLayerInfo); // Increment the counter which is being used to assign Layer IDs. counter++; } // Update the DynamicLayerInfos property on the dynamic map service layer. arcGisLocalDynamicMapServiceLayer.DynamicLayerInfos = dynamicLayerInfoCollection; // Call the Action delegate. callback(arcGisLocalDynamicMapServiceLayer); }; // Call the Initialize method on the layer to initialize the layer properties. arcGisLocalDynamicMapServiceLayer.Initialize(); }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }