Пример #1
0
        private CacheTemplate GetCacheTemplateFromProductRepository()
        {
            var type  = typeof(IProductRepository);
            var model = new CacheTemplate(type);

            var getProduct      = type.GetMethod(nameof(IProductRepository.GetProduct));
            var getProductAsync = type.GetMethod(nameof(IProductRepository.GetProductAsync));

            var getProductConfig = new MethodCacheConfiguration()
            {
                Name = getProduct.Name,
                ExpirationSeconds = 60,
                KeyTemplate       = "product_{id}"
            };
            var getProductAsyncConfig = new MethodCacheConfiguration()
            {
                Name = getProduct.Name,
                ExpirationSeconds = 60,
                KeyTemplate       = "product_async_{id}"
            };

            model.AddMethod(new CacheMethodTemplate(getProduct, getProductConfig));
            model.AddMethod(new CacheMethodTemplate(getProductAsync, getProductAsyncConfig));

            return(model);
        }
Пример #2
0
        private CacheTemplate GetCacheTemplateFromGroupRepository()
        {
            var type  = typeof(IGroupRepository);
            var model = new CacheTemplate(type);

            var getGroup       = type.GetMethod(nameof(IGroupRepository.GetGroup));
            var getGroupConfig = new MethodCacheConfiguration()
            {
                Name = getGroup.Name,
                ExpirationSeconds = 60,
                KeyTemplate       = "group_{id}"
            };

            model.AddMethod(new CacheMethodTemplate(getGroup, getGroupConfig));
            return(model);
        }
        public static CacheTemplate GetCacheTemplateFromReflectionType(this Type type, InterfaceCacheConfiguration cacheConfiguration)
        {
            if (type == null)
            {
                throw new Exception("Service type is no defined.");
            }

            if (!type.IsInterface)
            {
                throw new Exception("Only service interfaces are allowed for cache code generation.");
            }

            var cacheTemplate = new CacheTemplate(type);

            foreach (var method in type.GetAllMethods())
            {
                var methodConfiguration = cacheConfiguration.Methods.FirstOrDefault(x => x.Name == method.Name);
                var cacheMethod         = new CacheMethodTemplate(method, methodConfiguration);
                cacheTemplate.AddMethod(cacheMethod);
            }
            ;
            foreach (var property in type.GetProperties())
            {
                cacheTemplate.AddProperty(property);
            }

            var methodNamesCacheTemplate      = cacheTemplate.Methods.Select(m => m.Name);
            var methodNamesCacheConfiguration = cacheConfiguration.Methods.Select(m => m.Name);
            var methodsNotMatched             = methodNamesCacheConfiguration?.Where(x => !methodNamesCacheTemplate?.Contains(x) ?? false);

            if (methodsNotMatched?.Any() ?? false)
            {
                var methodName = methodsNotMatched.FirstOrDefault();
                throw new Exception($"Method '{methodName}' not found in interface {type.Name}.");
            }

            return(cacheTemplate);
        }
Пример #4
0
 /// <summary>
 /// Add cache configuration from a predefined cache template.
 /// Individual elements of this configuration can be overridden by
 /// using the
 /// <see cref="ConfigureCache(CacheType, ICacheOptions)"/>,
 /// <see cref="ConfigureCaches(Dictionary{CacheType, ICacheOptions})"/>,
 /// <see cref="SetCacheBuilder(CacheType, ICacheBuilder)"/> and
 /// <see cref="SetCacheBuilders(Dictionary{CacheType, ICacheBuilder})"/>
 /// methods
 /// </summary>
 /// <param name="template">A <see cref="CacheTemplate"/>.
 /// Example: <code>CacheTemplate.SingleThread</code></param>
 /// <returns>The <see cref="DataSetBuilder"/></returns>
 public T ConfigureCachesFromTemplate(CacheTemplate template)
 {
     return(ConfigureCachesFromCacheSet(template));
 }
Пример #5
0
        static void Main(string[] args)
        {
            Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue);
            Log.Texte("", "          _____   _____ ", ConsoleColor.Cyan);
            Log.Texte("", "    /\\   |  __ \\ / ____|", ConsoleColor.Cyan);
            Log.Texte("", "   /  \\  | |__) | (___  ", ConsoleColor.Cyan);
            Log.Texte("", "  / /\\ \\ |  ___/ \\___ \\ ", ConsoleColor.Cyan);
            Log.Texte("", " / ____ \\| |     ____) |", ConsoleColor.Cyan);
            Log.Texte("", "/_/    \\_\\_|    |_____/ Rift", ConsoleColor.Cyan);
            Log.Texte("", "http://AllPrivateServer.com", ConsoleColor.DarkCyan);
            Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue);

            // Loading all configs files
            ConfigMgr.LoadConfigs();
            Config = ConfigMgr.GetConfig <ExtractorConfig>();

            // Loading log level from file
            if (!Log.InitLog(Config.LogLevel, "Cache"))
            {
                ConsoleMgr.WaitAndExit(2000);
            }

            WorldDB = DBManager.Start(Config.WorldDB.Total(), ConnectionType.DATABASE_MYSQL, "World");
            if (WorldDB == null)
            {
                ConsoleMgr.WaitAndExit(2000);
            }

            PacketProcessor.RegisterDefinitions();

            int Count = 0;

            foreach (string FileDir in Directory.EnumerateFiles(Config.CacheFolder))
            {
                Log.Success("Extractor", "Opening Cache : " + FileDir);

                FileStream Str = File.Open(FileDir, FileMode.Open);

                byte[] Buff = new byte[Str.Length];
                Str.Read(Buff, 0, Buff.Length);

                PacketInStream      Pack   = new PacketInStream(Buff, Buff.Length);
                ISerializablePacket Packet = PacketProcessor.ReadPacket(ref Pack);


                if (Packet != null && Packet is CacheUpdate)
                {
                    CacheUpdate Cache = Packet as CacheUpdate;

                    CacheTemplate Template = Cache.CacheDatas.Find(info => info.Opcode == (long)Opcodes.CacheTemplate) as CacheTemplate;
                    CacheData     Data     = Cache.CacheDatas.Find(info => info.Opcode == (long)Opcodes.CacheData) as CacheData;

                    if (Template != null)
                    {
                        Template.CacheID   = Cache.CacheID;
                        Template.CacheType = Cache.CacheType;
                        WorldDB.AddObject(Template);
                    }

                    if (Data != null)
                    {
                        Data.CacheID   = Cache.CacheID;
                        Data.CacheType = Cache.CacheType;
                        WorldDB.AddObject(Data);
                    }
                    ++Count;
                }

                Str.Dispose();
            }

            Log.Success("Extractor", "" + Count + " Caches extracted");

            ConsoleMgr.Start();
        }