예제 #1
0
        /// <summary>
        /// Обновляет указанную сущность в базе данных.
        /// </summary>
        /// <typeparam name="T">Тип сущности.</typeparam>
        /// <param name="entry">Обновлённая сущность.</param>
        public void Update2 <T>(T entry)
        {
            CacheAspect.ClearCache(this.GetType());
            DbQuery query = Query;

            query.Update(GetDbManager(), entry);
        }
예제 #2
0
        /// <summary>
        /// Добавляет сущность в базу данных и возвращает новую сущность.
        /// </summary>
        /// <typeparam name="T">Тип сущности.</typeparam>
        /// <param name="entry">Сущность.</param>
        /// <returns></returns>
        public T Insert <T>(T entry)
        {
            CacheAspect.ClearCache(this.GetType());
            DbManager db = GetDbManager();

            return(Query.InsertEx(db, entry));
        }
예제 #3
0
        /// <summary>
        /// Добавляет сущность в базу данных.
        /// </summary>
        /// <typeparam name="T">Тип сущности.</typeparam>
        /// <param name="entry">Сущность.</param>
        public void Insert2 <T>(T entry)
        {
            CacheAspect.ClearCache(this.GetType());
            DbManager db = GetDbManager();

            Query.Insert(db, entry);
        }
예제 #4
0
        public void Test2()
        {
            TestClass tc = TestClass.CreateInstance();

            // Return value depends on parameter values.
            //
            TestClass.Value = /*[a]*/ 1 /*[/a]*/; Assert.AreEqual(/*[a]*/ 1 /*[/a]*/, tc.CachedMethod(1, 1));
            TestClass.Value = /*[a]*/ 2 /*[/a]*/; Assert.AreEqual(/*[a]*/ 1 /*[/a]*/, tc.CachedMethod(1, 1));         // no change
            TestClass.Value = /*[a]*/ 3 /*[/a]*/; Assert.AreEqual(/*[a]*/ 3 /*[/a]*/, tc.CachedMethod(2, 1));

            // However we can clear cache manually.
            // For particular method:
            //
            CacheAspect.ClearCache(typeof(TestClass), "CachedMethod", typeof(int), typeof(int));
            TestClass.Value = /*[a]*/ 4 /*[/a]*/; Assert.AreEqual(/*[a]*/ 4 /*[/a]*/, tc.CachedMethod(2, 1));

            // By MethodInfo:
            //
            MethodInfo methodInfo = tc.GetType().GetMethod("CachedMethod", new Type[] { typeof(int), typeof(int) });

            CacheAspect.ClearCache(methodInfo);
            TestClass.Value = /*[a]*/ 5 /*[/a]*/; Assert.AreEqual(/*[a]*/ 5 /*[/a]*/, tc.CachedMethod(2, 1));

            // For the all cached methods.
            //
            CacheAspect.ClearCache();
            TestClass.Value = /*[a]*/ 6 /*[/a]*/; Assert.AreEqual(/*[a]*/ 6 /*[/a]*/, tc.CachedMethod(2, 1));
        }
예제 #5
0
        public virtual void Insert(ref T obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            var res    = obj;
            var xmlDoc = XmlDocumentConverter.ConvertFrom(res);

            RunManualDbOperation(db =>
            {
                TKey key;

                // сохраняем
                XmlInsert(xmlDoc, out key);

                // гарантированно сбрасываем кэш, т.к. до insert-а могли сделать get с данным id
                CacheAspect.ClearCache(GetType(), "Get");

                // перевычитываем
                res = Get(key, null);
                if (res == null)
                {
                    throw new DeveloperException("Не удалось получить только-что добавленный объект. Проверьте, что процедуры возвращают правильный ключ");
                }

                return(0);
            }, true);

            obj = res;
        }
예제 #6
0
        public void Test()
        {
            TestClass t = TypeAccessor.CreateInstance <TestClass>();

            DateTime begin = DateTime.Now;

            for (TestClass.Value = 777; t.Test(2, 2) == 777; TestClass.Value++)
            {
                continue;
            }

            Assert.IsTrue((DateTime.Now - begin).TotalMilliseconds >= 500);

            TestClass.Value = 1; Assert.AreEqual(1, t.Test(1, 1));
            TestClass.Value = 2; Assert.AreEqual(1, t.Test(1, 1));
            TestClass.Value = 3; Assert.AreEqual(3, t.Test(2, 1));

            CacheAspect.ClearCache(typeof(TestClass), "Test", typeof(int), typeof(int));
            TestClass.Value = 4; Assert.AreEqual(4, t.Test(2, 1));

            CacheAspect.ClearCache(t.GetType(), "Test", typeof(int), typeof(int));
            TestClass.Value = 5; Assert.AreEqual(5, t.Test(2, 1));

            CacheAspect.ClearCache();
            TestClass.Value = 6; Assert.AreEqual(6, t.Test(2, 1));
        }
예제 #7
0
        public override void ClearCache()
        {
            // очистим все
            CacheAspect.ClearCache();

            // да еще и на сервер пошлем
            base.ClearCache();
        }
