Esempio n. 1
0
 public void Invalidate(ProxyDefinition proxy)
 {
     foreach (var p in ProxyDefinitions.Where(x => x.Key == proxy.Key))
     {
         Db.Config.Cache.InvalidateObject(p);
     }
 }
        public static TypeMetadata BuildTypeMetadata(ProxyDefinition proxyDefinition)
        {
            var classProxyDefinition = proxyDefinition as ClassProxyDefinition;

            if (classProxyDefinition != null)
            {
                return new ClassProxyMetadataBuilder(classProxyDefinition).Build();
            }

            var interfaceProxyDefinition = proxyDefinition as InterfaceProxyDefinition;

            if (interfaceProxyDefinition != null)
            {
                return new InterfaceProxyMetadataBuilder(interfaceProxyDefinition).Build();
            }

            var targetedClassProxyDefinition = proxyDefinition as TargetedClassProxyDefinition;

            if (targetedClassProxyDefinition != null)
            {
                return new TargetedClassProxyMetadataBuilder(targetedClassProxyDefinition).Build();
            }

            var targetedInterfaceProxyDefinition = proxyDefinition as TargetedInterfaceProxyDefinition;

            if (targetedInterfaceProxyDefinition != null)
            {
                return new TargetedInterfaceProxyMetadataBuilder(targetedInterfaceProxyDefinition).Build();
            }

            throw new NotSupportedException();
        }
Esempio n. 3
0
        public static T CreateProxy <T>(this ProxyDefinition definition)
        {
            var builder   = new ProxyBuilder();
            var proxyType = builder.GetProxyType(definition);

            return((T)Activator.CreateInstance(proxyType));
        }
Esempio n. 4
0
        public static object CreateDuck(this IInterceptor interceptor, Type proxyType)
        {
            var definition = new ProxyDefinition(proxyType, () => null);

            definition.Implement(() => interceptor);
            return(definition.CreateProxy());
        }
Esempio n. 5
0
        public object Deserialize(string fileName)
        {
            var game = DbContext.Get().Games.First(x => x.Id == GameId);
            var ret  = new ProxyDefinition(GameId, fileName, new FileInfo(game.Filename).Directory.FullName);

            return(ret);
        }
Esempio n. 6
0
        public static T CreateDuck <T>(this IInterceptor interceptor)
        {
            var definition = new ProxyDefinition(typeof(T), () => null);

            definition.Implement(() => interceptor);
            return(definition.CreateProxy <T>());
        }
        private T CreateProxyWithoutInterceptor <T>(T target)
        {
            var  proxyDefinition = new ProxyDefinition(typeof(T));
            Type proxyType       = CreateProxyBuilder().GetProxyType(proxyDefinition);

            return((T)Activator.CreateInstance(proxyType, new Lazy <T>(() => target)));
        }
Esempio n. 8
0
            public override void PushWooHoo(Sim actor, Sim target, IGameObject obj)
            {
                HoverTrainStation station = obj as HoverTrainStation;

                InteractionPriority priority = new InteractionPriority(InteractionPriorityLevel.UserDirected);

                HoverTrainStation[] listOfObjects = HoverTrainStation.GetHoverTrainStations().ToArray();
                if (listOfObjects.Length <= 1)
                {
                    return;
                }

                int choiceIndex = RandomUtil.GetInt(listOfObjects.Length - 0x1);
                HoverTrainStation destination = listOfObjects[choiceIndex];

                if (destination == station)
                {
                    choiceIndex++;
                    if (choiceIndex == listOfObjects.Length)
                    {
                        choiceIndex = 0x0;
                    }
                    destination = listOfObjects[choiceIndex];
                }

                HoverTrainWoohoo entry = new ProxyDefinition(this).CreateInstance(station, actor, priority, false, true) as HoverTrainWoohoo;

                entry.mWoohooee    = target;
                entry.mDestination = destination;
                actor.InteractionQueue.PushAsContinuation(entry, true);
            }
