예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Tests begin...");

            // 要使用 JointCode.Shuttle 进行跨 AppDomain 通信,首先必须初始化 ShuttleDomain。
            // 这个初始化操作一般在默认 AppDomain 执行,但也可以在其他 AppDomain 中执行,都是一样的。
            // To make cross-AppDomain communication with JointCode.Shuttle, initialize the ShuttleDomain at first.
            // It doesn't matter whether the initialization is done in default AppDomain or any other AppDomains,
            // but it must be done before any ShuttleDomain instance is created.
            ShuttleDomain.Initialize();

            // 在默认 AppDomain 中,创建一个 ShuttleDomain。
            // 事实上,在需要与其他 AppDomain 进行通信的每个 AppDomain 中,都要有一个且只能有一个 ShuttleDomain 对象。
            // 尝试在一个 AppDomain 中创建多个 ShuttleDomain 对象时将会抛出异常。
            // 该对象用于与其他 AppDomain 中的 ShuttleDomain 对象通信。
            // Creating a ShuttleDomain instance in default AppDomain.
            // Actually, we needs one and only one ShuttleDomain instance in every AppDomain that needs to communicate
            // with others. Trying to create another ShuttleDomain in the same AppDomain causes exceptions.
            // The ShuttleDomain instances communicates with each other across AppDomains.
            var str           = Guid.NewGuid().ToString();
            var shuttleDomain = ShuttleDomainHelper.Create(str, str);

            if (CallServicesDefinedInThisAssembly(shuttleDomain) &&
                CallServicesDefinedInAnotherAssembly(shuttleDomain))
            {
                Console.WriteLine("Tests completed...");
            }
            else
            {
                Console.WriteLine("Tests failed...");
            }

            shuttleDomain.Dispose();

            Console.Read();
        }
예제 #2
0
        static void Main(string[] args)
        {
            _tests.AddRange(new Test[]
            {
                new ShuttleDomainFunctionalTest(),
                new ShuttleDomainPerformanceTest(),
                new MarshalByObjectPerformanceTest(),
                new ShuttleDomainLifeTimeManagementTest(),
                new ShuttleDomainAnyAppDomainAccessTest(),
                new MarshalByRefCrossAccessTest(),
                new ShuttleDomainServiceUpdateTest(),
            });

            // 显示测试说明
            PrintNotification();

            // 初始化 ShuttleDomain
            ShuttleDomain.Initialize();

            // 初始化性能测量组件
            CodeTimer.Initialize();

            Console.WriteLine();
            Console.WriteLine("Beginning Tests...");
            Console.WriteLine("=========================================================================");

            do
            {
                if (_reEnter)
                {
                    var input = Console.ReadLine();
                    if (String.Equals("x", input, StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                }

                Console.WriteLine("Test List (SD stands for ShuttleDomain, MBO stands for MarshalByRefObject)");
                Console.WriteLine("=========================================================================");

                var testInfo = BuildTestInfo();
                Console.Write(testInfo);

                Console.WriteLine
                    ("Input the index of test to run:");
                int index;
                var strIndex = Console.ReadLine();
                if (!int.TryParse(strIndex, out index))
                {
                    throw new InvalidOperationException(string.Format("The [{0}] is not a number!", strIndex));
                }
                if (index > _tests.Count - 1)
                {
                    throw new InvalidOperationException(string.Format("The specified index [{0}] is out of range!", strIndex));
                }

                var test = _tests[index];
                test.Run();

                Console.WriteLine();
                var oldForeColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine
                    ("press [x] to exit the tests,or [c] to run other tests.");
                Console.ForegroundColor = oldForeColor;
                Console.WriteLine();

                _reEnter = true;
            } while (true);

            Console.WriteLine();
            Console.WriteLine("Tests completed!");
            Console.Read();
        }