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);
        }
Esempio n. 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)}.");
     }
 }
Esempio n. 3
0
        public void ValidTests(ValidTypes type, ValidUsers user, ValidDepts dept, ValidDates start, ValidDates end, ValidOptions option)
        {
            var request = CreateGetRequest(TypeMapper[type], null, null);

            GenerateParamValues(TypeToResource[type], user, dept, start, end, option, request);
            TestPerform(request);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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());
        }
Esempio n. 6
0
        public static bool AvaiValidCases(ValidTypes type)
        {
            var avaiTests = new List <ValidTypes>()
            {
                ValidTypes.PhaseClient,
                ValidTypes.PhaseRecruiter,
                ValidTypes.PhaseJob,
                ValidTypes.PhasePerson
            };

            return(avaiTests.Contains(type) ? true : false);
        }
Esempio n. 7
0
 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;
     }
 }
Esempio n. 8
0
        protected Type GetCastType(XElement setting, XAttribute elementType = null)
        {
            string type             = null;
            string itemType         = null;
            string elementTypeValue = null;

            var typeAttr     = setting.Attribute(XName.Get(XmlTags.SETTING_TYPE));
            var itemTypeAttr = setting.Attribute(XName.Get(XmlTags.SETTING_ITEMTYPE));

            if (elementType != null)
            {
                elementTypeValue = elementType.Value;
            }
            else if (typeAttr != null)
            {
                elementTypeValue = typeAttr.Value;
            }
            if (itemTypeAttr != null)
            {
                itemType = itemTypeAttr.Value;
            }

            ValidTypes typeEnum = ParseType(elementTypeValue);

            switch (typeEnum)
            {
            case ValidTypes.Int:
                return(typeof(System.Int32));

            case ValidTypes.Decimal:
                return(typeof(System.Decimal));

            case ValidTypes.Bit:
            case ValidTypes.Bool:
                return(typeof(System.Boolean));

            case ValidTypes.List:
                if (!setting.HasElements)
                {
                    throw new Exception(String.Format("Type List found with empty elements, unable to get child type."));
                }
                var qualifiedItemType = this.GetCastType(setting.Elements().First(), itemTypeAttr);
                type = String.Format(LIST_TYPE_MASK, qualifiedItemType.FullName, qualifiedItemType.Assembly.FullName);
                return(Type.GetType(type));

            case ValidTypes.Dictionary:
                if (!setting.HasElements)
                {
                    throw new Exception(String.Format("Type Dictionary found with empty elements, unable to get child type."));
                }
                var itemCastedType = this.GetCastType(setting.Elements().First(), itemTypeAttr);
                type = String.Format(DICTIONARY_TYPE_MASK, itemCastedType.FullName, itemCastedType.Assembly.FullName);
                return(Type.GetType(type));

            case ValidTypes.String:
                return(typeof(System.String));

            case ValidTypes.Custom:
            default:
                var t = Type.GetType(elementTypeValue);
                if (t == null)
                {
                    throw new LazyDeserializationNeededException(elementTypeValue);         // Preparamos el XML para que se deserialze en destino, dado que no tenemos tipo en origen.
                }
                return(t);
            }
        }
Esempio n. 9
0
        protected object CreateConfigElement(XElement setting, XAttribute elementType = null)
        {
            string     type         = null;
            XAttribute itemTypeAttr = setting.Attribute(XName.Get(XmlTags.SETTING_ITEMTYPE));

            if (setting.Attribute(XName.Get(XmlTags.SETTING_TYPE)) != null)
            {
                elementType = setting.Attribute(XName.Get(XmlTags.SETTING_TYPE));
            }
            type = elementType != null ? elementType.Value : String.Empty;

            Type       castType  = typeof(System.String);
            MethodInfo addMethod = null;

            ValidTypes typeEnum = ParseType(type);

            switch (typeEnum)
            {
            case ValidTypes.Int:
                return(int.Parse(setting.Attribute(XName.Get(XmlTags.SETTING_VALUE)).Value));

            case ValidTypes.Decimal:
                return(decimal.Parse(setting.Attribute(XName.Get(XmlTags.SETTING_VALUE)).Value, CultureInfo.InvariantCulture));

            case ValidTypes.Bit:
            case ValidTypes.Bool:
                return(bool.Parse(setting.Attribute(XName.Get(XmlTags.SETTING_VALUE)).Value));

            case ValidTypes.List:
                castType  = this.GetCastType(setting, elementType);
                addMethod = castType.GetMethod(ADD_LIST_METHOD);
                var list = Activator.CreateInstance(castType);
                foreach (var element in setting.Elements())
                {
                    addMethod.Invoke(list, new object[] { this.CreateConfigElement(element, itemTypeAttr) });
                }
                return(list);

            case ValidTypes.Dictionary:
                castType  = this.GetCastType(setting, elementType);
                addMethod = castType.GetMethod(ADD_LIST_METHOD);
                var dic = Activator.CreateInstance(castType);
                foreach (var element in setting.Elements(XName.Get(XmlTags.INNER_KEYVALUE)))
                {
                    var key = element.Attribute(XName.Get(XmlTags.SETTING_KEY));
                    addMethod.Invoke(dic, new object[] { key.Value, this.CreateConfigElement(element, itemTypeAttr) });
                }
                return(dic);

            case ValidTypes.String:
                return(setting.Attribute(XName.Get(XmlTags.SETTING_VALUE)) != null?setting.Attribute(XName.Get(XmlTags.SETTING_VALUE)).Value : setting.Value);

            case ValidTypes.Custom:
            default:
                var serializer = new System.Xml.Serialization.XmlSerializer(this.GetCastType(setting, elementType));
                var name       = setting.Name.ToString().ToLowerInvariant();
                if (name == XmlTags.INNER_ITEM || name == XmlTags.SETTING_TAG)
                {
                    return(serializer.Deserialize(new StringReader(setting.FirstNode.ToString())));
                }
                else
                {
                    return(serializer.Deserialize(new StringReader(setting.ToString())));
                }
            }
        }
Esempio n. 10
0
 public static IEnumerable <object[]> ValidTypeData()
 {
     return(ValidTypes.Select(i => new object[] { i }));
 }