示例#1
0
        static void Main(string[] args)
        {
            ISession    session = OracleSessionFactory.GetInstance().OpenSession(new TestInterceptor());
            NHCacheTest test    = IocCoreFactory.Get <NHCacheTest>();

            test.TestGetData("select * from city", OracleSessionFactory.DbOp);
            test.TestGetData("select * from city", OracleSessionFactory.DbOp);
            //IQuery sessionCreateQuery = session.CreateQuery("from CITY");
            //IList<CITY> pList = sessionCreateQuery.List<CITY>();
            //Console.WriteLine(pList.Count);
            //Console.ReadLine();
            ////session = SessionFactory.GetInstance().OpenSession(new TestInterceptor());
            ////sessionCreateQuery = session.CreateQuery("from CITY");

            //session.Evict(pList);
            //pList = sessionCreateQuery.List<CITY>();
            //session.Close();
            Console.ReadLine();
            OracleSessionFactory.Dispose();
            Console.ReadLine();
            #region
            //IDbOp op = IocCoreFactory.Get<IDbOp>();
            //op.Open();
            //CacheTest test = IocCoreFactory.Get<CacheTest>();
            //test.TestGetData("select * from bpxm t",op);
            //test.TestGetData("select * from bpxm t", op);
            ////op.Close();
            ////op.Open();
            ////Thread.Sleep(2000);
            ////test.TestGetData("select * from bpxm t", op);
            ////Console.ReadLine();
            ////test.TestGetData("select * from bpxm t", op);

            ////Console.ReadLine();
            //op.Close();
            //Console.ReadLine();
            #endregion
            #region
            //IDbOp op = IocCoreFactory.Get<IDbOp>();
            //bool a = false;
            //ConsoleKeyInfo keyInfo;
            //while (!a)
            //{
            //    if (System.Console.KeyAvailable)
            //    {
            //        keyInfo = System.Console.ReadKey(true);
            //        if (keyInfo.KeyChar == 'a')
            //            a = true;
            //    }
            //    op.Open();
            //    op.CacheQuery("select * from bpxm t");
            //    Thread.Sleep(2000);
            //}
            #endregion
        }
示例#2
0
        private bool tryAccess(IInvocation invocation)
        {
            PermissionPointAttribute attribute = AttributeHelper.GetAttribute <PermissionPointAttribute>(invocation) as PermissionPointAttribute;

            if (attribute == null)
            {
                return(true);
            }
            string strLogHeader = "Access accepted";

            try
            {
                IPermissionPointResolve resolve = IocCoreFactory.Get <IPermissionPointResolve>(attribute.ResolveType);
                PermissionPoint         point   = new DefaultPermissionPoint(attribute,
                                                                             InterceptorHelper.GetInvocationTarget(invocation),
                                                                             InterceptorHelper.GetInvocationMethod(invocation) as MemberInfo,
                                                                             InterceptorHelper.GetInvocationMethodArgs(invocation)) as PermissionPoint;
                PermissionInfo info = resolve.Resolve(point);
                info++;
                if (attribute.IsAcceptLog && LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("{0} {1} {2} {3}-----Access Log ", strLogHeader, PrincipalTokenHolder.CurrentPrincipal.ToString(), attribute.ToString(), InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel);
                }
            }
            catch (AccessException ex)
            {
                strLogHeader = "Access Denied";
                if (attribute.IsAcceptLog && LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("{0} {1} {2} {3}-----Access Log ", strLogHeader, PrincipalTokenHolder.CurrentPrincipal.ToString(), attribute.ToString(), InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel, ex);
                }
                if (attribute.IsAlert)
                {
                    Console.WriteLine("Access diny alert!");
                }
                if (attribute.IsThrow)
                {
                    throw ex;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
        public override void Intercept(IInvocation invocation)
        {
            CacheAttribute attribute = AttributeHelper.GetAttribute <CacheAttribute>(invocation) as CacheAttribute;

            attribute.Key = getKey(invocation, attribute);
            ICache cache     = IocCoreFactory.Get <ICache>();
            object cacheData = cache.Get(attribute.Key);

            if (cacheData != null)
            {
                invocation.ReturnValue = cacheData;
                if (LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("Cache Hit! Key:\"{0}\" Caller:{1}", attribute.Key, InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel);
                }
                return;
            }
            IDependencyWrapper dependency;

            if (!String.IsNullOrWhiteSpace(attribute.DependencyCallback))
            {
                dependency = getDependency(invocation, attribute);
            }
            else
            {
                dependency = null;
            }
            invocation.Proceed();
            if (dependency != null)
            {
                object     returnValue       = invocation.ReturnValue;
                MethodInfo onRemovedCallback = invocation.TargetType.GetMethod(attribute.OnRemovedCallback);
                cache.Insert(
                    attribute.Key,
                    returnValue,
                    dependency.Instance,
                    attribute.Absolute,
                    attribute.Sliding,
                    (int)attribute.Priority,
                    onRemovedCallback);
                if (LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("Cache Insert! Key:\"{0}\" Caller:{1}", attribute.Key, InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel);
                }
            }
        }
示例#4
0
        public static IDependencyWrapper TestGetData_CacheDependencyCallback(object target, object[] args)
        {
            CacheDependencyWrapper dependency = new CacheDependencyWrapper();

            try
            {
                if (args.Length == 2)
                {
                    IDependencyWrapper     dbDependency = IocCoreFactory.Get <IDependencyWrapper>("DBDependency");
                    DBDependencyCreateArgs dbArg
                        = new DBDependencyCreateArgs()
                        {
                        Sql = args[0] as string, DbOp = args[1] as IDbOp
                        };
                    dbDependency.Create(dbArg);
                    IDependencyWrapper         dbConnDependency = IocCoreFactory.Get <IDependencyWrapper>("DBConnDependency");
                    DBConnDependencyCreateArgs dbCoonArg
                        = new DBConnDependencyCreateArgs()
                        {
                        DbOp = args[1] as IDbOp
                        };
                    dbConnDependency.Create(dbCoonArg);
                    IDependencyWrapper            aggregateDependency = IocCoreFactory.Get <IDependencyWrapper>("AggregateDependency");
                    AggregateDependencyCreateArgs aggregateArg
                        = new AggregateDependencyCreateArgs()
                        {
                        Wrappers = new IDependencyWrapper[] { dbDependency, dbConnDependency }
                        };
                    aggregateDependency.Create(aggregateArg);
                    return(aggregateDependency);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            catch (Exception ex)
            {
                //这里处理缓存依赖生成过程中的异常
                throw ex;
                //return null;
            }
        }
示例#5
0
        public void TestSingleton()
        {
            IDbOp op2 = IocCoreFactory.Get <IDbOp>("OracleSingletonOp");

            Assert.AreEqual(true, object.ReferenceEquals(op, op2));
        }
示例#6
0
 /// <summary>
 /// 权限判断操作符,系统支持使用++操作符进行判断当前用户是否具有此权限
 /// </summary>
 public static PermissionInfo operator ++(PermissionInfo pinfo)
 {
     //判断当前用户是否具有此权限,否则抛出Access异常
     (IocCoreFactory.Get <IAccessDecider>() as IAccessDecider).Decide(PrincipalTokenHolder.CurrentPrincipal, pinfo);
     return(pinfo);
 }