Esempio n. 9
0
public void VerifyProxyDefPaths()
{
    const string  gError     = "{0} {1} does not exist here {1}. Remember paths cannot start with / or \\";
    XmlSerializer serializer = new XmlSerializer(typeof(game));
    var           fs         = File.Open(Directory.GetFiles().First(x => x.Name == "definition.xml").FullName, FileMode.Open);
    var           game       = (game)serializer.Deserialize(fs);

    fs.Close();

    var proxyDef = Path.Combine(Directory.FullName, game.proxygen.definitionsrc);

    Dictionary <string, string> blockSources = ProxyDefinition.GetBlockSources(proxyDef);

    foreach (KeyValuePair <string, string> kvi in blockSources)
    {
        string path = Path.Combine(Directory.FullName, kvi.Value);
        if (!File.Exists(path))
        {
            throw new UserMessageException(gError, "Block id: " + kvi.Key, "src: " + kvi.Value, path);
        }
    }

    List <string> templateSources = ProxyDefinition.GetTemplateSources(proxyDef);

    foreach (string source in templateSources)
    {
        string path = Path.Combine(Directory.FullName, source);
        if (!File.Exists(path))
        {
            throw new UserMessageException(gError, "Template", "src: " + source, path);
        }
    }
}
Esempio n. 10
0
        private void generateProxyButton_Click(object sender, EventArgs e)
        {
            CheckLoadArtOverlay();
            string tempImagePath = Path.Combine(GetExecutingDir(), "temp.png");

            if (File.Exists(tempImagePath))
            {
                File.Delete(tempImagePath);
            }
            ProxyDefinition def       = GetProxyDef(proxydefPathTextBox.Text, rootDirTextBox.Text);
            DateTime        startTime = DateTime.Now;

            if (LoadArtOverlay)
            {
                string artOverlayPath = artOverlayTextbox.Text;
                def.SaveProxyImage(GetValues(), tempImagePath, artOverlayPath);
            }
            else
            {
                def.SaveProxyImage(GetValues(), tempImagePath);
            }
            DateTime endTime = DateTime.Now;

            proxyPictureBox.ImageLocation = tempImagePath;
            proxyPictureBox.Refresh();
            TimeGeneratedTextBox.Text = string.Format("Generated in {0}ms", (endTime - startTime).Milliseconds);
        }
        private Type CreateProxyType(Type targetType)
        {
            var proxyDefinition = new ProxyDefinition(targetType);

            proxyDefinition.Implement(() => null, m => m.IsDeclaredBy(targetType));
            return(CreateProxyBuilder().GetProxyType(proxyDefinition));
        }
        protected ProxyMetadataBuilder(ProxyDefinition proxyDefinition, Type baseType)
        {
            _proxyDefinition = proxyDefinition;
            _baseType = baseType;

            _dispatcherField = new DispatcherFieldMetadata();
        }
Esempio n. 13
0
        private void DefineProxyType(IServiceFactory servicefactory, ProxyDefinition proxyDefinition)
        {
            //container.Register<ILogFactory, LogFactory>();
            //container.Register<ILogBase,log.Logger>();

            proxyDefinition.Implement(() => servicefactory.GetInstance<IInterceptor>("LogInterceptor"));
        }
        public void GetProxyType_DerivedFromInterfaceWithGenericMethod_ReturnsProxyType()
        {
            var proxyDefinition = new ProxyDefinition(typeof(IDerivedFromGenericMethod), () => null);

            proxyDefinition.Implement(() => null);
            var proxyType = CreateProxyType(proxyDefinition);
        }
Esempio n. 15
0
        public void GetProxyType_VirtualMethod_ReturnsSubclass()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod));

            Type proxyType = CreateProxyType(proxyDefinition);

            Assert.IsTrue(proxyType.IsSubclassOf(typeof(ClassWithVirtualMethod)));
        }
        public void GetProxyType_WithoutTargetFactory_DeclaresConstructorWithLazyTargetParameter()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget));
            var proxyType       = CreateProxyType(proxyDefinition);
            var constructor     = proxyType.GetConstructor(new[] { typeof(Lazy <ITarget>) });

            Assert.NotNull(constructor);
        }
        public void GetProxyType_WithoutTargetFactory_DoesNotDeclareParameterlessConstructor()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget));
            var proxyType       = CreateProxyType(proxyDefinition);
            var constructor     = proxyType.GetConstructor(Type.EmptyTypes);

            Assert.Null(constructor);
        }
Esempio n. 18
0
        public void GetProxyType_AdditionalInterface_ImplementsInterface()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod), typeof(IAdditionalInterface));

            var proxyType = CreateProxyType(proxyDefinition);

            Assert.IsTrue(typeof(IAdditionalInterface).IsAssignableFrom(proxyType));
        }
        public void GetProxyType_MustImplementProxyInterface()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget), () => null);

            var proxyType = CreateProxyType(proxyDefinition);

            Assert.True(typeof(IProxy).IsAssignableFrom(proxyType));
        }
        public void GetProxyType_AdditionalInterface_ImplementsInterface()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget), typeof(IAdditionalInterface));

            var proxyType = CreateProxyType(proxyDefinition);

            Assert.True(typeof(IAdditionalInterface).IsAssignableFrom(proxyType));
        }
