コード例 #1
0
        public void ModifyUserDetails(ModifyUserDetailsRequest request)
        {
            AuthenticationActions.ModifyUserDetailsAction action = PolicyInjection.Create <AuthenticationActions.ModifyUserDetailsAction>();

            action.Execute(
                Translators.ModifyUserDetailsTranslator.TranslateFromServiceToBusiness(request.ModifyUserDetailsParameters));
        }
コード例 #2
0
        public FindOutputManagersResponse FindOutputManagers(FindOutputManagersRequest request)
        {
            IClaimsIdentity identity = (IClaimsIdentity)Thread.CurrentPrincipal.Identity;
            string          upn      = identity.Claims.FindAll(c => { return(c.ClaimType == ClaimTypes.Upn); }).First().Value;

            InitializationActions.FindOutputManagersAction action = PolicyInjection.Create <InitializationActions.FindOutputManagersAction>();

            InitializationEntities.FindOutputManagersParameters parameters = Translators.FindOutputManagersTranslator.TranslateFromServiceToBusiness(request.FindOutputManagersParameters);

            //parameters.UserPrincipalIdentity = upn; /* user@domain */
            //parameters.UserIdentity = upn.Split('@')[0];


            InitializationEntities.FindOutputManagersResult r = action.Execute();

            FindOutputManagersResponse response = new FindOutputManagersResponse();

            response.FindOutputManagerResult = GenericMapper.MapNew <DataContracts.FindOutputManagerResult>(r);

            response.FindOutputManagerResult.OutputManagers =
                GenericMapper.MapListNew <DataContracts.OutputManagerCollection, InitializationEntities.FindOutputManagerResult, DataContracts.OutputManager>(
                    r.OutputManagers, Translators.FindOutputManagersTranslator.TranslateFromBusinessToService);


            return(response);
        }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: mayleng/AOP
        protected void Button1_Click(object sender, EventArgs e)
        {
            cn.com.webxml.www.WeatherWebService ws = new cn.com.webxml.www.WeatherWebService();

            string[] r = ws.getWeatherbyCityName(this.TextBox_CityName.Text);
            this.TextBox1.Text = " ";
            if (r == null)
            {
                this.TextBox1.Text = "无" + this.TextBox_CityName.Text + "城市的天气信息";
                return;
            }

            foreach (string i in r)
            {
                this.TextBox1.Text += i;
            }

            Employee emp = PolicyInjection.Create <Employee>();

            emp.Name = "weather";

            emp.Work();

            Response.Write(emp + "<br/>");
        }
コード例 #4
0
        public InterfaceTracingStatusResult Execute()
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            ITracingDao tracingDao = PolicyInjection.Create <TracingDao, ITracingDao>(connectionString);
            IList <CheckInterfaceTracingResult> resultList = null;

            resultList = tracingDao.CheckInterfaceTracing(new CheckInterfaceTracingParameters());

            InterfaceTracingStatusResult result = new InterfaceTracingStatusResult();

            if (resultList != null && resultList.Count > 0)
            {
                if (resultList[0].LoggOn)
                {
                    result.LoggIsOn  = true;
                    result.LoggStops = resultList[0].LoggStarted.AddSeconds(resultList[0].LoggInterval);
                }
                else
                {
                    result.LoggIsOn  = false;
                    result.LoggStops = null;
                }
            }

            return(result);
        }
コード例 #5
0
ファイル: User.svc.cs プロジェクト: mayleng/AOP
        public void DoWork()
        {
            Employee emp = PolicyInjection.Create <Employee>();

            emp.Name = "Lele";
            emp.Work();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            //BMIProcessor BMI =  new BMIProcessor();
            //上面這行改為底下這樣
            BMIProcessor BMI = PolicyInjection.Create <BMIProcessor>();

            //其餘程式碼完全不變
            BMI.Height = 170;
            BMI.Weight = 70;

            //計算BMI
            var ret = BMI.Calculate();

            Console.WriteLine($"\nBMI : {ret}");
            Console.ReadKey();

            //測試exception
            BMI.Height = 0;
            BMI.Weight = 0;

            //計算BMI
            ret = BMI.Calculate();

            Console.WriteLine($"\nBMI : {ret}");
            Console.ReadKey();
        }
コード例 #7
0
        public static T GetMethod <T>(Auth auth) where T : MethodBase
        {
            var method = PolicyInjection.Create <T>();

            method.Auth = auth;
            return(method);
        }
