Пример #1
0
        // 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();
                }
            }
        }
Пример #2
0
        // 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();
                    }
                }
            }
        }
Пример #3
0
    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);
        }
    }
Пример #4
0
    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);
    }
Пример #5
0
    /// <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);
            }
        }
    }
Пример #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            AssetCounter assetCounter = db.AssetCounters.Find(id);

            db.AssetCounters.Remove(assetCounter);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #7
0
 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));
 }
Пример #8
0
        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));
        }
Пример #9
0
    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);
    }
Пример #10
0
        // 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));
        }
Пример #11
0
    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);
            }
        }
    }
Пример #12
0
    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);
        }
    }
Пример #13
0
    /// <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));
        }
    }