Example #1
0
        private void BindData()
        {
            FactoryInfoBLL bll       = null;
            DataPage       dp        = new DataPage();
            FactoryInfo    condition = new FactoryInfo();

            try
            {
                bll             = BLLFactory.CreateBLL <FactoryInfoBLL>();
                condition.PCODE = this.PCODE.Text;
                condition.PNAME = this.PNAME.Text;

                PagerHelper.InitPageControl(this.AspNetPager1, dp, true);
                dp = bll.GetList(condition, dp);

                List <FactoryInfo> list = dp.Result as List <FactoryInfo>;
                this.GvList.DataSource = list;
                this.GvList.DataBind();

                for (int i = 0; i < this.GvList.Rows.Count; i++)
                {
                    string click = string.Format("return edit('{0}');", this.GvList.DataKeys[i]["PID"].ToString());

                    (this.GvList.Rows[i].Cells[5].Controls[0] as WebControl).Attributes.Add("onclick", click);
                }
                PagerHelper.SetPageControl(AspNetPager1, dp, true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Serialize a lamp to a .json file for easier creation of like objects.
        /// </summary>
        private static void SerializeLamps()
        {
            LampTileComponent lampTop = new LampTileComponent(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampTileComponent), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light.", "Lamps", Color.Brown, -300, 0, true, 100, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new Animation(new Rectangle(0, 0, 16, 16))), Color.White, true, new InventoryManager(), new LightManager()));

            LampTileComponent lampMiddle = new LampTileComponent(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampTileComponent), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light.", "Lamps", Color.Brown, -300, 0, true, 100, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new Animation(new Rectangle(0, 16, 16, 16))), Color.White, true, new InventoryManager(), new LightManager()));
            LampTileComponent lampBottom = new LampTileComponent(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampTileComponent), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light.", "Lamps", Color.Brown, -300, 0, true, 100, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new Animation(new Rectangle(0, 32, 16, 16))), Color.White, false, new InventoryManager(), new LightManager()));

            lampMiddle.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), lampMiddle);

            LampMultiTiledObject lamp = new LampMultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampMultiTiledObject), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, true, 300, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(), Color.White, false, new InventoryManager(), new LightManager()));

            lamp.addComponent(new Vector2(0, -2), lampTop);
            lamp.addComponent(new Vector2(0, -1), lampMiddle);
            lamp.addComponent(new Vector2(0, 0), lampBottom);

            FactoryInfo lT = new FactoryInfo(lampTop);
            FactoryInfo lM = new FactoryInfo(lampMiddle);
            FactoryInfo lB = new FactoryInfo(lampBottom);

            FactoryInfo lO = new FactoryInfo(lamp);

            ModCore.Serializer.SerializeContentFile("OakLamp_0_-2", lT, Path.Combine(LampsFolder, "OakLamp"));
            ModCore.Serializer.SerializeContentFile("OakLamp_0_-1", lM, Path.Combine(LampsFolder, "OakLamp"));
            ModCore.Serializer.SerializeContentFile("OakLamp_0_0", lB, Path.Combine(LampsFolder, "OakLamp"));
            ModCore.Serializer.SerializeContentFile("OakLamp", lO, Path.Combine(LampsFolder, "OakLamp"));

            //ModCore.customObjects.Add(lamp.info.id, lamp);
        }
        /// <summary>
        /// Creates an example storage file for the mod.
        /// </summary>
        private static void SerializeFurnitureStorageFiles()
        {
            StorageFurnitureTile upperLeft   = new StorageFurnitureTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Storage.OakCabinet", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), typeof(StorageFurnitureTile), Color.White), new BasicItemInformation("Oak Cabinet", "Omegasis.Revitalize.Furniture.Storage.OakCabinet", "A beautiful oak cabinet to place objects inside of.", "Storage", Color.Brown, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new Animation(0, 0, 16, 16)), Color.White, false, null, null));
            StorageFurnitureTile upperRight  = new StorageFurnitureTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Storage.OakCabinet", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), typeof(StorageFurnitureTile), Color.White), new BasicItemInformation("Oak Cabinet", "Omegasis.Revitalize.Furniture.Storage.OakCabinet", "A beautiful oak cabinet to place objects inside of.", "Storage", Color.Brown, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new Animation(16, 0, 16, 16)), Color.White, false, null, null));
            StorageFurnitureTile bottomLeft  = new StorageFurnitureTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Storage.OakCabinet", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), typeof(StorageFurnitureTile), Color.White), new BasicItemInformation("Oak Cabinet", "Omegasis.Revitalize.Furniture.Storage.OakCabinet", "A beautiful oak cabinet to place objects inside of.", "Storage", Color.Brown, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new Animation(0, 16, 16, 16)), Color.White, false, null, null));
            StorageFurnitureTile bottomRight = new StorageFurnitureTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Storage.OakCabinet", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), typeof(StorageFurnitureTile), Color.White), new BasicItemInformation("Oak Cabinet", "Omegasis.Revitalize.Furniture.Storage.OakCabinet", "A beautiful oak cabinet to place objects inside of.", "Storage", Color.Brown, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new Animation(16, 16, 16, 16)), Color.White, false, null, null));


            StorageFurnitureOBJ obj = new StorageFurnitureOBJ(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Storage.OakCabinet", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), typeof(StorageFurnitureTile), Color.White), new BasicItemInformation("Oak Cabinet", "Omegasis.Revitalize.Furniture.Storage.OakCabinet", "A beautiful oak cabinet to place objects inside of.", "Storage", Color.Brown, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Cabinet"), new Animation(16, 16, 16, 16)), Color.White, false, new InventoryManager(9), null));

            FactoryInfo uL      = new FactoryInfo(upperLeft);
            FactoryInfo uR      = new FactoryInfo(upperRight);
            FactoryInfo bL      = new FactoryInfo(bottomLeft);
            FactoryInfo bR      = new FactoryInfo(bottomRight);
            FactoryInfo cabinet = new FactoryInfo(obj);

            //TableMultiTiledObject obj = new TableMultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Tables.OakTable", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Table"), typeof(TableMultiTiledObject), Color.White), new BasicItemInformation("Oak Table", "Omegasis.Revitalize.Furniture.Tables.OakTable", "A simple oak table to place things on.", "Tables", Color.Brown, -300, 0, false, 350, Vector2.Zero, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Table"), new AnimationManager(), Color.White, false, null, null));

            //TableFactoryInfo uL = new TableFactoryInfo(upperLeft);
            //TableFactoryInfo uR = new TableFactoryInfo(upperRight);
            //TableFactoryInfo cL = new TableFactoryInfo(centerLeft);
            //TableFactoryInfo cR = new TableFactoryInfo(centerRight);
            //TableFactoryInfo bR = new TableFactoryInfo(bottomRight);



            ModCore.Serializer.SerializeContentFile("OakCabinet_0_0", uL, Path.Combine(StorageFolder, "OakCabinet"));
            ModCore.Serializer.SerializeContentFile("OakCabinet_1_0", uR, Path.Combine(StorageFolder, "OakCabinet"));
            ModCore.Serializer.SerializeContentFile("OakCabinet_0_1", bL, Path.Combine(StorageFolder, "OakCabinet"));
            ModCore.Serializer.SerializeContentFile("OakCabinet_1_1", bR, Path.Combine(StorageFolder, "OakCabinet"));
            ModCore.Serializer.SerializeContentFile("OakCabinet", cabinet, Path.Combine(StorageFolder, "OakCabinet"));
        }
