Exemplo n.º 1
0
        public void save(MasterPool dbitem, int id)
        {
            var query = "";

            if (dbitem.Id == 0) //create
            {
                context.MasterPool.Add(dbitem);
            }
            else //edit
            {
                context.MasterPool.Attach(dbitem);
                var entry = context.Entry(dbitem);
                entry.State = EntityState.Modified;
                query      += "DELETE FROM dbo.\"ZoneParkir\" WHERE \"IdPool\" = " + dbitem.Id + ";";
            }
            context.SaveChanges();
            foreach (Context.ZoneParkir item in dbitem.ListZoneParkir)
            {
                query += "INSERT INTO dbo.\"ZoneParkir\" (\"IdPool\", \"IdZone\", \"Pit\") VALUES (" + item.IdPool + ", " + dbitem.Id + ", " + item.Pit + ");";
            }
            var auditrail = new Auditrail {
                Actionnya = dbitem.Id == 0 ? "Add" : "Edit", EventDate = DateTime.Now, Modulenya = "Master Pool", QueryDetail = query, RemoteAddress = AppHelper.GetIPAddress(),
                IdUser    = id
            };

            context.Auditrail.Add(auditrail);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void BeginTransaction(IsolationLevel?isolationLevel)
        {
            if (TransactionCurrentThread != null)
            {
                return;
            }

            int                   tid    = Thread.CurrentThread.ManagedThreadId;
            Transaction2          tran   = null;
            Object <DbConnection> conn   = null;
            var                   before = new Aop.TraceBeforeEventArgs("ThreadTransaction", isolationLevel);

            _util?._orm?.Aop.TraceBeforeHandler?.Invoke(this, before);

            try
            {
                conn           = MasterPool.Get();
                tran           = new Transaction2(conn, isolationLevel == null ? conn.Value.BeginTransaction() : conn.Value.BeginTransaction(isolationLevel.Value), TimeSpan.FromSeconds(60));
                tran.AopBefore = before;
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"数据库出错(开启事务){ex.Message} \r\n{ex.StackTrace}");
                MasterPool.Return(conn);
                var after = new Aop.TraceAfterEventArgs(before, "", ex);
                _util?._orm?.Aop.TraceAfterHandler?.Invoke(this, after);
                throw ex;
            }
            if (_trans.ContainsKey(tid))
            {
                CommitTransaction();
            }
            _trans.TryAdd(tid, tran);
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            if (_isdisposed)
            {
                return;
            }
            try {
                Transaction2[] trans = null;
                lock (_trans_lock)
                    trans = _trans.Values.ToArray();
                foreach (Transaction2 tran in trans)
                {
                    CommitTransaction(false, tran);
                }
            } catch { }

            ObjectPool <DbConnection>[] pools = null;
            for (var a = 0; a < 10; a++)
            {
                try {
                    pools = SlavePools.ToArray();
                    SlavePools.Clear();
                    break;
                } catch {
                }
            }
            if (pools != null)
            {
                foreach (var pool in pools)
                {
                    try { pool.Dispose(); } catch { }
                }
            }
            try { MasterPool.Dispose(); } catch { }
        }
        public void BeginTransaction(TimeSpan timeout)
        {
            if (TransactionCurrentThread != null)
            {
                return;
            }

            int                   tid  = Thread.CurrentThread.ManagedThreadId;
            Transaction2          tran = null;
            Object <DbConnection> conn = null;

            try {
                conn = MasterPool.Get();
                tran = new Transaction2(conn, conn.Value.BeginTransaction(), timeout);
            } catch (Exception ex) {
                _log.LogError($"数据库出错(开启事务){ex.Message} \r\n{ex.StackTrace}");
                MasterPool.Return(conn);
                throw ex;
            }
            if (_trans.ContainsKey(tid))
            {
                CommitTransaction();
            }

            lock (_trans_lock)
                _trans.Add(tid, tran);
        }
Exemplo n.º 5
0
        public void delete(MasterPool dbitem)
        {
            context.MasterPool.Remove(dbitem);
            var auditrail = new Auditrail {
                Actionnya = "Delete", EventDate = DateTime.Now, Modulenya = "Master Pool", QueryDetail = "Delete " + dbitem.NamePool, RemoteAddress = AppHelper.GetIPAddress(),
                IdUser    = 1
            };

            context.Auditrail.Add(auditrail);
            context.SaveChanges();
        }
Exemplo n.º 6
0
        public ActionResult Edit(int id)
        {
            Context.MasterPool dbitem = RepoPool.FindByPK(id);
            MasterPool         model  = new MasterPool(dbitem);

            ViewBag.name = model.NamePool;
            if (dbitem.IdCreditCash.HasValue)
            {
                ac_mstr bk_credit_cash = Repoac_mstr.FindByPk(dbitem.IdCreditCash);
                model.IdCreditCash   = bk_credit_cash.id;
                model.CodeCreditCash = bk_credit_cash.ac_code;
                model.NamaCreditCash = bk_credit_cash.ac_name;
            }
            return(View("Form", model));
        }
