Пример #1
0
        public override void Run()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("WarSpot.Cloud.UserService entry point called", "Information");
            ServiceHost host = null;

            try
            {
                var address = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["ServiceEndpoint"];
                var prefix  = address.Protocol == "tcp" ? "net.tcp://" : "http://";
                host = new ServiceHost(typeof(WarSpotMainUserService),
                                       new Uri(prefix + address.IPEndpoint.ToString()));
                //var address2 = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MetadataEndpoint"];
                //prefix = address2.Protocol == "tcp" ? "net.tcp://" : "http://";
                //var behaviour = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
                //behaviour.InstanceContextMode = InstanceContextMode.PerSession;
                //host.Description.Endpoints[1].Address = new EndpointAddress(new Uri(prefix + address2.IPEndpoint));
                host.Open();
                Trace.TraceError("Host opened at {0}", host.BaseAddresses[0]);
                _tournamentManager.Start();
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception occured: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Trace.TraceError("Exception details: {0}", ex.InnerException.Message);
                }
            }

            //this.autoscaler = EnterpriseLibraryContainer.Current.GetInstance<Autoscaler>();
            //this.autoscaler.Start();

            _disposeEvent.WaitOne();
            _tournamentManager.Stop();
            if (host != null)
            {
                host.Close();
            }
            Trace.WriteLine("Stopped", "Information");
        }