コード例 #1
0
        /// <summary>
        /// Registers a remote service for the given interface
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="forceProxyAutoCreation">Forces proxy auto creation for interface type. No local implementation lookup.</param>
        public void RegisterRemoteService(Type interfaceType, bool forceProxyAutoCreation = false)
        {
            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException("Given service type must be an interface!", nameof(interfaceType));
            }

            if (localSessionServiceInterfaceTypesResolved != null)
            {
                throw new Exception($"{GetType().FullName} is already initialized.");
            }

            lock (syncObj)
            {
                // try get auto generated proxy implementation type from cache
                Type proxyImplementationType;
                if (!interfaceTypeProxyImplCache.TryGetValue(interfaceType, out proxyImplementationType))
                {
                    if (forceProxyAutoCreation || !localShare.TryFindInterfaceImplementation(interfaceType, null, out proxyImplementationType))
                    {
                        // auto generate proxy
                        proxyImplementationType = TypeService.BuildProxyImplementation(interfaceType); // "[System.Composition.Import]");
                        interfaceTypeProxyImplCache.Add(interfaceType, proxyImplementationType);
                    }

                    localShare.AddAssembly(proxyImplementationType.Assembly);
                }

                remoteServiceInterfaceTypes.Add(interfaceType);
                remoteServiceProxyTypes.Add(proxyImplementationType);
            }
        }
コード例 #2
0
        private void TestAdvancedProxyImplementation()
        {
            try
            {
                Type result = TypeService.BuildProxyImplementation(typeof(IPerformanceMonitorService));

                DummyCommunicationService dummyCommService = new DummyCommunicationService();

                var constructorParams = new object[2];
                constructorParams[0] = dummyCommService;

                IPerformanceMonitorService instance = (IPerformanceMonitorService)Activator.CreateInstance(result, constructorParams);

                TimeSpan      timeSpan = new TimeSpan(23532534);
                List <string> testColl = new List <string>();
                testColl.Add("item 1");
                string testOutput;
                instance.SubscribeCpuUsageNotification(timeSpan, out testOutput, testColl);
            }
            catch (Exception ex)
            {
                // because of buggy unit test environment
                throw;
            }
        }
コード例 #3
0
        public void TestCreateProxyImplementationGuidMethods()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(IAutoImplementTestInterface));

            IAutoImplementTestInterface instance = (IAutoImplementTestInterface)Activator.CreateInstance(result, new object[2]);

            Assert.NotNull(instance);
        }
コード例 #4
0
        public void TestCreateProxyImplementationAsyncAwaitMethods()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(IMyRemoteAsyncAwaitTestService));

            IMyRemoteAsyncAwaitTestService instance = (IMyRemoteAsyncAwaitTestService)Activator.CreateInstance(result, new object[2]);

            Assert.NotNull(instance);
        }
コード例 #5
0
        private static void SimpleProxyImplementationTest()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(IPerformanceMonitorClientNotification));

            IPerformanceMonitorClientNotification instance = (IPerformanceMonitorClientNotification)Activator.CreateInstance(result, new object[2]);

            //var piCommSerivce = instance.GetType().GetProperty("CommunicationService");

            //DummyCommunicationService dummyCommService = new DummyCommunicationService();

            //piCommSerivce.SetValue(instance, dummyCommService, null);

            //PerformanceData data = new PerformanceData();
            //data.Type = MeasureType.Cpu;
            //data.Unity = "test";
            //data.Value = 2;
            //instance.OnPerformanceData(data);
        }
コード例 #6
0
        private void TestAdvancedProxyImplementationOutParams()
        {
            Type result = TypeService.BuildProxyImplementation(typeof(ITestServiceSpecialOutPrams));

            DummyCommunicationService dummyCommService = new DummyCommunicationService();

            var constructorParams = new object[2];

            constructorParams[0] = dummyCommService;

            ITestServiceSpecialOutPrams instance = (ITestServiceSpecialOutPrams)Activator.CreateInstance(result, constructorParams);

            //int? nullableInt;
            //instance.GetData(out nullableInt);


            var invokeMethod = new InvokeMethodInfo(typeof(ITestServiceSpecialOutPrams), nameof(ITestServiceSpecialOutPrams.GetData));

            var invokeMethodDeserialize = new InvokeMethodInfo(invokeMethod.InterfaceMethod.DeclaringType, invokeMethod.QualifiedMethodName);


            Assert.NotNull(invokeMethodDeserialize);
        }