Exemplo n.º 7
0
        private void CommitTransaction(bool isCommit, Transaction2 tran)
        {
            if (tran == null || tran.Transaction == null || tran.Transaction.Connection == null)
            {
                return;
            }

            if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
            {
                lock (_trans_lock)
                    if (_trans.ContainsKey(tran.Conn.LastGetThreadId))
                    {
                        _trans.Remove(tran.Conn.LastGetThreadId);
                    }
            }

            var removeKeys = PreRemove();

            if (_preRemoveKeys.ContainsKey(tran.Conn.LastGetThreadId))
            {
                lock (_preRemoveKeys_lock)
                    if (_preRemoveKeys.ContainsKey(tran.Conn.LastGetThreadId))
                    {
                        _preRemoveKeys.Remove(tran.Conn.LastGetThreadId);
                    }
            }

            Exception ex   = null;
            var       f001 = isCommit ? "提交" : "回滚";

            try {
                Log.LogDebug($"线程{tran.Conn.LastGetThreadId}事务{f001},批量删除缓存key {Newtonsoft.Json.JsonConvert.SerializeObject(removeKeys)}");
                CacheRemove(removeKeys);
                if (isCommit)
                {
                    tran.Transaction.Commit();
                }
                else
                {
                    tran.Transaction.Rollback();
                }
            } catch (Exception ex2) {
                ex = ex2;
                Log.LogError($"数据库出错({f001}事务):{ex.Message} {ex.StackTrace}");
            } finally {
                MasterPool.Return(tran.Conn, ex);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Preload the pool with objects.
        /// </summary>
        private void InitializePools(MasterPool _masterPool)
        {
            // Create & rename a new GameObject to hold sub pools under masterpool.
            GameObject _emptyMasterPool = new GameObject();

            _emptyMasterPool.name             = _masterPool.masterTag;
            _emptyMasterPool.transform.parent = transform;

            // Initialize sub pool tag based on the prefab assigned to them
            for (int i = 0; i < _masterPool.subPools.Length; i++)
            {
                if (_masterPool.subPools[i].prefab != null)
                {
                    _masterPool.subPools[i].poolTag = _masterPool.subPools[i].prefab.name;
                }
                else
                {
                    _masterPool.subPools[i].poolTag = "This prefab is not assigned!";
                }
            }

            // Initializing sub pools
            for (int i = 0; i < _masterPool.subPools.Length; i++)
            {
                // Create & rename a new GameObject to hold items in sub pool
                GameObject _newObject = new GameObject();
                _newObject.transform.parent = _emptyMasterPool.transform;
                _newObject.name             = _masterPool.subPools[i].prefab.name;

                // Instantiate a number of objects into the sub pool.
                for (int j = 0; j < _masterPool.objectsPerPool + 1; j++)
                {
                    // Check if this pool has a prefab assigned.
                    if (_masterPool.subPools[i].prefab != null)
                    {
                        GameObject _clone = Instantiate(_masterPool.subPools[i].prefab, _newObject.transform);
                        _clone.SetActive(false);
                        _masterPool.subPools[i].pool.Add(_clone);
                    }
                    else
                    {
                        Debug.LogError("Pool " + _masterPool.subPools[i].poolTag + " doesn't have a prefab in it!!!");
                        break;
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void Dispose()
        {
            if (ResolveTransaction != null)
            {
                return;
            }
            if (Interlocked.Increment(ref _disposeCounter) != 1)
            {
                return;
            }
            try
            {
                var trans = _trans?.Values.ToArray();
                if (trans != null)
                {
                    foreach (var tran in trans)
                    {
                        CommitTransaction(false, tran, null, "Dispose自动提交");
                    }
                }
            }
            catch { }

            IObjectPool <DbConnection>[] pools = null;
            for (var a = 0; a < 10; a++)
            {
                try
                {
                    pools = SlavePools?.ToArray();
                    SlavePools?.Clear();
                    break;
                }
                catch
                {
                }
            }
            if (pools != null)
            {
                foreach (var pool in pools)
                {
                    try { pool?.Dispose(); } catch { }
                }
            }
            try { MasterPool?.Dispose(); } catch { }
        }
Exemplo n.º 10
0
        public ActionResult Add(MasterPool model)
        {
            if (ModelState.IsValid)
            {
                if (RepoPool.IsExist(model.NamePool))
                {
                    ModelState.AddModelError("NamePool", "Nama sudah dipakai.");
                    return(View("Form", model));
                }
                Context.MasterPool dbitem = new Context.MasterPool();
                model.setDb(dbitem);
                RepoPool.save(dbitem, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            ZoneParkir[] result = JsonConvert.DeserializeObject <ZoneParkir[]>(model.strPool);
            model.ListZoneParkir = result.ToList();
            return(View("Form", model));
        }
Exemplo n.º 11
0
        public ActionResult Add()
        {
            MasterPool model = new MasterPool();

            return(View("Form", model));
        }
Exemplo n.º 12
0
 private void OnEnable()
 {
     _target = target as MasterPool;
 }