Example #1
0
        public XMLGamesConfig(Stream Stream = null)
        {
            XElement Config;

            if (Stream == null)
            {
                Stream = new FileStream(ConfigFile, FileMode.Open);
            }
            using (Stream)
                Config = XElement.Load(Stream);
            Games = (from GameXML in Config.Descendants(AGameNode)
                     select new ConfigGameModel()
            {
                GUID = GameXML.Attribute(IDAttribute)?.Value,
                Name = GameXML.Attribute(NameAttribute)?.Value,
                Path = GameXML.Attribute(PathAttribute)?.Value,
                ImagePath = GameXML.Attribute(ImagePathAttribute)?.Value,
                PlayTime = ulongParseOrNull(GameXML.Attribute(PlayTimeAttribute)?.Value),
                CostToPlay = IntParseOrNull(GameXML.Attribute(CostToPlayAttribute)?.Value),
                StartOptions = GameXML.Attribute(StartOptionsAttribute)?.Value,
                IOptionalAddtionalExeStarts = (from ExeXML in GameXML.Descendants(AddtionalExeStartNode)
                                               select new ConfigOptionalAddtionalExeStartsModel()
                {
                    Path = ExeXML.Attribute(PathAttribute)?.Value,
                    Delay = IntParseOrNull(ExeXML.Attribute(DelayAttribute)?.Value)
                }).Cast <IOptionalAddtionalExeStartsModel>().ToList()
            }).Cast <IGameModel>().ToList();

            //a trick to quickly convert to json when making the json config class test subject. Not really relavat to the code however.
            //string Result = JsonConvert.SerializeObject(Games);

            if (Games.Any(x => x.GUID == null || x.Path == null || x.PlayTime == null || x.IOptionalAddtionalExeStarts.Any(j => j.Path == null || j.Delay == null)))
            {
                throw new Exception(NotSetError);
            }
        }