Esempio n. 1
0
        public MainViewModel()
        {
            var template = LayerSerializer.ReadResourceTemplates().First();
            var layer    = new Layer(template);

            OpenLayer(layer);
        }
        public static SerializedNetwork Serialize(INetwork network)
        {
            int layerLength = network.Layers.Length;

            ISerializedLayer[] serializedLayers = new ISerializedLayer[layerLength];
            for (int i = 0; i < layerLength; ++i)
            {
                serializedLayers[i] = LayerSerializer.SerializeLayer(network.Layers[i]);
            }
            return(new SerializedNetwork(network.BatchSize, serializedLayers));
        }
Esempio n. 3
0
        private void OnOpenTemplateMenuItemClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            if (ofd.ShowDialog() ?? false)
            {
                try
                {
                    using (var file = File.OpenRead(ofd.FileName))
                    {
                        ViewModel.OpenLayer(new Layer(LayerSerializer.ReadTemplate(file)));
                    }
                }
                catch (Exception ex)
                {
                    // todo: handling
                    MessageBox.Show("Failed to open layer data", "Error", MessageBoxButton.OK);
                }
            }
        }
Esempio n. 4
0
        private void OnSaveMenuItemClick(object sender, RoutedEventArgs e)
        {
            var sfd = new SaveFileDialog();

            if (sfd.ShowDialog() ?? false)
            {
                try
                {
                    using (var file = File.OpenWrite(sfd.FileName))
                    {
                        file.SetLength(0);
                        LayerSerializer.WriteLayer(file, ViewModel.Layer);
                    }
                }
                catch (Exception ex)
                {
                    // todo: handling
                    MessageBox.Show("Failed to save layer data", "Error", MessageBoxButton.OK);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Deserialize LabelLayer
        /// </summary>
        /// <param name="labelLayerElement">Root element to deserialize</param>
        /// <returns>LabelLayer</returns>
        public static EidssLabelLayer Deserialize(XmlElement labelLayerElement)
        {
            EidssLabelLayer resultLabelLayer = null;

            LayerSerializer.LayerInfo lyrInfo;
            XmlNode tempNode;
            int     tempInt;

            #region <<Deserialize LayerFields >>

            try
            { lyrInfo = LayerSerializer.DeserializeLayerFields(labelLayerElement); }
            catch (Exception ex)
            { throw new EidssLabelLayerDeserializationException("LabelLayer can't be deserialized: " + ex.Message, ex); }

            //create layer
            switch (labelLayerElement.Attributes["Type"].Value)
            {
            case "eidss.gis.Layers.EidssLabelLayer":
                resultLabelLayer = new EidssLabelLayer(lyrInfo.LayerName, lyrInfo.Guid);
                break;

            case "eidss.gis.Layers.EidssSystemLabelLayer":
                resultLabelLayer = new EidssSystemLabelLayer(lyrInfo.LayerName, lyrInfo.Guid);
                break;

            case "eidss.gis.Layers.EidssExtSystemLabelLayer":
                resultLabelLayer = new EidssExtSystemLabelLayer(lyrInfo.LayerName, lyrInfo.Guid);
                break;
            }

            resultLabelLayer.ControledByUser = lyrInfo.ControledByUser;
            resultLabelLayer.Enabled         = lyrInfo.Enabled;
            resultLabelLayer.MaxVisible      = lyrInfo.MaxVisible;
            resultLabelLayer.MinVisible      = lyrInfo.MinVisible;
            //resultLabelLayer.SRID = lyrInfo.SRID; - тут бля косяк в провайдере! нет проверки!
            resultLabelLayer.VisibleInTOC = lyrInfo.VisibleInTOC;
            resultLabelLayer.Transparency = lyrInfo.Transparency;
            #endregion

            #region << Deserialize >>

            //DataSource - переделать
            try
            { resultLabelLayer.DataSource = EidssProviderSerializer.Instance.DeserializeFromNode(labelLayerElement, "DataSource"); }
            catch (Exception ex)
            { throw new EidssLabelLayerDeserializationException("DataSource can't be deserialized: " + ex.Message, ex); }

            //LabelColumn
            tempNode = labelLayerElement.SelectSingleNode("LabelColumn");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'LabelColumn'!");
            }
            resultLabelLayer.LabelColumn = tempNode.InnerText;

            //LabelFilter
            tempNode = labelLayerElement.SelectSingleNode("LabelFilter");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'LabelFilter'!");
            }
            resultLabelLayer.LabelFilter = LabelLayerSerializer.GetFilterLabelDelegate(tempNode.InnerText);

            //LabelStringDelegate
            //NotImplemented

            //MultipartGeometryBehaviour
            tempNode = labelLayerElement.SelectSingleNode("MultipartGeometryBehaviour");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'MultipartGeometryBehaviour'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt) || !Enum.IsDefined(typeof(SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum), tempInt))
            {
                throw new EidssLabelLayerDeserializationException("Can't parse node 'MultipartGeometryBehaviour'!");
            }
            resultLabelLayer.MultipartGeometryBehaviour = (SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum)tempInt;

            //Priority
            tempNode = labelLayerElement.SelectSingleNode("Priority");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'Priority'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt) || tempInt < 0)
            {
                throw new EidssLabelLayerDeserializationException("Can't parse node 'Priority'!");
            }
            resultLabelLayer.Priority = tempInt;

            //RotationColumn
            tempNode = labelLayerElement.SelectSingleNode("RotationColumn");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'RotationColumn'!");
            }
            resultLabelLayer.RotationColumn = tempNode.InnerText;

            //SmoothingMode
            tempNode = labelLayerElement.SelectSingleNode("SmoothingMode");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'SmoothingMode'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt) || !Enum.IsDefined(typeof(SmoothingMode), tempInt))
            {
                throw new EidssLabelLayerDeserializationException("Can't parse node 'SmoothingMode'!");
            }
            resultLabelLayer.SmoothingMode = (SmoothingMode)tempInt;


            //SRID
            tempNode = labelLayerElement.SelectSingleNode("SRID");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'SRID'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt))
            {
                throw new EidssLabelLayerDeserializationException("Can't parse node 'SRID'!");
            }
            resultLabelLayer.SRID = tempInt;

            //Style
            try
            { resultLabelLayer.Style = (LabelStyle)StyleSerializer.DeserializeFromNode(labelLayerElement, "Style"); }
            catch (Exception ex)
            { throw new EidssLabelLayerDeserializationException("Style can't be deserialized: " + ex.Message, ex); }


            //TextRenderingHint
            tempNode = labelLayerElement.SelectSingleNode("TextRenderingHint");
            if (tempNode == null)
            {
                throw new EidssLabelLayerDeserializationException("'LabelLayerElement' don't have element 'TextRenderingHint'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt) || !Enum.IsDefined(typeof(TextRenderingHint), tempInt))
            {
                throw new EidssLabelLayerDeserializationException("Can't parse node 'TextRenderingHint'!");
            }
            resultLabelLayer.TextRenderingHint = (TextRenderingHint)tempInt;

            //Theme
            //NotImplemented

            #endregion

            return(resultLabelLayer);
        }
Esempio n. 6
0
        /// <summary>
        /// Serialize LabelLayer
        /// </summary>
        /// <param name="labelLayer">LabelLayer to serialize</param>
        /// <param name="labelLayerElement">Root element to serialize</param>
        public static void Serialize(EidssLabelLayer labelLayer, XmlElement labelLayerElement)
        {
            XmlElement xmlElement;

            LayerSerializer.SerializeLayerFields(labelLayer, labelLayerElement);

            #region << Serialization >>

            //DataSource - это не правильно, так как соурс копируется два раза!
            // после изменения лееров переделать на связь по id!
            try
            { EidssProviderSerializer.Instance.SerializeAsNode(labelLayer.DataSource, labelLayerElement, "DataSource"); }
            catch (Exception ex)
            { throw new EidssLabelLayerSerializationException("DataSource can't be serialized: " + ex.Message, ex); }

            //LabelColumn
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("LabelColumn");
            xmlElement.InnerText = labelLayer.LabelColumn;
            labelLayerElement.AppendChild(xmlElement);

            //LabelFilter (Temporary version)
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("LabelFilter");
            xmlElement.InnerText = labelLayer.LabelFilter != null?labelLayer.LabelFilter.Method.DeclaringType.FullName.ToString() + "+" + labelLayer.LabelFilter.Method.Name.ToString() : null;

            labelLayerElement.AppendChild(xmlElement);

            //LabelStringDelegate
            //NotImplemented

            //MultipartGeometryBehaviour
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("MultipartGeometryBehaviour");
            xmlElement.InnerText = labelLayer.MultipartGeometryBehaviour.ToString("D");
            labelLayerElement.AppendChild(xmlElement);

            //Priority
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("Priority");
            xmlElement.InnerText = labelLayer.Priority.ToString();
            labelLayerElement.AppendChild(xmlElement);

            //RotationColumn
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("RotationColumn");
            xmlElement.InnerText = labelLayer.RotationColumn;
            labelLayerElement.AppendChild(xmlElement);

            //SmoothingMode
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("SmoothingMode");
            xmlElement.InnerText = labelLayer.SmoothingMode.ToString("D");
            labelLayerElement.AppendChild(xmlElement);

            //SRID
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("SRID");
            xmlElement.InnerText = labelLayer.SRID.ToString("F0");
            labelLayerElement.AppendChild(xmlElement);

            //Style
            try
            { StyleSerializer.SerializeAsNode(labelLayer.Style, labelLayerElement); }
            catch (Exception ex)
            { throw new LabelLayerSerializationException("Style can't be serialized: " + ex.Message, ex); }

            //TextRenderingHint
            xmlElement           = labelLayerElement.OwnerDocument.CreateElement("TextRenderingHint");
            xmlElement.InnerText = labelLayer.TextRenderingHint.ToString("D");
            labelLayerElement.AppendChild(xmlElement);

            //Theme
            //NotImplemented

            #endregion
        }
Esempio n. 7
0
        /// <summary>
        /// Serialize VectorLayer
        /// </summary>
        /// <param name="vectorLayer">VectorLayer to serialize</param>
        /// <param name="vectorLayerElement">Root element to serialize</param>
        public static void Serialize(EidssUserDbLayer vectorLayer, XmlElement vectorLayerElement)
        {
            XmlElement xmlElement;

            LayerSerializer.SerializeLayerFields(vectorLayer, vectorLayerElement);

            #region << Serialization >>

            //TODO[enikulin]: need refactoring. only one property (LayerDBguid) and type of layer is changed from VectorLayer

            //LayerDbGuid
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("LayerDbGuid");
            xmlElement.InnerText = vectorLayer.LayerDbGuid.ToString();
            vectorLayerElement.AppendChild(xmlElement);

            //LabelLayerGuid
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("LabelLayerGuid");
            xmlElement.InnerText = vectorLayer.LabelLayerGuid.ToString();
            vectorLayerElement.AppendChild(xmlElement);

            //ClippingEnabled
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("ClippingEnabled");
            xmlElement.InnerText = vectorLayer.ClippingEnabled.ToString();
            vectorLayerElement.AppendChild(xmlElement);

            //SmoothingMode
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("SmoothingMode");
            xmlElement.InnerText = vectorLayer.SmoothingMode.ToString("D");
            vectorLayerElement.AppendChild(xmlElement);

            //SRID
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("SRID");
            xmlElement.InnerText = vectorLayer.SRID.ToString("F0");
            vectorLayerElement.AppendChild(xmlElement);


            //Style
            try
            { StyleSerializer.SerializeAsNode(vectorLayer.Style, vectorLayerElement); }
            catch (Exception ex)
            { throw new VectorLayerSerializationException("Style can't be serialized: " + ex.Message, ex); }

            //Theme
            try
            { ThemeSerializer.SerializeAsNode(vectorLayer.Theme, vectorLayerElement); }
            catch (Exception ex)
            { throw new VectorLayerSerializationException("Theme can't be serialized: " + ex.Message, ex); }



            //Marker size
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("MarkerSize");
            xmlElement.InnerText = vectorLayer.MarkerSize.ToString();
            vectorLayerElement.AppendChild(xmlElement);

            //Marker color
            try
            {
                ColorSerializer.SerializeAsNode(vectorLayer.MarkerColor, vectorLayerElement, "MarkerColor");
            }
            catch (Exception ex)
            {
                throw new VectorLayerSerializationException("'MarkerColor' can't be serialized: " + ex.Message, ex);
            }

            //Polygon Fill Style
            xmlElement           = vectorLayerElement.OwnerDocument.CreateElement("PolygonFillStyle");
            xmlElement.InnerText = vectorLayer.PolygonFillStyle;
            vectorLayerElement.AppendChild(xmlElement);

            //Polygon Fill Color
            try
            {
                ColorSerializer.SerializeAsNode(vectorLayer.PolygonFillColor, vectorLayerElement, "PolygonFillColor");
            }
            catch (Exception ex)
            {
                throw new VectorLayerSerializationException("'PolygonFillColor' can't be serialized: " + ex.Message, ex);
            }

            #endregion
        }
Esempio n. 8
0
        /// <summary>
        /// Deserialize VectorLayer
        /// </summary>
        /// <param name="vectorLayerElement">Root element to deserialize</param>
        /// <returns>VectorLayer</returns>
        public static EidssUserDbLayer Deserialize(XmlElement vectorLayerElement)
        {
            EidssUserDbLayer resultVectorLayer = null;
            XmlNode          tempNode;

            LayerSerializer.LayerInfo lyrInfo;
            bool tempBool;
            int  tempInt;

            #region <<Deserialize LayerFields >>

            try
            { lyrInfo = LayerSerializer.DeserializeLayerFields(vectorLayerElement); }
            catch (Exception ex)
            { throw new VectorLayerDeserializationException("VectorLayer can't be deserialized: " + ex.Message, ex); }

            //LayerDbGuid
            tempNode = vectorLayerElement.SelectSingleNode("LayerDbGuid");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("VectorLayer can't be deserialized: 'LayerElement' don't have element 'LayerDbGuid'!");
            }
            var layerDbGuid = new Guid(tempNode.InnerText);


            //LabelLayer Guid
            tempNode = vectorLayerElement.SelectSingleNode("LabelLayerGuid");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("VectorLayer can't be deserialized: 'LayerElement' don't have element 'LabelLayerGuid'!");
            }
            var labelLayerGuid = new Guid(tempNode.InnerText);

            //create layer
            switch (vectorLayerElement.Attributes["Type"].Value)
            {
            case "eidss.gis.Layers.EidssUserDbLayer":
                resultVectorLayer = new EidssUserDbLayer(layerDbGuid, lyrInfo.LayerName, lyrInfo.Guid, labelLayerGuid);
                break;

            case "eidss.gis.Layers.EidssUserBufZoneLayer":
                resultVectorLayer = new EidssUserBufZoneLayer(layerDbGuid, lyrInfo.LayerName, lyrInfo.Guid, labelLayerGuid);
                break;
            }


            resultVectorLayer.ControledByUser = lyrInfo.ControledByUser;
            resultVectorLayer.Enabled         = lyrInfo.Enabled;
            resultVectorLayer.MaxVisible      = lyrInfo.MaxVisible;
            resultVectorLayer.MinVisible      = lyrInfo.MinVisible;
            //resultVectorLayer.SRID = lyrInfo.SRID; - тут бля косяк в провайдере! нет проверки!
            resultVectorLayer.VisibleInTOC = lyrInfo.VisibleInTOC;
            resultVectorLayer.Transparency = lyrInfo.Transparency;
            #endregion

            #region << Deserialize >>

            //ClippingEnabled
            tempNode = vectorLayerElement.SelectSingleNode("ClippingEnabled");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("'VectorLayerElement' don't have element 'ClippingEnabled'!");
            }
            if (!bool.TryParse(tempNode.InnerText, out tempBool))
            {
                throw new VectorLayerDeserializationException("Can't parse node 'ClippingEnabled'!");
            }
            resultVectorLayer.ClippingEnabled = tempBool;


            //SmoothingMode
            tempNode = vectorLayerElement.SelectSingleNode("SmoothingMode");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("'VectorLayerElement' don't have element 'SmoothingMode'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt) || !Enum.IsDefined(typeof(SmoothingMode), tempInt))
            {
                throw new VectorLayerDeserializationException("Can't parse node 'SmoothingMode'!");
            }
            resultVectorLayer.SmoothingMode = (SmoothingMode)tempInt;

            //SRID
            tempNode = vectorLayerElement.SelectSingleNode("SRID");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("'VectorLayerElement' don't have element 'SRID'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt))
            {
                throw new VectorLayerDeserializationException("Can't parse node 'SRID'!");
            }
            resultVectorLayer.SRID = tempInt;

            //Style
            try
            { resultVectorLayer.Style = (VectorStyle)StyleSerializer.DeserializeFromNode(vectorLayerElement); }
            catch (Exception ex)
            { throw new VectorLayerSerializationException("Style can't be deserialized: " + ex.Message, ex); }

            //Theme
            try
            { resultVectorLayer.Theme = ThemeSerializer.DeserializeFromNode(vectorLayerElement); }
            catch (Exception ex)
            { throw new VectorLayerSerializationException("Theme can't be deserialized: " + ex.Message, ex); }


            //Marker size
            tempNode = vectorLayerElement.SelectSingleNode("MarkerSize");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("'VectorLayerElement' don't have element 'MarkerSize'!");
            }
            if (!Int32.TryParse(tempNode.InnerText, out tempInt))
            {
                throw new VectorLayerDeserializationException("Can't parse node 'MarkerSize'!");
            }
            resultVectorLayer.MarkerSize = tempInt;

            //Marker color
            try
            {
                resultVectorLayer.MarkerColor = ColorSerializer.DeserializeFromNode(vectorLayerElement, "MarkerColor");
            }
            catch (Exception ex)
            {
                throw new VectorLayerSerializationException("MarkerColor can't be deserialized: " + ex.Message, ex);
            }

            //Polygon Fill Style
            tempNode = vectorLayerElement.SelectSingleNode("PolygonFillStyle");
            if (tempNode == null)
            {
                throw new VectorLayerDeserializationException("'VectorLayerElement' don't have element 'PolygonFillStyle'!");
            }
            resultVectorLayer.PolygonFillStyle = tempNode.InnerText;

            //Polygon Fill Color
            try
            {
                resultVectorLayer.PolygonFillColor = ColorSerializer.DeserializeFromNode(vectorLayerElement, "PolygonFillColor");
            }
            catch (Exception ex)
            {
                throw new VectorLayerSerializationException("PolygonFillColor can't be deserialized: " + ex.Message, ex);
            }

            #endregion

            return(resultVectorLayer);
        }