Esempio n. 21
0
        public Type Build(ProxyDefinition proxyDefinition)
        {
            var typeMetadata = ProxyMetadataFactory.BuildTypeMetadata(proxyDefinition);

            var generator = new TypeGenerator(_moduleBuilder, _proxyNamespace, typeMetadata);

            return generator.Generate();
        }
        public void GetProxyType_AdditionalInterface_ImplementsInterface()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod), typeof(IAdditionalInterface));

            var proxyType = CreateProxyType(proxyDefinition);

            Assert.IsTrue(typeof(IAdditionalInterface).IsAssignableFrom(proxyType));
        }
        private void ParseDefinitions(JObject jObject, ProxyDefinition proxyDefinition)
        {
            foreach (var definitionToken in jObject["definitions"].Where(i => i.Type == JTokenType.Property).Cast <JProperty>())
            {
                bool addIt           = true;
                var  classDefinition = new ClassDefinition(definitionToken.Name);
                var  allOf           = definitionToken.First["allOf"];
                if (allOf != null)
                {
                    foreach (var itemToken in allOf)
                    {
                        var refType = itemToken["$ref"] as JValue;
                        if (refType != null)
                        {
                            classDefinition.Inherits = refType.Value.ToString();
                        }

                        var properties = itemToken["properties"];
                        if (properties != null)
                        {
                            foreach (var prop in properties)
                            {
                                var type = ParseType(prop);
                                classDefinition.Properties.Add(type);
                            }
                        }
                    }
                }
                else
                {
                    var properties = definitionToken.Value["properties"];
                    if (properties != null)
                    {
                        foreach (var prop in properties)
                        {
                            var type = ParseType(prop);
                            classDefinition.Properties.Add(type);
                        }
                    }
                    else
                    {
                        addIt = false;
                    }
                }


                classDefinition.Name = FixGenericName(classDefinition.Name);
                if (classDefinition.Name.Equals("Void", StringComparison.InvariantCulture))
                {
                    addIt = false;
                }

                if (addIt)
                {
                    proxyDefinition.ClassDefinitions.Add(classDefinition);
                }
            }
        }
Esempio n. 24
0
        public static T CreateLightInjectInterfaceProxy <T>(T target)
        {
            var proxyDefinition = new ProxyDefinition(typeof(T), () => target);

            proxyDefinition.Implement(() => new LightInjectInterceptor());
            var proxyBuilder = new ProxyBuilder();

            return((T)Activator.CreateInstance(proxyBuilder.GetProxyType(proxyDefinition)));
        }
 public void Execute_InterceptedMethodWithTargetReturnType_ReturnsProxy()
 {
     var proxyBuilder = CreateProxyBuilder();
     var proxyDefinition = new ProxyDefinition(typeof(ClassWithTargetReturnType));
     proxyDefinition.Implement(() => new SampleInterceptor());
     var proxyType = proxyBuilder.GetProxyType(proxyDefinition);
     var instance = (ClassWithTargetReturnType)Activator.CreateInstance(proxyType);
     Assert.IsAssignableFrom(typeof (IProxy), instance);
 }
        public void Create_TargetWithEventWithoutInterceptingAddRemove_CanCreateProxyType()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithEvent));

            proxyDefinition.Implement(() => new SampleInterceptor(), method => method.Name == "ToString");
            Type proxyType = CreateProxyType(proxyDefinition);

            Assert.True(typeof(ClassWithEvent).IsAssignableFrom(proxyType));
        }
