Beispiel #1
0
        public ChargeResult ImportResourceProducts(int resourceId, int operate_user)
        {
            ChargeResult result = new ChargeResult()
            {
                Status = ChargeStatus.SUCCEED
            };
            ICharge           chargeMgr = null;
            chargebitEntities db        = new chargebitEntities();

            try
            {
                KMBit.DAL.Resource resource = (from ri in db.Resource
                                               where ri.Id == resourceId
                                               select ri).FirstOrDefault <Resource>();

                if (resource == null)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源不存在", resourceId));
                }
                if (!resource.Enabled)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源没有启用,请先启用在进行资源产品导入", resourceId));
                }

                KMBit.DAL.Resrouce_interface rInterface = (from ri in db.Resrouce_interface where ri.Resource_id == resourceId select ri).FirstOrDefault <Resrouce_interface>();
                if (rInterface == null)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源没有配置资源接口,请先配置资源接口,并配置产品导入接口URL,然后进行资源产品导入", resourceId));
                }
                object   o        = null;
                Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                Type     type     = assembly.GetType(rInterface.Interface_classname);
                o = Activator.CreateInstance(type);
                if (o != null)
                {
                    chargeMgr = (ICharge)o;
                    chargeMgr.ImportProducts(resourceId, operate_user);
                }
            }
            catch (Exception ex)
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = ex.Message;
            }finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return(result);
        }