/GPX.FireMap.Workflow/GPX.FireMap.Workflow/ConvertMGRSReference.cs
C# | 227 lines | 139 code | 59 blank | 29 comment | 8 complexity | c87f311a3eac1aafeb80845ad306dbd0 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Activities;
- using System.ComponentModel;
- using GPX.Firemap.Workflow.Activities;
- using Geocortex.Logging;
- using Geocortex.Workflow.Activities;
- using ESRI.ArcGIS.Client.Tasks;
- using ESRI.ArcGIS.Client;
- using System.Net;
- using System.IO;
- using ESRI.ArcGIS.Client.Geometry;
- using Newtonsoft.Json.Linq;
- using ESRI.ArcGIS.Client.Symbols;
-
- namespace GPX.Firemap.Workflow.Activities.Server
- {
-
-
- /// <summary>
- /// Todo - document
- /// </summary>
- [Description("Converts an MGRS reference to a coordinate")]
- [WorkflowDesigner(
- DisplayName = "Convert MGRS Reference",
- ToolboxCategory = "Firemap Server Activities")]
- public sealed class ConvertMGRSReference : CodeActivity
- {
-
- [CategoryAttribute("In Arguments")]
- [Description(@"MGRS Reference")]
- [DefaultValue(null)]
- [DisplayName("MGRS Reference")]
- public InArgument<string> MGRSReference { get; set; }
-
-
- [CategoryAttribute("In Arguments")]
- [Description(@"Spatial Reference Identifier")]
- [DefaultValue(null)]
- [DisplayName("Spatial Reference Identifier")]
- public InArgument<int> Wkid { get; set; }
-
- [CategoryAttribute("In Arguments")]
- [Description(@"Convert MGRS Service URL")]
- [DefaultValue(null)]
- [DisplayName("Convert MGRS Service URL")]
- public InArgument<string> MGRSServiceUrl { get; set; }
-
-
- [CategoryAttribute("Out Arguments")]
- [Description(@"Geometries")]
- [DefaultValue(null)]
- [DisplayName("Geometries")]
- public OutArgument<FeatureSet> Geometries { get; set; }
-
-
- /// <summary>
- /// When implemented in a derived class, performs the execution of the activity.
- /// </summary>
- /// <param name="context">The execution context under which the activity executes.</param>
- protected override void Execute(CodeActivityContext context)
- {
-
- try
- {
-
- // Convert to a Geocortex geometry
- Logger.SystemInfo(this.DisplayName + " beginning activity execute ");
-
- // Obtain the runtime values
- string inputCoordinate = context.GetValue(this.MGRSReference);
- if (string.IsNullOrEmpty(inputCoordinate))
- Logger.SystemError("The MGRS reference is not defined");
-
- string serviceUrl = context.GetValue(this.MGRSServiceUrl);
- if (string.IsNullOrEmpty(serviceUrl))
- Logger.SystemError("The MGRS service url is not defined");
-
-
- int inputSrid = context.GetValue(this.Wkid);
- if (inputSrid==0)
- Logger.SystemError("The WKID is not defined");
-
- JObject serverResponse;
- AGSServerSupport.CallArcGISServer(AGSServerSupport.CreateMGRSConvertRequest(serviceUrl, inputCoordinate, inputSrid.ToString()), out serverResponse);
-
-
- FeatureSet fs = new FeatureSet();
- fs.GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Point;
-
- if (serverResponse != null)
- {
-
- //List<MapPoint> points = new List<MapPoint>();
- string wkid = (string)serverResponse["wkid"];
- SpatialReference sr = new SpatialReference(Convert.ToInt32(wkid));
-
- //SH - DFU-40
- //JArray coordinates = (JArray)serverResponse["ConvertedCoordinates"];
- JArray coordinates = (JArray)serverResponse["convertedReferences"];
-
- foreach (var coordinate in coordinates)
- {
-
- string reference = (string)coordinate["reference"];
-
- float x = (float)coordinate["point"]["x"];
- float y = (float)coordinate["point"]["y"];
-
- // float x = (float)coordinate["x"];
- // float y = (float)coordinate["y"];
-
- MapPoint pnt = new MapPoint(x, y);
- pnt.SpatialReference = sr;
-
- Graphic grp = CreateGraphic(reference, pnt);
- if (grp != null)
- fs.Features.Add(grp);
- //points.Add(pnt);
-
- }
-
- // fs = CreateFeatureSet(points);
-
- }
-
-
- context.SetValue(Geometries, fs);
-
- Logger.SystemInfo(this.DisplayName + " ending activity execute ");
-
- }
- catch (System.Exception e)
- {
- Logger.SystemError("ERROR occurred in " + this.DisplayName + e.Message);
- }
-
- }
-
- //SH - DFU-40
- /// <summary>
- /// Creates the graphic.
- /// </summary>
- /// <param name="reference">The reference.</param>
- /// <param name="point">The point.</param>
- /// <returns></returns>
- private Graphic CreateGraphic(string reference, MapPoint point)
- {
- Graphic grp = null;
-
- try
- {
-
- SimpleMarkerSymbol symbol = new SimpleMarkerSymbol();
- symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
- symbol.Size = 20;
-
- grp = new Graphic();
-
- grp.Symbol = symbol;
- grp.Geometry = point;
-
- grp.Attributes.Add("reference", reference);
-
- return grp;
- }
- catch (System.Exception e)
- {
- Logger.SystemError("ERROR occurred in " + this.DisplayName + e.Message);
- return grp;
- }
- finally
- {
-
- }
-
- }
-
-
- /// <summary>
- /// Creates a client feature set from an array of points.
- /// </summary>
- /// <param name="points">The points.</param>
- /// <returns></returns>
- /// <remarks>Adds a graphic to each point for display</remarks>
- private FeatureSet CreateFeatureSet(List<MapPoint> points)
- {
-
- FeatureSet fs = new FeatureSet();
-
- try
- {
- fs.GeometryType = ESRI.ArcGIS.Client.Tasks.GeometryType.Point;
- SimpleMarkerSymbol symbol = new SimpleMarkerSymbol();
- symbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;
- symbol.Size = 20;
-
- for (int i = 0; i < points.Count; i++)
- {
- Graphic grp = new Graphic();
- grp.Symbol = symbol;
- grp.Geometry = points[i];
-
-
- fs.Features.Add(grp);
-
- }
-
- return fs;
- }
- catch (System.Exception e)
- {
- Logger.SystemError("ERROR occurred in " + this.DisplayName + e.Message);
- return fs;
- }
- finally
- {
-
- }
-
- }
-
- }
- }
-