/// <summary>
        /// SqlServer 2005 upwards supports XML data types. 
        /// You could have xml text node containing data you wish converted to an int array for simpler data mapping
        /// within your mapper file.
        /// </summary>
        /// <param name="getter"></param>
        /// <returns></returns>
        public object GetResult(IResultGetter getter)
        {
            if (getter.Value == null)
                return null;

            var xmlString = getter.Value.ToString();

            if (String.IsNullOrEmpty(xmlString) || xmlString.Trim().Length == 0)
                return null;

            var integerArray = new List<int>();

            using (var reader = new XmlTextReader(new StringReader(xmlString)))
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Text)
                        continue;

                    if (String.IsNullOrEmpty(reader.Value))
                        continue;

                    integerArray.Add(reader.ReadContentAsInt());
                }
            }

            return integerArray.ToArray();
        }
        public void Deserialize(string str)
        {
            using (TextReader textReader = new StringReader(str))
            using (XmlReader xmlReader = new XmlTextReader(textReader))
            {
                xmlReader.ReadStartElement();

                xmlReader.ReadStartElement();
                this.Id = new Guid(xmlReader.ReadContentAsString());
                xmlReader.ReadEndElement();

                xmlReader.ReadStartElement();
                this.Value1 = xmlReader.ReadContentAsInt();
                xmlReader.ReadEndElement();

                xmlReader.ReadStartElement();
                this.Value2 = xmlReader.ReadContentAsDateTime();
                xmlReader.ReadEndElement();

                xmlReader.ReadStartElement();
                this.Value3 = xmlReader.ReadContentAsString();
                xmlReader.ReadEndElement();

                xmlReader.ReadStartElement();
                this.Value4 = xmlReader.ReadContentAsDecimal();
                xmlReader.ReadEndElement();

                xmlReader.ReadEndElement();
            }
        }
Exemplo n.º 3
0
        public static NamingRules LoadRules(string xmlPath)
        {
            NamingRules namingRules = new NamingRules();
            namingRules.rules = new List<NamingRule>();

            using (XmlReader reader = new XmlTextReader(xmlPath))
            {
                reader.ReadStartElement("Rules");
                reader.ReadStartElement("GeneralSettings");
                
                reader.ReadStartElement("FilenameRegex");
                namingRules.filenameRegex = reader.ReadString();
                reader.ReadEndElement();
                
                reader.ReadStartElement("ContextDepth");
                namingRules.contextDepth = reader.ReadContentAsInt();
                if (namingRules.ContextDepth < 1 || namingRules.ContextDepth > 4)
                    throw new FormatException("Context Depth must be between 1 and 4");
                reader.ReadEndElement();
                
                reader.ReadStartElement("ContextSeparator");
                namingRules.contextSeparator = reader.ReadString();
                reader.ReadEndElement();
                
                reader.ReadEndElement();
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        System.Diagnostics.Debug.Assert(reader.Name == "Rules");
                        break;
                    }
                    //if (reader.IsStartElement())
                    //    System.Diagnostics.Debug.Assert(reader.Name == "Rule");
                    reader.ReadStartElement("Rule");
                    //reader.Read();

                    reader.ReadStartElement("SearchString");
                    string regex = reader.ReadString();
                    reader.ReadEndElement();
                    reader.ReadStartElement("Replacement");
                    string replacement = reader.ReadString();
                    reader.ReadEndElement();
                    reader.ReadEndElement();
                    namingRules.rules.Add(new NamingRule(regex, replacement));
                }
                reader.ReadEndElement();
            }
            return namingRules;
        }
