static void Read() { string data = ReadFile(Path(SaveModelFileName)); if (string.IsNullOrEmpty(data)) { Model = new SaveModel(); CharacterAry.Clear(); for (int i = 0; i < Model.CharacterAry.Count; i++) { CharacterAry.Add(Model.CharacterAry[i].id, Model.CharacterAry[i]); } Write(); Read(); } else { Model = JsonUtility.FromJson <SaveModel>(data); CharacterAry.Clear(); for (int i = 0; i < Model.CharacterAry.Count; i++) { CharacterAry.Add(Model.CharacterAry[i].id, Model.CharacterAry[i]); } } }
public void Save(string file) { // чтобы не сохранять terrain var needToSaveObjects = new List <GameObject>(); foreach (var obj in objects) { if (obj.Name.Equals("Terrain")) { continue; } needToSaveObjects.Add(obj); } var saveModel = new SaveModel { Objects = needToSaveObjects, Date = DateTime.Now }; var jsonOpt = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects, Formatting = Formatting.Indented }; var jsonData = JsonConvert.SerializeObject(saveModel, jsonOpt); File.WriteAllText(file, jsonData); }
public override WebResponseContent Add(SaveModel saveDataModel) { WebResponseContent responseContent = WebResponseContent.Instance; AddOnExecuting = (NewsPraise newsPraise, object list) => { if (newsPraise.NewsId > 0) { if (repository.Exists(m => m.NewsId == newsPraise.NewsId && m.CreateID == UserContext.Current.UserId)) { return(responseContent.Error("已赞过了..")); } } else { return(responseContent.Error("未获取到点赞文章..")); } return(responseContent.OK()); }; AddOnExecuted = (NewsPraise user, object list) => { return(responseContent.OK("点赞成功.")); }; return(base.Add(saveDataModel)); }
/// <summary> /// 编辑操作 /// </summary> /// <param name="saveModel"></param> /// <returns></returns> public override WebResponseContent Update(SaveModel saveModel) { //此处saveModel是从前台提交的原生数据,可对数据进修改过滤 UpdateOnExecute = (SaveModel model) => { ////这里的设置配合下面order.Remark = "888"代码位置使用 // saveModel.MainData.TryAdd("Remark", "1231"); //如果不想前端提交某些可以编辑的字段的值,直接移除字段 // saveModel.MainData.Remove("字段"); //如果返回false,后面代码不会再执行 return(webResponse.OK()); }; //编辑方法保存数据库前处理 UpdateOnExecuting = (SellOrder order, object addList, object updateList, List <object> delKeys) => { if (order.TranNo == "2019000001810001") { //如果设置code=-1会强制返回,不再继续后面的操作,2021.07.04更新LambdaExtensions文件后才可以使用此属性 //webResponse.Code = "-1"; // webResponse.Message = "测试强制返回"; //return webResponse.OK(); return(webResponse.Error("不能更新此[" + order.TranNo + "]单号")); } ////如果要手动设置某些字段的值,值不是前端提交的(代码生成器里面编辑行必须设置为0并生成model),如Remark字段: ////注意必须设置上面saveModel.MainData.TryAdd("Remark", "1231") //order.Remark = "888"; //新增的明细表 List <SellOrderList> add = addList as List <SellOrderList>; //修改的明细表 List <SellOrderList> update = updateList as List <SellOrderList>; //删除明细表Id var guids = delKeys?.Select(x => (Guid)x); return(webResponse.OK()); }; //编辑方法保存数据库后处理 //此方法中已开启了事务,如果在此方法中做其他数据库操作,请不要再开启事务 // 在保存数据库后的操作,此时已进行数据提交,但未提交事务,如果返回false,则会回滚提交 UpdateOnExecuted = (SellOrder order, object addList, object updateList, List <object> delKeys) => { //新增的明细 List <SellOrderList> add = addList as List <SellOrderList>; //修改的明细 List <SellOrderList> update = updateList as List <SellOrderList>; //删除的行的主键 var guids = delKeys?.Select(x => (Guid)x); return(webResponse.OK()); }; return(base.Update(saveModel)); }
public void Load() { ClearSavedPatients(); var json = PlayerPrefs.GetString("saveData", null); if (string.IsNullOrWhiteSpace(json)) { this.saveModel = new SaveModel() { patients = new List <Patient>() { } }; } else { this.saveModel = JsonUtility.FromJson <SaveModel>(json); } foreach (Transform child in this.patientsList.transform) { GameObject.Destroy(child.gameObject); } for (int i = 0; i < this.saveModel.patients.Count; i++) { var clone = GameObject.Instantiate(patientPrefab, patientsList); var patientController = clone.GetComponent <PatientInfoController>(); patientController.Initialize(this.saveModel.patients[i], calendarController); } }
/// <summary> /// 自定义保存从表数据逻辑 /// </summary> /// <param name="saveDataModel"></param> /// <returns></returns> public override WebResponseContent Add(SaveModel saveDataModel) { //校验从表配置 ValidateExtra(saveDataModel); if (!_webResponse.Status) { return(_webResponse); } //取出校验完成后的从表1.2的数据 TableExtra tableExtra = _webResponse.Data as TableExtra; //保存到数据库前 AddOnExecuting = (App_ReportPrice price, object obj) => { return(WebResponseContent.Instance.OK()); }; //App_ReportPrice 此处已经提交了数据库,处于事务中 AddOnExecuted = (App_ReportPrice price, object obj) => { //在此操作tableExtra从表信息 return(WebResponseContent.Instance.OK()); }; return(base.Add(saveDataModel)); }
private WebResponseContent Add <TDetail>(SaveModel saveDataModel) where TDetail : class { T mainEntity = saveDataModel.MainData.DicToEntity <T>(); //验证明细 string reslut = typeof(TDetail).ValidateDicInEntity(saveDataModel.DetailData, true, false, new string[] { TProperties.GetKeyName() }); if (reslut != string.Empty) { return(Response.Error(reslut)); } List <TDetail> list = saveDataModel.DetailData.DicToList <TDetail>(); Response = Add <TDetail>(mainEntity, list, false); //保存失败 if (!Response.Status) { Logger.Error(LoggerType.Add, saveDataModel.Serialize() + Response.Message); return(Response); } PropertyInfo propertyKey = typeof(T).GetKeyProperty(); saveDataModel.MainData[propertyKey.Name] = propertyKey.GetValue(mainEntity); Response.Data = new { data = saveDataModel.MainData, list }; return(Response.Set(ResponseType.SaveSuccess)); }
/// <summary> /// 修改系统用户资料 /// </summary> /// <param name="saveModel"></param> /// <returns></returns> public override WebResponseContent Update(SaveModel saveModel) { if (saveModel == null) { return(Response.Error(ResponseType.ParametersLack)); } if (saveModel.MainData.Count <= 1) { return(Response.Error("系统没有配置好编辑的数据,请检查model!")); } //设置修改时间,修改人的默认值 var userInfo = UserContext.Current.UserInfo; // 设置默认字段的值"CreateID", "Creator", "CreateDate","ModifyID", "Modifier", "ModifyDate" saveModel.MainData.Add("Modifier", userInfo.UserName); saveModel.MainData.Add("ModifyDate", DateTime.Now); var model = saveModel.MainData.DicToEntity <Sys_Role>(); Response.Status = repository.Sys_Role.Update(q => new Sys_Role { Dept_Id = model.Dept_Id, DeptName = model.DeptName, }, q => q.Role_Id == model.Role_Id); if (Response.Status) { return(Response.OK(ResponseType.EidtSuccess)); } return(Response); }
/// <summary> /// 添加 /// </summary> /// <param name="saveModel"></param> /// <returns></returns> public override WebResponseContent Add(SaveModel saveModel) { if (saveModel == null) { return(Response.Error(ResponseType.ParametersLack)); } if (saveModel.MainData.Count <= 1) { return(Response.Error("系统没有配置好编辑的数据,请检查model!")); } //设置修改时间,修改人的默认值 var userInfo = UserContext.Current.UserInfo; // 设置默认字段的值"CreateID", "Creator", "CreateDate","ModifyID", "Modifier", "ModifyDate" // saveModel.MainData.Add("Creator", userInfo.UserName); // saveModel.MainData.Add("CreateDate", DateTime.Now); var model = saveModel.MainData.DicToEntity <Sys_Role>(); model.Creator = userInfo.UserName; model.CreateDate = DateTime.Now; Response.Status = repository.Sys_Role.Add(model); if (Response.Status) { return(Response.OK(ResponseType.SaveSuccess)); } return(Response); }
public ValidationError?ValidateUsername(SaveModel model, bool checkUsernameExists) { if (string.IsNullOrWhiteSpace(model.Username)) { return(ValidationError.UsernameMissing); } string username = model.Username.Trim(); if (username.Length > 100) { return(ValidationError.UsernameToLong); } if (checkUsernameExists) { IUser user = _userFactory.Get(username); if (user != null) { return(ValidationError.UsernameExists); } } return(null); }
public virtual async Task <WebResponseContent> Add(SaveModel saveModel) { ResponseContent = await Task.FromResult(InvokeService("Add", new Type[] { typeof(SaveModel) }, new object[] { saveModel })) as WebResponseContent; Logger.Info(Enums.LoggerType.Add, saveModel.Serialize(), ResponseContent.Status ? "Ok" : ResponseContent.Message); return(ResponseContent); }
/// <summary> /// Exports the save based on previous save. /// (model db ids are copied). /// </summary> /// <param name="from">Save to override</param> /// <returns>Overridden save</returns> public SaveModel Export(SaveModel from) { var save = this.Export(from.Name, id: from.Id); // Transfer the database ids to new models save.Id = from.Id; save.Player.Id = from.Player.Id; if (this.levelIndex == from.LevelIndex) { // This stinks, but no time to fix :( foreach (var item in save.Items) { item.Id = from.Items .Where(i => i.InGameId == item.InGameId) .Select(i => i.Id) .First(); } foreach (var enemy in save.Enemies) { enemy.Id = from.Enemies .Where(i => i.InGameId == enemy.InGameId) .Select(i => i.Id) .First(); } } return(save); }
public override WebResponseContent Add(SaveModel saveDataModel) { if (saveDataModel.MainData.DicKeyIsNullOrEmpty("DicNo")) { return(base.Add(saveDataModel)); } string dicNo = saveDataModel.MainData["DicNo"].ToString(); if (base.repository.Exists(x => x.DicNo == dicNo)) { return(new WebResponseContent().Error("字典编号:" + dicNo + "已存在")); } base.AddOnExecuting = (Sys_Dictionary dic, object obj) => { WebResponseContent _responseData = CheckKeyValue(obj as List <Sys_DictionaryList>); if (!_responseData.Status) { return(_responseData); } dic.DbSql = SqlFilters(dic.DbSql); return(new WebResponseContent(true)); }; return(RemoveCache(base.Add(saveDataModel))); }
public override WebResponseContent Update(SaveModel saveDataModel) { if (saveDataModel.MainData.DicKeyIsNullOrEmpty("DicNo") || saveDataModel.MainData.DicKeyIsNullOrEmpty("Dic_ID")) { return(base.Add(saveDataModel)); } //判断修改的字典编号是否在其他ID存在 string dicNo = saveDataModel.MainData["DicNo"].ToString().Trim(); if (base.repository.Exists(x => x.DicNo == dicNo && x.Dic_ID != saveDataModel.MainData["Dic_ID"].GetInt())) { return(new WebResponseContent().Error($"字典编号:{ dicNo}已存在。!")); } base.UpdateOnExecuting = (Sys_Dictionary dictionary, object addList, object editList, List <object> obj) => { List <Sys_DictionaryList> listObj = new List <Sys_DictionaryList>(); listObj.AddRange(addList as List <Sys_DictionaryList>); listObj.AddRange(editList as List <Sys_DictionaryList>); WebResponseContent _responseData = CheckKeyValue(listObj); if (!_responseData.Status) { return(_responseData); } dictionary.DbSql = SqlFilters(dictionary.DbSql); return(new WebResponseContent(true)); }; return(RemoveCache(base.Update(saveDataModel))); }
public IActionResult SetConfig(Config config) { _scanner.ConfigureScanner(config); var res = _scanner.Scan(); List <string> links = new List <string>(); List <string> linksHtml = new List <string>(); foreach (var dic in res) { foreach (var linkAndHtml in dic) { links.Add(linkAndHtml.Key); linksHtml.Add(linkAndHtml.Value); } } SaveModel model = new SaveModel(); model.linksHtml = links; model.scannedLinks = linksHtml; return(View(model)); }
public virtual async Task <WebResponseContent> Update(SaveModel saveModel) { ResponseContent = await Task.Run(() => InvokeService("Update", new object[] { saveModel })) as WebResponseContent; Logger.Info(Enums.LoggerType.Edit, saveModel.Serialize(), ResponseContent.Status ? "Ok" : ResponseContent.Message); return(ResponseContent); }
public object Save2(SaveModel message) { user user = (user)HttpContext.Current.Session[ECGlobalConstants.CurrentUserMarcker]; if (user == null || user.id == 0) { return(null); } var model = DB.company_disclamer_page .FirstOrDefault(x => x.company_id == user.company_id); if (model == null) { model = new company_disclamer_page(); model.company_id = user.company_id; DB.company_disclamer_page.Add(model); } model.message_about_guidelines = message.Message; model.message_about_guidelines_created_dt = DateTime.Now; model.message_about_guidelines_user_id = user.id; DB.SaveChanges(); return(new { }); }
private static SaveModel ReplaceData(SaveModel saveModel, Dictionary <string, Dictionary <string, string> > replacements) { if (!replacements.ContainsKey("Weapons")) { return(saveModel); } var weaponReplacements = replacements["Weapons"]; if (weaponReplacements == null || weaponReplacements.Count == 0) { return(saveModel); } foreach (Team team in saveModel.Teams) { foreach (Member member in team.Members) { foreach (MemberWeapon memberWeapon in member.MemberWeapons) { if (memberWeapon.WeaponId != null && weaponReplacements.ContainsKey(memberWeapon.WeaponId)) { memberWeapon.WeaponId = weaponReplacements[memberWeapon.WeaponId]; } } } } return(saveModel); }
public ValidationError?ValidateEmail(SaveModel model) { if (string.IsNullOrWhiteSpace(model.Email)) { return(ValidationError.EmailMissing); } string email = model.Email.Trim(); if (email.Length > 250) { return(ValidationError.EmailToLong); } string pattern = @"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*" // local-part + "@" + @"((([\w]+([-\w]*[\w]+)*\.)+[a-zA-Z]+)|" // domain + @"((([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]).){3}[01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]))\z"; // or IP Address Regex regex = new Regex(pattern); Match match = regex.Match(email); if (!match.Success) { return(ValidationError.EmailWrongFormat); } return(null); }
public new async Task <ActionResult> Update([FromBody] SaveModel saveModel) { WebResponseContent responseContent = await base.Update(saveModel); responseContent.Data = responseContent.Data?.Serialize(); return(Json(responseContent)); }
public void SetFileSaving([FromBody] SaveModel person) { if (!string.IsNullOrEmpty(person.PersonId)) { _personManager.SetFileSaving(person.PersonId); } }
public virtual ActionResult Update([FromBody] SaveModel saveModel) { _baseWebResponseContent = InvokeService("Update", new object[] { saveModel }) as WebResponseContent; Logger.Info(Enums.LoggerType.Edit, saveModel.Serialize(), _baseWebResponseContent.Status ? "Ok" : _baseWebResponseContent.Message); _baseWebResponseContent.Data = _baseWebResponseContent.Data?.Serialize(); return(Json(_baseWebResponseContent)); }
public override Task <UploadReply> Upload(UploadRequest request, ServerCallContext context) { UploadReply result = new UploadReply(); try { Stream imageStream = new MemoryStream(request.File.ToByteArray()); Image originalImage = Image.FromStream(imageStream); List <Image> images = ImageFactory.CreateNewSizeImages(originalImage); SaveModel saveModel = new SaveModel() { Directory = request.Directory, FileName = request.FileName, Images = images, OriginalImage = originalImage }; var saveList = imageCollectionSaver.Save(saveModel); result.UploadPath = "upload/" + request.Directory + request.FileName; } catch (Exception ex) { result = new UploadReply() { ErrorMessage = ex.Message, HasError = true }; } return(Task.FromResult(result)); }
public override WebResponseContent Update(SaveModel saveModel) { UpdateOnExecuting = (Sys_Role role, object obj1, object obj2, List <object> obj3) => { return(ValidateRoleName(role, x => x.RoleName == role.RoleName && x.Role_Id != role.Role_Id)); }; return(RemoveCache(base.Update(saveModel))); }
private void LoadData() { if (File.Exists(savePath)) { SaveModel saveModel = JsonUtility.FromJson <SaveModel>(File.ReadAllText(savePath)); money = saveModel._money; } }
public override WebResponseContent Add(SaveModel saveDataModel) { AddOnExecuting = (Sys_Role role, object obj) => { return(ValidateRoleName(role, x => x.RoleName == role.RoleName)); }; return(RemoveCache(base.Add(saveDataModel))); }
public static SaveModel GetInstance() { if (singleInstance == null) { singleInstance = LoadSave(); } return(singleInstance); }
public async Task <IActionResult> Save([FromBody] SaveModel saveModel) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.FindByIdAsync(saveModel.UserId); IdentityResult identityResult; if (user != null) { identityResult = await _userManager.UpdateAsync(user); } else { user = new ApplicationUser { UserName = saveModel.Email, Email = saveModel.Email }; identityResult = await _userManager.CreateAsync(user, saveModel.Password); } if (identityResult.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); if (saveModel.RoleModelIds.Any()) { IList <string> existRole = await _userManager.GetRolesAsync(user); foreach (var roleModel in saveModel.RoleModelIds) { IdentityRole selectedIdentityRole = await _roleManager.FindByIdAsync(roleModel); if (selectedIdentityRole != null) { if (!existRole.Any(x => x == selectedIdentityRole.Name)) { IdentityResult newRoleResult = await _userManager.AddToRoleAsync(user, selectedIdentityRole.Name); if (newRoleResult.Succeeded) { } } } } } var token = await GenerateJwtTokenAsync(user); return(Ok(token)); } else { return(BadRequest(identityResult.Errors.Any() ? identityResult.Errors.FirstOrDefault().Description : string.Empty)); } } else { return(BadRequest(saveModel)); } }
public void UploadCusTomsDatatest() { MessageServiceHelper helper = new MessageServiceHelper(); string cusCiqNo = helper.GetCusCiqNo("0", "5100"); XDocument declDoc = XDocument.Load(@"F:\Temp\DeclMsg\DECL_FILE.xml"); SaveModel model = helper.UploadCusTomsData("130409667935", "00-21-70-67-E8-27", "1", "5100", cusCiqNo, 2, declDoc.ToString()); Assert.AreEqual <Boolean>(true, model.IsSuccess); }
public async Task <ActionResult> Add([ModelBinder] Dictionary <string, object> mainData, [ModelBinder] List <Dictionary <string, object> > detailData) { SaveModel saveModel = new SaveModel() { MainData = mainData, DetailData = detailData }; return(Json(await base.Add(saveModel))); }
public static SaveModel<Texture2DWithPos> ToTexture2D(this SaveModel<BitmapWithPos> modelIn, GraphicsDevice graphicsDevice) { SaveModel<Texture2DWithPos> modelOut = new SaveModel<Texture2DWithPos>(modelIn.Name); modelOut.Blocks.AddRange(modelIn.Blocks); foreach (SaveSubModel<BitmapWithPos> subModel in modelIn.SubModels) { modelOut.SubModels.Add(subModel.ToTexture2D(graphicsDevice)); } foreach (SaveAnimation<BitmapWithPos> animation in modelIn.Animations) { modelOut.Animations.Add(animation.ToTexture2D(graphicsDevice)); } return modelOut; }
public IHttpActionResult Put(SaveModel model) { _repo.Save(model); return Ok("yo"); }
/// <summary> /// Imports a model from the file /// <code>directoryPath+"/"+modelName+".egg"</code> /// including sub models /// </summary> /// <param name="directoryPath"></param> /// <param name="modelName"></param> /// <returns></returns> public static SaveModel<BitmapWithPos> Load(string directoryPath, string modelName) { SaveModel<BitmapWithPos> model = new SaveModel<BitmapWithPos>(modelName); using (ZipFile modelFile = new ZipFile(directoryPath + "/" + modelName + ".egg")) { using (PackagedBitmapsManager bitmapManager = new PackagedBitmapsManager(modelFile, "textures/")) { ZipEntry xmlEntry = modelFile.GetEntry("model.xml"); Stream xmlStream = modelFile.GetInputStream(xmlEntry); XDocument doc = XDocument.Load(xmlStream); XElement root = doc.Element("model"); // blocks { foreach (XElement blockElement in root.Element("blocks").Elements("block")) { Position pos = blockElement.Attribute("offset").Value.LoadPosition(); SaveBlock block = new SaveBlock(pos); model.Blocks.Add(block); block.Type = blockElement.Attribute("type").Value.LoadBlockType(); XAttribute scriptAttribute = blockElement.Attribute("script"); if (scriptAttribute != null) { block.Script = scriptAttribute.Value; } } } // imports foreach (XElement modelElement in root.Element("imports").Elements("model")) { Position offset = modelElement.Attribute("offset").Value.LoadPosition(); model.SubModels.Add(new SaveSubModel<BitmapWithPos>(Load(directoryPath, modelElement.Value), offset)); } // animations foreach (XElement animationElement in root.Element("animations").Elements("animation")) { SaveAnimation<BitmapWithPos> animation = new SaveAnimation<BitmapWithPos>(animationElement.Attribute("name").Value); animation.Facing = animationElement.Attribute("facing").Value.LoadFacing(); model.Animations.Add(animation); foreach (XElement frameElement in animationElement.Elements("frame")) { SaveFrame<BitmapWithPos> frame = new SaveFrame<BitmapWithPos>(frameElement.Attribute("duration").Value.LoadInt()); animation.Frames.Add(frame); foreach (XElement imageElement in frameElement.Elements("image")) { BitmapWithPos bitmapWithPos = new BitmapWithPos(); frame.Images.AddToFront(bitmapWithPos); bitmapWithPos.Position = imageElement.Attribute("coord").Value.LoadPoint(); bitmapWithPos.name = imageElement.Attribute("name").Value; bitmapWithPos.projectedOnto.AddRange(imageElement.Elements("projectedOnto").Select(e => model.Blocks[e.Value.LoadInt()])); bitmapWithPos.bitmap = bitmapManager[bitmapWithPos.name]; } } } } } return model; }