public async Task <object> Handle(DesignHub hub, InvokeArgs args) { //TODO:先判断DataStoreRootNode有没有被当前用户签出 // 获取接收到的参数 var storeType = (DataStoreKind)args.GetInt32(); var storeProvider = args.GetString(); var storeName = args.GetString(); // 验证类名称的合法性 if (string.IsNullOrEmpty(storeName)) { throw new Exception("DataStore name can not be null"); } if (!CodeHelper.IsValidIdentifier(storeName) || storeName == "Default") { throw new Exception("DataStore name invalid"); } // TODO: 验证名称是否已存在 // 开始新建存储节点 var model = new DataStoreModel(storeType, storeProvider, storeName); //添加节点至模型树并绑定签出信息 var node = hub.DesignTree.StoreRootNode.AddModel(model, hub); // 保存至本地 await node.SaveAsync(); // 新建RoslynDocument hub.TypeSystem.CreateStoreDocument(node); return(node); }
//Add public void Add(DataStoreModel siEntity) //Add { try { var doc = XDocument.Load(Config.dataStoreFile); var batchmatching = new XElement("Entity", new XElement("Id", siEntity.Id), new XElement("Japanese", siEntity.Japanese), new XElement("Pronounce", siEntity.Pronounce), new XElement("Mean", siEntity.Mean), new XElement("Genre", siEntity.Genre), new XElement("Example", siEntity.Example), new XElement("Speak", siEntity.Speak), new XElement("Date", siEntity.Date), new XElement("Picture", siEntity.Picture) ); doc.Element("DocumentElement").Add(batchmatching); doc.Save(Config.dataStoreFile); } catch (Exception) { } //Bỏ qua các giá trị lỗi như NULL... }
private void btnAddFast_Click(object sender, EventArgs e) { try{ if (!string.IsNullOrWhiteSpace(txtStart.Text)) { DataStoreModel _reModel = new DataStoreModel(); List <DataStoreModel> getDataStoreModels = _listDic.GetRange(Convert.ToInt32(txtStart.Text), Convert.ToInt32(txtEnd.Text)); foreach (DataStoreModel dataStoreModel in getDataStoreModels) { dataStoreModel.Id = Unitils.RandomGUID(); dataStoreModel.Date = dateDate.Value.ToString("dd/MM/yyyy"); } _dataStoreEntity.AddByList(getDataStoreModels); GetAll(); myFlagChange(true); mainStatus.Text = (string)statusObj["AddSuccess"]; } else { mainStatus.Text = (string)statusObj["AddFaile"]; } } catch { mainStatus.Text = (string)statusObj["AddFaile"]; } }
/// <summary> /// Registers a given <see cref="DataStoreModel{SingleComponentDataStore}"/> and generates a <see cref="IEditorDrawable"/> /// view for the model. /// </summary> /// <param name="model">Model to register.</param> /// <returns>A new view setup to push messages back to the model.</returns> public IEditorDrawable RegisterModel(DataStoreModel<SingleComponentDataStore> model) { SingleView view = new SingleView(() => model.SerializedObject?.StoredComponent, model.DataType, model.SerializedName); view.OnEditorValueChanged += (s, args) => model.Update(args.ChangedValue); return view; }
internal static string GenDataStoreDummyCode(DataStoreModel model) { var sb = StringBuilderCache.Acquire(); sb.Append("public static partial class DataStore { "); sb.Append($"public static {model.Kind.ToString()}Store {model.Name} {{get{{return null;}}}} }}"); return(StringBuilderCache.GetStringAndRelease(sb)); }
internal DataStoreNode AddModel(DataStoreModel model, DesignHub hub) { //注意model可能被签出的本地替换掉,所以相关操作必须指向node.Model var node = new DataStoreNode(model, hub); DesignTree.BindCheckoutInfo(node, model.PersistentState == PersistentState.Detached); Nodes.Add(node); return(node); }
/// <summary> /// Registers a given <see cref="DataStoreModel{CollectionComponentDataStore}"/> and generates a <see cref="IEditorDrawable"/> /// view for the model. /// </summary> /// <param name="model">Model to register.</param> /// <returns>A new view setup to push messages back to the model.</returns> public IEditorDrawable RegisterModel(DataStoreModel<CollectionComponentDataStore> model) { //create the view for lists CollectionView view = new CollectionView(model.SerializedObject.dataStoreCollection, model.SerializedName, model.DataType); //setup the view to send updates back to the model view.OnEditorValueChanged += (s, args) => model.Update(args.ChangedValue); return view; }
private void Add() { try { if (txtJapanese.Text != "") { DataStoreModel _reModel = new DataStoreModel(); _reModel.Id = Unitils.RandomGUID(); _reModel.Japanese = txtJapanese.Text.Trim(); _reModel.Pronounce = txtPronounce.Text; _reModel.Mean = txtMean.Text; _reModel.Example = txtExample.Text; _reModel.Genre = txtRemember.Text; _reModel.Date = dateDate.Value.ToString("dd/MM/yyyy"); try { if (!String.IsNullOrEmpty(txtChooseImage.Text)) { if (!File.Exists(picImage.ImageLocation)) { System.IO.File.Copy(picImage.ImageLocation, Config.pictureFolder + imgTempUrl, true); } _reModel.Picture = imgTempUrl; } else { _reModel.Picture = ""; } } catch (Exception ex) { string abc = ex.ToString(); } _dataStoreEntity.Add(_reModel); GetAll(); myFlagChange(true); mainStatus.Text = (string)statusObj["AddSuccess"]; } else { mainStatus.Text = (string)statusObj["AddFaile"]; } } catch { mainStatus.Text = (string)statusObj["AddFaile"]; } }
public JsonDataStoreService() { if(_datastore == null) { var text = File.ReadAllText("_local_model_sotre_.json"); _datastore = JsonConvert .DeserializeObject<DataStoreModel>( text, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); } }
public JsonDataStoreService() { if (_datastore == null) { var text = File.ReadAllText("_local_model_sotre_.json"); _datastore = JsonConvert .DeserializeObject <DataStoreModel>( text, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); } }
private void btnAddLesson_Click(object sender, EventArgs e) { using (var webClient = new System.Net.WebClient()) { if (string.IsNullOrWhiteSpace(txtNumerLession.Text)) { return; } var json = webClient.DownloadString(string.Format("http://japaneseclub.jp//eBooks/MinnaNihongo/Lesson-{0}/Vocabulary/Vocabulary-vi.json", txtNumerLession.Text)); List <VocabularyModel> m = JsonConvert.DeserializeObject <List <VocabularyModel> >(json); foreach (var item in m) { try { DataStoreModel _reModel = new DataStoreModel(); _reModel.Id = Unitils.RandomGUID(); _reModel.Japanese = item.Hiragana; _reModel.Pronounce = item.Category; _reModel.Mean = item.Mean; _reModel.Genre = item.Category; _reModel.Date = dateDate.Value.ToString("dd/MM/yyyy"); if (!String.IsNullOrEmpty(txtChooseImage.Text)) { if (!File.Exists(picImage.ImageLocation)) { System.IO.File.Copy(picImage.ImageLocation, Config.pictureFolder + imgTempUrl, true); } _reModel.Picture = imgTempUrl; } else { _reModel.Picture = ""; } _dataStoreEntity.Add(_reModel); } catch (Exception ex) { string abc = ex.ToString(); } } GetAll(); myFlagChange(true); mainStatus.Text = (string)statusObj["AddSuccess"]; } }
//Edit public bool Update(string Id, DataStoreModel siModel) { try { var doc = XDocument.Load(Config.dataStoreFile); var siNode = doc.Elements("DocumentElement").Elements("Entity").Where(x => x.Element("Id").Value == Id.Trim()).Take(1); if (siModel.Id != null) { siNode.Elements("Id").SingleOrDefault().Value = siModel.Id; } if (siModel.Japanese != null) { siNode.Elements("Japanese").SingleOrDefault().Value = siModel.Japanese; } if (siModel.Pronounce != null) { siNode.Elements("Pronounce").SingleOrDefault().Value = siModel.Pronounce; } if (siModel.Mean != null) { siNode.Elements("Mean").SingleOrDefault().Value = siModel.Mean; } if (siModel.Genre != null) { siNode.Elements("Genre").SingleOrDefault().Value = siModel.Genre; } siNode.Elements("Example").SingleOrDefault().Value = siModel.Example; if (siModel.Speak != null) { siNode.Elements("Speak").SingleOrDefault().Value = siModel.Speak; } siNode.Elements("Date").SingleOrDefault().Value = siModel.Date; if (siModel.Picture != null) { siNode.Elements("Picture").SingleOrDefault().Value = siModel.Picture; } doc.Save(Config.dataStoreFile); return(true); } catch (Exception) { return(false); } }
public string Do(string doWhat, string para1, bool isLogin) { // 如果admin账户登陆时有错误发生,则返回错误信息 var result = LetAdminLogin("CH", isLogin); if (string.IsNullOrEmpty(result) == false) { return(result); } switch (doWhat) { case "GenerFlowTemplete": Flow temp = new BP.WF.Flow(para1); return(null); case "GetFlowSorts": //获取所有流程类型 DataTable dtSorts = null; try { dtSorts = BP.DA.DBAccess.RunSQLReturnTable("SELECT no,name FROM WF_FlowSort"); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true, msg = string.Empty, data = dtSorts.Rows.Cast <DataRow>().Select(dr => new { Key = dr["no"].ToString(), Value = dr["name"].ToString() }) })); case "NewSameLevelFrmSort": //创建同级别的 表单树 目录. SysFormTree frmSort = null; try { var para = para1.Split(','); frmSort = new SysFormTree(para[0]); string sameNodeNo = frmSort.DoCreateSameLevelNode().No; frmSort = new SysFormTree(sameNodeNo); frmSort.Name = para[1]; frmSort.Update(); return(null); } catch (Exception ex) { return("Do Method NewFormSort Branch has a error , para:\t" + para1 + ex.Message); } case "NewSubLevelFrmSort": //创建子级别的 表单树 目录. SysFormTree frmSortSub = null; try { var para = para1.Split(','); frmSortSub = new SysFormTree(para[0]); string sameNodeNo = frmSortSub.DoCreateSubNode().No; frmSortSub = new SysFormTree(sameNodeNo); frmSortSub.Name = para[1]; frmSortSub.Update(); return(null); } catch (Exception ex) { return("Do Method NewSubLevelFrmSort Branch has a error , para:\t" + para1 + ex.Message); } case "NewSameLevelFlowSort": //创建同级别的 流程树 目录. FlowSort fs = null; try { var para = para1.Split(','); fs = new FlowSort(para[0]); string sameNodeNo = fs.DoCreateSameLevelNode().No; fs = new FlowSort(sameNodeNo); fs.Name = para[1]; fs.Update(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = fs.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewSameLevelFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "NewSubFlowSort": //创建子级别的 表单树 目录. try { var para = para1.Split(','); FlowSort fsSub = new FlowSort(para[0]); string subNodeNo = fsSub.DoCreateSubNode().No; FlowSort subFlowSort = new FlowSort(subNodeNo); subFlowSort.Name = para[1]; subFlowSort.Update(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = subFlowSort.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewSubFlowSort Branch has a error , para:\t" + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "EditFlowSort": //编辑表单树. try { var para = para1.Split(','); fs = new FlowSort(para[0]); fs.Name = para[1]; fs.Save(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = fs.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method EditFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "NewFlow": //创建新流程. Flow fl = new Flow(); try { string[] ps = para1.Split(','); if (ps.Length != 5) { throw new Exception("@创建流程参数错误"); } string fk_floSort = ps[0]; //类别编号. string flowName = ps[1]; // 流程名称. DataStoreModel dataSaveModel = (DataStoreModel)int.Parse(ps[2]); //数据保存方式。 string pTable = ps[3]; // 物理表名。 string FlowMark = ps[4]; // 流程标记. fl.DoNewFlow(fk_floSort, flowName, dataSaveModel, pTable, FlowMark); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = new { no = fl.No, name = fl.Name } })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewFlow Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelFlow": //删除流程. try { return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = WorkflowDefintionManager.DeleteFlowTemplete(para1) })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelFlowSort": try { FlowSort delfs = new FlowSort(); delfs.No = para1; delfs.Delete(); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelNode": try { if (!string.IsNullOrEmpty(para1)) { BP.WF.Node delNode = new BP.WF.Node(int.Parse(para1)); delNode.Delete(); } else { throw new Exception("@参数错误:" + para1); } } catch (Exception ex) { return("err:" + ex.Message); } return(null); case "GetSettings": return(SystemConfig.AppSettings[para1]); case "SaveFlowFrm": //保存独立表单. Entity en = null; try { AtPara ap = new AtPara(para1); string enName = ap.GetValStrByKey("EnName"); string pk = ap.GetValStrByKey("PKVal"); en = ClassFactory.GetEn(enName); en.ResetDefaultVal(); if (en == null) { throw new Exception("无效的类名:" + enName); } if (string.IsNullOrEmpty(pk) == false) { en.PKVal = pk; en.RetrieveFromDBSources(); } foreach (string key in ap.HisHT.Keys) { if (key == "PKVal") { continue; } en.SetValByKey(key, ap.HisHT[key].ToString().Replace('^', '@')); } en.Save(); return(en.PKVal as string); } catch (Exception ex) { if (en != null) { en.CheckPhysicsTable(); } return("Error:" + ex.Message); } case "ChangeNodeType": var p = para1.Split(','); try { if (p.Length != 3) { throw new Exception("@修改节点类型参数错误"); } //var sql = "UPDATE WF_Node SET Icon='{0}' WHERE FK_Flow='{1}' AND NodeID='{2}'"; var sql = "UPDATE WF_Node SET RunModel={0} WHERE FK_Flow='{1}' AND NodeID={2}"; DBAccess.RunSQL(string.Format(sql, p[0], p[1], p[2])); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "ChangeNodeIcon": p = para1.Split(','); try { if (p.Length != 3) { throw new Exception("@修改节点图标参数错误"); } var sql = "UPDATE WF_Node SET Icon='{0}' WHERE FK_Flow='{1}' AND NodeID={2}"; DBAccess.RunSQL(string.Format(sql, p[0], p[1], p[2])); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } default: throw new Exception("@没有约定的执行标记:" + doWhat); } }
public string Do(string doWhat, string para1, bool isLogin) { // 如果admin账户登陆时有错误发生,则返回错误信息 var result = LetAdminLogin("CH", isLogin); if (string.IsNullOrEmpty(result) == false) { return(result); } switch (doWhat) { case "GenerFlowTemplete": Flow temp = new BP.WF.Flow(para1); return(null); case "NewFrmSort": BP.Sys.FrmSort frmSort = null; try { frmSort = new FrmSort(); frmSort.No = "01"; frmSort.Name = para1; frmSort.No = frmSort.GenerNewNo; frmSort.Insert(); return(null); } catch (Exception ex) { return("Do Method NewFlowSort Branch has a error , para:\t" + para1 + ex.Message); } case "NewFlowSort": BP.WF.FlowSort fs = null; try { fs = new FlowSort(); fs.Name = para1; fs.No = fs.GenerNewNo; fs.Insert(); return(fs.No); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(null); } case "EditFlowSort": try { var para = para1.Split(','); fs = new FlowSort(para[0]); fs.Name = para[1]; fs.Save(); return(fs.No); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method EditFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(null); } case "NewFlow": Flow fl = new Flow(); try { string[] ps = para1.Split(','); if (ps.Length != 5) { throw new Exception("@创建流程参数错误"); } string fk_floSort = ps[0]; string flowName = ps[1]; DataStoreModel dataSaveModel = (DataStoreModel)int.Parse(ps[2]); string pTable = ps[3]; string flowCode = ps[4]; fl.DoNewFlow(fk_floSort, flowName, dataSaveModel, pTable, flowCode); return(fl.No + ";" + fl.Name); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewFlow Branch has a error , para:\t" + para1 + ex.Message); return(ex.Message); } case "DelFlow": BP.WF.Flow fl1 = new BP.WF.Flow(para1); try { fl1.DoDelete(); return(null); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelFlow Branch has a error , para:\t" + para1 + ex.Message); return(ex.Message); } case "DelLable": BP.WF.LabNote ln = new BP.WF.LabNote(para1); try { ln.Delete(); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelLable Branch has a error , para:\t" + para1 + ex.Message); } return(null); case "DelFlowSort": try { FlowSort delfs = new FlowSort(para1); delfs.Delete(); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelFlowSort Branch has a error , para:\t" + para1 + ex.Message); } return(null); case "NewNode": try { BP.WF.Flow fl11 = new BP.WF.Flow(para1); BP.WF.Node node = new BP.WF.Node(); node.FK_Flow = ""; node.X = 0; node.Y = 0; node.Insert(); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewNode Branch has a error , para:\t" + para1 + ex.Message); } return(null); case "DelNode": try { if (!string.IsNullOrEmpty(para1)) { BP.WF.Node delNode = new BP.WF.Node(int.Parse(para1)); delNode.Delete(); } } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelNode Branch has a error , para:\t" + para1 + ex.Message); } return(null); case "NewLab": BP.WF.LabNote lab = new BP.WF.LabNote();; try { lab.FK_Flow = para1; lab.MyPK = BP.DA.DBAccess.GenerOID().ToString(); lab.Insert(); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewLab Branch has a error , para:\t" + para1 + ex.Message); } return(lab.MyPK); case "DelLab": try { BP.WF.LabNote dellab = new BP.WF.LabNote(); dellab.MyPK = para1; dellab.Delete(); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelLab Branch has a error , para:\t" + para1 + ex.Message); } return(null); case "GetSettings": return(SystemConfig.AppSettings[para1]); case "GetFlows": string sqls = "SELECT NO,NAME FROM WF_FlowSort"; sqls += "@SELECT No,Name,FK_FlowSort FROM WF_Flow"; return(RunSQLReturnTableS(sqls)); case "SaveFlowFrm": Entity en = null; try { AtPara ap = new AtPara(para1); string enName = ap.GetValStrByKey("EnName"); string pk = ap.GetValStrByKey("PKVal"); en = ClassFactory.GetEn(enName); en.ResetDefaultVal(); if (en == null) { throw new Exception("无效的类名:" + enName); } if (string.IsNullOrEmpty(pk) == false) { en.PKVal = pk; en.RetrieveFromDBSources(); } foreach (string key in ap.HisHT.Keys) { if (key == "PKVal") { continue; } en.SetValByKey(key, ap.HisHT[key].ToString().Replace('^', '@')); } en.Save(); return(en.PKVal as string); } catch (Exception ex) { if (en != null) { en.CheckPhysicsTable(); } return("Error:" + ex.Message); } case "ReleaseToFTP": // 暂时注释,下次更新ftp功能时会得新编译 。 //var args = para1.Split(','); //var binaryData = Convert.FromBase64String(args[1]); //var imageFilePath = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath) + "/Temp/" + args[0] + ".jpg"; //if (File.Exists(imageFilePath)) //{ // File.Delete(imageFilePath); //} //System.IO.Directory.CreateDirectory( // Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath) + "/Temp"); //var stream = new System.IO.FileStream(imageFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); //stream.Write(binaryData, 0, binaryData.Length); //stream.Close(); //var xmlFilePath = FlowTemplete_Gener(args[0], true); //string remoteDr = "/" + ConfigurationSettings.AppSettings["UserIdentifier"];; //var ftp = new FtpConnection(); //try //{ // string ftpIP = ConfigurationSettings.AppSettings["FTPServerIP"]; // string email = ConfigurationSettings.AppSettings["FTPUserEmail"]; // Session session = new Session(); // session.Server = ftpIP; // session.Connect("anonymous", "*****@*****.**"); // ftp.Connect(ftpIP, "anonymous", email); // remoteDr = remoteDr; // if(!ftp.DirectoryExist(remoteDr)) // { // ftp.CreateDirectory(remoteDr); // } // ftp.SetCurrentDirectory(remoteDr); // ftp.PutFile(imageFilePath, remoteDr); // return string.Empty;//上传成功 //} //catch (Exception err) //{ // return err.Message;//上传失败 //} //finally //{ // ftp.Close(); //} return(string.Empty); default: throw null; } }
static TestHelper() { SysAppModel = new ApplicationModel("appbox", Consts.SYS, Consts.SYS_APP_ID); AdminPermissionModel = new PermissionModel(Consts.SYS_PERMISSION_ADMIN_ID, "Admin"); DeveloperPermissionModel = new PermissionModel(Consts.SYS_PERMISSION_DEVELOPER_ID, "Developer"); OrderStatusModel = new EnumModel(SYS_ENUM_MODEL_ID | (1 << IdUtil.MODELID_SEQ_OFFSET), "OrderStatus"); OrderStatusModel.Items.Add(new EnumModelItem("New", 0)); OrderStatusModel.Items.Add(new EnumModelItem("Paid", 1)); EmploeeModel = new EntityModel(Consts.SYS_EMPLOEE_MODEL_ID, Consts.EMPLOEE, EntityStoreType.StoreWithMvcc); var name = new DataFieldModel(EmploeeModel, Consts.NAME, EntityFieldType.String); EmploeeModel.AddSysMember(name, Consts.EMPLOEE_NAME_ID); var account = new DataFieldModel(EmploeeModel, Consts.ACCOUNT, EntityFieldType.String); account.AllowNull = true; EmploeeModel.AddSysMember(account, Consts.EMPLOEE_ACCOUNT_ID); var password = new DataFieldModel(EmploeeModel, Consts.PASSWORD, EntityFieldType.Binary); password.AllowNull = true; EmploeeModel.AddSysMember(password, Consts.EMPLOEE_PASSWORD_ID); //Add indexes var ui_account_pass = new EntityIndexModel(EmploeeModel, "UI_Account_Password", true, new FieldWithOrder[] { new FieldWithOrder(Consts.EMPLOEE_ACCOUNT_ID) }, new ushort[] { Consts.EMPLOEE_PASSWORD_ID }); EmploeeModel.SysStoreOptions.AddSysIndex(EmploeeModel, ui_account_pass, Consts.EMPLOEE_UI_ACCOUNT_ID); //测试用分区表 VehicleStateModel = new EntityModel(((ulong)Consts.SYS_APP_ID << 32) | 18, "VehicleState", EntityStoreType.StoreWithMvcc); var vid = new DataFieldModel(VehicleStateModel, "VehicleId", EntityFieldType.Int32); VehicleStateModel.AddMember(vid); var lng = new DataFieldModel(VehicleStateModel, "Lng", EntityFieldType.Float); VehicleStateModel.AddMember(lng); var lat = new DataFieldModel(VehicleStateModel, "Lat", EntityFieldType.Float); VehicleStateModel.AddMember(lat); var pks = new PartitionKey[1]; pks[0] = new PartitionKey() { MemberId = vid.MemberId, OrderByDesc = false }; VehicleStateModel.SysStoreOptions.SetPartitionKeys(VehicleStateModel, pks); //测试树状结构 ulong orgUnitModelId = ((ulong)Consts.SYS_APP_ID << 32) | 19; OrgUnitModel = new EntityModel(orgUnitModelId, "OrgUnit", EntityStoreType.StoreWithMvcc); var ouName = new DataFieldModel(OrgUnitModel, "Name", EntityFieldType.String); OrgUnitModel.AddSysMember(ouName, 1 << IdUtil.MEMBERID_SEQ_OFFSET); var parentId = new DataFieldModel(OrgUnitModel, "ParentId", EntityFieldType.EntityId, true); parentId.AllowNull = true; OrgUnitModel.AddSysMember(parentId, 2 << IdUtil.MEMBERID_SEQ_OFFSET); var parent = new EntityRefModel(OrgUnitModel, "Parent", orgUnitModelId, new ushort[] { parentId.MemberId }); parent.AllowNull = true; OrgUnitModel.AddSysMember(parent, 3 << IdUtil.MEMBERID_SEQ_OFFSET); var childs = new EntitySetModel(OrgUnitModel, "Childs", orgUnitModelId, parent.MemberId); OrgUnitModel.AddSysMember(childs, 4 << IdUtil.MEMBERID_SEQ_OFFSET); //----以下测试映射至SqlStore的实体--- SqlStoreModel = new DataStoreModel(DataStoreKind.Sql, "appbox.Store.PostgreSQL;appbox.Store.PgSqlStore", "DemoDB"); ulong cityModelId = ((ulong)Consts.SYS_APP_ID << 32) | 25; CityModel = new EntityModel(cityModelId, "City", new SqlStoreOptions(SqlStoreModel.Id)); var cityCode = new DataFieldModel(CityModel, "Code", EntityFieldType.Int32); CityModel.AddMember(cityCode); var cityName = new DataFieldModel(CityModel, "Name", EntityFieldType.String); CityModel.AddMember(cityName); var cityPerson = new DataFieldModel(CityModel, "Persons", EntityFieldType.Int32); CityModel.AddMember(cityPerson); var cityPk = new List <FieldWithOrder>(); cityPk.Add(new FieldWithOrder { MemberId = cityCode.MemberId, OrderByDesc = false }); CityModel.SqlStoreOptions.SetPrimaryKeys(CityModel, cityPk); ulong customerModelId = ((ulong)Consts.SYS_APP_ID << 32) | 26; CustomerModel = new EntityModel(customerModelId, "Customer", new SqlStoreOptions(SqlStoreModel.Id)); var customerId = new DataFieldModel(CustomerModel, "Id", EntityFieldType.Int32); CustomerModel.AddMember(customerId); var customerName = new DataFieldModel(CustomerModel, "Name", EntityFieldType.String); CustomerModel.AddMember(customerName); var customerCityId = new DataFieldModel(CustomerModel, "CityId", EntityFieldType.Int32, true); CustomerModel.AddMember(customerCityId); var customerCity = new EntityRefModel(CustomerModel, "City", cityModelId, new ushort[] { customerCityId.MemberId }); CustomerModel.AddMember(customerCity); var customerPk = new List <FieldWithOrder>(); customerPk.Add(new FieldWithOrder { MemberId = customerId.MemberId, OrderByDesc = false }); CustomerModel.SqlStoreOptions.SetPrimaryKeys(CustomerModel, customerPk); ulong orderModelId = ((ulong)Consts.SYS_APP_ID << 32) | 27; OrderModel = new EntityModel(orderModelId, "Order", new SqlStoreOptions(SqlStoreModel.Id)); var orderId = new DataFieldModel(OrderModel, "Id", EntityFieldType.Int32); OrderModel.AddMember(orderId); var orderCustomerId = new DataFieldModel(OrderModel, "CustomerId", EntityFieldType.Int32, true); OrderModel.AddMember(orderCustomerId); var orderCustomer = new EntityRefModel(OrderModel, "Customer", customerModelId, new ushort[] { orderCustomerId.MemberId }); OrderModel.AddMember(orderCustomer); var orderPk = new List <FieldWithOrder>(); orderPk.Add(new FieldWithOrder { MemberId = orderId.MemberId, OrderByDesc = false }); OrderModel.SqlStoreOptions.SetPrimaryKeys(OrderModel, orderPk); }
internal DataStoreNode(DataStoreModel model, DesignHub hub) { Model = model ?? throw new ArgumentNullException(nameof(model)); RoslynDocumentId = DocumentId.CreateNewId(hub.TypeSystem.ServiceBaseProjectId); }
internal async Task LoadNodesAsync() { if (Interlocked.CompareExchange(ref _loadingFlag, 1, 0) != 0) { throw new Exception("DesignTree are loading."); } //先判断是否已经加载过,是则清空准备重新加载 if (Nodes.Count > 0) { DesignHub.ResetTypeSystem(); Nodes.Clear(); } //开始加载 StoreRootNode = new DataStoreRootNode(this); Nodes.Add(StoreRootNode); AppRootNode = new ApplicationRootNode(this); Nodes.Add(AppRootNode); //先加载签出信息及StagedModels _checkouts = await CheckoutService.LoadAllAsync(); Staged = await StagedService.LoadStagedAsync(onlyModelsAndFolders : true); var amodels = await Store.ModelStore.LoadAllApplicationAsync(); var applicationModels = new List <ApplicationModel>(amodels); applicationModels.Sort((a, b) => a.Name.CompareTo(b.Name)); var mfolders = await Store.ModelStore.LoadAllFolderAsync(); var folders = new List <ModelFolder>(mfolders); //从staged中添加新建的并更新修改的文件夹 Staged.UpdateFolders(folders); var mmodels = await Store.ModelStore.LoadAllModelAsync(); var models = new List <ModelBase>(mmodels); #if !FUTURE //加载默认存储模型 var defaultStoreType = Store.SqlStore.Default.GetType(); var defaultStoreModel = new DataStoreModel(DataStoreKind.Sql, $"{defaultStoreType.Assembly.GetName().Name};{defaultStoreType.Name}", "Default"); defaultStoreModel.NameRules = DataStoreNameRules.AppPrefixForTable; //defaultStoreModel.Settings = ""; //TODO:fix settings defaultStoreModel.AcceptChanges(); models.Add(defaultStoreModel); #endif //加载staged中新建的模型,可能包含DataStoreModel models.AddRange(Staged.FindNewModels()); //加入AppModels节点 foreach (var app in applicationModels) { AppRootNode.Nodes.Add(new ApplicationNode(this, app)); } //加入Folders foreach (var f in folders) { FindModelRootNode(f.AppId, f.TargetModelType).AddFolder(f); } //加入Models Staged.RemoveDeletedModels(models); //先移除已删除的 var allModelNodes = new List <ModelNode>(models.Count); foreach (var m in models) { if (m.ModelType == ModelType.DataStore) { var dsModel = (DataStoreModel)m; var dsNode = StoreRootNode.AddModel(dsModel, DesignHub); DesignHub.TypeSystem.CreateStoreDocument(dsNode); } else { allModelNodes.Add(FindModelRootNode(m.AppId, m.ModelType).AddModel(m)); } } //在所有节点加载完后创建模型对应的RoslynDocument foreach (var n in allModelNodes) { await DesignHub.TypeSystem.CreateModelDocumentAsync(n); } Interlocked.Exchange(ref _loadingFlag, 0); //清空Staged Staged = null; #if DEBUG ThreadPool.QueueUserWorkItem(s => { DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ModelProjectId); //DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.SyncSysServiceProjectId); DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ServiceBaseProjectId); }); #endif }
/// <summary> /// 树节点管理 /// </summary> public string Do() { string doWhat = getUTF8ToString("doWhat"); string para1 = getUTF8ToString("para1"); // 如果admin账户登陆时有错误发生,则返回错误信息 var result = LetAdminLogin("CH", true); if (string.IsNullOrEmpty(result) == false) { return(result); } switch (doWhat) { case "GetFlowSorts": //获取所有流程类型 try { FlowSorts flowSorts = new FlowSorts(); flowSorts.RetrieveAll(FlowSortAttr.Idx); return(BP.Tools.Entitis2Json.ConvertEntitis2GenerTree(flowSorts, "0")); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "NewSameLevelFrmSort": //创建同级别的 表单树 目录. SysFormTree frmSort = null; try { var para = para1.Split(','); frmSort = new SysFormTree(para[0]); string sameNodeNo = frmSort.DoCreateSameLevelNode().No; frmSort = new SysFormTree(sameNodeNo); frmSort.Name = para[1]; frmSort.Update(); return(null); } catch (Exception ex) { return("Do Method NewFormSort Branch has a error , para:\t" + para1 + ex.Message); } case "NewSubLevelFrmSort": //创建子级别的 表单树 目录. SysFormTree frmSortSub = null; try { var para = para1.Split(','); frmSortSub = new SysFormTree(para[0]); string sameNodeNo = frmSortSub.DoCreateSubNode().No; frmSortSub = new SysFormTree(sameNodeNo); frmSortSub.Name = para[1]; frmSortSub.Update(); return(null); } catch (Exception ex) { return("Do Method NewSubLevelFrmSort Branch has a error , para:\t" + para1 + ex.Message); } case "NewSameLevelFlowSort": //创建同级别的 流程树 目录. FlowSort fs = null; try { var para = para1.Split(','); fs = new FlowSort(para[0].Replace("F", "")); //传入的编号多出F符号,需要替换掉 string sameNodeNo = fs.DoCreateSameLevelNode().No; fs = new FlowSort(sameNodeNo); fs.Name = para[1]; fs.Update(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = "F" + fs.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewSameLevelFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "NewSubFlowSort": //创建子级别的 流程树 目录. try { var para = para1.Split(','); FlowSort fsSub = new FlowSort(para[0].Replace("F", ""));//传入的编号多出F符号,需要替换掉 string subNodeNo = fsSub.DoCreateSubNode().No; FlowSort subFlowSort = new FlowSort(subNodeNo); subFlowSort.Name = para[1]; subFlowSort.Update(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = "F" + subFlowSort.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewSubFlowSort Branch has a error , para:\t" + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "EditFlowSort": //编辑表单树. try { var para = para1.Split(','); fs = new FlowSort(para[0].Replace("F", ""));//传入的编号多出F符号,需要替换掉 fs.Name = para[1]; fs.Save(); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = fs.No })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method EditFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "NewFlow": //创建新流程. try { string[] ps = para1.Split(','); if (ps.Length != 6) { throw new Exception("@创建流程参数错误"); } string fk_floSort = ps[0]; //类别编号. fk_floSort = fk_floSort.Replace("F", ""); //传入的编号多出F符号,需要替换掉 string flowName = ps[1]; // 流程名称. DataStoreModel dataSaveModel = (DataStoreModel)int.Parse(ps[2]); //数据保存方式。 string pTable = ps[3]; // 物理表名。 string flowMark = ps[4]; // 流程标记. string flowVer = ps[5]; // 流程版本 string FK_Flow = BP.BPMN.Glo.NewFlow(fk_floSort, flowName, dataSaveModel, pTable, flowMark, flowVer); return (Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = string.Empty, data = new { no = FK_Flow, name = flowName } })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method NewFlow Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelFlow": //删除流程. try { return(Newtonsoft.Json.JsonConvert.SerializeObject( new { success = true, msg = WorkflowDefintionManager.DeleteFlowTemplete(para1) })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelFlowSort": try { string FK_FlowSort = para1.Replace("F", ""); string forceDel = getUTF8ToString("force"); FlowSort delfs = new FlowSort(); delfs.No = FK_FlowSort; //强制删除,不需判断是否含有子项。 if (forceDel == "true") { delfs.DeleteFlowSortSubNode_Force(); delfs.Delete(); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true, reason = "" })); } //判断是否包含子类别 if (delfs.HisSubFlowSorts != null && delfs.HisSubFlowSorts.Count > 0) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, reason = "havesubsorts", msg = "此类别下包含子类别。" })); } //判断是否包含工作流程 if (delfs.HisFlows != null && delfs.HisFlows.Count > 0) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, reason = "haveflows", msg = "此类别下包含流程。" })); } //执行删除 delfs.Delete(); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true, reason = "" })); } catch (Exception ex) { BP.DA.Log.DefaultLogWriteLineError("Do Method DelFlowSort Branch has a error , para:\t" + para1 + ex.Message); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "DelNode": try { if (!string.IsNullOrEmpty(para1)) { BP.WF.Node delNode = new BP.WF.Node(int.Parse(para1)); delNode.Delete(); } else { throw new Exception("@参数错误:" + para1); } } catch (Exception ex) { return("err:" + ex.Message); } return(null); case "SetBUnit": try { if (!string.IsNullOrEmpty(para1)) { BP.WF.Node nd = new BP.WF.Node(int.Parse(para1)); nd.IsTask = !nd.IsBUnit; nd.Update(); } else { throw new Exception("@参数错误:" + para1); } } catch (Exception ex) { return("err:" + ex.Message); } return(null); case "GetSettings": return(SystemConfig.AppSettings[para1]); case "SaveFlowFrm": //保存流程表单. Entity en = null; try { AtPara ap = new AtPara(para1); string enName = ap.GetValStrByKey("EnName"); string pk = ap.GetValStrByKey("PKVal"); en = ClassFactory.GetEn(enName); en.ResetDefaultVal(); if (en == null) { throw new Exception("无效的类名:" + enName); } if (string.IsNullOrEmpty(pk) == false) { en.PKVal = pk; en.RetrieveFromDBSources(); } foreach (string key in ap.HisHT.Keys) { if (key == "PKVal") { continue; } en.SetValByKey(key, ap.HisHT[key].ToString().Replace('^', '@')); } en.Save(); return(en.PKVal as string); } catch (Exception ex) { if (en != null) { en.CheckPhysicsTable(); } return("Error:" + ex.Message); } case "ChangeNodeType": var p = para1.Split(','); try { if (p.Length != 3) { throw new Exception("@修改节点类型参数错误"); } //var sql = "UPDATE WF_Node SET Icon='{0}' WHERE FK_Flow='{1}' AND NodeID='{2}'"; var sql = "UPDATE WF_Node SET RunModel={0} WHERE FK_Flow='{1}' AND NodeID={2}"; DBAccess.RunSQL(string.Format(sql, p[0], p[1], p[2])); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } case "ChangeNodeIcon": p = para1.Split(','); try { if (p.Length != 3) { throw new Exception("@修改节点图标参数错误"); } var sql = "UPDATE WF_Node SET Icon='{0}' WHERE FK_Flow='{1}' AND NodeID={2}"; DBAccess.RunSQL(string.Format(sql, p[0], p[1], p[2])); return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true })); } catch (Exception ex) { return(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = ex.Message })); } default: throw new Exception("@没有约定的执行标记:" + doWhat); } }