Esempio n. 1
0
        /// <summary>
        /// ctor
        /// </summary>
        public LangDataMapper()
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            string    entityName = typeof(TEntity).Name;
            ModelRule modelRule  = ModelRule.Get <TModel>();
            ModelRule entityRule = ModelRule.Get <TEntity>();
            string    lang       = ResHelper.CurrentCultureName.ToLower();

            _converter = GetConverter <TModel, TEntity>();
            IMappingExpression <TModel, TEntity> expm2t = null;
            IMappingExpression <TEntity, TModel> expt2m = null;

            Mapper.Initialize(cfg =>
            {
                expm2t = cfg.CreateMap <TModel, TEntity>();
                expt2m = cfg.CreateMap <TEntity, TModel>();
            });
            if (_converter != null)
            {
                expt2m.ProjectUsing(_converter.EntityToModel);
                // expm2t.ConstructUsing(_converter.ModelToEntity.Compile()); 不知为何这句无效
            }
            else
            {
                if (typeof(IMultiLanguage).IsAssignableFrom(typeof(TEntity)))
                {
                    RefHelper.CallMethod(this, "MapperLangProperties", new Type[] { typeof(TModel), typeof(TEntity) });
                }
                foreach (var r in modelRule.CollectionRules)
                {
                    if (r.Attr.EntityType != null && Mapper.Configuration.FindTypeMapFor(r.ModelType, r.Attr.EntityType) == null)
                    {
                        Mapper.Initialize(cfg =>
                        {
                            cfg.CreateMap(r.Attr.EntityType, r.ModelType);
                            cfg.CreateMap(r.ModelType, r.Attr.EntityType);
                        });
                    }
                    expt2m.ForMember(r.Name, opt => opt.Ignore());
                }
                foreach (var r in entityRule.CollectionRules)
                {
                    expm2t.ForMember(r.Name, opt => opt.Ignore());
                }
            }
            //Debug.WriteLine("Mapper Elapsed == " + sw.ElapsedMilliseconds);
        }
Esempio n. 2
0
        public object Done(string actionName, string controllerName, string ids)
        {
            var controller = ControllerBuilder.Current.GetControllerFactory()
                             .CreateController(this.Request.RequestContext, controllerName) as BaseController;

            controller.ControllerContext = this.ControllerContext;

            int[] idArr = CommOp.ToIntArray(ids, ',');
            ResourceFileInfo[] results = new ResourceFileInfo[idArr.Length];
            int i = 0;

            foreach (int id in idArr)
            {
                //调用业务逻辑得到stream数组
                var file = _resourceFileService.GetFile(id);
                results[i++] = file;
            }

            var obj = RefHelper.CallMethod(controller, actionName, new object[] { results });

            results.Each(r => r.FileStream.Dispose());
            return(obj);
        }