public IApplicationInstance Run(string path, string verb, string[] args, IComponentDirectory environ)
        {
            ApplicationDesc app = null;

            try
            {
                app = databaseManager.Find <ApplicationDesc>(path).Object;
            }
            catch (Exception)
            {
            }

            if (app == null)
            {
                throw new Exception(
                          String.Format(
                              "There is no application present at: '{0}'", path));
            }

            ComponentDirectory localEnvironment = new ComponentDirectory(this.componentDirectory, path);

            foreach (IComponentProvider component in environ.RegisteredProviders)
            {
                localEnvironment.Register(component);
            }

            LocalApplication application = new LocalApplication(
                localEnvironment,
                app, Guid.NewGuid(), NewInstanceNumber(app));

            application.Callback = this;
            applicationInstances.Add(application);
            application.Start(verb, args);

            return(application);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IComponentDirectory icd = new ComponentDirectory();

            icd.Register(new ConfiguredComponent(typeof(StandardConsole).FullName, "Console"));

            using (ThreadControl tc = new ThreadControl())
            {
                tc.Components = icd;
                (tc as IComponentPostInitialization).PostComponentInit(icd);

                tc.Register(new LastResortOptimizer());

                Parallel parallel = new Parallel();
                parallel.ThreadControl = tc;
                long baseTime = DateTime.Now.Ticks;

                Int32 finished = 0;

                long[] tickTimes = new long[count];
                int[]  threadIds = new int[count];

                List <int> ilist = new List <int>();
                Random     r     = new Random();
                for (int i = 0; i < count; ++i)
                {
                    ilist.Add(r.Next());
                }

                Console.Out.WriteLine("a1:" + (DateTime.Now.Ticks - baseTime));

                parallel.ForEach(ilist,
                                 delegate(int i)
                {
                    // Console.Out.WriteLine("# {0} (finished {1}, Thread {2})", i, finished, Thread.CurrentThread.ManagedThreadId);

                    finished++;
                });

                Console.Out.WriteLine("a3:" + (DateTime.Now.Ticks - baseTime));

                while (finished < count)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(0.5f));
                }

                long startupTime = TimeSpan.FromMilliseconds(10).Ticks;

                /*
                 * for (int i = 0; i < 100; ++i)
                 * {
                 *  Console.Out.WriteLine("{0}: Thread: {2} {1} ticks", i,
                 *      tickTimes[i] - baseTime - startupTime,
                 *      threadIds[i]);
                 * }
                 */

                foreach (IWorkUnit wu in tc.WorkUnits.All <ICPUWorkUnit>())
                {
                    Console.Out.WriteLine(wu);
                }
            }
        }
Ejemplo n.º 3
0
        public override int StartDocument(DocumentParameter[] parameters)
        {
            if (parameters.Length > 0)
            {
                throw new Exception("Shell application does not allow any parameters.");
            }

            // We first check if render target parameters are set.
            if (rtParameters == null)
            {
                rtParameters = new RenderTargetParameters();
                rtParameters.BackBufferCount          = 2;
                rtParameters.BackBufferWidth          = 1024;
                rtParameters.BackBufferHeight         = 768;
                rtParameters.DepthStencilCommonFormat = CommonPixelFormatLayout.D24_UNORM_S8_UINT;
                rtParameters.FormatCommon             = CommonPixelFormatLayout.X8Y8Z8W8_UNORM;
                rtParameters.MultiSampleQuality       = 0;
                rtParameters.MultiSampleType          = 1;
                rtParameters.RefreshRate = 0;
                rtParameters.Windowed    = true;
            }


            // We create graphics device.
            Window         window  = null;
            GraphicsDevice device  = null;
            IWindowManager manager = null;

            try {
                // 1) We create graphics device in owned mode.
                device = graphicsService.CreateDevice(true, graphicsDebug, rtParameters, out window);

                // 2) We initialize input.
                inputService.Initialize(window);

                // 3) We create window manager.
                manager = new Default.DefaultWindowManager(device, device.SwapChain, inputService, defaultTheme);

                // 4) We replace component directory (add new stuff in shell enviorment).
                IComponentDirectory newDirectory = new ComponentDirectory(componentDirectory, "Shell");
                newDirectory.Register(new Instance(true, "ShellFinishedConfiguring"));
                newDirectory.Register(new Instance(manager));
                newDirectory.Register(new Instance(defaultTheme));

                // 5) We replace console by Shell provided console.
                newDirectory.Register(new AlwaysNewConfiguredComponent(
                                          typeof(ShellTextConsole).FullName));

                // 6) We set the component directory.



                // 7) We unregister component directory.
            } finally {
                if (manager != null && manager is IDisposable)
                {
                    (manager as IDisposable).Dispose();
                }
                if (inputService != null)
                {
                    inputService.Dispose();
                }
                if (device != null)
                {
                    device.Dispose();
                }
            }

            return(0);
        }