public static string GetSystemName <T>(this T enumerationValue)
            where T : struct
        {
            var type = enumerationValue.GetType();

            if (!type.IsEnum)
            {
                throw new ArgumentException(@"EnumerationValue must be of Enum type", nameof(enumerationValue));
            }

            var name = enumerationValue.ToString();

            // see if this is one of the valid types
            if (ValidTypes.Contains(type))
            {
                //Tries to find a DescriptionAttribute for a potential friendly name
                //for the enum
                var memberInfo = type.GetMember(enumerationValue.ToString());
                if (memberInfo.Length > 0)
                {
                    var attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (attrs.Length > 0)
                    {
                        //Pull out the description value
                        name += " " + ((DescriptionAttribute)attrs[0]).Description;
                    }
                }
            }

            return(name);
        }
示例#2
0
 private void checkType(Type type)
 {
     if (!ValidTypes.Contains(type))
     {
         throw new InvalidOperationException($"The requested operation specified a type of {type}, which is invalid for this {nameof(DatabaseBackedStore)}.");
     }
 }
示例#3
0
        private void Load(string file)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Entries = new SortedDictionary <int, SteamApp>();

            var index      = 0;
            var cacheLines = File.ReadAllLines(file);

            foreach (var line in cacheLines)
            {
                try
                {
                    var steamApp = new SteamApp(line);
                    if (ValidTypes == null || ValidTypes.Contains(steamApp.Type.ToLower()))
                    {
                        Entries.Add(Int32.Parse(steamApp.Id), steamApp);
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLine($"{ CurrentClassName }.{ Utils.GetCurrentMethodName() }({ file }): index={ index }, line='{ line }', ex={ ex }");
                }
                index++;
            }

            stopwatch.Stop();
            var duration = stopwatch.ElapsedMilliseconds;

            Log.WriteLine($"{ CurrentClassName }.{ Utils.GetCurrentMethodName() }({ file }): [{ Entries.Count } entries] in { duration }ms");

            CurrentCacheFile = file;
        }
示例#4
0
        /// <summary>
        /// query https://steamdb.info/search/?q=... for new SteamAppId-s
        /// also adds result to cache
        /// </summary>
        /// <param name="gameTitle"></param>
        /// <returns></returns>
        private SteamApp[] QuerySteamDb(string gameTitle)
        {
            var result = new List <SteamApp>();

            var url      = $"https://steamdb.info/search/?q={ WebUtility.UrlEncode(gameTitle) }";
            var response = WebUtils.WebRequest(url);

            if (response == null)
            {
                return(result.ToArray());
            }

            var tableElementStart = response.IndexOf("<tbody hidden>");

            if (tableElementStart < 0)
            {
                return(result.ToArray());
            }

            var tableBodyElement = response.Substring(tableElementStart, response.IndexOf("</tbody>", tableElementStart) - tableElementStart + "</tbody>".Length);

            tableBodyElement = tableBodyElement.Replace("<tbody hidden>", "<tbody>");

            var decodedAndCleaned = WebUtility.HtmlDecode(tableBodyElement).Replace("&", string.Empty);

            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(decodedAndCleaned);

            foreach (XmlNode steamAppNode in xmlDocument.DocumentElement.ChildNodes)
            {
                var type = steamAppNode.ChildNodes[1].InnerText.ToLower();

                if (!ValidTypes.Contains(type))
                {
                    continue;
                }

                var steamAppId = steamAppNode.Attributes["data-appid"].Value;

                var title = steamAppNode.ChildNodes[2].InnerText;

                // remove muted part of title
                title = Strings.RemoveFromTo(title, "<i class=\"muted\">", "</i>").Trim();
                title = title.Trim('\n');

                result.Add(SteamApp.Create(steamAppId, type, title));
            }

            // add new steam apps to cache
            foreach (var newSteamApp in result)
            {
                AddOrUpdateSteamApp(newSteamApp);
            }

            return(result.ToArray());
        }
示例#5
0
文件: Str.cs 项目: FranklinDM/PJSE
 private void FileDescriptor_ChangedData(SimPe.Interfaces.Files.IPackedFileDescriptor pfd)
 {
     if (pfd == null)
     {
         return;
     }
     if (!ValidTypes.Contains(pfd.Type))
     {
         return;
     }
     if (this[pfd.Group, pfd.Instance, pfd.Type] != null)
     {
         this[pfd.Group, pfd.Instance, pfd.Type] = null;
     }
 }