示例#1
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            WarServices warServices = new WarServices();
            // Create an AOP proxy object that we can hang Castle.DynamicProxies upon. These are useful for operations across the whole
            //   of the service, or for when we need to fail a message in a reasonable way.
            var proxy = new Castle.DynamicProxy.ProxyGenerator()
                        .CreateClassProxyWithTarget <WarServices>(warServices, new Castle.DynamicProxy.IInterceptor[] {
                new UserQuotaInterceptor(), new AdminKeyRequiredInterceptor()
            });

            return(proxy);
        }
示例#2
0
 static void Main(string[] args)
 {
     try {
         WarServices               warServices  = new WarServices();
         WebServiceHost            _serviceHost = new WebServiceHost(warServices, new Uri("http://localhost:8001/warServices"));
         ServiceThrottlingBehavior behaviour    = new ServiceThrottlingBehavior();
         behaviour.MaxConcurrentSessions  = 9999;
         behaviour.MaxConcurrentCalls     = 9999;
         behaviour.MaxConcurrentInstances = 9999;
         _serviceHost.Description.Behaviors.Add(behaviour);
         _serviceHost.Open();
         Console.WriteLine("Open Press Key to close");
         Console.ReadKey();
         _serviceHost.Close();
         Console.WriteLine("Connection Closed");
     } catch (Exception e) {
         Console.WriteLine(e);
         Console.ReadKey();
     }
 }
示例#3
0
        /*
         * Application that uses Windows Communications Foundation (WCF) to provide a RESTful API that allows persistence of Morphyum's WarTech.
         * If you're unfamiliar with WCF, checkout the following:
         *
         * http://dotnetmentors.com/wcf/overview-on-wcf-service-architecture.aspx
         * https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/extending-dispatchers
         *
         * The client is the PersistentMapClient, in this repository.
         * This PersistentMapServer is the server.
         *
         * Note that WCF is no longer the preferred solution for REST endpoints, which has become ASP.NET5 w/ MVC6.
         *  See https://blog.tonysneed.com/2016/01/06/wcf-is-dead-long-live-mvc-6/.
         */
        static void Main(string[] args)
        {
            try {
                // Start a heart-beat monitor to check the server status
                BackgroundWorker heartbeatWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                heartbeatWorker.DoWork             += new DoWorkEventHandler(HeartBeatMonitor.DoWork);
                heartbeatWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(HeartBeatMonitor.RunWorkerCompleted);
                heartbeatWorker.RunWorkerAsync();

                SettingsFileMonitor monitor = new SettingsFileMonitor();
                monitor.enable();

                BackgroundWorker playerHistoryPruner = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                playerHistoryPruner.DoWork             += new DoWorkEventHandler(PlayerHistoryPruner.DoWork);
                playerHistoryPruner.RunWorkerCompleted += new RunWorkerCompletedEventHandler(PlayerHistoryPruner.RunWorkerCompleted);
                playerHistoryPruner.RunWorkerAsync();

                BackgroundWorker backupWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };

                backupWorker.DoWork             += new DoWorkEventHandler(BackupWorker.DoWork);
                backupWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackupWorker.RunWorkerCompleted);
                backupWorker.RunWorkerAsync();

                // Preload the data to allow any necessary initialization to happen
                StarMapStateManager.Build();
                FactionInventoryStateManager.Build();
                PlayerStateManager.Build();

                WarServices warServices = new WarServices();
                // Create an AOP proxy object that we can hang Castle.DynamicProxies upon. These are useful for operations across the whole
                //   of the service, or for when we need to fail a message in a reasonable way.
                var proxy = new Castle.DynamicProxy.ProxyGenerator()
                            .CreateClassProxyWithTarget <WarServices>(warServices, new Castle.DynamicProxy.IInterceptor[] {
                    new UserQuotaInterceptor(), new AdminKeyRequiredInterceptor()
                });

                // Create a RESTful service host. The service instance is automatically, through
                //   the WarServiceInstanceProviderBehaviorAttribute. We create the singleton this way to give
                //   us the chance to customize the binding
                WebServiceHost _serviceHost = new WebServiceHost(typeof(WarServices), new Uri(ServiceUrl));
                AddServiceBehaviors(_serviceHost);

                // Create a binding that wraps the default WebMessageEncodingBindingElement with a BindingElement
                //   that can GZip compress responses when a client requests it.
                WebMessageEncodingBindingElement innerEncoding = new WebMessageEncodingBindingElement {
                    ContentTypeMapper = new ForceJsonWebContentMapper()
                };
                GZipMessageEncodingBindingElement encodingWrapper = new GZipMessageEncodingBindingElement(innerEncoding);

                var transport = new HttpTransportBindingElement {
                    ManualAddressing = true,
                    KeepAliveEnabled = false,
                    AllowCookies     = false
                };

                var customBinding = new CustomBinding(encodingWrapper, transport);

                // Create a default endpoint with the JSON/XML behaviors and the behavior to check the incoming headers for GZIP requests
                var endpoint = _serviceHost.AddServiceEndpoint(typeof(IWarServices), customBinding, "");
                endpoint.Behaviors.Add(new WebHttpBehavior());
                endpoint.Behaviors.Add(new GZipBehavior());

                _serviceHost.Open();

                Console.WriteLine("Open Press Key to close");
                Console.ReadKey();

                _serviceHost.Close();
                Console.WriteLine("Connection Closed");

                // Cleanup any outstanding processes
                monitor.disable();

                heartbeatWorker.CancelAsync();

                playerHistoryPruner.CancelAsync();
                PlayerHistoryPruner.PruneOnExit();

                backupWorker.CancelAsync();
                BackupWorker.BackupOnExit();
            } catch (Exception e) {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }
 public WarServicesTests()
 {
     _warServices = new WarServices();
 }
示例#5
0
        static void Main(string[] args)
        {
            WarServices war = new WarServices();

            war.StartWar();
        }