示例#1
0
        public static int Main(string[] args)
        {
            Program.WaitForDebugger(args);

            if (args.Length == 0)
            {
                return(-1);
            }

            bool isAdHoc = args[0] == "adhoc";

            args = args.Skip(1).ToArray();

            if (isAdHoc)
            {
                AdHocHost.Run(args);
            }
            else
            {
                ManagedHost.Setup(args);

                ManagedHost.Run(args);
            }

            return(0);
        }
示例#2
0
        public static int Run(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            AdHocHost.Log("Starting");
            AdHocHost.ParseArguments(args);

            AdHocHost.Log("Querying activation context");
            try
            {
                FabricRuntime.GetActivationContext();
                AdHocHost.isActivationContextAvailable = true;
                AdHocHost.Log("ActivationContext get success");
            }
            catch (InvalidOperationException)
            {
                AdHocHost.Log("ActivationContext get failed. InvalidOp");
            }

            FabricRuntime runtime       = null;
            Action        exitedHandler = () =>
            {
                AdHocHost.Log("Fabric Exited");
                AdHocHost.hasFabricDied = true;

                // try creating the fabric runtime on a background thread
                // this should not av
                if (AdHocHost.recreateRuntimeOnCrash)
                {
                    Task.Factory.StartNew(() =>
                    {
                        while (true)
                        {
                            try
                            {
                                AdHocHost.Log("Creating again");
                                runtime = FabricRuntime.Create();
                                AdHocHost.Log("Recreated");
                                break;
                            }
                            catch (AccessViolationException)
                            {
                                AdHocHost.Log("AV");
                                throw;
                            }
                            catch (Exception ex)
                            {
                                AdHocHost.Log("Error {0} when re-creating", ex);
                            }
                        }
                    });
                }
            };

            AdHocHost.Log("Creating FabricRuntime");
            var runtimeTask = FabricRuntime.CreateAsync(exitedHandler, TimeSpan.FromSeconds(5), CancellationToken.None);

            runtimeTask.Wait();

            runtime = runtimeTask.Result;


            AdHocHost.Log("Registering factories");
            foreach (var item in AdHocHost.serviceTypes)
            {
                AdHocHost.Log("Registering: {0}", item.Name);

                var factory = new MyServiceFactory {
                    ServiceImplementationType = item
                };

                Task registerTask = null;
                if (factory.IsStateful)
                {
                    registerTask = runtime.RegisterStatefulServiceFactoryAsync(item.Name, factory, TimeSpan.FromSeconds(5), CancellationToken.None);
                }
                else
                {
                    registerTask = runtime.RegisterStatelessServiceFactoryAsync(item.Name, factory, TimeSpan.FromSeconds(5), CancellationToken.None);
                }

                registerTask.Wait();
            }

            AdHocHost.Log("Connecting to pipe");
            var pipeWrapper = new PipeWrapper(AdHocHost.pipeServerAddress);

            AdHocHost.Log("Waiting for quit...");
            shouldQuitNowEvent.WaitOne();

            return(0);
        }
示例#3
0
 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     AdHocHost.Log("Unhandled exception: {0}", e.ExceptionObject);
 }