コード例 #8
0
        public FindUserDetailsResponse FindUserDetails(FindUserDetailsRequest request)
        {
            IClaimsIdentity identity = (IClaimsIdentity)Thread.CurrentPrincipal.Identity;
            string          upn      = identity.Claims.FindAll(c => { return(c.ClaimType == ClaimTypes.Upn); }).First().Value;

            AuthenticationActions.FindUserDetailsAction action = PolicyInjection.Create <AuthenticationActions.FindUserDetailsAction>();

            AuthenticationEntities.FindUserDetailsParameters parameters = Translators.FindUserDetailsTranslator.TranslateFromServiceToBusiness(request.FindUserDetailsParameters);

            parameters.UserPrincipalIdentity = upn; /* user@domain */
            parameters.UserIdentity          = upn.Split('@')[0];

            AuthenticationEntities.FindUserDetailsResult r = action.Execute(parameters);

            FindUserDetailsResponse response = new FindUserDetailsResponse();

            response.FindUserDetailsResult = GenericMapper.MapNew <DataContracts.FindUserDetailsResult>(r);

            response.FindUserDetailsResult.UserWarehouses = GenericMapper.MapListNew <DataContracts.UserWarehouseCollection, AuthenticationEntities.FindUserWarehousesResult, DataContracts.UserWarehouse>(
                r.Warehouses, Translators.FindUserDetailsTranslator.TranslateFromBusinessToService);

            response.FindUserDetailsResult.UserCompanies = GenericMapper.MapListNew <DataContracts.UserCompanyCollection, AuthenticationEntities.FindUserCompaniesResult, DataContracts.UserCompany>(
                r.Companies, Translators.FindUserDetailsTranslator.TranslateFromBusinessToService);

            return(response);
        }
コード例 #9
0
        public void CanCreateWrappedObject()
        {
            SetupContainer("CanCreateWrappedObject");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>();

            Assert.IsNotNull(wrappable);
            Assert.IsTrue(RemotingServices.IsTransparentProxy(wrappable));
        }
コード例 #10
0
        public void CanCreateWrappedObject()
        {
            IConfigurationSource configurationSource = CreateConfigurationSource("CanCreateWrappedObject");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>(configurationSource);

            Assert.IsNotNull(wrappable);
            Assert.IsTrue(RemotingServices.IsTransparentProxy(wrappable));
        }
コード例 #11
0
ファイル: TestTool.cs プロジェクト: yekainew/DemoSee
        // 定义单例模式将PolicyInjection.Create<UserOperation>()产生的这个对象传出去,这样就避免了在调用处写这些东西
        public static TestTool GetInstance()
        {
            if (oUserOpertion == null)
            {
                oUserOpertion = PolicyInjection.Create <TestTool>();
            }

            return(oUserOpertion);
        }
コード例 #12
0
        //定义单例模式将PolicyInjection.Create<UserOperation>()产生的这个对象传出去,这样就避免了在调用处写这些东西
        public static UserOperation GetInstance()
        {
            if (oUserOpertion == null)
            {
                oUserOpertion = PolicyInjection.Create <UserOperation>();
            }

            return(oUserOpertion);
        }
コード例 #13
0
        public void StaticFacadeUsesTheCurrentServiceLocator()
        {
            GlobalCountCallHandler.Calls.Clear();

            var interceptionConfigurationSource = new DictionaryConfigurationSource();

            interceptionConfigurationSource.Add(
                PolicyInjectionSettings.SectionName,
                new PolicyInjectionSettings
            {
                Policies =
                {
                    new PolicyData("policy")
                    {
                        MatchingRules =
                        {
                            new CustomMatchingRuleData("always", typeof(AlwaysMatchingRule))
                        },
                        Handlers =
                        {
                            new CustomCallHandlerData("count", typeof(GlobalCountCallHandler))
                            {
                                Attributes ={                  { "callhandler","count"  } }
                            }
                        }
                    }
                }
            });
            var interceptionLocator = EnterpriseLibraryContainer.CreateDefaultContainer(interceptionConfigurationSource);

            var noInterceptionLocator = EnterpriseLibraryContainer.CreateDefaultContainer(new DictionaryConfigurationSource());

            try
            {
                EnterpriseLibraryContainer.Current = interceptionLocator;

                var interceptedWrappable = PolicyInjection.Create <Wrappable>();
                interceptedWrappable.Method();
                Assert.AreEqual(1, GlobalCountCallHandler.Calls.Count);
                GlobalCountCallHandler.Calls.Clear();


                EnterpriseLibraryContainer.Current = noInterceptionLocator;

                var nonInterceptedWrappable = PolicyInjection.Create <Wrappable>();
                nonInterceptedWrappable.Method();
                Assert.AreEqual(0, GlobalCountCallHandler.Calls.Count);
            }
            finally
            {
                EnterpriseLibraryContainer.Current = null;
                GlobalCountCallHandler.Calls.Clear();
                interceptionLocator.Dispose();
                noInterceptionLocator.Dispose();
            }
        }
コード例 #14
0
ファイル: Default.aspx.cs プロジェクト: mayleng/AOP
        protected void Page_Load(object sender, EventArgs e)
        {
            Employee emp = PolicyInjection.Create <Employee>();

            emp.Name = "Lele";

            emp.Work();

            Response.Write(emp);
        }
コード例 #15
0
        public void CanInterceptWrappedObjectWithNonGenericMethods()
        {
            SetupContainer("CanCreateWrappedObject");

            Wrappable wrappable = (Wrappable)PolicyInjection.Create(typeof(Wrappable));

            wrappable.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]);
        }
コード例 #16
0
        public void CanInterceptCallsToDerivedOfMBRO()
        {
            SetupContainer("CanInterceptCallsToDerivedOfMBRO");

            DerivedWrappable wrappable = PolicyInjection.Create <DerivedWrappable>();

            wrappable.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallsToDerivedOfMBRO"]);
        }
