コード例 #1
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);
        }
コード例 #2
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);
        }