예제 #1
0
        static DbHelper()
        {
            ProviderTypesCache   = new NameCache <DbProviderFactory>();
            SQLBuilderTypesCache = new NameCache <SqlBuilder>();

            RegisterSQLBuilder(new MsSqlBuilder());
        }
예제 #2
0
 protected Enumeration(string name, int value)
 {
     Name  = name;
     Value = value;
     ValueCache.Add(value, this);
     NameCache.Add(name, this);
 }
예제 #3
0
 // Initialize the document.
 private void Initialize()
 {
     baseURI            = String.Empty;
     preserveWhitespace = false;
     placeholder        = new XmlDocumentFragment(this);
     nameCache          = new NameCache(implementation.nameTable);
 }
예제 #4
0
파일: XObjectRW.cs 프로젝트: cardinals/Yus
        internal XObjectRW(XTypeInfo typeInfo, XBindingFlags flags)
        {
            this.flags = flags;

            fieldsCache = typeInfo.rwFieldsCache;
            fields      = typeInfo.rwFields;
            type        = typeInfo.Type;
        }
예제 #5
0
 public static bool TryParse(string name, out T value)
 {
     if (NameCache.TryGetValue(name, out var containedValue))
     {
         value = (T)containedValue;
         return(true);
     }
     value = default(T);
     return(false);
 }
예제 #6
0
        /// <summary>
        /// Converts a supplied enum value of type <typeparamref name="T"/> to its string representation, as defined by <see cref="EnumDisplayNameAttribute"/>.
        /// </summary>
        /// <typeparam name="T">Type of the enum value.</typeparam>
        /// <param name="enum">Value to convert.</param>
        /// <returns>String representation or default string conversion, if a representation is not defined.</returns>
        public string Convert <T>(T @enum) where T : Enum
        {
            var t = typeof(T);

            if (this._typeNameCaches.TryGetValue(t, out var nc))
            {
                return((nc as NameCache <T>).Convert(@enum));
            }

            var nct = NameCache.CreateForType <T>();

            this._typeNameCaches.TryAdd(t, nct);
            return(nct.Convert(@enum));
        }
        public override string GetName([NotNull] T item)
        {
            if (NameCache.ContainsKey(item))
            {
                return(base.GetName(item));
            }

            var input  = base.GetName(item);
            var name   = input;
            var suffix = 1;

            while (_usedNames.Contains(name))
            {
                name = input + suffix++;
            }

            _usedNames.Add(name);
            NameCache[item] = name;

            return(name);
        }
예제 #8
0
 public static bool IsDefined(string name)
 {
     return(NameCache.ContainsKey(name));
 }
예제 #9
0
파일: XTypeInfo.cs 프로젝트: cardinals/Yus
        private XTypeInfo(Type type, XBindingFlags flags)
        {
            this.type  = type;
            this.flags = flags;

            IEqualityComparer <string> rwKeyComparer;

            if ((flags & XBindingFlags.RWIgnoreCase) != 0)
            {
                rwKeyComparer = new IgnoreCaseEqualityComparer();
            }
            else
            {
                rwKeyComparer = EqualityComparer <string> .Default;
            }

            var fields     = new List <XFieldInfo>();
            var properties = new List <XPropertyInfo>();
            var indexers   = new List <XIndexerInfo>();
            var methods    = new List <XMethodInfo>();
            var rwFields   = new List <IXFieldRW>();

            GetItems(type, flags, fields, properties, indexers, methods);

            foreach (var item in fields)
            {
                var rwField = item as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.FieldInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFields.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFields.Add(rwField);
                }
            }

            foreach (var item in properties)
            {
                var rwField = item as IXFieldRW;

                if (rwField == null)
                {
                    continue;
                }

                var attributes = item.PropertyInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                if (attributes != null && attributes.Length != 0)
                {
                    foreach (RWFieldAttribute attribute in attributes)
                    {
                        var attributedFieldRW = new XAttributedFieldRW(rwField, attribute);

                        if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                        {
                            rwFields.Add(attributedFieldRW);
                        }
                    }
                }
                else
                {
                    rwFields.Add(rwField);
                }
            }

            rwFields.Sort((x, y) => x.Order.CompareTo(y.Order));

            this.fields     = fields.ToArray();
            this.properties = properties.ToArray();
            this.indexers   = indexers.ToArray();
            this.methods    = methods.ToArray();
            this.rwFields   = rwFields.ToArray();

            fieldsCache     = new NameCache <XFieldInfo>();
            propertiesCache = new NameCache <XPropertyInfo>();
            indexersCache   = new HashCache <RuntimeParamsSign, XIndexerInfo>();
            methodsCache    = new HashCache <RuntimeMethodSign, XMethodInfo>();
            rwFieldsCache   = new NameCache <IXFieldRW>();

            foreach (var item in fields)
            {
                fieldsCache[item.name] = item;
            }
            foreach (var item in properties)
            {
                propertiesCache[item.name] = item;
            }
            foreach (var item in indexers)
            {
                indexersCache[new RuntimeParamsSign(ParametersToTypes(item.PropertyInfo.GetIndexParameters()))] = item;
            }
            foreach (var item in methods)
            {
                methodsCache[new RuntimeMethodSign(item.MethodInfo.Name, ParametersToTypes(item.MethodInfo.GetParameters()))] = item;
            }
            foreach (var item in rwFields)
            {
                rwFieldsCache[item.Name] = item;
            }
        }
