// POST api/values public void Post([FromBody] AssetCounter jsonValue) { if (jsonValue == null) { return; } var existingCounter = db.AssetCounters.FirstOrDefault(counter => string.Compare(counter.ClientID, jsonValue.ClientID, StringComparison.InvariantCulture) == 0 && counter.AssetType == jsonValue.AssetType && counter.AssetSubType == jsonValue.AssetSubType); using (var tx = db.Database.BeginTransaction()) { try { if (existingCounter != null) { existingCounter.Count += jsonValue.Count; } else { db.AssetCounters.Add(jsonValue); } db.SaveChanges(); tx.Commit(); } catch (Exception) { tx.Rollback(); } } }
// PUT api/values/5 public void Put(int id, [FromBody] AssetCounter jsonValue) { if (jsonValue == null) { return; } var existingCounter = db.AssetCounters.FirstOrDefault(counter => counter.AssetType == jsonValue.AssetType && counter.AssetSubType == jsonValue.AssetSubType); if (existingCounter != null) { using (var tx = db.Database.BeginTransaction()) { try { existingCounter.Count += jsonValue.Count; db.SaveChanges(); tx.Commit(); } catch (Exception) { tx.Rollback(); } } } }
private void HandlerLoadAssetBundleAsync(string bundlePath, string assetName, System.Action <string, string, Object> act) { AssetBundle ab = bundleDicts [bundlePath].asset; if (ab == null) { if (act != null) { act(bundlePath, assetName, null); } return; } Object obj = ab.LoadAsset(assetName); UnLoadAssetBundle(bundlePath); AssetCounter ac = new AssetCounter(obj, 1, bundlePath + "/" + assetName); assetDicts [bundlePath + "/" + assetName] = ac; if (act != null) { act(bundlePath, assetName, obj); } }
public static bool InvokePost(string ClientID, int assetType, int subAssetType, int count = 1) { try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(GetRestServiceBaseAddress()); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var assetCounter = new AssetCounter() { AssetType = assetType, AssetSubType = subAssetType, Count = count, ClientID = ClientID }; var response = client.PostAsJsonAsync("Values", assetCounter).Result; if (response.IsSuccessStatusCode) { return(true); } } catch (Exception ex) { throw ex; } return(false); }
/// <summary> /// Loads the object form asset bundle async. /// 外部唯一异步加载接口加载对象 /// -------------------记载完对象后会立即删除AssetBundle /// </summary> /// <param name="bundlePath">Bundle path.</param> /// <param name="assetName">Asset name.</param> /// <param name="act">Act.</param> public void LoadObjectFormAssetBundleAsync(string bundlePath, string assetName, System.Action <string, string, Object> act) { FixedBundleFilePath(ref bundlePath); AssetCounter asset = null; assetDicts.TryGetValue(bundlePath + "/" + assetName, out asset); if (asset != null) { asset.count++; act(bundlePath, assetName, asset.obj); return; } else { if (!bundleDicts.ContainsKey(bundlePath)) { HandlerLoadAssetBundleAsyncWithDepedence(bundlePath, assetName, act); } else { HandlerLoadAssetBundleAsync(bundlePath, assetName, act); } } }
public ActionResult DeleteConfirmed(int id) { AssetCounter assetCounter = db.AssetCounters.Find(id); db.AssetCounters.Remove(assetCounter); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "AssetCounterID,AssetType,AssetSubType,Count")] AssetCounter assetCounter) { if (ModelState.IsValid) { db.Entry(assetCounter).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assetCounter)); }
public ActionResult Create([Bind(Include = "AssetCounterID,AssetType,AssetSubType,Count")] AssetCounter assetCounter) { if (ModelState.IsValid) { db.AssetCounters.Add(assetCounter); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assetCounter)); }
public Object GetAssetBundleAsset(string bundlePath, string assetName) { FixedBundleFilePath(ref bundlePath); AssetCounter asset = null; if (assetDicts.TryGetValue(bundlePath + "/" + assetName, out asset)) { return(asset.obj); } return(null); }
// GET: AssetCounters/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AssetCounter assetCounter = db.AssetCounters.Find(id); if (assetCounter == null) { return(HttpNotFound()); } return(View(assetCounter)); }
public void UnLoadObject(string bundlePath, string assetName) { FixedBundleFilePath(ref bundlePath); AssetCounter ac = null; if (assetDicts.TryGetValue(bundlePath + "/" + assetName, out ac)) { ac.count--; if (ac.count <= 0) { //TODO assetDicts.Remove(bundlePath + "/" + assetName); } } }
private Object HandlerLoadAssetBundle(string bundlePath, string assetName) { AssetBundle ab = bundleDicts [bundlePath].asset; if (ab != null) { Object obj = ab.LoadAsset(assetName); UnLoadAssetBundle(bundlePath); AssetCounter ac = new AssetCounter(obj, 1, bundlePath + "/" + assetName); assetDicts [bundlePath + "/" + assetName] = ac; return(obj); } else { return(null); } }
/// <summary> /// Loads the object form asset bundle. /// 外部唯一同步加载家口加载OBJECT /// -------------------记载完对象后会立即删除AssetBundle /// </summary> /// <returns>The object form asset bundle.</returns> /// <param name="bundlePath">Bundle path.</param> /// <param name="assetName">Asset name.</param> public Object LoadObjectFormAssetBundle(string bundlePath, string assetName) { FixedBundleFilePath(ref bundlePath); AssetCounter asset = null; assetDicts.TryGetValue(bundlePath + "/" + assetName, out asset); if (asset != null) { asset.count++; return(asset.obj); } if (!bundleDicts.ContainsKey(bundlePath)) { return(HandlerLoadAssetBundleWithDepedence(bundlePath, assetName)); } else { return(HandlerLoadAssetBundle(bundlePath, assetName)); } }