예제 #8
0
        /// <summary>
        /// Добавляет сущность в базу данных и возвращает идентификатор для неё.
        /// </summary>
        /// <typeparam name="T">Тип сущности</typeparam>
        /// <typeparam name="TID">Тип идентификтора.</typeparam>
        /// <param name="entry">Сущность.</param>
        /// <returns>Идентификатор новой сущности</returns>
        public TID InsertAndGetID <T, TID>(T entry)
            where T : IUniqueID <TID>
            where TID : struct
        {
            CacheAspect.ClearCache(this.GetType());
            DbManager db = GetDbManager();

            return(Query.InsertAndGetIdentity <T, TID>(db, entry));
        }
예제 #9
0
        /// <summary>
        /// Обновляет указанную сущность в базе данных.
        /// </summary>
        /// <typeparam name="T">Тип сущности.</typeparam>
        /// <param name="entry">Сущность.</param>
        /// <returns>Обновлённая сущность.</returns>
        public T Update <T>(T entry)
            where T : IUnique
        {
            CacheAspect.ClearCache(this.GetType());
            DbQuery   query = Query;
            DbManager db    = GetDbManager();

            query.Update(db, entry);
            return(query.SelectByKey <T>(db, entry.GetUniqueID()));
        }
예제 #10
0
 public void MultiThreadTest10()
 {
     for (int i = 0; i < 10; i++)
     {
         Console.WriteLine("Iteration {0}", i + 1);
         MultiThread.Value = 0;
         Console.WriteLine("ClearCache");
         CacheAspect.ClearCache();
         Console.WriteLine("ClearCache - complete");
         MultiThreadTest();
     }
 }
예제 #11
0
    public override void ClearAll()
    {
        try
        {
        }
        finally
        {
            if (_type3 == null)
            {
                _type3 = ClearCacheAspect.GetType(this, typeof(TestClass));
            }

            CacheAspect.ClearCache(_type3);
        }
    }
예제 #12
0
    public override void ClearAll2()
    {
        try
        {
        }
        finally
        {
            if (_type4 == null)
            {
                _type4 = ClearCacheAspect.GetType(this, null);
            }

            CacheAspect.ClearCache(_type4);
        }
    }
예제 #13
0
    public override void ClearCache()
    {
        try
        {
            // Here should be main method implementation.
            // It is empty as this method does nothing.
        }
        finally
        {
            if (_methodInfo1 == null)
            {
                _methodInfo1 =
                    ClearCacheAspect.GetMethodInfo(this, null, "CachedMethod", null);
            }

            CacheAspect.ClearCache(_methodInfo1);
        }
    }
예제 #14
0
    public override void ClearCache2()
    {
        try
        {
        }
        finally
        {
            if (_methodInfo2 == null)
            {
                _methodInfo2 = ClearCacheAspect.GetMethodInfo(
                    this,
                    null,
                    "CachedMethod",
                    new Type[] { typeof(int), typeof(int) });
            }

            CacheAspect.ClearCache(_methodInfo2);
        }
    }
예제 #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["cleanup"] == "1")
        {
            CacheAspect.ClearCache();
            Response.Redirect("Counters.aspx");
        }

        List <MethodCallCounter> counters = new List <MethodCallCounter>();

        lock (CounterAspect.Counters.SyncRoot)
            foreach (MethodCallCounter c in CounterAspect.Counters)
            {
                lock (c.CurrentCalls.SyncRoot)
                    if (c.TotalCount > 0 || c.CachedCount > 0 | c.CurrentCalls.Count > 0)
                    {
                        counters.Add(c);
                    }
            }

        counters.Sort(delegate(MethodCallCounter x, MethodCallCounter y)
        {
            int c = string.Compare(
                x.MethodInfo.DeclaringType.Name,
                y.MethodInfo.DeclaringType.Name);

            if (c != 0)
            {
                return(c);
            }

            return(string.Compare(x.MethodInfo.Name, y.MethodInfo.Name));
        });

        counterRepeater.DataSource = counters;

        DataBind();
    }
예제 #16
0
 /// <summary>
 /// Deletes the user setting.
 /// </summary>
 /// <param name="clientApplicationSettingID">The client application setting ID.</param>
 /// <param name="employeeID">The employee ID.</param>
 /// <param name="parameter">The parameter.</param>
 public void DeleteUserSetting(int clientApplicationSettingID, int employeeID, string parameter)
 {
     CacheAspect.ClearCache(this.GetType());
     Query.DeleteByKey <UserSetting>(clientApplicationSettingID, employeeID, parameter);
 }
예제 #17
0
 public override void ClearCache()
 {
     // чистим весь имеющийся кэш
     CacheAspect.ClearCache();
 }
예제 #18
0
 public virtual void ClearLocalCache()
 {
     CacheAspect.ClearCache(GetType());
 }
예제 #19
0
 public void ClearCache()
 {
     CacheAspect.ClearCache(GetType());
 }
예제 #20
0
 /// <summary>
 /// Удаляет указанную сущность в базе данных.
 /// </summary>
 /// <typeparam name="T">Тип сущности.</typeparam>
 /// <param name="entry">Сущность.</param>
 public void Delete <T>(T entry)
     where T : IUnique
 {
     CacheAspect.ClearCache(this.GetType());
     Query.DeleteByKey <T>(GetDbManager(), entry.GetUniqueID());
 }
예제 #21
0
 public void LiteClearCache()
 {
     CacheAspect.ClearCache();
     ClearCacheInternal();
 }