/// <summary>
        /// 插入一个对象到容器中
        /// </summary>
        /// <param name="t">对象的值</param>
        /// <param name="k">对象的键,用于检索对象</param>
        public bool Insert(K k, T t)
        {
            //设置回滚标记;用来同步数据库操作和内存操作
            int rollback = 0;

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //如果插入数据库失败,直接返回
                if (false == InsertDB(k, t))
                {
                    return(false);
                }
                else
                {
                    rollback = 1;
                }
                obj_dependency.Insert(k, new CCacheItem_WuQi <K, T>(k, t), ref obj_containers);
            }
            catch (System.Exception e)
            {
                if (0 != rollback)
                {
                    DeleteDB(k, t);
                }
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(true);
        }
 /// <summary>
 /// 与数据库同步所有的对象
 /// </summary>
 /// <param name="objs"></param>
 public int SynchronousAllObject()
 {
     try
     {
         obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
         Dictionary <K, T> objs = SynchronousDB();
         if (null == objs || 0 == objs.Count)
         {
             return(0);
         }
         List <CCacheItem_WuQi <K, T> > litem = new List <CCacheItem_WuQi <K, T> >();
         foreach (KeyValuePair <K, T> kvp in objs)
         {
             litem.Add(new CCacheItem_WuQi <K, T>(kvp.Key, kvp.Value));
         }
         obj_dependency.SynchronousAllObject(litem, ref this.obj_containers);
     }
     catch (System.Exception e)
     {
         CExceptionContainer_WuQi.ProcessException(e);
         throw e;
     }
     finally
     {
         obj_rwl.ReleaseWriterLock();
     }
     return(this.obj_containers.Count);
 }
        protected override void ClearDB()
        {
            if (null == this.str_conn)
            {
                return;
            }
            System.Data.SqlClient.SqlConnection conn = null;
//             lock (this)
            {
                try
                {
                    conn = new System.Data.SqlClient.SqlConnection(this.str_conn);
                    conn.Open();
                    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("DELETE  FROM [logmarkinfo]", conn);
                    cmd.ExecuteNonQuery();
                }
                catch (System.Exception e)
                {
                    CExceptionContainer_WuQi.ProcessException(e);
                    throw e;
                }
                finally
                {
                    if (null != conn)
                    {
                        conn.Close();
                    }
                }
            }
        }
 private void ProcessStorage()
 {
     try
     {
         obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
         //在对象集合中寻找
         List <CCacheItem_WuQi <K, T> > result = new List <CCacheItem_WuQi <K, T> >();
         foreach (KeyValuePair <K, CCacheItem_WuQi <K, T> > defront in obj_containers)
         {
             CCacheItem_WuQi <K, T> item = (CCacheItem_WuQi <K, T>)defront.Value;
             if (false != item.IsExpire(intervalMinuteTime))
             {
                 result.Add(item);
             }
         }
         foreach (CCacheItem_WuQi <K, T> item in result)
         {
             obj_containers.Remove(item.key);
         }
     }
     catch (System.Exception e)
     {
         CExceptionContainer_WuQi.ProcessException(e);
         throw e;
     }
     finally
     {
         obj_rwl.ReleaseWriterLock();
     }
 }
Beispiel #5
0
        public ActionResult ManagerMsg(FormCollection collection)
        {
            try
            {
                string sdelete = Request.Form["delete"];

                IList <CLogMsgInfo> result     = TempData["msginfos"] as IList <CLogMsgInfo>;
                List <CLogMsgInfo>  deletinfos = new List <CLogMsgInfo>();

                string[]    stringsplit = collection.GetValue("Guid").AttemptedValue.Split(',');
                List <uint> ls          = new List <uint>();
                foreach (var item in stringsplit)
                {
                    if (0 == item.CompareTo("false") || 0 == item.CompareTo("true"))
                    {
                    }
                    else
                    {
                        ls.Add(uint.Parse(item));
                        foreach (CLogMsgInfo info in result)
                        {
                            if (info.ui_id == uint.Parse(item))
                            {
                                deletinfos.Add(info);
                            }
                        }
                    }
                }
                if (ls.Count == 0)
                {
                    TempData["msginfos"] = result;
                    return(RedirectToAction("ListMsgInfos"));
                }


                if (null != sdelete)
                {
                    CLog_WuQi log   = CLog_WuQi.GetLog();
                    int       count = log.DeleteMsgs(ls);
                    if (count > 0)
                    {
                        foreach (CLogMsgInfo item in deletinfos)
                        {
                            result.Remove(item);
                        }
                    }
                    TempData["msginfos"] = result;
                    return(RedirectToAction("ListMsgInfos"));
                }
                return(RedirectToAction("ListMsgInfos"));
            }
            catch (System.Exception e)
            {
                ViewData["msg"] = CExceptionContainer_WuQi.ProcessException(e);
                return(View("Error"));
            }
        }
