示例#1
0
        static void Main(string[] args)
        {
            LogFactory.Assign(new ConsoleLogFactory());
            ServiceProvider.Bootstrap();

            ServiceHostInfo info = new ServiceHostInfo();

            info.Name     = ConfigurationMaster.Get(ServiceConfiguration.DefaultServiceConfigurationName);
            info.Address  = Dns.GetHostName();
            info.Port     = int.Parse(ConfigurationMaster.Get(ServiceConfiguration.DefaultServicePortConfigurationName));
            info.Binding  = new NetTcpBinding(ServiceConfiguration.DefaultNetTcpBindingName);
            info.Contract = typeof(IDeviceProfileService);
            info.Service  = typeof(DeviceProfileService);

            Console.WriteLine(string.Format(@"Service is starting on [{0}]", info.ToString()));

            ManagedServiceHostActivator <IDeviceProfileService> activator = new ManagedServiceHostActivator <IDeviceProfileService>(info);

            activator.Start();

            Console.WriteLine(string.Format(@"Service address [{0}]", activator.ServiceHost.Description.Endpoints.First().Address));

            string serverName      = ConfigurationMaster.Get(@"HttpServerName");
            string httpServerName  = serverName + " HTTP Server";
            int    httpBindingPort = int.Parse(ConfigurationMaster.Get(@"HttpServerPort"));

            Server server = null;

            server = new Server(httpServerName);
            server.Add(HttpListenerFactory.Create(IPAddress.Any, httpBindingPort));

            server.Add(new CameraListModule());
            server.Add(new CameraModule());
            server.Add(new CameraThumbnailModule());

            FileModule             fileModule = new FileModule();
            EmbeddedResourceLoader embedded   = new EmbeddedResourceLoader();

            embedded.Add("/", Assembly.GetExecutingAssembly(),
                         Assembly.GetExecutingAssembly().GetName().Name,
                         Assembly.GetExecutingAssembly().GetName().Name + @".Resources.favicon.ico");
            fileModule.Resources.Add(embedded);
            server.Add(fileModule);
            server.Add(new SimpleRouter("/favicon.ico", "/resources/favicon.ico"));

            server.Start(5);

            Console.WriteLine(string.Format("Start {0} on {1}.", httpServerName, httpBindingPort));

            Console.WriteLine();
            Console.WriteLine("Press any key to close service.");
            Console.ReadKey();

            server.Stop(true);
            activator.Stop();
        }
示例#2
0
        static void Main(string[] args)
        {
            string serverName      = "Dennis Gao";
            string httpServerName  = serverName + " HTTP Server";
            int    httpBindingPort = 8000;

            Server server = null;

            server = new Server(httpServerName);
            server.Add(HttpListenerFactory.Create(IPAddress.Any, httpBindingPort));

            FileModule fileModule = new FileModule();

            server.Add(fileModule);

            EmbeddedResourceLoader embedded = new EmbeddedResourceLoader();

            fileModule.Resources.Add(embedded);

            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".img.favicon.ico");
            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".img.camera.jpg");
            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".js.jquery-2-0-3.js");
            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".js.jquery-mobile-1-3-2.js");
            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".css.jquery-mobile-1-3-2.css");
            embedded.Add("/", Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly().GetName().Name, Assembly.GetExecutingAssembly().GetName().Name + @".html.login.html");

            server.Add(new HomeModule());

            server.Add(new SimpleRouter("/", "/html/login.html"));
            server.Add(new SimpleRouter("/favicon.ico", "/img/favicon.ico"));

            server.Start(5);

            Console.WriteLine(string.Format("Start {0} on {1}.", httpServerName, httpBindingPort));

            Console.WriteLine();
            Console.WriteLine("Press any key to close service.");
            Console.ReadKey();

            server.Stop(true);
        }
 public void Add()
 {
     _resource.Add("/users/", GetType().Assembly, GetType().Namespace + ".Views",
                   GetType().Namespace + ".Views.MyFile.xml.spark");
 }