Exemplo n.º 4
0
        internal void Deserialize(XmlTextReader reader)
        {
            bool keepreading = true;
            while (keepreading)
            {
                reader.Read();
                if (reader.Name.Equals("material") && reader.NodeType.Equals(XmlNodeType.Element))
                {
                    VoxMaterial mat = new VoxMaterial();
                    mat.ID = (byte)reader.ReadContentAsInt();
                    mat.Name = reader.ReadContentAsString();
                    mat.Flags = (MatFlags)Enum.Parse(typeof(MatFlags), reader.ReadContentAsString());
                    mat.Density = reader.ReadContentAsFloat();
                    mat.Deposit = (DepositType)Enum.Parse(typeof(DepositType), reader.ReadContentAsString());
                    mat.Texture = UUID.Parse(reader.ReadContentAsString());
                    mat.Type = (MaterialType)Enum.Parse(typeof(MaterialType), reader.ReadContentAsString());

                    if (mat.ID > index)
                    {
                        index = mat.ID;
                        index++;
                    }

                    mMaterials.Add(mat.ID, mat);
                    mName2Byte.Add(mat.Name, mat.ID);
                }
            }
        }
Exemplo n.º 5
0
		public static SystemConfig LoadFromXml(Stream stream, bool isEncrypted)
		{
			if (stream == null)
			{
				throw new ArgumentNullException("stream");
			}

			using (XmlTextReader reader = new XmlTextReader(stream))
			{
				if (reader != null)
				{
					SystemConfig config = new SystemConfig();
					while (reader.Read())
					{
						if (reader.NodeType == XmlNodeType.Element && reader.Name == XmlElementConfig)
						{
							reader.MoveToAttribute(XmlAttribute);
							string attribute = reader.ReadContentAsString();
							switch (attribute)
							{
								case "MaxConnectionCount":
									reader.MoveToAttribute(XmlValue);
									config._maxConnectionCount = (ushort)reader.ReadContentAsInt();
									break;
                                case "AdminServerListenIP":
                                    reader.MoveToAttribute(XmlValue);
                                    config._adminServerListenIP = reader.ReadContentAsString();
                                    break;
								case "AdminServerListenPort":
									reader.MoveToAttribute(XmlValue);
									config._adminServerListenPort = reader.ReadContentAsInt();
									break;                                
								case "SecondaryAdminServerListenPort":
									reader.MoveToAttribute(XmlValue);
									config._secondaryAdminServerListenPort = reader.ReadContentAsInt();
									break;
								case "AdminServerUploadFileRootPath":
									reader.MoveToAttribute(XmlValue);
									config._adminServerUploadFileRootPath = reader.ReadContentAsString();

                                    if (!config._adminServerUploadFileRootPath.EndsWith(@"\")) config._adminServerUploadFileRootPath += @"\";

                                    //若该文件夹不存在,则创建它
                                    if (Directory.Exists(config._adminServerUploadFileRootPath) == false)
                                    {
                                        Directory.CreateDirectory(config._adminServerUploadFileRootPath);
                                    }

									break;
								case "DbConnectionString":
									{
										reader.MoveToAttribute(XmlValue);
										string readConnectionString = reader.ReadContentAsString();
										if (isEncrypted)
										{
											try
											{
												config._dbConnectionString = CryptographyManager.TheInstance.PredefinedDecrypt(readConnectionString, Encoding.Default);
											}
											catch (Exception ex)
											{
												throw new Exception("Decrypt SystemConfig Entry \"DbConnectionString\" Failed.", ex);
											}
										}
										else
										{
											config._dbConnectionString = readConnectionString;
										}
									}
									break;
								case "DefaultDbName":
									reader.MoveToAttribute(XmlValue);
									config._defaultDbName = reader.ReadContentAsString();
									break;
								case "DefaultEncoding":
									reader.MoveToAttribute(XmlValue);
									config._defaultEncoding = Encoding.GetEncoding(reader.ReadContentAsString());
									break;
								case "DefaultNewLine":
									{
										reader.MoveToAttribute(XmlValue);
										string newLine = reader.ReadContentAsString();
										if (newLine == @"\n")
										{
											config._defaultNewLine = "\n";
										}
										else if (newLine == @"\r\n")
										{
											config._defaultNewLine = "\r\n";
										}
									}
									break;
								case "LogDir":
									reader.MoveToAttribute(XmlValue);
									config._logDir = reader.ReadContentAsString();

                                    if (!config._logDir.EndsWith(@"\")) config._logDir+=@"\";

                                    //若该文件夹不存在,则创建它
                                    if (Directory.Exists(config._logDir) == false)
                                    {
                                        Directory.CreateDirectory(config._logDir);
                                    }

									break;
								case "LogEnabled":
									reader.MoveToAttribute(XmlValue);
									config._logEnabled = reader.ReadContentAsBoolean();
									break;
								case "ListenForConfigGuardReturnPort":
									reader.MoveToAttribute(XmlValue);
									config._listenForConfigGuardReturnPort = reader.ReadContentAsInt();
									break;
								case "ConfigGuardPort":
									reader.MoveToAttribute(XmlValue);
									config._configGuardPort = reader.ReadContentAsInt();
									break;
								case "NeedGuardAuthorization":
									reader.MoveToAttribute(XmlValue);
									config._needGuardAuthorization = reader.ReadContentAsBoolean();
									break;
								case "GameSettingDir":
									reader.MoveToAttribute(XmlValue);
                                    config._gameSettingDir = reader.ReadContentAsString();

                                    if (!config._gameSettingDir.EndsWith(@"\")) config._gameSettingDir += @"\";

                                    //若该文件夹不存在,则创建它
                                    if (Directory.Exists(config._gameSettingDir) == false)
                                    {
                                        Directory.CreateDirectory(config._gameSettingDir);
                                    }
									
									break;
								case "GuardAuthorizationTimeout":
									reader.MoveToAttribute(XmlValue);
									config._guardAuthorizationTimeout = reader.ReadContentAsLong();
									break;
                                case "EnablePaysys":
                                    reader.MoveToAttribute(XmlValue);
                                    config._enablePaysys = reader.ReadContentAsBoolean();
                                    break;
                                case "DBDefaultIP":
                                    reader.MoveToAttribute(XmlValue);
                                    config.dbDefaultIP = reader.ReadContentAsString();
                                    break;
                                case "DefaultGameDbName":
                                    reader.MoveToAttribute(XmlValue);
                                    config.defaultGameDbName = reader.ReadContentAsString();
                                    break;
								case "PaySysDbConnectionString":
									{
										reader.MoveToAttribute(XmlValue);
										string readConnectionString = reader.ReadContentAsString();
                                        if (config._enablePaysys)
                                        {
                                            if (isEncrypted)
                                            {
                                                try
                                                {
                                                    config._paySysDbConnectionString = CryptographyManager.TheInstance.PredefinedDecrypt(readConnectionString, Encoding.Default);
                                                }
                                                catch (Exception ex)
                                                {
                                                    throw new Exception("Decrypt SystemConfig Entry \"PaySysDbConnectionString\" Failed.", ex);
                                                }
                                            }
                                            else
                                            {
                                                config._paySysDbConnectionString = readConnectionString;
                                            }
                                        }										
									}
									break;
								case "PreloadGameData":
									reader.MoveToAttribute(XmlValue);
									config._preloadGameData = reader.ReadContentAsBoolean();
									break;
                                case "ServerListFileDir":
                                    reader.MoveToAttribute(XmlValue);
                                    config._serverListFileDir = reader.ReadContentAsString();
                                    
                                    if (!config._serverListFileDir.EndsWith(@"\")) config._serverListFileDir += @"\";

                                    //若该文件夹不存在,则创建它
                                    if (Directory.Exists(config._serverListFileDir) == false)
                                    {
                                        Directory.CreateDirectory(config._serverListFileDir);
                                    }

                                    break;
                                case "ServerListFileName":
                                    reader.MoveToAttribute(XmlValue);
                                    config._serverListFileName = reader.ReadContentAsString();
                                    break;
                                case "PakFileName":
                                    reader.MoveToAttribute(XmlValue);
                                    config._pakFileName = reader.ReadContentAsString();
                                    break;
                                case "ServerListCRCFileName":
                                    reader.MoveToAttribute(XmlValue);
                                    config._serverListCRCFileName = reader.ReadContentAsString();
                                    break;
                                case "ServerListServerGroupMaxPlayer":
                                    reader.MoveToAttribute(XmlValue);
                                    config._serverListServerGroupMaxPlayer = reader.ReadContentAsInt();
                                    break;
                                case "SMSUrl":
                                    reader.MoveToAttribute(XmlValue);
                                    config._smsUrl = reader.ReadContentAsString();
                                    break;
                                case "SMSCommand":
                                    reader.MoveToAttribute(XmlValue);
                                    config._smsCommand = reader.ReadContentAsString();
                                    break;
                                case "WebSiteVersion":
                                    reader.MoveToAttribute(XmlValue);
                                    config.websiteVersion = reader.ReadContentAsString();
                                    break;
                                case "GroupPlayerCountDir":
                                    reader.MoveToAttribute(XmlValue);
                                    config._groupPlayerCountDir = reader.ReadContentAsString();
                                    if (!config._groupPlayerCountDir.EndsWith(@"\")) config._groupPlayerCountDir += @"\";

                                    //若该文件夹不存在,则创建它
                                    if (Directory.Exists(config._groupPlayerCountDir) == false)
                                    {
                                        Directory.CreateDirectory(config._groupPlayerCountDir);
                                    }
                                    break;
                                case "GroupPlayerCountFileName":
                                    reader.MoveToAttribute(XmlValue);
                                    config._groupPlayerCountFileName = reader.ReadContentAsString();
                                    break;
                                case "GroupPlayerCountKickInterval":
                                    reader.MoveToAttribute(XmlValue);
                                    config._groupPlayerCountKickInterval = reader.ReadContentAsInt();
                                    break;
								default:
									throw new Exception("Unknown attribute '" + attribute + "' found in xml stream.");
							}
						}
					}
					return config;
				}
			}

			return null;
		}
Exemplo n.º 6
0
        /// <summary>Loads the image from the given file</summary>
        /// <param name="filename">The file to load from</param>
        public void LoadFromFile(String filename)
        {
            XmlTextReader reader = null;
            try
            {
                // Open the file
                reader = new XmlTextReader(filename);

                // Read to the root and determine the file version
                int version = 0;
                while(reader.Read())
                {
                    if(reader.NodeType == XmlNodeType.Element && reader.Name == "schets")
                    {
                        // Determine the version
                        while(reader.MoveToNextAttribute())
                        {
                            if(reader.Name == "version")
                            {
                                try
                                {
                                    version = reader.ReadContentAsInt();
                                    break;
                                }
                                catch(Exception)
                                { throw new Exception("De versie lijkt in een verkeerd formaat te staan."); }
                            }
                        }

                        break;
                    }
                }

                if(version != 1)
                    throw new Exception("Foutieve bestandsversie: " + version + ".");

                // Read the layers
                try
                {
                    layers.Clear();
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "schets")
                            break;
                        else if (reader.NodeType == XmlNodeType.Element && reader.Name.StartsWith("layer"))
                        {
                            // Determine the layer type
                            Layer layer = null;
                            switch (reader.Name)
                            {
                                case LayerText.XML_NAME:
                                    layer = new LayerText(new Point(0, 0), Color.Black, "");
                                    break;

                                case LayerLine.XML_NAME:
                                    layer = new LayerLine(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerRectFilled.XML_NAME:
                                    layer = new LayerRectFilled(new Point(0, 0), new Point(1, 1), Color.Black);
                                    break;

                                case LayerRectOpen.XML_NAME:
                                    layer = new LayerRectOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerEllipseFilled.XML_NAME:
                                    layer = new LayerEllipseFilled(new Point(0, 0), new Point(1, 1), Color.Black);
                                    break;

                                case LayerEllipseOpen.XML_NAME:
                                    layer = new LayerEllipseOpen(new Point(0, 0), new Point(1, 1), 3.0f, Color.Black);
                                    break;

                                case LayerPath.XML_NAME:
                                    layer = new LayerPath(new Point(0, 0), 3.0f, Color.Black);
                                    break;

                                case LayerBitmap.XML_NAME:
                                    layer = new LayerBitmap(new Point(0, 0), new Bitmap(1,1));
                                    break;
                            }

                            // Read the actual layer contents
                            if (layer != null)
                            {
                                layer.ReadFromXml(reader);
                                layers.Add(layer);
                            }
                        }
                        else throw new Exception(reader.Name);
                    }
                }
                catch(XmlException e)
                { throw new Exception(e.Message); }
                catch(Exception e)
                { throw new Exception("Er is een onverwachte fout opgetreden! Foutmelding: " + e.Message); }
            }
            catch(UnauthorizedAccessException)
            { throw new Exception("U heeft niet de juiste rechten om het bestand te openen voor lezen."); }
            catch(System.IO.DirectoryNotFoundException)
            { throw new Exception("Kon het bestand niet vinden."); }
            finally
            {
                // Close the file
                reader.Close();
            }
        }
Exemplo n.º 7
0
        private static void FromFile(string fileName)
        {
            XmlTextReader reader = new XmlTextReader(fileName);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            try
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "Paths")
                    {
                        while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Paths"))
                        {
                            reader.Read();
                            if (reader.Name == "MeshPath")
                                meshPath = DefaultValues.MediaPath + reader.ReadString();
                            else if (reader.Name == "TexturePath")
                                texturePath = DefaultValues.MediaPath + reader.ReadString();
                            else if (reader.Name == "EffectPath")
                                effectPath = DefaultValues.MediaPath + reader.ReadString();
                            else if (reader.Name == "MapPath")
                                mapPath = DefaultValues.MediaPath + reader.ReadString();
                            else if (reader.Name == "ObjectPath")
                                objectPath = DefaultValues.MediaPath + reader.ReadString();
                        }
                    }
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "Graphics")
                    {
                        while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Graphics"))
                        {
                            reader.Read();
                            if (reader.Name == "Resolution")
                            {
                                reader.MoveToAttribute("width");
                                WindowWidth = reader.ReadContentAsInt();

                                reader.MoveToAttribute("height");
                                WindowHeight = reader.ReadContentAsInt();
                            }

                        }
                    }
                }
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }
        //Read Program
        public ProgramData ReadXMLProgram()
        {
            ProgramData CurrentProgram = new ProgramData();
            string RootDiretory = AppDomain.CurrentDomain.BaseDirectory;
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            XmlTextReader reader = null;

            switch (this.ProgramSelector)
            {
                case Enumerators.ProgramSelect.FTPTest:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\FTPTestConcentric.xml");
                    break;
                case Enumerators.ProgramSelect.VO2MaxTest:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxTest.xml");
                    break;
                default:
                    break;
            }

            while (reader.Read())
            {
                if (reader.ReadToFollowing("StageIndex"))
                {
                    ProgramStage newFTPStage = new ProgramStage();
                    reader.Read();
                    newFTPStage.StageIndex = reader.ReadContentAsInt();
                    reader.ReadToFollowing("StageNumber");
                    reader.Read();
                    newFTPStage.StageNumber = reader.ReadContentAsInt();
                    reader.ReadToFollowing("StageName");
                    reader.Read();
                    newFTPStage.StageName = reader.ReadContentAsString();
                    reader.ReadToFollowing("StageDuration");
                    reader.Read();
                    newFTPStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
                    reader.ReadToFollowing("Sets");
                    reader.Read();

                    while (reader.Read())
                    {
                        if (reader.Name == "Set")
                        {
                            ProgramSet newFTPSet = new ProgramSet();
                            reader.ReadToFollowing("SetIndex");
                            reader.Read();
                            newFTPSet.SetIndex = reader.ReadContentAsInt();
                            reader.ReadToFollowing("Number");
                            reader.Read();
                            newFTPSet.SetNumber = reader.ReadContentAsInt();
                            reader.ReadToFollowing("Duration");
                            reader.Read();
                            newFTPSet.TimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
                            reader.ReadToFollowing("Direction");
                            reader.Read();
                            newFTPSet.Direction = reader.ReadContentAsString();
                            reader.ReadToFollowing("DirectionFlag");
                            reader.Read();
                            int DirectionVariable = reader.ReadContentAsInt();
                            if (DirectionVariable == 1)
                                newFTPSet.SelectedDirection = Enumerators.Direction.Forward;
                            else if (DirectionVariable == -1)
                                newFTPSet.SelectedDirection = Enumerators.Direction.Backward;
                            reader.ReadToFollowing("Contraction");
                            reader.Read();
                            newFTPSet.Contraction = reader.ReadContentAsString();
                            reader.ReadToFollowing("Legs");
                            reader.Read();
                            newFTPSet.Legs = reader.ReadContentAsString();
                            reader.ReadToFollowing("Position");
                            reader.Read();
                            newFTPSet.Position = reader.ReadContentAsString();
                            reader.ReadToFollowing("RestDuration");
                            reader.Read();
                            newFTPSet.RestTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
                            reader.ReadToFollowing("Instructions");
                            reader.Read();
                            newFTPSet.Instructions = reader.ReadContentAsString();
                            newFTPStage.FTPSetConcentricCollection.Add(newFTPSet);

                            reader.Read();  //Read White Space
                            reader.Read();  //Read Set
                            reader.Read();  //Read White Space

                        }
                        else
                        {
                            break;
                        }
                    }
                    CurrentProgram.FTPStageCollection.Add(newFTPStage);
                }
            }

            CurrentProgram.CurrentFTPStage = CurrentProgram.FTPStageCollection[0];
            CurrentProgram.CurrentFTPStage.CurrentFTPSet = CurrentProgram.CurrentFTPStage.FTPSetConcentricCollection[0];
            return CurrentProgram;
        }
        //Read Program - This method must be refactored into DataSample
        private void ReadXMLProgram()
        {
            CurrentVO2MaxProgram = new VO2MaxProgram();
            string RootDiretory = AppDomain.CurrentDomain.BaseDirectory;
            XmlTextReader reader = null;

            switch (DataSample.ProgramSelector)
            {
                case Enumerators.ProgramSelect.VO2MaxProgram1:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram1.xml");
                    lblTitle.Text = "Program: VO2 Max Program 1";
                    lblDescription.Text = "Program Time: 30 min";
                    CurrentPowerIndex = GlobalVariables.VO2MaxProgram1PB;
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram2:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram2.xml");
                    lblTitle.Text = "Program: VO2 Max Program 2";
                    lblDescription.Text = "Program Time: 30 min";
                    CurrentPowerIndex = GlobalVariables.VO2MaxProgram2PB;
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram3:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram3.xml");
                    lblTitle.Text = "Program: VO2 Max Program 3";
                    lblDescription.Text = "Program Time: 26 min";
                    CurrentPowerIndex = GlobalVariables.VO2MaxProgram3PB;
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram4:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxProgram4.xml");
                    lblTitle.Text = "Program: VO2 Max Program 4";
                    lblDescription.Text = "Program Time: 20 min";
                    CurrentPowerIndex = GlobalVariables.VO2MaxProgram4PB;
                    break;
                case Enumerators.ProgramSelect.CPM:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\CPMProgram.xml");
                    lblTitle.Text = "Program: Continuous Passive Motion (CPM)";
                    lblDescription.Text = "Program Time: 20 min";
                    CurrentPowerIndex = GlobalVariables.CPMProgramPB;
                    break;
                case Enumerators.ProgramSelect.Proprioception:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\ProprioceptionProgram.xml");
                    lblTitle.Text = "Program: Proprioception";
                    lblDescription.Text = "Program Time: 10 min";
                    CurrentPowerIndex = GlobalVariables.PropriocenptionProgramPB;
                    break;
                case Enumerators.ProgramSelect.RehabBilateral:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml");
                    lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)";
                    lblDescription.Text = "Program Time: 15 min";
                    CurrentPowerIndex = GlobalVariables.RehabProgramPB;
                    break;
                case Enumerators.ProgramSelect.RehabLeftLeg:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabLeftLeg.xml");
                    lblTitle.Text = "Program: Rehabilitation - Left Leg (11 Stages)";
                    lblDescription.Text = "Program Time: 15 min";
                    CurrentPowerIndex = GlobalVariables.RehabProgramLeftPB;
                    break;
                case Enumerators.ProgramSelect.RehabRightLeg:
                    reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabRightLeg.xml");
                    lblTitle.Text = "Program: Rehabilitation - Right Leg (11 Stages)";
                    lblDescription.Text = "Program Time: 15 min";
                    CurrentPowerIndex = GlobalVariables.RehabProgramRightPB;
                    break;
                //case Enumerators.ProgramSelect.CustomProgram:
                //    reader = new XmlTextReader(RootDiretory + "\\Programs\\ProgramRehabBilateral.xml");
                //    lblTitle.Text = "Program: Rehabilitation - Bilateral (9 Stages)";
                //    lblDescription.Text = "Program Time: 15 min";
                //    CurrentPowerIndex = GlobalVariables.RehabProgramPB;
                //    break;
                default:
                    break;
            }

            while (reader.Read())
            {
                if (reader.ReadToFollowing("StageIndex"))
                {
                    VO2MaxStage newVO2MaxStage = new VO2MaxStage();
                    reader.Read();
                    newVO2MaxStage.StageIndex = reader.ReadContentAsInt();
                    reader.ReadToFollowing("StageNumber");
                    reader.Read();
                    newVO2MaxStage.StageNumber = reader.ReadContentAsInt();
                    reader.ReadToFollowing("StageName");
                    reader.Read();
                    newVO2MaxStage.StageName = reader.ReadContentAsString();
                    reader.ReadToFollowing("StageDuration");
                    reader.Read();
                    newVO2MaxStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
                    reader.ReadToFollowing("Sets");
                    reader.Read();

                    while (reader.Read())
                    {
                        if (reader.Name == "Set")
                        {
                            VO2MaxSet newVO2MaxSet = new VO2MaxSet();
                            reader.ReadToFollowing("SetIndex");
                            reader.Read();
                            newVO2MaxSet.SetIndex = reader.ReadContentAsInt();
                            reader.ReadToFollowing("Number");
                            reader.Read();
                            newVO2MaxSet.SetNumber = reader.ReadContentAsInt();
                            reader.ReadToFollowing("Duration");
                            reader.Read();
                            double SetTime = reader.ReadContentAsDouble();
                            if (SetTime < 1)
                            {
                                SetTime = SetTime * 60;
                                newVO2MaxSet.TimeRemaining = new TimeSpan(0, 0, Convert.ToInt32(SetTime));
                            }
                            else
                            {
                                newVO2MaxSet.TimeRemaining = new TimeSpan(0, Convert.ToInt32(SetTime), 0);
                            }
                            reader.ReadToFollowing("Direction");
                            reader.Read();
                            newVO2MaxSet.Direction = reader.ReadContentAsString();
                            reader.ReadToFollowing("DirectionFlag");
                            reader.Read();
                            int DirectionVariable = reader.ReadContentAsInt();
                            if (DirectionVariable == 1)
                                newVO2MaxSet.SelectedDirection = Enumerators.Direction.Forward;
                            else if (DirectionVariable == -1)
                                newVO2MaxSet.SelectedDirection = Enumerators.Direction.Backward;
                            reader.ReadToFollowing("Contraction");
                            reader.Read();
                            newVO2MaxSet.Contraction = reader.ReadContentAsString();
                            reader.ReadToFollowing("Legs");
                            reader.Read();
                            newVO2MaxSet.Legs = reader.ReadContentAsString();
                            reader.ReadToFollowing("Position");
                            reader.Read();
                            newVO2MaxSet.Position = reader.ReadContentAsString();
                            reader.ReadToFollowing("RestDuration");
                            reader.Read();
                            newVO2MaxSet.RestTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0);
                            reader.ReadToFollowing("Instructions");
                            reader.Read();
                            newVO2MaxSet.Instructions = reader.ReadContentAsString();
                            newVO2MaxStage.VO2MaxSetCollection.Add(newVO2MaxSet);

                            reader.Read();  //Read White Space
                            reader.Read();  //Read Set
                            reader.Read();  //Read White Space

                        }
                        else
                        {
                            break;
                        }
                    }
                    CurrentVO2MaxProgram.VO2MaxStageCollection.Add(newVO2MaxStage);
                }
            }

            CurrentVO2MaxProgram.ProgramTime = new TimeSpan(0, 0, 0);
            foreach (VO2MaxStage stage in CurrentVO2MaxProgram.VO2MaxStageCollection)
            {
                CurrentVO2MaxProgram.ProgramTime = CurrentVO2MaxProgram.ProgramTime + stage.StageTimeRemaining;
            }
        }