Пример #1
0
        public override void Run()
        {
            Trace.UseGlobalLock = false;
            Trace.TraceInformation("WrapperRoleListener 'run' was requested");
            var endpoints = new List <Endpoint>();

            HardReference <Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener>();

            try
            {
                foreach (var pair in RoleEnvironment.CurrentRoleInstance.InstanceEndpoints)
                {
                    endpoints.Add(new Endpoint {
                        Name       = pair.Key,
                        Protocol   = pair.Value.Protocol,
                        IPEndpoint = pair.Value.IPEndpoint.ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to read endpoint configuration: " + ex);
                throw;
            }
            try
            {
                core = new ListenerLoop();
                core.Listen(cancellationTokenSource.Token, endpoints);
            }
            finally
            {
                runCompleteEvent.Set();
            }
        }
Пример #2
0
        /// <summary>
        /// This is the entry point for the Wrapper run as a standard exe.
        /// It is usable for self hosting, and is also how the IIS integration is done (This gets around problems with integrated mode).
        /// It is *not* used for Azure integration, as process-to-process communication is very poor.
        /// </summary>
        /// <remarks>
        /// The parameters passed are:
        ///     [0] = listen address
        ///     [1] = parent process ID (the child should terminate if the parent becomes unavailable)
        /// </remarks>
        public static int Main(string[] args)
        {
            Trace.UseGlobalLock = false;
            Console.WriteLine("Waking up listener...");
            Trace.Listeners.Add(ConsoleTrace.Instance);
            Trace.TraceInformation("WrapperRoleListener 'run' was requested");

            var listeningPort = 8080;

            if (args.Length > 0 && int.TryParse(args[0], out var port))
            {
                listeningPort = port;
            }
            if (args.Length > 1 && int.TryParse(args[1], out var pProc))
            {
                ParentProcessId = pProc;
            }

            var endpoints = new List <Endpoint> {
                new Endpoint {
                    Protocol   = "http",
                    Name       = "defaultLocal",
                    IPEndpoint = "127.0.0.1:" + listeningPort
                }
            };

            try
            {
                core = new ListenerLoop();
                if (ParentProcessId > 0)
                {
                    core.PeriodicCheck += Core_PeriodicCheck;
                }
                core.Listen(cancellationTokenSource.Token, endpoints);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Hosting failure: " + ex);
                return(-1);
            }
            finally
            {
                runCompleteEvent.Set();
                core.Shutdown();
            }

            return(0);
        }