Exemplo n.º 1
0
    private IEnumerator LoadResourceAsync0(string resourcePath, System.Action <string, Object> act)
    {
        ResourceRequest request = Resources.LoadAsync(resourcePath);

        yield return(request);

        assetContainer[resourcePath] = new ObjectCounter(request.asset, 1);
        act(resourcePath, request.asset);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Starts a catch block
 /// </summary>
 /// <param name="ExceptionType">Exception type to catch</param>
 /// <returns>The resulting catch block</returns>
 public virtual Utilities.Reflection.Emit.Commands.Catch Catch(Type ExceptionType)
 {
     Utilities.Reflection.Emit.Commands.Catch TempCommand = new Utilities.Reflection.Emit.Commands.Catch(ExceptionType);
     TempCommand.Setup();
     Commands.Add(TempCommand);
     TempCommand.Exception = CreateLocal("ExceptionLocal" + ObjectCounter.ToString(CultureInfo.InvariantCulture), ExceptionType);
     TempCommand.Exception.Save(Generator);
     ++ObjectCounter;
     return(TempCommand);
 }
Exemplo n.º 3
0
        private void DisposeContext()
        {
            Exception exeption = null;

            if (_context != null)
            {
                try
                {
                    var cancel = false;
                    if (HttpContext.Current != null)
                    {
                        if (HttpContext.Current.Items["tran_cancel"] != null)
                        {
                            if (HttpContext.Current.Items["tran_cancel"].ToString() == "1")
                            {
                                cancel = true;
                            }
                        }
                    }
                    if (!cancel)
                    {
                        _context.SaveChanges();
                    }
                }
                catch (DbEntityValidationException e)
                {
                    var errorMsg = new StringBuilder();
                    foreach (var errors in e.EntityValidationErrors)
                    {
                        foreach (var error in errors.ValidationErrors)
                        {
                            errorMsg.AppendFormat("Entity:{0},property:{1},error:{2}",
                                                  errors.Entry.Entity.GetType().Name
                                                  , error.PropertyName, error.ErrorMessage);
                        }
                    }
                    exeption = new Exception(errorMsg.ToString(), e);
                }
                catch (Exception e)
                {
                    exeption = e;
                }
                finally
                {
                    ObjectCounter.DecreseDbContextCount(LocatorId);
                    _context.Dispose();
                    _context = null;
                }
                if (exeption != null)
                {
                    throw exeption;
                }
            }
        }
Exemplo n.º 4
0
 private void EnsureContext(string identity)
 {
     if (_context != null)
     {
         return;
     }
     _context = GetContext();
     Interlocked.Increment(ref IdSeed);
     LocatorId = IdSeed;
     ObjectCounter.IncreseDbContextCount(LocatorId,
                                         string.Format("source:{0},str:{1}", identity, _context.Database.Connection.ConnectionString));
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Starts a catch block
        /// </summary>
        /// <param name="exceptionType">Exception type to catch</param>
        /// <returns>The resulting catch block</returns>
        public virtual Catch Catch(Type exceptionType)
        {
            var tempCommand = new Catch(exceptionType);

            tempCommand.Setup();
            Commands.Add(tempCommand);
            tempCommand.Exception = CreateLocal(
                "ExceptionLocal" + ObjectCounter.ToString(CultureInfo.InvariantCulture), exceptionType);
            tempCommand.Exception.Save(Generator);
            ++ObjectCounter;
            return(tempCommand);
        }
Exemplo n.º 6
0
        public static IList <ObjectCountInfo> Create(ObjectCounter counter)
        {
            var infos = new List <ObjectCountInfo>();

            foreach (var item in counter.Items)
            {
                var theType = item.Key;
                var info    = new ObjectCountInfo();
                info.Name  = theType.FullName;
                info.Count = item.Value;
                infos.Add(info);
            }
            return(infos);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 卸载资源, 引用计数为零将其从内存中清除
 /// </summary>
 /// <param name="resourcePath">资源路径</param>
 public void UnloadResource(string resourcePath)
 {
     if (assetContainer.ContainsKey(resourcePath))
     {
         ObjectCounter oc      = assetContainer[resourcePath];
         int           counter = --oc.count;
         if (counter == 0)
         {
             assetContainer.Remove(resourcePath);
             if (oc.resource != null && (oc.resource is GameObject) == false)
             {
                 Resources.UnloadAsset(oc.resource as Object);
             }
         }
     }
 }
Exemplo n.º 8
0
        public async Task SaveAsync()
        {
            Exception exeption = null;

            if (_context != null)
            {
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbEntityValidationException e)
                {
                    var errorMsg = new StringBuilder();
                    foreach (var errors in e.EntityValidationErrors)
                    {
                        foreach (var error in errors.ValidationErrors)
                        {
                            errorMsg.AppendFormat("Entity:{0},property:{1},error:{2}",
                                                  errors.Entry.Entity.GetType().Name
                                                  , error.PropertyName, error.ErrorMessage);
                        }
                    }
                    exeption = new Exception(errorMsg.ToString(), e);
                }
                catch (Exception e)
                {
                    exeption = e;
                }
                finally
                {
                    ObjectCounter.DecreseDbContextCount(LocatorId);
                    _context.Dispose();
                    _context = null;
                }
                if (exeption != null)
                {
                    throw exeption;
                }
            }
        }