Esempio n. 27
0
        private ProxyDefinition CreateProxyDefinition(Type serviceType)
        {
            var proxyDefinition = new ProxyDefinition(serviceType, () => null);

            proxyDefinition.Implement(
                () => new ServiceInterceptor(serviceClient),
                method => method.DeclaringType == serviceType);
            return(proxyDefinition);
        }
        public void GetProxyType_VirtualMethod_ReturnsSubclass()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod));

            Type proxyType = CreateProxyType(proxyDefinition);

            Assert.IsTrue(proxyType.IsSubclassOf(typeof(ClassWithVirtualMethod)));

        }
        private T CreateProxy <T>(IInterceptor interceptor, T target)
        {
            var proxyDefinition = new ProxyDefinition(typeof(T));

            proxyDefinition.Implement(info => info.Name == "Execute", () => interceptor);
            Type proxyType = CreateProxyBuilder().GetProxyType(proxyDefinition);

            return((T)Activator.CreateInstance(proxyType, new Lazy <T>(() => target)));
        }
        private T CreateProxy <T>(IInterceptor interceptor)
        {
            var proxyDefinition = new ProxyDefinition(typeof(T));

            proxyDefinition.Implement(() => interceptor, info => info.Name == "Execute");
            Type proxyType = CreateProxyBuilder().GetProxyType(proxyDefinition);

            return((T)Activator.CreateInstance(proxyType, (object)null));
        }
        public void GetProxyType_InterfaceThatInheritsAnotherInterface_ImplementsBothInterfaces()
        {
            var proxyDefinition = new ProxyDefinition(typeof(IDisposableTarget), () => null);
            var proxyType       = CreateProxyType(proxyDefinition);

            var disposable = (IDisposable)Activator.CreateInstance(proxyType);

            Assert.IsAssignableFrom <IProxy>(disposable);
        }
        private T1 CreateProxy <T1, T2>(IInterceptor interceptor, string methodName)
        {
            var proxyDefinition = new ProxyDefinition(typeof(T1), typeof(T2), false);

            proxyDefinition.Implement(() => interceptor, info => info.Name == methodName);
            Type proxyType = CreateProxyBuilder().GetProxyType(proxyDefinition);

            return((T1)Activator.CreateInstance(proxyType, (object)null));
        }
Esempio n. 33
0
        static void Main(string[] args)
        {
            var definition = new ProxyDefinition()
            {
                ServerAddress = IPAddress.Any
            };

            // Use localhost if the debugger is attached
            if (Debugger.IsAttached)
            {
                definition.ServerAddress = IPAddress.Any;
                definition.ServerPort    = 4501;
            }
            else
            {
                Console.WriteLine("Enter server port:");
                var port = Console.ReadLine();
                if (!String.IsNullOrEmpty(port))
                {
                    definition.ServerPort = Convert.ToInt16(port);
                }

                Console.WriteLine("Enter client/destination address:");
                var address = Console.ReadLine();
                if (!String.IsNullOrEmpty(port))
                {
                    definition.ClientAddress = IPAddress.Parse(address);
                }

                Console.WriteLine("Enter client/destination port:");
                var clientPort = Console.ReadLine();

                if (!String.IsNullOrEmpty(port))
                {
                    definition.ClientPort = Convert.ToInt16(clientPort);
                }
            }


            Proxy = new TcpProxy(definition);
            Proxy.Start();

            Console.WriteLine("Proxy started between {0}:{1} and {2}:{3}",
                              definition.ServerAddress, definition.ServerPort,
                              definition.ClientAddress, definition.ClientPort);

            Proxy.BytesTransfered        += Proxy_BytesTransfered;
            Proxy.ServerDataSentToClient += Proxy_ServerDataSentToClient;
            Proxy.ClientDataSentToServer += Proxy_ClientDataSentToServer;

            Console.WriteLine("Press any key to stop proxy");
            Console.ReadLine();
            Proxy.Stop();
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
        public void GetProxyType_ForProxyDefinition_DeclaresLazyTargetField()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget));

            var proxyType = CreateProxyType(proxyDefinition);

            FieldInfo targetField = proxyType.GetField("target", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.Equal(typeof(Lazy <ITarget>), targetField.FieldType);
        }
        public void GetProxyType_InterceptedVirtualMethod_ReturnsSubClass()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod));

            proxyDefinition.Implement(() => null, info => info.Name == "Execute");

            Type proxyType = CreateProxyType(proxyDefinition);

            Assert.IsTrue(proxyType.IsSubclassOf(typeof(ClassWithVirtualMethod)));
        }
        private T CreateProxy <T>(T target, string methodName)
        {
            var proxyDefinition = new ProxyDefinition(typeof(T));
            var interceptor     = CreateProceedingInterceptor();

            proxyDefinition.Implement(() => interceptor, m => m.Name == methodName);
            Type proxyType = CreateProxyBuilder().GetProxyType(proxyDefinition);

            return((T)Activator.CreateInstance(proxyType, new Lazy <T>(() => target)));
        }
        public void GetProxyType_WithoutLazyTargetConstructor_DeclaresTargetField()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ITarget), false);

            var proxyType = CreateProxyType(proxyDefinition);

            FieldInfo targetField = proxyType.GetField("target", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.Equal(typeof(ITarget), targetField.FieldType);
        }
        public void GetProxyType_TypeAttributeWithStaticConstructor_ReturnsProxyWithClassAttribute()
        {
            var proxyDefinition = new ProxyDefinition(typeof(IMethodWithNoParameters));

            proxyDefinition.AddCustomAttributes(typeof(ClassWithCustomAttributeWithStaticConstructor).GetCustomAttributesData().ToArray());
            var proxyBuilder = new ProxyBuilder();
            var proxyType    = proxyBuilder.GetProxyType(proxyDefinition);

            Assert.True(proxyType.IsDefined(typeof(CustomAttributeWithStaticConstructor), true));
        }
        public void GetProxyType_VirtualMethod_DoesNotDeclareTargetField()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod));

            Type proxyType = CreateProxyType(proxyDefinition);
            
            FieldInfo targetField = proxyType.GetField("target", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNull(targetField);
        }
        public void GetProxyType_ClassProxyWithConstructorParameters_ReturnsProxyWithNamedConstructorParameters()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithConstructor));

            Type proxyType = CreateProxyType(proxyDefinition);

            var constructor = proxyType.GetConstructor(new Type[] { typeof(string) });

            Assert.AreEqual("value", constructor.GetParameters()[0].Name);

        }
        public void Execute_VirtualMethod_CallsMethodInBaseClass()
        {                        
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualMethod));

            proxyDefinition.Implement(() => new SampleInterceptor(), info => info.Name == "Execute");

            Type proxyType = CreateProxyType(proxyDefinition);

            var proxy = (ClassWithVirtualMethod)Activator.CreateInstance(proxyType);

            proxy.Execute();
        }
