Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void SetUp()
        {
            context = new GenericApplicationContext();

            cacheAspect = new CacheAspect();
            cacheAspect.ApplicationContext = context;
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public override void ClearCache()
        {
            // очистим все
            CacheAspect.ClearCache();

            // да еще и на сервер пошлем
            base.ClearCache();
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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()));
        }
Ejemplo n.º 11
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();
     }
 }
Ejemplo n.º 12
0
 public static void Clear(DbManagerProxy manager, string lookup_object)
 {
     lock (g_Lookups)
     {
         if (g_Lookups.ContainsKey(lookup_object))
         {
             CacheAspect.ClearAllCache(g_Lookups[lookup_object].Key);
             if (g_Lookups[lookup_object].Value != null)
             {
                 CacheAspect.ClearAllCache(g_Lookups[lookup_object].Value);
             }
         }
     }
 }
Ejemplo n.º 13
0
    public override void ClearAll()
    {
        try
        {
        }
        finally
        {
            if (_type3 == null)
            {
                _type3 = ClearCacheAspect.GetType(this, typeof(TestClass));
            }

            CacheAspect.ClearCache(_type3);
        }
    }
Ejemplo n.º 14
0
    public override void ClearAll2()
    {
        try
        {
        }
        finally
        {
            if (_type4 == null)
            {
                _type4 = ClearCacheAspect.GetType(this, null);
            }

            CacheAspect.ClearCache(_type4);
        }
    }
Ejemplo n.º 15
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);
        }
    }
Ejemplo n.º 16
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);
        }
    }
Ejemplo n.º 17
0
 public static void ClearAndReload(DbManagerProxy manager, string lookup_object)
 {
     lock (g_Lookups)
     {
         if (g_Lookups.ContainsKey(lookup_object))
         {
             CacheAspect.ClearAllCache(g_Lookups[lookup_object].Key);
             if (g_Lookups[lookup_object].Value != null)
             {
                 CacheAspect.ClearAllCache(g_Lookups[lookup_object].Value);
             }
         }
     }
     lock (g_LookupUsages)
     {
         if (g_LookupUsages.ContainsKey(lookup_object))
         {
             var list = g_LookupUsages[lookup_object];
             foreach (var w in list)
             {
                 if (w.IsAlive)
                 {
                     var icu = w.Target as ILookupUsage;
                     if (icu != null)
                     {
                         try
                         {
                             icu.ReloadLookupItem(manager, lookup_object);
                         }
                         catch (Exception)
                         {
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 18
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();
    }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
0
 public override void ClearCache()
 {
     // чистим весь имеющийся кэш
     CacheAspect.ClearCache();
 }
Ejemplo n.º 21
0
 public virtual void ClearLocalCache()
 {
     CacheAspect.ClearCache(GetType());
 }
Ejemplo n.º 22
0
 public void ClearCache()
 {
     CacheAspect.ClearCache(GetType());
 }
Ejemplo n.º 23
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());
 }
Ejemplo n.º 24
0
 public void LiteClearCache()
 {
     CacheAspect.ClearCache();
     ClearCacheInternal();
 }