Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var port = ConfigurationManager.AppSettings["Port"] ?? "8080";
            var hostname = ConfigurationManager.AppSettings["Hostname"] ?? "localhost";

            //The url that the service can be called on
            var serviceUrl = string.Format("http://{0}:{1}", hostname, port);

            //Service configuration
            var config = new HttpSelfHostConfiguration(serviceUrl);

            //Add routes to controllers
            config.Routes.MapHttpRoute("DefaultApi ", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            //Writes list of available mediatype formatters to console
            Console.WriteLine("{0}{1}", "Registered media type formatters:\n", string.Join("\n", config.Formatters.Select(x => x.GetType())));

            //Initialize server
            _selfHostServerServer = new HttpSelfHostServer(config);

            //Start server
            _selfHostServerServer.OpenAsync().Wait();
            Console.WriteLine("{1}Self hosting server is running on: {0}", serviceUrl, Environment.NewLine);
            Console.WriteLine("Press Enter to quit.");
            Console.ReadLine();

            //Wires up application close handler
            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
                                                       {
                                                           //Close server
                                                           _selfHostServerServer.CloseAsync();
                                                           _selfHostServerServer.Dispose();
                                                       };
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var form = new RenderForm("KinectLight");
            form.Size = new System.Drawing.Size(1920,1200);

            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            SharpDX.Direct3D10.Device1 device;
            SwapChain swapChain;
            SharpDX.Direct3D10.Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_1, out device, out swapChain);

            var d2dFactory = new SharpDX.Direct2D1.Factory();
            var surface = Surface.FromSwapChain(swapChain, 0);

            RenderTarget dc = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            MainGame.Instance.Height = form.ClientSize.Height;
            MainGame.Instance.Width = form.ClientSize.Width;
            GameTime gameTime = new GameTime();

            var config = new HttpSelfHostConfiguration("http://localhost:8080");

            config.Routes.MapHttpRoute(
                "API Default", "api/{controller}/{action}/{name}",
                new { id = RouteParameter.Optional });

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();

            RenderLoop.Run(form, () =>
            {
                gameTime.StartFrame();
                MainGame.Instance.Update(gameTime);
                dc.BeginDraw();
                dc.Clear(Colors.White);
                MainGame.Instance.Render(dc);
                var res = dc.EndDraw();
                swapChain.Present(1, PresentFlags.None);
                //Thread.Sleep(1);
            });

            server.Dispose();
            MainGame.Instance.Dispose();
            dc.Dispose();
            surface.Dispose();
            d2dFactory.Dispose();
            device.Dispose();
            swapChain.Dispose();
        }
Ejemplo n.º 3
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("AzureTicker.Worker entry point called", "Information");

            HttpSelfHostServer server = null;
            try
            {
                var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["webapi"];
                Uri baseAddress = new Uri(string.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint.ToString()));

                // Set up server configuration
                HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );

                // Create server
                server = new HttpSelfHostServer(config);

                // Start listening
                server.OpenAsync().Wait();
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed to open Web Api host.", "Error");
                Trace.WriteLine(e.ToString(), "Error");
                if (server != null)
                {
                    server.Dispose();
                }
            }

            while (true)
            {
                Thread.Sleep(10000);
            }
        }
        public void ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass()
        {
            HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:8080");
            configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            configuration.Services.Replace(typeof(IAssembliesResolver), new WebApiClassBase.TestAssemblyResolver(typeof(ValuesController)));
            configuration.Routes.MapHttpRoute("Default", "{controller}", new { controller = "Home" });

            HttpSelfHostServer server = new HttpSelfHostServer(configuration);
            try
            {
                server.OpenAsync().Wait();

                var request = new HttpRequestMessage();

                request.RequestUri = new Uri("http://localhost:8080");

                request.Method = HttpMethod.Get;

                var client = new HttpClient(server);
                using (HttpResponseMessage response = client.SendAsync(request).Result)
                {
                    response.Should().Not.Be.Null();
                    response.IsSuccessStatusCode.Should().Be.True();

                    string[] result = response.Content.ReadAsAsync<string[]>().Result;

                    result.Length.Should().Be.EqualTo(4);
                    result[0].Should().Be.EqualTo("http://tostring.it");
                    result[1].Should().Be.EqualTo("http://imperugo.tostring.it");
                    result[2].Should().Be.EqualTo("http://twitter.com/imperugo");
                    result[3].Should().Be.EqualTo("http://www.linkedin.com/in/imperugo");
                }
            }
            finally
            {
                configuration.Dispose();
                server.Dispose();
            }
        }
Ejemplo n.º 5
0
        static async Task RunControlEndpoint(IPEndPoint controlEP, MessagingFactory messagingFactory)
        {
            var config = new HttpSelfHostConfiguration(new UriBuilder(Uri.UriSchemeHttp, "localhost", controlEP.Port).Uri);

            var injector = new StandardKernel();
            injector.Bind<MessagingFactory>().ToConstant(messagingFactory);
            config.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(injector);

            config.Routes.MapHttpRoute("API", "{controller}/{id}", new { id = RouteParameter.Optional });
            var controlServer = new HttpSelfHostServer(config);
            try
            {
                await controlServer.OpenAsync();
                Trace.TraceInformation("Control endpoint listening at {0}", config.BaseAddress);
            }
            catch (Exception exception)
            {
                controlServer.Dispose();
                Trace.TraceError("Control endpoint cannot open, {0}", exception.Message);
                throw;
            }
            await ClosingEvent.Task;
            try
            {
                await controlServer.CloseAsync();
            }
            finally
            {
                controlServer.Dispose();
            }
        }