Esempio n. 42
0
        static void Main(string[] args)
        {
            var definition = new ProxyDefinition() { ServerAddress = IPAddress.Any };

            // Use localhost if the debugger is attached
            if (Debugger.IsAttached)
            {
                definition.ServerAddress = IPAddress.Any;
                definition.ServerPort = 4501;
            }
            else
            {
                Console.WriteLine("Enter server port:");
                var port = Console.ReadLine();
                if (!String.IsNullOrEmpty(port))
                {
                    definition.ServerPort = Convert.ToInt16(port);
                }

                Console.WriteLine("Enter client/destination address:");
                var address = Console.ReadLine();
                if (!String.IsNullOrEmpty(port))
                {
                    definition.ClientAddress = IPAddress.Parse(address);
                }

                Console.WriteLine("Enter client/destination port:");
                var clientPort = Console.ReadLine();

                if (!String.IsNullOrEmpty(port))
                {
                    definition.ClientPort = Convert.ToInt16(clientPort);
                }
            }

            Proxy = new TcpProxy(definition);
            Proxy.Start();

            Console.WriteLine("Proxy started between {0}:{1} and {2}:{3}",
                definition.ServerAddress, definition.ServerPort,
                definition.ClientAddress, definition.ClientPort);

            Proxy.BytesTransfered += Proxy_BytesTransfered;
            Proxy.ServerDataSentToClient += Proxy_ServerDataSentToClient;
            Proxy.ClientDataSentToServer += Proxy_ClientDataSentToServer;

            Console.WriteLine("Press any key to stop proxy");
            Console.ReadLine();
            Proxy.Stop();
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            if (serviceType == null)
                throw new ArgumentNullException("serviceType");

            var attribute = serviceType.GetCustomAttributes(typeof(ServiceContractAttribute), true)
                                       .Cast<ServiceContractAttribute>()
                                       .FirstOrDefault();

            if (!serviceType.IsInterface || attribute == null)
                throw new NotSupportedException("Only interfaces with [ServiceContract] attribute are supported with LightInjectServiceHostFactory.");

            var container = new ServiceContainer();
            var proxyBuilder = new ProxyBuilder();
            var proxyDefinition = new ProxyDefinition(serviceType, () => container.GetInstance(serviceType));
            var proxyType = proxyBuilder.GetProxyType(proxyDefinition);

            return base.CreateServiceHost(proxyType, baseAddresses);
        }