コード例 #17
0
        public void InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes()
        {
            SetupContainer("InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes");

            DerivedWrappable wrappable = PolicyInjection.Create <DerivedWrappable>();

            wrappable.Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes"]);
        }
コード例 #18
0
        public void CanInterceptWrappedObject()
        {
            SetupContainer("CanCreateWrappedObject");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>();

            wrappable.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]);
        }
コード例 #19
0
        public GetSystemTimeResponse GetSystemTime()
        {
            GetSystemTimeAction action = PolicyInjection.Create <GetSystemTimeAction>();

            GetSystemTimeResponse response = new GetSystemTimeResponse();

            response.GetSystemTimeResult = GetSystemTimeResultTranslator.TranslateFromBusinessToService(action.Execute());

            return(response);
        }
コード例 #20
0
        public void CanInterceptCallsToMBROOverInterface()
        {
            SetupContainer("CanInterceptCallsToMBROOverInterface");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>();

            ((Interface)wrappable).Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallsToMBROOverInterface"]);
        }
コード例 #21
0
        public void CanCreateWrappedObjectOverInterfaceWithNonGenericMethods()
        {
            SetupContainer("CanCreateWrappedObjectOverInterface");

            Interface wrappedOverInterface = (Interface)PolicyInjection.Create(typeof(WrappableThroughInterface), typeof(Interface));

            wrappedOverInterface.Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObjectOverInterface"]);
        }
コード例 #22
0
 public OutputHandlerServiceAdapter()
 {
     lock (_createOutputActionLock)
     {
         if (_createOutputAction == null)
         {
             _createOutputAction = PolicyInjection.Create <CreateOutputAction>();
         }
     }
 }
コード例 #23
0
        public void CanInterceptCallFromBaseOfWrappedInterface()
        {
            SetupContainer("CanInterceptCallFromBaseOfWrappedInterface");

            Interface wrappedOverInterface = PolicyInjection.Create <WrappableThroughInterface, Interface>();

            wrappedOverInterface.Method3();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallFromBaseOfWrappedInterface"]);
        }
コード例 #24
0
        static void Main()
        {
            //PolicyInjection.SetPolicyInjector(new PolicyInjector());
            Employee emp = PolicyInjection.Create <Employee>();

            emp.Name = "Lele";

            emp.Work();
            Console.WriteLine(emp);
            Console.Read();
        }
コード例 #25
0
        public LogonResponse Logon(LogonRequest request)
        {
            AuthenticationActions.LogonAction action = PolicyInjection.Create <AuthenticationActions.LogonAction>();

            AuthenticationEntities.LogonResult resultParams = action.Execute(Translators.LogonTranslator.TranslateFromServiceToBusiness(request.LogonParameters));
            LogonResponse response = new LogonResponse();

            response.LogonResult = Translators.LogonTranslator.TranslateFromBusinessToService(resultParams);

            return(response);
        }
コード例 #26
0
        public void CanInterceptCallFromBaseOfWrappedInterface()
        {
            GlobalCountCallHandler.Calls.Clear();

            IConfigurationSource configurationSource = CreateConfigurationSource("CanInterceptCallFromBaseOfWrappedInterface");

            Interface wrappedOverInterface = PolicyInjection.Create <WrappableThroughInterface, Interface>(configurationSource);

            wrappedOverInterface.Method3();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallFromBaseOfWrappedInterface"]);
        }
コード例 #27
0
        public void CanInterceptWrappedObject()
        {
            GlobalCountCallHandler.Calls.Clear();

            IConfigurationSource configurationSource = CreateConfigurationSource("CanCreateWrappedObject");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>(configurationSource);

            wrappable.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]);
        }
コード例 #28
0
        public void CanInterceptCallsToDerivedOfMBRO()
        {
            GlobalCountCallHandler.Calls.Clear();

            IConfigurationSource configurationSource = CreateConfigurationSource("CanInterceptCallsToDerivedOfMBRO");

            DerivedWrappable wrappable = PolicyInjection.Create <DerivedWrappable>(configurationSource);

            wrappable.Method2();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallsToDerivedOfMBRO"]);
        }
コード例 #29
0
        public void InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes()
        {
            GlobalCountCallHandler.Calls.Clear();

            IConfigurationSource configurationSource = CreateConfigurationSource("InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes");

            DerivedWrappable wrappable = PolicyInjection.Create <DerivedWrappable>(configurationSource);

            wrappable.Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["InterfaceImplementationsOnDerivedClassesAreWrappedMultipleTimes"]);
        }
コード例 #30
0
        public void CanInterceptCallsToMBROOverInterface()
        {
            GlobalCountCallHandler.Calls.Clear();

            IConfigurationSource configurationSource = CreateConfigurationSource("CanInterceptCallsToMBROOverInterface");

            Wrappable wrappable = PolicyInjection.Create <Wrappable>(configurationSource);

            ((Interface)wrappable).Method();

            Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallsToMBROOverInterface"]);
        }