Exemplo n.º 1
0
        public static void RunUnpackTest(ref TestSettings settings)
        {
            TestSettings r1 = null;
            TestSettings r2 = null;

            using (var nativeManager = new LocalManager())
            {
                Guid id = Guid.NewGuid();

                var nativeResult = nativeManager.BeginInvoke(typeof(TestRunner), "Unpack", id, false, settings);

                using (var managedManager = new InprocManager())
                    r2 = (TestSettings)managedManager.Invoke(typeof(TestRunner), "Unpack", id, true, settings);

                r1 = (TestSettings)nativeManager.EndInvoke(nativeResult);
            }

            if (r1.WrittenSize != r2.WrittenSize)
                throw new InvalidOperationException();

            if (r1.UsedSize != r2.UsedSize)
                throw new InvalidOperationException();

            for (int i = 0; i < r1.WrittenSize; i++)
                if (r1.Dst[i] != r2.Dst[i])
                    throw new InvalidOperationException();

            settings = r1;
        }
Exemplo n.º 2
0
        private static void Initialize(string[] args)
        {
            int index = Array.IndexOf(args, "-ipc") + 1; // zero if not found

            if (0 < index && index < args.Length && IsChannelId(args[index]))
            {
                LocalManager.EnsureServer(args[index]);
            }
            else
            {
                try { Program.RunSandbox(); }
                finally { Application.Exit(); }
            }
        }
Exemplo n.º 3
0
        public static void RunPackTest(ref TestSettings settings)
        {
            TestSettings r1 = null;
            TestSettings r2 = null;

            using (var nativeManager = new LocalManager())
            {
                Guid id = Guid.NewGuid();

                var nativeResult = nativeManager.BeginInvoke(typeof(TestRunner), "Pack", id, false, settings);

                using (var managedManager = new InprocManager())
                    r2 = (TestSettings)managedManager.Invoke(typeof(TestRunner), "Pack", id, true, settings);

                r1 = (TestSettings)nativeManager.EndInvoke(nativeResult);
            }

            if (r1.WrittenSize != r2.WrittenSize)
            {
                throw new InvalidOperationException();
            }

            for (int i = 0; i < r1.WrittenSize; i++)
            {
                if (r1.Dst[i] != r2.Dst[i])
                {
                    throw new InvalidOperationException();
                }
            }

            if (r1.Enc.Length != r2.Enc.Length)
            {
                throw new InvalidOperationException();
            }

            for (int i = 0; i < r1.Enc.Length; i++)
            {
                if (r1.Enc[i] != r2.Enc[i])
                {
                    throw new InvalidOperationException();
                }
            }

            settings = r1;
        }
Exemplo n.º 4
0
        public static void Main(params string[] args)
        {
            if (Array.IndexOf(args, "-debug") >= 0)
            {
                if (!System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Launch();
                }
                else
                {
                    System.Diagnostics.Debugger.Break();
                }
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-remote" && i + 1 < args.Length)
                {
                    LocalManager.RegisterRemote(args[++i]);
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Exception    error   = null;
            EventHandler handler = null;

            Application.Idle += handler = delegate
            {
                // Must be reentrant because we are triggered by the application-idle event.
                // (The next event may be "on air" before we are executed and unsubscribe ourselves.)
                if (handler == null)
                {
                    return;
                }

                Application.Idle -= handler;
                handler           = null;

                try
                {
                    mControl = new Control();
                    mControl.CreateControl();

                    Initialize(args);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            };

            EventHandler exitHandler = null;

            Application.ApplicationExit += exitHandler = delegate
            {
                if (exitHandler == null)
                {
                    return;
                }

                Application.ApplicationExit -= exitHandler;
                exitHandler = null;

                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-remote" && i + 1 < args.Length)
                    {
                        try { LocalManager.ShutdownRemote(args[++i]); }
                        catch { }
                    }
                }
            };

            Application.Run();

            if (mControl != null)
            {
                try
                {
                    mControl.Dispose();
                }
                catch
                {
                    // Ignore error if we already have something more important.
                    if (error == null)
                    {
                        throw;
                    }
                }

                mControl = null;
            }

            if (error != null)
            {
                throw new TargetInvocationException(error);
            }
        }