Esempio n. 44
0
        static void Main(string[] args)
        {
            // Create a localhost definition if the debugger is attached
            var definition = new ProxyDefinition() { ServerAddress = IPAddress.Any };

            if (Debugger.IsAttached)
            {
                definition.ServerAddress = IPAddress.Any;
                definition.ServerPort = 4501;
            }
            else
            {
                Console.WriteLine("Enter server port:");
                var port = Console.ReadLine();
                if (!String.IsNullOrEmpty(port))
                {
                    definition.ServerPort = Convert.ToInt16(port);
                }

            }

            // Create a new VNC Repeater
            Proxy = new TcpVNCRepeater(definition.ServerPort, definition.ServerAddress);
            Proxy.Start();

            Console.WriteLine("Repeater started on {0}:{1}", definition.ServerAddress, definition.ServerPort);

            // Proxy.BytesTransfered += Proxy_BytesTransfered;
            // Proxy.ServerDataSentToClient += Proxy_ServerDataSentToClient;
            // Proxy.ClientDataSentToServer += Proxy_ClientDataSentToServer;

            Console.WriteLine("Press any key to stop repeater");
            Console.ReadLine();
            Proxy.Stop();
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
        public void Create_NonInterceptedTargetWithVirtualProperty_PassesValueToBaseClass()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithVirtualProperty));
            proxyDefinition.Implement(() => new SampleInterceptor(), info => false);
                

            Type proxyType = CreateProxyType(proxyDefinition);

            var proxy = (ClassWithVirtualProperty)Activator.CreateInstance(proxyType);

            proxy.Value = "SomeValue";
            
            Assert.AreEqual("SomeValue", proxy.value);
        }
 private static void DefineProxyType(IServiceFactory serviceFactory, ProxyDefinition proxyDefinition)
 {
     proxyDefinition.Implement(() => new FirstInterceptor());
     proxyDefinition.Implement(() => new SecondInterceptor());
 }
 private void Apply(IServiceFactory factory, ProxyDefinition proxyDefinition)
 {
     proxyDefinition.Implement(factory.GetInstance<AopProxy>);
 }
 private static void DefineProxyType(ProxyDefinition definition, IInterceptor myInterceptor)
 {
     definition.Implement(
         () => myInterceptor,
         m => m.IsDeclaredBy(definition.TargetType) && m.IsPublic);
 }
 private Type CreateProxyType(ProxyDefinition proxyDefinition)
 {
     return CreateProxyBuilder().GetProxyType(proxyDefinition);
 }
        public void Create_TargetWithEventWithoutInterceptingAddRemove_CanCreateProxyType()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithEvent));
            proxyDefinition.Implement(() => new SampleInterceptor(), method => method.Name == "ToString");            
            Type proxyType = CreateProxyType(proxyDefinition);
            Assert.True(typeof(ClassWithEvent).IsAssignableFrom(proxyType));

        }
        public void Execute_AbstractMethod_InvokeInterceptor()
        {
            var interceptorMock = new Mock<IInterceptor>();
            var proxyBuilder = new ProxyBuilder();
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithAbstractMethod), () => null);
            proxyDefinition.Implement(() => interceptorMock.Object);            
            var proxyType = proxyBuilder.GetProxyType(proxyDefinition);
            var instance = (ClassWithAbstractMethod)Activator.CreateInstance(proxyType);
            instance.Execute();
            interceptorMock.Verify(interceptor => interceptor.Invoke(It.IsAny<IInvocationInfo>()), Times.Once);

        }
 public InterfaceProxyMetadataBuilder(ProxyDefinition proxyDefinition)
     : base(proxyDefinition, typeof(object))
 {
 }
Esempio n. 53
0
 private static void ImplementDisposeMethod(IServiceFactory serviceFactory, ProxyDefinition proxyDefinition)
 {
     proxyDefinition.Implement(
         () => new HubDisposeInterceptor(serviceFactory),
         m => m.Name == "Dispose" && m.GetParameters().Any(p => p.ParameterType == typeof(bool)));
 }        
        public void Create_TargetWithConstructorParameter_PassesValueToBaseClass()
        {
            var proxyDefinition = new ProxyDefinition(typeof(ClassWithConstructor));

            proxyDefinition.Implement(() => new SampleInterceptor(), info => info.Name == "Execute");

            Type proxyType = CreateProxyType(proxyDefinition);

            var proxy = (ClassWithConstructor)Activator.CreateInstance(proxyType, "SomeValue");
            
            Assert.AreEqual("SomeValue", proxy.Value);
        }