Beispiel #1
0
        public static void AddModelLoader(Type type, int interval = -1)
        {
            TypeInfo             typeInfo        = type.GetTypeInfo();
            ModelLoaderAttribute customAttribute = typeInfo.GetCustomAttribute <ModelLoaderAttribute>(false);

            if (customAttribute != null)
            {
                if (typeInfo.DeclaredConstructors.FirstOrDefault <ConstructorInfo>((ConstructorInfo p) => p.GetParameters().Length == 0) == null)
                {
                    throw new Exception(string.Concat(type.FullName, " not exist default constructor"));
                }
                ModelLoader modelLoader = new ModelLoader(type, customAttribute);
                ModelLoader.Loaders.Add(type, modelLoader);
                if (interval == -1)
                {
                    interval = customAttribute.Interval;
                }
                modelLoader.Start(interval, true);
            }
        }
Beispiel #2
0
        internal ModelLoader(Type type, ModelLoaderAttribute attr)
        {
            this.type = type;
            object obj = Activator.CreateInstance(type);

            this.loader = obj as IModelLoader;
            if (this.loader == null)
            {
                throw new NotImplementedException(string.Concat(type.FullName, " not Implemented IModelLoader interface"));
            }
            BaseMapperService baseMapperService = obj as BaseMapperService;

            if (baseMapperService != null)
            {
                baseMapperService.SetModelLoader(this);
            }
            this.interval    = attr.Interval;
            this.timer       = new Timer(new TimerCallback(this.TimerCallback), null, -1, -1);
            this.maxTryCount = attr.TryCount;
        }