MediaConvertGUI.MediaInfo.OpenSchemeFromXML C# (CSharp) Method

OpenSchemeFromXML() public method

public OpenSchemeFromXML ( string fileName ) : void
fileName string
return void
        public void OpenSchemeFromXML(string fileName)
        {
            // http://stackoverflow.com/questions/243022/parsing-through-xml-elements-in-xmlreader

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(fileName);
            var xmlRoot = xmlDoc.DocumentElement;

            foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme"))
            {
                ContainerEnum container;

                var node = item.SelectSingleNode("Container");
                if ((node != null) &&
                    (node.FirstChild != null))
                {
                    if (Enum.TryParse(node.FirstChild.Value,out container))
                        TargetContainer =  container;
                    if (Enum.TryParse("_" + node.FirstChild.Value,out container))
                        TargetContainer =  container;
                }
            }

            var firstVideoTrack =  FirstVideoTrack;

            if (firstVideoTrack != null)
            {
                foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme/Video"))
                {
                    int width;
                    var widthNode = item.SelectSingleNode("Width");
                    if ((widthNode!= null) && (widthNode.FirstChild != null))
                    {
                        if (int.TryParse(widthNode.FirstChild.Value,out width))
                            firstVideoTrack.Width = width;
                    }

                    int height;
                    var heightNode = item.SelectSingleNode("Height");
                    if ((heightNode!= null) && (heightNode.FirstChild != null))
                    {
                        if (int.TryParse(heightNode.FirstChild.Value,out height))
                            firstVideoTrack.Height = height;
                    }

                    int bitrate;
                    var bitrateNode = item.SelectSingleNode("Bitrate");
                    if ((bitrateNode!= null) && (bitrateNode.FirstChild != null))
                    {
                        if (int.TryParse(bitrateNode.FirstChild.Value,out bitrate))
                            firstVideoTrack.Bitrate = bitrate;
                    }

                    decimal framerate;
                    var framerateNode = item.SelectSingleNode("Framerate");
                    if ((framerateNode!= null) && (framerateNode.FirstChild != null))
                    {
                        if (decimal.TryParse(framerateNode.FirstChild.Value,out framerate))
                            firstVideoTrack.FrameRate = framerate;
                    }

                    var aspectNode = item.SelectSingleNode("Aspect");
                    if ((aspectNode!= null) && (aspectNode.FirstChild != null))
                    {
                        if (Regex.IsMatch(aspectNode.FirstChild.Value,"^[0-9]+:[0-9]+$"))
                        {
                            firstVideoTrack.Aspect = aspectNode.FirstChild.Value;
                        }
                    }

                    var codecNode = item.SelectSingleNode("Codec");
                    if ((codecNode!= null) && (codecNode.FirstChild != null))
                    {
                        VideoCodecEnum codec;
                        if (Enum.TryParse<VideoCodecEnum>(codecNode.FirstChild.Value,out codec))
                        {
                            //firstVideoTrack.Codec = codec.ToString();
                            this.TargetVideoCodec = codec;
                        }
                    }
                }
            }

            var firstAudioTrack =  FirstAudioTrack;

            if (this.AudioTracks.Count>0)
            {
                var actualTrackIndex = 1;
                foreach (XmlNode trackNode in xmlRoot.SelectNodes(@"/MultimediaScheme/Audio/Track"))
                {
                    var codecNode = trackNode.SelectSingleNode("Codec");
                    if ((codecNode!= null) && (codecNode.FirstChild != null))
                    {
                        AudioCodecEnum codec;
                        if (Enum.TryParse<AudioCodecEnum>(codecNode.FirstChild.Value,out codec))
                        {
                            AudioTracks[actualTrackIndex].TargetAudioCodec = codec;
                        }
                    }

                    int channels;
                    var channelsNode = trackNode.SelectSingleNode("Channels");
                    if ((channelsNode!= null) && (channelsNode.FirstChild != null))
                    {
                        if (int.TryParse(channelsNode.FirstChild.Value,out channels))
                            AudioTracks[actualTrackIndex].Channels = channels;
                    }

                    int bitrate;
                    var bitrateNode = trackNode.SelectSingleNode("Bitrate");
                    if ((bitrateNode!= null) && (bitrateNode.FirstChild != null))
                    {
                        if (int.TryParse(bitrateNode.FirstChild.Value,out bitrate))
                            AudioTracks[actualTrackIndex].Bitrate = bitrate;
                    }

                    decimal sRate;
                    var sRateNode = trackNode.SelectSingleNode("SamplingRate");
                    if ((sRateNode!= null) && (sRateNode.FirstChild != null))
                    {
                        if (decimal.TryParse(sRateNode.FirstChild.Value,out sRate))
                            AudioTracks[actualTrackIndex].SamplingRateHz = sRate;
                    }

                    actualTrackIndex ++;
                    if (actualTrackIndex > AudioTracks.Count)
                    {
                        break;
                    }

                }
            }
        }