public async Task <IActionResult> PutPoolAction([FromRoute] int id, [FromBody] PoolAction poolAction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != poolAction.idPool) { return(BadRequest()); } _context.Entry(poolAction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PoolActionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostPoolAction([FromBody] PoolAction poolAction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PoolAction.Add(poolAction); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPoolAction", new { id = poolAction.idPool }, poolAction)); }
/// <summary> /// 新增或更新Pool的數據 Add or update pool data. /// </summary> /// <param name="Action">change pool behaivor.</param> /// <param name="Items">communication enumerable item.</param> /// <returns></returns> private bool ChangePoolData(PoolAction Action, IDictionary <string, object> Items) { bool result = false; // declare remote server response object .. KeyValuePair <string, object> responseObject; do { // confirm current resquest status .. if (EnvComm.CanRequest) { // declare package sent data type .. IList <object> packaged = null; switch (Action) { case PoolAction.Add: case PoolAction.Update: // package sent data .. packaged = EnvComm.Package(Client2Server.CommunicationType.POOLINFO, Items); break; case PoolAction.Delete: // package sent data .. packaged = EnvComm.Package(Client2Server.CommunicationType.DELETEPOOLINFO, Items); break; } // wait for result .. responseObject = EnvComm.Request(packaged); break; } } while (true); // 確認正確結果 confirm correct result .. if (responseObject.Key.Substring(0, 1).Equals("+")) { result = true; } return(result); }
private void ExecuteRemoveListener(string id, PoolEvent evt, PoolAction target) { if (!_pools.ContainsKey(id)) { Debug.LogWarning("No {id} pool found."); return; } var pool = _pools[id]; if (evt == PoolEvent.OnAquire) { pool.onPoolableAquire -= target; } else { pool.onPoolableRelease -= target; } }
private Tag GetTagInstance(PoolAction action, string name, Type type, bool doPostProcessing, bool @lock, bool permanent, bool addToPool) { return(GetTagInstance(action, name, type, doPostProcessing, @lock, permanent, addToPool, "")); }
/// <summary> /// Creates an instance of a Tag object, optionally loading pre-existing data /// from one of the pool's internal ILibrary objects. /// </summary> private Tag GetTagInstance(PoolAction action, string name, Type type, bool doPostProcessing, bool @lock, bool permanent, bool addToPool, string gameID) { // Parse the name TagPath path = new TagPath(name); if (path.Game == "") { path.Game = gameID; } if (path.Location == TagLocation.Auto) { name = QualifyScope(path.Game, path.Path + "." + path.Extension); if (String.IsNullOrEmpty(name)) { throw new TagNotFoundException("Tag {0}.{1} does not exist.", path.Path, path.Extension); } path = new TagPath(name); } name = path.Path; // make sure that type is inheriting from Tag if (!type.IsSubclassOf(typeof(Tag))) { throw new PoolException("Cannot instantiate a tag of type {0} because it does not inherit from {1}.", type.Name, typeof(Tag).Name); } Tag match = tags.LocateTag(name, type); if (match != null) { if (action == PoolAction.CreateNew) { throw new TagAlreadyExistsException("The tag {0} of type {1} already exists in this pool. It cannot be created again.", name, type.Name); } match.ReferenceCount++; if (doPostProcessing && !match.PostProcessed) { match.DoPostProcess(); } return(match); } // Create the tag object. Tag tag = Activator.CreateInstance(GetUpdatedType(type, path.Game)) as Tag; tag.TagPath = path; tag.Initialize(name, idCurrent++, path.Game, !permanent, this); path.Extension = tag.FileExtension; tag.ReferenceCount = 1; tag.NotReferenced += new EventHandler(DisposeOfTag); tag.Locked = @lock; if (action == PoolAction.LoadExisting) { try { byte[] meta = GetTagBinary(path); if (meta == null) { throw new TagNotFoundException("The tag {0} of type {1} was requested for open and was not found.", name, type.Name); } else { tag.Load(meta); } } catch (Exception ex) { throw new PoolException(ex, "An error occured during the deserialization of {0} of type {1}.", name, type.Name); } if (doPostProcessing) { try { tag.DoPostProcess(); } catch (Exception ex) { throw new PoolException(ex, "An error occured during postprocessing of {0} of type {1}.", name, type.Name); } } } else { tag.New(); } // If the deserialization and postprocessing were successful, add the tag to the pool. if (addToPool) { tags.Add(tag); } return(tag); }
/// <summary> /// Removes a listener of <paramref name="id"/>'s <paramref name="evt"/> /// </summary> /// <param name="id">The poolable ID</param> /// <param name="evt">The event type</param> /// <param name="target">The callback method to be removed</param> public static void RemoveListener(string id, PoolEvent evt, PoolAction target) { Instance.ExecuteRemoveListener(id, evt, target); }
/// <inheritdoc cref="ExecuteRemoveListener(string, PoolEventType, PoolAction)"/> public static void RemoveListener(Enum idEnum, PoolEventType evt, PoolAction target) { Instance.ExecuteRemoveListener(idEnum.ToString(), evt, target); }
/// <inheritdoc cref="ExecuteAddListener(string, PoolEventType, PoolAction)"/> public static void AddListener(string id, PoolEventType evt, PoolAction target) { Instance.ExecuteAddListener(id, evt, target); }