Beispiel #6
0
        //
        // GET: /Log/

        public ActionResult  Index()
        {
            try
            {
                //throw new System.NullReferenceException();
            }
            catch (System.Exception e)
            {
                ViewData["msg"] = CExceptionContainer_WuQi.ProcessException(e);
                return(View("Error"));
            }
            return(View());
        }
        public override System.Collections.Generic.Dictionary <uint, CLogMark_WuQi> SynchronousDB()
        {
            if (null == this.str_conn)
            {
                return(null);
            }
            Dictionary <uint, CLogMark_WuQi> dict = new Dictionary <uint, CLogMark_WuQi>();

            System.Data.SqlClient.SqlConnection conn   = null;
            System.Data.SqlClient.SqlDataReader reader = null;
            try
            {
//                 lock (this)
                {
                    uint uguid = 0;
                    conn = new System.Data.SqlClient.SqlConnection(this.str_conn);
                    conn.Open();
                    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM logmarkinfo", conn);
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        uguid = uint.Parse(reader["markid"].ToString());
                        uint          id      = uguid;
                        string        sdesc   = reader["markdesc"].ToString();
                        string        sowner  = reader["markowner"].ToString();
                        int           istate  = int.Parse(reader["markstate"].ToString());
                        string        logtime = reader["marktime"].ToString();
                        CLogMark_WuQi record  = new CLogMark_WuQi(id, sdesc, sowner, istate, DateTime.Parse(logtime));
                        dict.Add(id, record);
                    }
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
                if (null != conn)
                {
                    conn.Close();
                }
            }
            return(dict);
        }
        public int Delete(int condition, List <T> lt)
        {
            if (0 == lt.Count)
            {
                return(0);
            }
            int rollback = 0;//设置回滚标记;用来同步数据库操作和内存操作
            int count    = 0;

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //首先从数据库中删除,如果成功将回滚置1
                if (false == DeleteDB(condition, lt))
                {
                    return(0);
                }
                else
                {
                    rollback = 1;
                }
                //在对象集合中寻找
                List <CCacheItem_WuQi <K, T> > litem = new List <CCacheItem_WuQi <K, T> >();
                foreach (T t in lt)
                {
                    litem.Add(new CCacheItem_WuQi <K, T>(t.GetMyGuid(), t));
                }

                count = obj_dependency.Delete(litem, ref this.obj_containers);
            }
            catch (System.Exception e)
            {
                //如果回滚标志置1
                if (0 != rollback)
                {
                    InsertDB(condition, lt);
                    count = 0;
                }
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(count);
        }
        private void SetMaxGuid()
        {
            if (null == this.str_conn)
            {
                return;
            }

            System.Data.SqlClient.SqlConnection conn   = null;
            System.Data.SqlClient.SqlDataReader reader = null;
            try
            {
//                 lock (this)
                {
                    uint ui_guid = 0;
                    conn = new System.Data.SqlClient.SqlConnection(this.str_conn);
                    conn.Open();
                    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT Max(markid) FROM logmarkinfo", conn);
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            ui_guid = uint.Parse(reader[0].ToString());
                        }
                    }
                    CLogMark_WuQi.SetMyGuid(ui_guid);
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (null != reader)
                {
                    reader.Close();
                }
                if (null != conn)
                {
                    conn.Close();
                }
            }
            return;
        }
        /// <summary>
        /// 查找符合条件的对象,并将它们存入一个list中
        /// </summary>
        /// <param name="adapter">查找条件</param>
        /// <returns>如果返回的list的长度为0,表示没有找到符合条件的对象</returns>
        public List <T> Search(int adapter, Hashtable paraset)
        {
            List <T> result = null;

            try
            {
                obj_rwl.AcquireReaderLock(System.Threading.Timeout.Infinite);
                //在对象集合中寻找
                int getall;//根据管理策略的不同而选择不同的值,如果该策略缓存了所有的数据,则getall为1,表示不需要再到数据库中查询了。
                result = this.obj_dependency.Search(ref this.obj_containers, adapter, paraset, out getall);
                obj_rwl.ReleaseReaderLock();

                if (0 == getall)
                {
                    obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                    result.Clear();
                    result = SearchDB(adapter, paraset);
                    if (result.Count > 0)
                    {
                        foreach (T t in result)
                        {
                            this.obj_dependency.Insert(t.GetMyGuid(), new CCacheItem_WuQi <K, T>(t.GetMyGuid(), t), ref this.obj_containers);
                        }
                    }
                    obj_rwl.ReleaseWriterLock();
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (obj_rwl.IsReaderLockHeld)
                {
                    obj_rwl.ReleaseReaderLock();
                }
                if (obj_rwl.IsWriterLockHeld)
                {
                    obj_rwl.ReleaseWriterLock();
                }
            }
            return(result);
        }
        /// <summary>
        /// 查找单个对象
        /// </summary>
        /// <param name="k">对象的键,用于检索对象</param>
        /// <returns>为null时表示未找到对象</returns>
        public T SelectSingleObject(K k)
        {
            T result = default(T);

            try
            {
                obj_rwl.AcquireReaderLock(System.Threading.Timeout.Infinite);
                int getall;
                result = this.obj_dependency.SelectSingleObject(ref this.obj_containers, k, out getall);
                obj_rwl.ReleaseReaderLock();
                //如果已经查询到对象,则不需要再到数据库中查询了
                if (!result.Equals(default(T)))
                {
                    return(result);
                }
                if (0 == getall)
                {
                    obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                    result = SelectSingleObjectDB(k);
                    if (!result.Equals(default(T)))
                    {
                        this.obj_dependency.Insert(result.GetMyGuid(), new CCacheItem_WuQi <K, T>(result.GetMyGuid(), result), ref this.obj_containers);
                    }
                    obj_rwl.ReleaseWriterLock();
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (obj_rwl.IsReaderLockHeld)
                {
                    obj_rwl.ReleaseReaderLock();
                }
                if (obj_rwl.IsWriterLockHeld)
                {
                    obj_rwl.ReleaseWriterLock();
                }
            }
            return(result);
        }
        public bool Insert(int condition, List <T> lt)
        {
            if (0 == lt.Count)
            {
                return(true);
            }
            //设置回滚标记;用来同步数据库操作和内存操作
            int rollback = 0;

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //如果插入数据库失败,直接返回
                if (false == InsertDB(condition, lt))
                {
                    return(false);
                }
                else
                {
                    rollback = 1;
                }

                List <CCacheItem_WuQi <K, T> > litem = new List <CCacheItem_WuQi <K, T> >();
                foreach (T t in lt)
                {
                    litem.Add(new CCacheItem_WuQi <K, T>(t.GetMyGuid(), t));
                }
                obj_dependency.Insert(litem, ref obj_containers);
            }
            catch (System.Exception e)
            {
                if (0 != rollback)
                {
                    DeleteDB(condition, lt);
                }
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(true);
        }
Beispiel #13
0
        protected override bool UpdateDB(uint k, CLogMark_WuQi t)
        {
            if (null == this.str_conn)
            {
                return(false);
            }
            System.Data.SqlClient.SqlConnection conn = null;
            try
            {
//                 lock (this)
                {
                    conn = new System.Data.SqlClient.SqlConnection(this.str_conn);
                    conn.Open();

                    System.Data.SqlClient.SqlCommand cmd =
                        new System.Data.SqlClient.SqlCommand("update logmarkinfo set markdesc=@markdesc,markowner=@markowner,markstate=@markstate,marktime=@marktime  where markid = @markid;", conn);
                    cmd.Parameters.AddWithValue("@markdesc", t.s_Desc);
                    cmd.Parameters.AddWithValue("@markowner", t.s_Owner);
                    cmd.Parameters.AddWithValue("@markstate", t.IsOpen);
                    cmd.Parameters.AddWithValue("@marktime", t.CreateTime.ToString().Trim());

                    cmd.Parameters.AddWithValue("@markid", t.i_Guid.ToString());

                    if (0 == cmd.ExecuteNonQuery())
                    {
                        return(false);
                    }
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (null != conn)
                {
                    conn.Close();
                }
            }

            return(true);
        }
        public bool Update(int condition, List <T> lt)
        {
            if (0 == lt.Count)
            {
                return(true);
            }
            List <CCacheItem_WuQi <K, T> > backT = new List <CCacheItem_WuQi <K, T> >();

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //在对象集合中寻找,此处不需要过期策略
                foreach (T t in lt)
                {
                    if (false != this.obj_containers.Contains(t.GetMyGuid()))
                    {
                        backT.Add((CCacheItem_WuQi <K, T>) this.obj_containers[t.GetMyGuid()]);
                        this.obj_containers[t.GetMyGuid()] = new CCacheItem_WuQi <K, T>(t.GetMyGuid(), t);
                    }
                }
                //从数据库中更新,如果成功将回滚置1
                //该操作将同时更新该对象的所有数据项,而没有排除不需要更新的数据项;
                //所以该操作要求数据库表存储在一个数据服务器上。
                //不适用于分布式服务器,因为分布式服务器常采用分表策略,该操作将大大降低效率。
                if (false == UpdateDB(condition, lt))
                {
                    foreach (CCacheItem_WuQi <K, T> item in backT)
                    {
                        this.obj_containers[item.key] = item;
                    }
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(true);
        }
Beispiel #15
0
        public ActionResult ManagerMark(FormCollection collection)
        {
            try
            {
                string sswitch = Request.Form["switch"];

                IList <CLogMarkInfo> result = TempData["infos"] as IList <CLogMarkInfo>;
                TempData["infos"] = result;

                string[]    stringsplit = collection.GetValue("Guid").AttemptedValue.Split(',');
                List <uint> ls          = new List <uint>();
                foreach (var item in stringsplit)
                {
                    if (0 == item.CompareTo("false") || 0 == item.CompareTo("true"))
                    {
                    }
                    else
                    {
                        ls.Add(uint.Parse(item));
                    }
                }
                if (ls.Count == 0)
                {
                    return(RedirectToAction("ListInfos"));
                }

                if (null != sswitch)
                {
                    CLog_WuQi log = CLog_WuQi.GetLog();
                    foreach (var item in ls)
                    {
                        log.ChangeMarkState((int)item);
                    }
                }

                return(RedirectToAction("ListInfos"));
            }
            catch (System.Exception e)
            {
                ViewData["msg"] = CExceptionContainer_WuQi.ProcessException(e);
                return(View("Error"));
            }
        }
        /// <summary>
        /// 更新一个对象
        /// </summary>
        /// <param name="t">对象的值</param>
        /// <param name="k">对象的键</param>
        /// <returns></returns>
        public bool Update(K k, T t)
        {
            int rollback = 0;//设置回滚标记;用来同步数据库操作和内存操作
            CCacheItem_WuQi <K, T> backT = null;

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //在对象集合中寻找,此处不需要过期策略
                if (false != this.obj_containers.Contains(k))
                {
                    backT = this.obj_containers[k];
                    this.obj_containers[k] = new CCacheItem_WuQi <K, T>(k, t);
                    rollback = 1;
                }
                //从数据库中更新,如果成功将回滚置1
                //该操作将同时更新该对象的所有数据项,而没有排除不需要更新的数据项;
                //所以该操作要求数据库表存储在一个数据服务器上。
                //不适用于分布式服务器,因为分布式服务器常采用分表策略,该操作将大大降低效率。
                if (false == UpdateDB(k, t))
                {
                    this.obj_containers[k] = backT;
                }
            }
            catch (System.Exception e)
            {
                //如果回滚标志置1
                if (0 != rollback)
                {
                    this.obj_containers[k] = backT;
                }
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(true);
        }
        /// <summary>
        /// 删除一个对象
        /// </summary>
        /// <param name="t">对象的值</param>
        /// <param name="k">对象的键</param>
        /// <returns></returns>
        public bool Delete(K k, T t)
        {
            int rollback = 0;//设置回滚标记;用来同步数据库操作和内存操作

            try
            {
                obj_rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                //首先从数据库中删除,如果成功将回滚置1
                if (false == DeleteDB(k, t))
                {
                    return(false);
                }
                else
                {
                    rollback = 1;
                }
                //在对象集合中寻找
                if (false != this.obj_containers.Contains(k))
                {
                    obj_dependency.Delete(k, ref this.obj_containers);
                    return(true);
                }
            }
            catch (System.Exception e)
            {
                //如果回滚标志置1
                if (0 != rollback)
                {
                    InsertDB(k, t);
                }
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                obj_rwl.ReleaseWriterLock();
            }
            return(true);
        }
Beispiel #18
0
        protected override bool DeleteDB(uint k, CLogMark_WuQi t)
        {
            if (null == this.str_conn)
            {
                return(false);
            }
            System.Data.SqlClient.SqlConnection conn = null;
            try
            {
//                 lock (this)
                {
                    conn = new System.Data.SqlClient.SqlConnection(this.str_conn);
                    conn.Open();
                    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("delete from logmarkinfo where markid = @markid;", conn);
                    cmd.Parameters.AddWithValue("@markid", t.i_Guid);
                    if (0 == cmd.ExecuteNonQuery())
                    {
                        return(false);
                    }
                }
            }
            catch (System.Exception e)
            {
                CExceptionContainer_WuQi.ProcessException(e);
                throw e;
            }
            finally
            {
                if (null != conn)
                {
                    conn.Close();
                }
            }

            return(true);
        }