예제 #10
0
 public static NameCache <T> CreateForType <T>() where T : Enum
 => NameCache <T> .Create();
예제 #11
0
        internal XTypeInfo(Type type, XBindingFlags flags)
        {
            RWObjectAttribute[] rwAttributes = null;

            if ((flags & RW) != 0)
            {
                rwAttributes = type.GetDefinedAttributes <RWObjectAttribute>(true);
            }

            if (rwAttributes != null && rwAttributes.Length != 0)
            {
                foreach (var item in rwAttributes)
                {
                    Switch(ref flags, XBindingFlags.RWIgnoreCase, item.IgnoreCace);

                    Switch(ref flags, XBindingFlags.RWNotFoundException, item.NotFoundException);

                    Switch(ref flags, XBindingFlags.RWCannotGetException, item.CannotGetException);

                    Switch(ref flags, XBindingFlags.RWCannotSetException, item.CannotSetException);

                    Switch(ref flags, XBindingFlags.Property, item.IncludeProperties);

                    Switch(ref flags, XBindingFlags.Field, item.IncludeFields);

                    Switch(ref flags, XBindingFlags.RWSkipDefaultValue, item.SkipDefaultValue);

                    Switch(ref flags, XBindingFlags.RWMembersOptIn, item.MembersOptIn);
                }
            }

            this.type  = type;
            this.flags = flags;

            var fields     = new List <XFieldInfo>();
            var properties = new List <XPropertyInfo>();
            var indexers   = new List <XIndexerInfo>();
            var methods    = new List <XMethodInfo>();
            var rwFields   = new List <IXFieldRW>();

            GetItems(type, flags, fields, properties, indexers, methods);

            foreach (var item in fields)
            {
                if (item is IXFieldRW rwField)
                {
                    var attributes = item.FieldInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                    if (attributes != null && attributes.Length != 0)
                    {
                        foreach (RWFieldAttribute attribute in attributes)
                        {
                            XAttributedFieldRW attributedFieldRW = (rwField, attribute);

                            if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                            {
                                rwFields.Add(attributedFieldRW);
                            }
                        }
                    }
                    else
                    {
                        rwFields.Add(rwField);
                    }
                }
            }

            foreach (var item in properties)
            {
                if (item is IXFieldRW rwField)
                {
                    var attributes = item.PropertyInfo.GetCustomAttributes(typeof(RWFieldAttribute), true);

                    if (attributes != null && attributes.Length != 0)
                    {
                        // Attributed property allow access non-Public accessor.
                        item.Initialize(item.propertyInfo, item.flags | XBindingFlags.NonPublic);

                        foreach (RWFieldAttribute attribute in attributes)
                        {
                            XAttributedFieldRW attributedFieldRW = (rwField, attribute);

                            if (attributedFieldRW.CanRead || attributedFieldRW.CanWrite)
                            {
                                rwFields.Add(attributedFieldRW);
                            }
                        }
                    }
                    else
                    {
                        rwFields.Add(rwField);
                    }
                }
            }

            rwFields.Sort((x, y) => x.Order.CompareTo(y.Order));

            if (rwAttributes != null && rwAttributes.Length != 0)
            {
                var temp = rwFields.Cast <IObjectField>().ToList();

                foreach (var item in rwAttributes)
                {
                    item.OnCreate(type, ref temp);
                }

                rwFields = temp.Cast <IXFieldRW>().ToList();
            }

            this.fields     = fields.ToArray();
            this.properties = properties.ToArray();
            this.indexers   = indexers.ToArray();
            this.methods    = methods.ToArray();
            this.rwFields   = rwFields.ToArray();

            fieldsCache     = new NameCache <XFieldInfo>();
            propertiesCache = new NameCache <XPropertyInfo>();
            indexersCache   = new HashCache <RuntimeParamsSign, XIndexerInfo>();
            methodsCache    = new HashCache <RuntimeMethodSign, XMethodInfo>();
            rwFieldsCache   = new RWNameCache <IXFieldRW>(flags);

            foreach (var item in fields)
            {
                fieldsCache[item.name] = item;
            }
            foreach (var item in properties)
            {
                propertiesCache[item.name] = item;
            }
            foreach (var item in indexers)
            {
                indexersCache[ParametersToTypes(item.PropertyInfo.GetIndexParameters())] = item;
            }
            foreach (var item in methods)
            {
                methodsCache[(item.MethodInfo.Name, ParametersToTypes(item.MethodInfo.GetParameters()))] = item;
예제 #12
0
 public NameRandomGenerator(NameType type)
 {
     _list = NameCache.GetList(type);
 }
예제 #13
0
 public FixupCaches(string connectionString, int timeoutSecs, TableMappings.TableMappings tableMappings)
 {
     _nameCache      = new NameCache(connectionString, timeoutSecs, tableMappings);
     _eventTimeCache = new EventTimeCache(connectionString, timeoutSecs);
     _weekDatesCache = new WeekDatesCache(connectionString, timeoutSecs);
 }
예제 #14
0
        public static IEnumerable <NameCache> ResolveIdToName(params int[] id)
        {
            var Context = new AppDbContext();
            var lookUp  = new List <int>();

            // For each Id check if it is cached in database and yield return the results.
            // Query all Ids that were not found in the cache.
            foreach (var i in id)
            {
                if (Context.NameCache.Any(t => t.Id == i))
                {
                    yield return(Context.NameCache.FirstOrDefault(t => t.Id == i));
                }
                else
                {
                    lookUp.Add(i);
                }
            }

            // Now look up the missing Ids
            List <UniverseNameResponse> responses;

            //try {
            responses = Esi.UniverseApi.GetUniverseNames(lookUp.ToArray());
            //}
            // There's a chance something will randomly go wrong or the API will not find anything (and will scream).
            //catch (Exception e) {
            //    responses = new List<UniverseNameResponse>();
            //    throw new Exception($"Error while querying API for resolving IDs: {JsonConvert.SerializeObject(id)}",
            //        e);
            //}

            foreach (var r in responses)
            {
                var entry = new NameCache {
                    Id       = r.ID,
                    Name     = r.Name,
                    Category = r.Category
                };
                Context.NameCache.AddOrUpdate(entry);
                yield return(entry);
            }

            // Context.SaveChanges();

            //// First check the cache.
            //foreach (var i in id) {
            //    if (NameCache.Any(t => t.Id == i))
            //        yield return NameCache.FirstOrDefault(t => t.Id == i);
            //    else {
            //        lookUp.Add(i);
            //    }
            //}

            //// Now look up any and all IDs that we didn't have cached.
            //List<UniverseNameResponse> response;
            //try {
            //    response = Esi.UniverseApi.GetUniverseNames(lookUp.ToArray());
            //}
            //catch (Exception e) {
            //    response = new List<UniverseNameResponse>();
            //}

            //foreach (var r in response) {
            //    var entry = new NameCache() {
            //        Id = r.ID,
            //        Name = r.Name,
            //        Category = r.Category
            //    };
            //    NameCache.Add(entry);
            //    yield return entry;
            //}
        }