Example #4
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="page">数据页</param>
        /// <returns>数据页</returns>
        public DataPage GetList(FactoryInfo condition, DataPage page)
        {
            string sql = null;
            List <DataParameter> parameters = new List <DataParameter>();

            try
            {
                sql = this.GetQuerySql(condition, ref parameters);
                //分页关键字段及排序
                page.KeyName = "PID";
                if (string.IsNullOrEmpty(page.SortExpression))
                {
                    page.SortExpression = "UPDATETIME DESC";
                }
                using (IDataSession session = AppDataFactory.CreateMainSession())
                {
                    page = session.GetDataPage <FactoryInfo>(sql, parameters.ToArray(), page);
                }
                return(page);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        /// <summary>
        /// 获取查询语句
        /// </summary>
        /// <param name="user">查询条件</param>
        /// <param name="parameters">参数</param>
        /// <returns>查询语句</returns>
        private string GetQuerySql(FactoryInfo condition, ref List <DataParameter> parameters)
        {
            StringBuilder sqlBuilder   = new StringBuilder();
            StringBuilder whereBuilder = new StringBuilder();

            try
            {
                //构成查询语句
                sqlBuilder.Append(@"SELECT * FROM T_FP_FACTORYINFO t1");

                if (!string.IsNullOrEmpty(condition.PCODE))
                {
                    whereBuilder.Append(" AND t1.PCODE like @PCODE");
                    parameters.Add(new DataParameter("PCODE", "%" + condition.PCODE + "%"));
                }

                if (!string.IsNullOrEmpty(condition.PNAME))
                {
                    whereBuilder.Append(" AND t1.PNAME like @PNAME");
                    parameters.Add(new DataParameter("PNAME", "%" + condition.PNAME + "%"));
                }

                //查询条件
                if (whereBuilder.Length > 0)
                {
                    sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
                }
                return(sqlBuilder.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        /// <summary>
        /// 插入信息(单表)
        /// </summary>
        /// <param name="">信息</param>
        /// <returns>插入行数</returns>
        public DataResult <int> Insert(FactoryInfo model)
        {
            DataResult <int> result = new DataResult <int>();

            try
            {
                //基本信息
                model.PID        = Guid.NewGuid().ToString();
                model.CREATEUSER = this.LoginUser.UserID;
                model.CREATETIME = DateTime.Now;
                model.UPDATEUSER = model.CREATEUSER;
                model.UPDATETIME = model.CREATETIME;
                FactoryInfoDAL cmdDAL = new FactoryInfoDAL();
                if (ExistsCode(model))
                {
                    result.Msg    = "编号已存在";
                    result.Result = -1;
                    return(result);
                }
                if (ExistsName(model))
                {
                    result.Msg    = "名称已存在";
                    result.Result = -1;
                    return(result);
                }
                result.Result    = new FactoryInfoDAL().Insert(model);
                result.IsSuccess = true;
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name="">信息</param>
        /// <returns>更新行数</returns>
        public DataResult <int> Update(FactoryInfo model)
        {
            DataResult <int> result = new DataResult <int>();

            try
            {
                if (ExistsCode(model))
                {
                    result.Msg    = "编号已存在";
                    result.Result = -1;
                    return(result);
                }
                if (ExistsName(model))
                {
                    result.Msg    = "名称已存在";
                    result.Result = -1;
                    return(result);
                }
                model.UPDATEUSER = this.LoginUser.UserID;
                result.Result    = new FactoryInfoDAL().Update(model);
                result.IsSuccess = true;
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #8
0
    public void WaveInit(FactoryInfo info)
    {
        initInfo = info;
        curCnt   = 0;      //現在の敵数

        isSpawned = false; //生成したか
    }
Example #9
0
    List <FactoryInfo> LoadFactoryData()
    {
        List <FactoryInfo> factoryInfoList = new List <FactoryInfo>();
        StreamReader       theReader       = new StreamReader("Factory.csv", Encoding.Default);
        string             line;

        do
        {
            line = theReader.ReadLine();

            if (line != null)
            {
                List <string> entries = new List <string>(line.Split(','));
                FactoryInfo   info    = new FactoryInfo();
                info.name                = entries[0];
                info.initialCost         = float.Parse(entries[1]);
                info.coefficient         = float.Parse(entries[2]);
                info.initialIncome       = float.Parse(entries[3]);
                info.initialProductivity = float.Parse(entries[4]);
                factoryInfoList.Add(info);
            }
        } while (line != null);

        theReader.Close();
        return(factoryInfoList);
    }
Example #10
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            FactoryInfo    info = new FactoryInfo();
            FactoryInfoBLL bll  = null;

            try
            {
                UIBindHelper.BindModelByControls(this.Page, info);

                bll = BLLFactory.CreateBLL <FactoryInfoBLL>();

                if (this.hiID.Value == "")
                {
                    bll.Insert(info);
                }
                else
                {
                    info.CREATEUSER = this.HiCREATEUSER.Value;
                    info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value);
                    info.PID        = this.hiID.Value;
                    bll.Update(info);
                }

                ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        private void BindData()
        {
            string         id   = Request.QueryString["id"];
            FactoryInfoBLL bll  = null;
            FactoryInfo    info = new FactoryInfo();

            try
            {
                bll = BLLFactory.CreateBLL <FactoryInfoBLL>();
                if (string.IsNullOrEmpty(id) == false)
                {
                    info.PID = id;
                    info     = bll.Get(info);

                    UIBindHelper.BindForm(this.Page, info);
                    this.hiID.Value         = info.PID;
                    this.HiCREATEUSER.Value = info.CREATEUSER;
                    this.HiCREATETIME.Value = info.CREATETIME.ToString();
                }
                else
                {
                    info = new FactoryInfo();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
 private static void RemoveCache(FactoryInfo item)
 {
     if (item == null)
     {
         return;
     }
     RedisHelper.Remove(string.Concat("pifa_BLL_Factory_", item.Id));
 }
Example #13
0
 public static pifa.DAL.Factory.SqlUpdateBuild UpdateDiy(FactoryInfo item, uint Id)
 {
     if (itemCacheTimeout > 0)
     {
         RemoveCache(item != null ? item : GetItem(Id));
     }
     return(new pifa.DAL.Factory.SqlUpdateBuild(item, Id));
 }
Example #14
0
 public static int Update(FactoryInfo item)
 {
     if (itemCacheTimeout > 0)
     {
         RemoveCache(item);
     }
     return(dal.Update(item));
 }
Example #15
0
 public static T GetFromParentOrCurrent<T>(FactoryDelegate<T> fd, FactoryInfo<T> fi, IResolverContext r)
 {
     var id = fi.Id;
     for (var s = r.CurrentScope; s != null; s = s.Parent)
         if (s.TryGet(out var res, id))
             return (T)res;
     return fd(r);
 }
Example #16
0
 public static FactoryInfo Insert(FactoryInfo item)
 {
     item = dal.Insert(item);
     if (itemCacheTimeout > 0)
     {
         RemoveCache(item);
     }
     return(item);
 }
Example #17
0
    GameObject CreateFactory(FactoryInfo factoryInfo, int index)
    {
        GameObject fObject = Instantiate(factoryPrefab);

        // Model
        FactoryController factory = fObject.GetComponent <FactoryController>();

        factory.CanvasHUD     = CanvasHUD;
        factory.EconomyObject = EconomyObject;
        factory.SetUpParams(factoryInfo);

        // View
        float invRatio = 1 / GoldenRatio;

        fObject.transform.SetParent(this.transform, false);

        float prevScale = StarterScale;

        Debug.Log(string.Format("making factory {0}", index));
        Debug.Log(string.Format("starting location {0}", fObject.transform.position));

        for (int loop = 0; loop < index; loop++)
        {
            float   newScale  = prevScale * invRatio;
            Vector3 vectorAdd = new Vector3(0, 0, 0);
            switch (loop % 4)
            {
            case 0:
                vectorAdd = new Vector3(DefaultFactorySize * (prevScale / 2 + newScale / 2),
                                        DefaultFactorySize * (prevScale / 2 - newScale / 2), 0);
                break;

            case 1:
                vectorAdd = new Vector3(DefaultFactorySize * (prevScale / 2 - newScale / 2),
                                        -DefaultFactorySize * (prevScale / 2 + newScale / 2), 0);
                break;

            case 2:
                vectorAdd = new Vector3(-DefaultFactorySize * (prevScale / 2 + newScale / 2),
                                        -DefaultFactorySize * (prevScale / 2 - newScale / 2), 0);
                break;

            case 3:
                vectorAdd = new Vector3(-DefaultFactorySize * (prevScale / 2 - newScale / 2),
                                        DefaultFactorySize * (prevScale / 2 + newScale / 2), 0);
                break;
            }
            Debug.Log(vectorAdd);
            fObject.transform.position += vectorAdd;
            prevScale = newScale;
        }
        fObject.transform.localScale = new Vector3(prevScale,
                                                   prevScale,
                                                   prevScale);
        return(fObject);
    }
        private static void AddFactory(FactoryInfo info, List <FactoryInfo> factories)
        {
            FactoryInfo current = factories.FirstOrDefault(item => item.DataType == info.DataType);

            if (current != null)
            {
                factories.Remove(current);
            }
            factories.Add(info);
        }
Example #19
0
        public FactoryInfo Insert(FactoryInfo item)
        {
            uint loc1;

            if (uint.TryParse(string.Concat(SqlHelper.ExecuteScalar(TSQL.Insert, GetParameters(item))), out loc1))
            {
                item.Id = loc1;
            }
            return(item);
        }
Example #20
0
        public object GetItem(IDataReader dr, ref int index)
        {
            FactoryInfo item = new FactoryInfo();

            if (!dr.IsDBNull(++index))
            {
                item.Id = (uint?)dr.GetInt32(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Area_id = (uint?)dr.GetInt32(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Capacity = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Create_time = (DateTime?)dr.GetDateTime(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Main_business = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Min_order = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Process_cost = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Sampling_period = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Sampling_price = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Telphone = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Title = dr.GetString(index);
            }
            if (!dr.IsDBNull(++index))
            {
                item.Turn_single_time = dr.GetString(index);
            }
            return(item);
        }
Example #21
0
        public ActionResult Edit([FromQuery] uint Id)
        {
            FactoryInfo item = Factory.GetItem(Id);

            if (item == null)
            {
                return(APIReturn.记录不存在_或者没有权限);
            }
            ViewBag.item = item;
            return(View());
        }
Example #22
0
        private static MethodDeclarationSyntax CreateModuleTypeMethodDeclaration(FactoryInfo factory)
        {
            var moduleTypeMethodDeclaration = SyntaxFactory
                                              .MethodDeclaration(SyntaxFactory.ParseTypeName("Type"), Constants.GetModuleTypeMethodName)
                                              .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword),
                                                            SyntaxFactory.Token(SyntaxKind.StaticKeyword))
                                              .WithBody(SyntaxFactory.Block(SyntaxFactory.ParseStatement(
                                                                                $"return typeof({factory.ModuleFullName});")));

            return(moduleTypeMethodDeclaration);
        }
Example #23
0
 /// <summary>
 /// 获取信息
 /// </summary>
 /// <param name="">条件</param>
 /// <returns>信息</returns>
 public FactoryInfo Get(FactoryInfo model)
 {
     try
     {
         return(new FactoryInfoDAL().Get(model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #24
0
 /// <summary>
 /// 删除信息
 /// </summary>
 /// <param name="">信息</param>
 /// <returns>删除个数</returns>
 public int DeleteFactory(FactoryInfo model)
 {
     try
     {
         return(new FactoryInfoDAL().Delete(model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #25
0
 /// <summary>
 /// 获取列表
 /// </summary>
 /// <param name="condition">条件</param>
 /// <param name="page">数据页</param>
 /// <returns>数据页</returns>
 public DataPage GetList(FactoryInfo condition, DataPage page)
 {
     try
     {
         return(new FactoryInfoDAL().GetList(condition, page));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #26
0
 /// <summary>
 /// 判断名称是否存在
 /// </summary>
 /// <param name="">信息</param>
 /// <returns>true:已存在;fasel:不存在。</returns>
 public bool ExistsName(FactoryInfo model)
 {
     try
     {
         return(new FactoryInfoDAL().ExistsName(model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #27
0
        private bool CheckIfFactoryAlreadyAdded(FactoryInfo factory)
        {
            return(factoryInfos.FindIndex(f =>
            {
                if (f.FactoryType == factory.FactoryType)
                {
                    return true;
                }

                return false;
            }) != -1);
        }
 /// <summary>
 /// Returns <see cref="IIdGeneratorFactory"/> for specified <paramref name="connectionString"/> and database
 /// type <paramref name="clientName"/>.
 /// </summary>
 /// <param name="dataType">ID generator data type.</param>
 /// <param name="connectionString">Connection string for database.</param>
 /// <param name="clientName">Name, which specifies database type.</param>
 /// <returns>Instance of <see cref="IIdGeneratorFactory"/>.</returns>
 /// <exception cref="InvalidOperationException">
 /// Factory for database type specified by <paramref name="clientName"/> is not registered.
 /// </exception>
 public static IIdGeneratorFactory GetFactory(Type dataType, string connectionString, string clientName)
 {
     if (_byClientName.TryGetValue(clientName, out List <FactoryInfo> factories))
     {
         FactoryInfo factory = factories.FirstOrDefault(item => item.DataType == dataType);
         if (factory != null)
         {
             return(factory.FactoryByClientName(connectionString));
         }
     }
     throw new InvalidOperationException(string.Format(Resources.FactoryNotRegisteredForClient,
                                                       nameof(IIdGeneratorFactory), clientName));
 }
Example #29
0
        private static FactoryInfo CreateFactoryInfo(
            IServiceProvider services,
            Type type)
        {
#if NETSTANDARD1_4
            ConstructorInfo[] constructors = type.GetTypeInfo()
                                             .DeclaredConstructors
                                             .Where(t => t.IsPublic && !t.IsAbstract)
                                             .ToArray();
#else
            ConstructorInfo[] constructors = type
                                             .GetConstructors(BindingFlags.Public | BindingFlags.Instance);
#endif

            if (constructors.Length == 0)
            {
                // TODO : Resource
                throw new CreateServiceException(
                          $"The instance type `{type.FullName}` " +
                          "must have at least on public constructor.");
            }

            if (services is null)
            {
                ConstructorInfo constructor = constructors
                                              .FirstOrDefault(t => !t.GetParameters().Any());
                if (constructor is null)
                {
                    // TODO : Resource
                    throw new CreateServiceException(
                              $"The instance type `{type.FullName}` " +
                              "must have a parameterless constructor .");
                }
                return(new FactoryInfo(type, constructor));
            }

            FactoryInfo factoryInfo = GetBestMatchingConstructor(
                services, type, constructors);

            if (factoryInfo is null)
            {
                // TODO : Resource
                throw new CreateServiceException(
                          $"Unable to find a constructor on type `{type.FullName}` " +
                          "that can be fulfilled with the currently " +
                          "available set of services. Check if " +
                          "all dependent services for this type are registered.");
            }

            return(factoryInfo);
        }
Example #30
0
    public void SetUpParams(FactoryInfo info)
    {
        factoryLevel = 0;
        maxLevel     = 10;

        levelToIncomeMap      = new Dictionary <int, float>();
        levelToLevelUpCostMap = new Dictionary <int, float>();

        for (var i = 0; i < maxLevel; i++)
        {
            levelToLevelUpCostMap[i] = info.initialCost * (float)Math.Pow(info.coefficient, i);
            levelToIncomeMap[i]      = info.initialIncome * i * info.initialProductivity;
        }
    }
        /// <summary>
        /// Call to find interpreters in the associated project. Separated from
        /// the constructor to allow exceptions to be handled without causing
        /// the project node to be invalid.
        /// </summary>
        /// <exception cref="InvalidDataException">
        /// One or more interpreters failed to load. The error message should be
        /// presented to the user, but can otherwise be ignored.
        /// </exception>
        public void DiscoverInterpreters() {
            // <Interpreter Include="InterpreterDirectory">
            //   <Id>guid</Id>
            //   <BaseInterpreter>guid</BaseInterpreter>
            //   <Version>...</Version>
            //   <InterpreterPath>...</InterpreterPath>
            //   <WindowsInterpreterPath>...</WindowsInterpreterPath>
            //   <LibraryPath>...</LibraryPath>
            //   <PathEnvironmentVariable>...</PathEnvironmentVariable>
            //   <Description>...</Description>
            // </Interpreter>

            var errors = new StringBuilder();
            errors.AppendLine("Some project interpreters failed to load:");
            bool anyChange = false, anyError = false;

            var projectHome = PathUtils.GetAbsoluteDirectoryPath(_project.DirectoryPath, _project.GetPropertyValue("ProjectHome"));
            var factories = new Dictionary<IPythonInterpreterFactory, FactoryInfo>();
            foreach (var item in _project.GetItems(InterpreterItem)) {
                IPythonInterpreterFactory fact;
                Guid id, baseId;

                // Errors in these options are fatal, so we set anyError and
                // continue with the next entry.
                var dir = item.EvaluatedInclude;
                if (!PathUtils.IsValidPath(dir)) {
                    errors.AppendLine(string.Format("Interpreter has invalid path: {0}", dir ?? "(null)"));
                    anyError = true;
                    continue;
                }
                dir = PathUtils.GetAbsoluteDirectoryPath(projectHome, dir);

                var value = item.GetMetadataValue(IdKey);
                if (string.IsNullOrEmpty(value) || !Guid.TryParse(value, out id)) {
                    errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, IdKey, value));
                    anyError = true;
                    continue;
                }
                if (factories.Keys.Any(f => f.Id == id)) {
                    errors.AppendLine(string.Format("Interpreter {0} has a non-unique id: {1}", dir, id));
                    continue;
                }

                var verStr = item.GetMetadataValue(VersionKey);
                Version ver;
                if (string.IsNullOrEmpty(verStr) || !Version.TryParse(verStr, out ver)) {
                    errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, VersionKey, verStr));
                    anyError = true;
                    continue;
                }

                // The rest of the options are non-fatal. We create an instance
                // of NotFoundError with an amended description, which will
                // allow the user to remove the entry from the project file
                // later.
                bool hasError = false;

                var description = item.GetMetadataValue(DescriptionKey);
                if (string.IsNullOrEmpty(description)) {
                    description = PathUtils.CreateFriendlyDirectoryPath(projectHome, dir);
                }

                value = item.GetMetadataValue(BaseInterpreterKey);
                PythonInterpreterFactoryWithDatabase baseInterp = null;
                if (!string.IsNullOrEmpty(value) && Guid.TryParse(value, out baseId)) {
                    // It's a valid GUID, so find a suitable base. If we
                    // don't find one now, we'll try and figure it out from
                    // the pyvenv.cfg/orig-prefix.txt files later.
                    // Using an empty GUID will always go straight to the
                    // later lookup.
                    if (baseId != Guid.Empty) {
                        baseInterp = _service.FindInterpreter(baseId, ver) as PythonInterpreterFactoryWithDatabase;
                    }
                }

                var path = item.GetMetadataValue(InterpreterPathKey);
                if (!PathUtils.IsValidPath(path)) {
                    errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, InterpreterPathKey, path));
                    hasError = true;
                } else if (!hasError) {
                    path = PathUtils.GetAbsoluteFilePath(dir, path);
                }

                var winPath = item.GetMetadataValue(WindowsPathKey);
                if (!PathUtils.IsValidPath(winPath)) {
                    errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, WindowsPathKey, winPath));
                    hasError = true;
                } else if (!hasError) {
                    winPath = PathUtils.GetAbsoluteFilePath(dir, winPath);
                }

                var libPath = item.GetMetadataValue(LibraryPathKey);
                if (string.IsNullOrEmpty(libPath)) {
                    libPath = "lib";
                }
                if (!PathUtils.IsValidPath(libPath)) {
                    errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, LibraryPathKey, libPath));
                    hasError = true;
                } else if (!hasError) {
                    libPath = PathUtils.GetAbsoluteDirectoryPath(dir, libPath);
                }

                var pathVar = item.GetMetadataValue(PathEnvVarKey);
                if (string.IsNullOrEmpty(pathVar)) {
                    if (baseInterp != null) {
                        pathVar = baseInterp.Configuration.PathEnvironmentVariable;
                    } else {
                        pathVar = "PYTHONPATH";
                    }
                }

                string arch = null;
                if (baseInterp == null) {
                    arch = item.GetMetadataValue(ArchitectureKey);
                    if (string.IsNullOrEmpty(arch)) {
                        arch = "x86";
                    }
                }

                if (baseInterp == null && !hasError) {
                    // Only thing missing is the base interpreter, so let's try
                    // to find it using paths
                    baseInterp = DerivedInterpreterFactory.FindBaseInterpreterFromVirtualEnv(dir, libPath, _service) as
                        PythonInterpreterFactoryWithDatabase;

                    if (baseInterp == null) {
                        errors.AppendLine(string.Format("Interpreter {0} has invalid value for '{1}': {2}", dir, BaseInterpreterKey, value ?? "(null)"));
                        hasError = true;
                    }
                }

                if (hasError) {
                    fact = new NotFoundInterpreterFactory(
                        id,
                        ver,
                        string.Format("{0} (unavailable)", description),
                        Directory.Exists(dir) ? dir : null
                    );
                } else if (baseInterp != null) {
                    MigrateOldDerivedInterpreterFactoryDatabase(id, baseInterp.Configuration.Version, dir);
                    fact = new DerivedInterpreterFactory(
                        baseInterp,
                        new InterpreterFactoryCreationOptions {
                            LanguageVersion = baseInterp.Configuration.Version,
                            Id = id,
                            Description = description,
                            InterpreterPath = path,
                            WindowInterpreterPath = winPath,
                            LibraryPath = libPath,
                            PrefixPath = dir,
                            PathEnvironmentVariableName = pathVar,
                            Architecture = baseInterp.Configuration.Architecture,
                            WatchLibraryForNewModules = true
                        }
                    );
                } else {
                    fact = InterpreterFactoryCreator.CreateInterpreterFactory(new InterpreterFactoryCreationOptions {
                        LanguageVersion = ver,
                        Id = id,
                        Description = description,
                        InterpreterPath = path,
                        WindowInterpreterPath = winPath,
                        LibraryPath = libPath,
                        PrefixPath = dir,
                        PathEnvironmentVariableName = pathVar,
                        ArchitectureString = arch,
                        WatchLibraryForNewModules = true
                    });
                }
                var existing = FindInterpreter(id, ver);
                if (existing != null && existing.IsEqual(fact)) {
                    factories[existing] = new FactoryInfo(item, factories[existing].Owned);
                    var disposable = fact as IDisposable;
                    if (disposable != null) {
                        disposable.Dispose();
                    }
                } else {
                    _rootPaths[id] = dir;
                    factories[fact] = new FactoryInfo(item, true);
                    anyChange = true;
                }
            }

            // <InterpreterReference Include="{guid};{version}" />
            foreach (var item in _project.GetItems(InterpreterReferenceItem)) {
                var match = InterpreterReferencePath.Match(item.EvaluatedInclude);
                if (match == null || !match.Success || !match.Groups.Cast<Group>().All(g => g.Success)) {
                    errors.AppendLine(string.Format("Interpreter reference has invalid path: {0}", item.EvaluatedInclude));
                    anyError = true;
                    continue;
                }
                Guid id;
                var value = match.Groups["id"];
                if (string.IsNullOrEmpty(value.Value) || !Guid.TryParse(value.Value, out id)) {
                    errors.AppendLine(string.Format("Interpreter reference has invalid id: {0}", value.Value ?? "(null)"));
                    anyError = true;
                    continue;
                }
                Version ver;
                value = match.Groups["version"];
                if (string.IsNullOrEmpty(value.Value) || !Version.TryParse(value.Value, out ver)) {
                    errors.AppendLine(string.Format("Interpreter reference has invalid version: {0}", value.Value ?? "(null)"));
                    anyError = true;
                    continue;
                }

                bool owned = false;
                var fact = _service.FindInterpreter(id, ver);
                if (fact == null) {
                    owned = true;
                    fact = new NotFoundInterpreterFactory(id, ver);
                }

                var existing = FindInterpreter(id, ver);
                if (existing != null) {
                    factories[existing] = new FactoryInfo(item, factories[existing].Owned);
                    if (owned) {
                        ((PythonInterpreterFactoryWithDatabase)fact).Dispose();
                    }
                } else {
                    factories[fact] = new FactoryInfo(item, owned);
                    anyChange = true;
                }
            }

            if (anyChange || _factories == null || factories.Count != _factories.Count) {
                // Lock here mainly to ensure that any searches complete before
                // we trigger the changed event.
                lock (_factoriesLock) {
                    _factories = factories;
                }
                OnInterpreterFactoriesChanged();
                UpdateActiveInterpreter();
            }

            if (anyError) {
                throw new InvalidDataException(errors.ToString());
            }
        }
        /// <summary>
        /// Adds the specified factory to the project. If the factory was
        /// created by this provider, it will be added as an Interpreter element
        /// with full details. If the factory was not created by this provider,
        /// it will be added as an InterpreterReference element with only the
        /// ID and version.
        /// </summary>
        /// <param name="factory">The factory to add.</param>
        public void AddInterpreter(IPythonInterpreterFactory factory, bool disposeInterpreter = false) {
            if (factory == null) {
                throw new ArgumentNullException("factory");
            }

            if (_factories.ContainsKey(factory)) {
                return;
            }

            MSBuild.ProjectItem item;

            var derived = factory as DerivedInterpreterFactory;
            if (derived != null) {
                var projectHome = PathUtils.GetAbsoluteDirectoryPath(_project.DirectoryPath, _project.GetPropertyValue("ProjectHome"));
                var rootPath = PathUtils.EnsureEndSeparator(factory.Configuration.PrefixPath);
                _rootPaths[factory.Id] = rootPath;

                item = _project.AddItem(InterpreterItem,
                    PathUtils.GetRelativeDirectoryPath(projectHome, rootPath),
                    new Dictionary<string, string> {
                        { IdKey, derived.Id.ToString("B") },
                        { BaseInterpreterKey, derived.BaseInterpreter.Id.ToString("B") },
                        { VersionKey, derived.BaseInterpreter.Configuration.Version.ToString() },
                        { DescriptionKey, derived.Description },
                        { InterpreterPathKey, PathUtils.GetRelativeFilePath(rootPath, derived.Configuration.InterpreterPath) },
                        { WindowsPathKey, PathUtils.GetRelativeFilePath(rootPath, derived.Configuration.WindowsInterpreterPath) },
                        { LibraryPathKey, PathUtils.GetRelativeDirectoryPath(rootPath, derived.Configuration.LibraryPath) },
                        { PathEnvVarKey, derived.Configuration.PathEnvironmentVariable },
                        { ArchitectureKey, derived.Configuration.Architecture.ToString() }
                    }).FirstOrDefault();
            } else if (_service.FindInterpreter(factory.Id, factory.Configuration.Version) != null) {
                // The interpreter exists globally, so add a reference.
                item = _project.AddItem(InterpreterReferenceItem,
                    string.Format("{0:B}\\{1}", factory.Id, factory.Configuration.Version)
                    ).FirstOrDefault();
            } else {
                // Can't find the interpreter anywhere else, so add its
                // configuration to the project file.
                var projectHome = PathUtils.GetAbsoluteDirectoryPath(_project.DirectoryPath, _project.GetPropertyValue("ProjectHome"));
                var rootPath = PathUtils.EnsureEndSeparator(factory.Configuration.PrefixPath);

                item = _project.AddItem(InterpreterItem,
                    PathUtils.GetRelativeDirectoryPath(projectHome, rootPath),
                    new Dictionary<string, string> {
                        { IdKey, factory.Id.ToString("B") },
                        { VersionKey, factory.Configuration.Version.ToString() },
                        { DescriptionKey, factory.Description },
                        { InterpreterPathKey, PathUtils.GetRelativeFilePath(rootPath, factory.Configuration.InterpreterPath) },
                        { WindowsPathKey, PathUtils.GetRelativeFilePath(rootPath, factory.Configuration.WindowsInterpreterPath) },
                        { LibraryPathKey, PathUtils.GetRelativeDirectoryPath(rootPath, factory.Configuration.LibraryPath) },
                        { PathEnvVarKey, factory.Configuration.PathEnvironmentVariable },
                        { ArchitectureKey, factory.Configuration.Architecture.ToString() }
                    }).FirstOrDefault();
            }

            lock (_factoriesLock) {
                _factories[factory] = new FactoryInfo(item, disposeInterpreter);
            }
            OnInterpreterFactoriesChanged();
            UpdateActiveInterpreter();
        }
Example #33
0
 private static void MergeFactory(ProjectInfo projectInfo, Dictionary<string, FactoryInfo> factories, FactoryInfo info)
 {
     FactoryInfo existing;
     if (projectInfo.Factories != null &&
         projectInfo.Factories.TryGetValue(info.Config.Id, out existing) &&
         existing.Equals(info)) {
         // keep the existing factory, we may have already created it's IPythonInterpreterFactory instance
         factories[info.Config.Id] = existing;
     } else {
         factories[info.Config.Id] = info;
     }
 }