示例#1
0
        static void Main()
        {
            XmlPresetReader   reader = new XmlPresetReader();
            PresetInformation pi     = reader.ReadXmlFile("Abd_shaded_A.xml");

            Console.ReadKey();
            Console.WriteLine(pi.Series[0].ToString());
        }
        /// <summary>
        /// Reads opacity and color function from the open xml.
        /// </summary>
        /// <returns>Information about the preset, which includes series of color and opacity function.</returns>
        public PresetInformation ReadOpacityAndColorFunction()
        {
            PresetInformation presetInformation = new PresetInformation();

            if (_reader.ReadToFollowing("ColoredFunctions"))
            {
                //Console.WriteLine("<ColoredFunctions>");

                while (_reader.Read())
                {
                    if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("PointList"))
                    {
                        //Console.WriteLine("<PointList>");
                        Dictionary <float, float>   opacityFunction = new Dictionary <float, float>();
                        Dictionary <float, Color[]> colorFunction   = new Dictionary <float, Color[]>();
                        while (_reader.Read())
                        {
                            if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("First"))
                            {
                                Color[] colorArray = new Color[2];
                                float   first      = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                                _reader.ReadToFollowing("LeftColor");
                                colorArray[0] = ReadColor();
                                _reader.ReadToFollowing("RightColor");
                                colorArray[1] = ReadColor();
                                _reader.ReadToFollowing("Opacity");
                                float opacity = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));

                                opacityFunction.Add(first, opacity);
                                colorFunction.Add(first, colorArray);
                            }

                            if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("PointList"))
                            {
                                //Console.WriteLine("</PointList>");
                                presetInformation.AddSerie(opacityFunction, colorFunction);
                                break;
                            }
                        }
                    }

                    if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("ColoredFunctions"))
                    {
                        //Console.WriteLine("</ColoredFunctions>"); ;
                        break;
                    }
                }
            }
            return(presetInformation);
        }
        /// <summary>
        /// Reads opacity and color function from the open xml. 
        /// </summary>
        /// <returns>Information about the preset, which includes series of color and opacity function.</returns>
        public PresetInformation ReadOpacityAndColorFunction()
        {
            PresetInformation presetInformation = new PresetInformation();

            if (_reader.ReadToFollowing("ColoredFunctions"))
                //Console.WriteLine("<ColoredFunctions>");

            while (_reader.Read())
            {
                if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("PointList"))
                {
                    //Console.WriteLine("<PointList>");
                    Dictionary<float, float> opacityFunction = new Dictionary<float, float>();
                    Dictionary<float, Color[]> colorFunction = new Dictionary<float, Color[]>();
                    while (_reader.Read())
                    {
                        if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("First"))
                        {
                            Color[] colorArray = new Color[2];
                            float first = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                            _reader.ReadToFollowing("LeftColor");
                            colorArray[0] = ReadColor();
                            _reader.ReadToFollowing("RightColor");
                            colorArray[1] = ReadColor();
                            _reader.ReadToFollowing("Opacity");
                            float opacity = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));

                            opacityFunction.Add(first, opacity);
                            colorFunction.Add(first, colorArray);
                        }

                        if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("PointList"))
                        {
                            //Console.WriteLine("</PointList>");
                            presetInformation.AddSerie(opacityFunction, colorFunction);
                            break;
                        }
                    }
                }

                if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("ColoredFunctions"))
                {
                    //Console.WriteLine("</ColoredFunctions>"); ;
                    break;
                }
            }
            return presetInformation;
        }
        /// <summary>
        /// Reads opacity function from the open xml
        /// </summary>
        /// <param name="colorFunction">Color function which will be appply to loaded opacity function</param>
        /// <param name="fileName">Name of open xml</param>
        /// <returns>Information about the preset, which includes series of color and opacity function</returns>
        public PresetInformation ReadOpacityFunction(String fileName, Dictionary <float, Color[]> colorFunction)
        {
            PresetInformation presetInformation = new PresetInformation();

            _reader = new XmlTextReader(@"..\..\presety\" + fileName);

            if (_reader.ReadToFollowing("OpacityFunctions"))
            {
                Console.WriteLine("<Opacity Function>");
            }

            while (_reader.Read())
            {
                if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("PointList"))
                {
                    Console.WriteLine("<PointList>");;
                    Dictionary <float, float> opacityFunction = new Dictionary <float, float>();
                    while (_reader.Read())
                    {
                        if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("First"))
                        {
                            float first = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                            _reader.ReadToFollowing("Second");
                            float second = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                            opacityFunction.Add(first, second);
                            //Console.WriteLine(first + " " + second);
                        }
                        if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("PointList"))
                        {
                            Console.WriteLine("</PointList>");
                            presetInformation.AddSerie(opacityFunction, colorFunction);
                            break;
                        }
                    }
                }
                if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("OpacityFunctions"))
                {
                    //Console.WriteLine("</OpacityFunctions>"); ;
                    break;
                }
            }
            return(presetInformation);
        }
        /// <summary>
        /// Reads opacity function from the open xml
        /// </summary>
        /// <param name="colorFunction">Color function which will be appply to loaded opacity function</param>
        /// <param name="fileName">Name of open xml</param>
        /// <returns>Information about the preset, which includes series of color and opacity function</returns>
        public PresetInformation ReadOpacityFunction(String fileName, Dictionary<float, Color[]> colorFunction)
        {
            PresetInformation presetInformation = new PresetInformation();
            _reader = new XmlTextReader(@"..\..\presety\" + fileName);

            if (_reader.ReadToFollowing("OpacityFunctions"))
                Console.WriteLine("<Opacity Function>");

            while (_reader.Read())
            {
                if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("PointList"))
                {
                    Console.WriteLine("<PointList>"); ;
                    Dictionary<float, float> opacityFunction = new Dictionary<float, float>();
                    while (_reader.Read())
                    {
                        if ((_reader.NodeType == XmlNodeType.Element) && _reader.Name.Equals("First"))
                        {
                            float first = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                            _reader.ReadToFollowing("Second");
                            float second = float.Parse(_reader.ReadElementContentAsString().Replace('.', ','));
                            opacityFunction.Add(first, second);
                            //Console.WriteLine(first + " " + second);
                        }
                        if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("PointList"))
                        {
                            Console.WriteLine("</PointList>");
                            presetInformation.AddSerie(opacityFunction,colorFunction);
                            break;
                        }
                    }
                }
                if ((_reader.NodeType == XmlNodeType.EndElement) && _reader.Name.Equals("OpacityFunctions"))
                {
                    //Console.WriteLine("</OpacityFunctions>"); ;
                    break;
                }
            }
            return presetInformation;
        }