private void UpdateCurrentMessage(TimeAwareMilitaryMessage tam, Geometry geometry)
        {
            var cpts = string.Empty;

            // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn

            List<MapPoint> mpList = null;

            var polyline = geometry as Polyline;

            if (polyline != null)
            {
                if (tam[MilitaryMessage.SicCodePropertyName].Contains("POLA") ||
                    tam[MilitaryMessage.SicCodePropertyName].Contains("PPA"))
                {
                    mpList = AdjustMapPoints(polyline, DrawShape.Arrow);
                }
                else
                {
                    mpList = AdjustMapPoints(polyline, DrawShape.Polyline);
                }
            }
            else
            {
                var polygon = geometry as Polygon;

                if (polygon != null)
                {
                    mpList = new List<MapPoint>();
                    foreach (var part in polygon.Parts)
                    {
                        mpList.AddRange(part.GetPoints());
                    }
                }
            }

            if (mpList != null)
            {
                var msg = new MilitaryMessage(tam.Id, MilitaryMessageType.PositionReport, MilitaryMessageAction.Update,
                    mpList);

                tam[MilitaryMessage.ControlPointsPropertyName] = msg[MilitaryMessage.ControlPointsPropertyName];

                if (_militaryMessageLayer.ProcessMessage(msg))
                {
                    UpdateMilitaryMessageControlPoints(msg);

                    DoCloneMission(null);
                }
            }
        }
        private void AddNewMessage(SymbolViewModel symbolViewModel, Point p, string guid)
        {
            //create a new message
            var tam = new TimeAwareMilitaryMessage
            {
                VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start,
                    _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End),
                Id = guid
            };

            tam.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT);
            tam.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE);
            tam.Add(MilitaryMessage.WkidPropertyName, "3857");
            tam.Add(MilitaryMessage.SicCodePropertyName, symbolViewModel.SymbolID);
            tam.Add(MilitaryMessage.UniqueDesignationPropertyName, "1");

            // Construct the Control Points based on the geometry type of the drawn geometry.
            var point = _mapView.ScreenToLocation(p);
            tam.SymbolGeometry = point;
            tam.Add(MilitaryMessage.ControlPointsPropertyName, point.X.ToString() + "," + point.Y.ToString());

            //Process the message
            if (ProcessMessage(_militaryMessageLayer, tam))
            {
                RecordMessageBeingAdded(tam);

                DoCloneMission(null);
            }
            else
            {
                MessageBox.Show("Failed to process message.");
            }
        }
 private void AddMilitaryMessageToMessageList(TimeAwareMilitaryMessage tam)
 {
     if (_mission.MilitaryMessages.Count(m => m.Id == tam.Id) == 0)
     {
         _mission.MilitaryMessages.Add(tam);
     }
 }
        private void RecordMessageBeingAdded(TimeAwareMilitaryMessage tam)
        {
            tam.PhaseControlPointsDictionary.Add(_mission.PhaseList[CurrentPhaseIndex].ID, tam[MilitaryMessage.ControlPointsPropertyName]);

            AddMilitaryMessageToMessageList(tam);
        }
        private void ProcessSymbol(SymbolViewModel symbol, Geometry geometry)
        {
            if (symbol == null || geometry == null)
            {
                return;
            }

            //create a new message
            var msg = new TimeAwareMilitaryMessage
            {
                VisibleTimeExtent = new TimeExtent(_mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.Start,
                    _mission.PhaseList[CurrentPhaseIndex].VisibleTimeExtent.End),
                Id = Guid.NewGuid().ToString("D"),
                SymbolGeometry = geometry
            };

            // set default time extent

            //set the ID and other parts of the message
            msg.Add(MilitaryMessage.TypePropertyName, Constants.MSG_TYPE_POSITION_REPORT);
            msg.Add(MilitaryMessage.ActionPropertyName, Constants.MSG_ACTION_UPDATE);
            msg.Add(MilitaryMessage.WkidPropertyName, "3857");
            msg.Add(MilitaryMessage.SicCodePropertyName, symbol.SymbolID);
            msg.Add(MilitaryMessage.UniqueDesignationPropertyName, "1");

            // Construct the Control Points based on the geometry type of the drawn geometry.
            switch (geometry.GeometryType)
            {
                case GeometryType.Point:
                    MapPoint point = geometry as MapPoint;
                    if (point != null)
                        msg.Add(MilitaryMessage.ControlPointsPropertyName, string.Format("{0},{1}", point.X.ToString(), point.Y.ToString()));
                    break;
                case GeometryType.Polygon:
                    Polygon polygon = geometry as Polygon;
                    string cpts = polygon.Parts.SelectMany(pt => pt.GetPoints()).Aggregate(string.Empty, (current, segpt) => current + (";" + segpt.X.ToString() + "," + segpt.Y.ToString()));
                    //foreach (var pt in polygon.Rings[0])
                    msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts);
                    break;
                case GeometryType.Polyline:
                    Polyline polyline = geometry as Polyline;
                    cpts = string.Empty;

                    // TODO find a way to determine if polyline map points need adjustment based on symbol being drawn
                    var mpList = AdjustMapPoints(polyline, symbol);

                    cpts = mpList.Aggregate(cpts, (current, mp) => current + (";" + mp.X.ToString() + "," + mp.Y.ToString()));

                    msg.Add(MilitaryMessage.ControlPointsPropertyName, cpts);
                    break;
            }

            //Process the message
            if (ProcessMessage(_militaryMessageLayer, msg))
            {
                RecordMessageBeingAdded(msg);

                DoCloneMission(null);
            }
            else
            {
                MessageBox.Show("Failed to process message.");
            }
        }
        private void RemoveMessageFromPhase(int phaseIndex, TimeAwareMilitaryMessage tam)
        {
            // check if message is only is this phase
            var phaseTimeExtent = _mission.PhaseList[phaseIndex].VisibleTimeExtent;

            if (tam.VisibleTimeExtent.Start >= phaseTimeExtent.Start && tam.VisibleTimeExtent.End <= phaseTimeExtent.End)
            {
                // contained in this phase only, remove completely
                _mission.MilitaryMessages.Remove(tam);

                Mediator.NotifyColleagues(Constants.ACTION_ITEM_WITH_GUID_REMOVED, tam.Id);
                return;
            }
            else if (tam.VisibleTimeExtent.Start >= phaseTimeExtent.Start && tam.VisibleTimeExtent.End > phaseTimeExtent.End)
            {
                // message starts in this phase but goes into next phase
                // update start with next phase Start
                if (phaseIndex < _mission.PhaseList.Count() - 1)
                {
                    tam.VisibleTimeExtent.Start = _mission.PhaseList[phaseIndex + 1].VisibleTimeExtent.Start;
                }
            }
            else if (tam.VisibleTimeExtent.Start < phaseTimeExtent.Start)
            {
                // message starts in previous phase, update END to previous phase END
                if (phaseIndex > 0)
                {
                    tam.VisibleTimeExtent.End = _mission.PhaseList[phaseIndex - 1].VisibleTimeExtent.End;
                }
            }
        }