예제 #1
0
        public void SaveConfiguration()
        {
            try
            {
                string configPath = RegistryHelper.GetString(Registry.LocalMachine, Constants.RegsitryKey, "", "ConfigPath");

                string configurationText = JsonConvert.SerializeObject(_config);
                File.WriteAllText(Path.Combine(configPath, Constants.ServerConfigFileName), configurationText);

                string routesText = JsonConvert.SerializeObject(_routers.Routes());
                File.WriteAllText(Path.Combine(configPath, Constants.RoutesConfigFileName), routesText);
            }
            catch (Exception ex)
            {
                Singletons.EventLog.WriteEvent(new EventLogging.EventPayload
                {
                    Severity   = EventLogging.Severity.Error,
                    CustomText = "Failed to save configuration.",
                    Exception  = ex
                });
            }
        }
예제 #2
0
        private void AddTestRoutes()
        {
            Routers routers = new Routers();

            //------------------------------------------------------------------------------------------------------------------
            {
                Route route = new Route()
                {
                    Name                 = "NetworkDLS",
                    ListenPort           = 80,
                    TrafficType          = TrafficType.Http,
                    MaxBufferSize        = 1021 * 1024,
                    ListenOnAllAddresses = false,
                    AutoStart            = true,
                    Description          = "Default example route."
                };

                route.Bindings.Add(new Binding {
                    Enabled = true, Address = "127.0.0.1"
                });

                route.Endpoints.ConnectionPattern = ConnectionPattern.FailOver;
                route.Endpoints.Add(new Endpoint("www.NetworkDLS.com", 80));

                route.HttpHeaderRules.Add(new HttpHeaderRule(HttpHeaderType.Request, HttpVerb.Any, "Host", HttpHeaderAction.Upsert, "www.NetworkDLS.com"));

                routers.Add(new Router(route));
            }
            //------------------------------------------------------------------------------------------------------------------
            {
                Route route = new Route()
                {
                    Name                 = "Ingenuity",
                    ListenPort           = 81,
                    TrafficType          = TrafficType.Http,
                    MaxBufferSize        = 1021 * 1024,
                    ListenOnAllAddresses = true,
                    AutoStart            = true
                };

                //route.Bindings.Add(new Binding { Enabled = true, Address = "127.0.0.1" });

                route.Endpoints.ConnectionPattern = ConnectionPattern.FailOver;
                route.Endpoints.Add(new Endpoint("www.IngenuitySC.com", 80));

                route.HttpHeaderRules.Add(new HttpHeaderRule(HttpHeaderType.Request, HttpVerb.Any, "Host", HttpHeaderAction.Upsert, "www.IngenuitySC.com"));

                routers.Add(new Router(route));
            }
            //------------------------------------------------------------------------------------------------------------------
            {
                Route route = new Route()
                {
                    Name                 = "Microsoft LIVE!",
                    ListenPort           = 82,
                    TrafficType          = TrafficType.Https,
                    MaxBufferSize        = 1021 * 1024,
                    ListenOnAllAddresses = true,
                    AutoStart            = true
                };

                //route.Bindings.Add(new Binding { Enabled = true, Address = "127.0.0.1" });

                route.Endpoints.ConnectionPattern = ConnectionPattern.FailOver;
                route.Endpoints.Add(new Endpoint("login.live.com", 443));

                route.HttpHeaderRules.Add(new HttpHeaderRule(HttpHeaderType.Request, HttpVerb.Any, "Host", HttpHeaderAction.Upsert, "login.live.com"));

                routers.Add(new Router(route));
            }
            //------------------------------------------------------------------------------------------------------------------

            string routesText = JsonConvert.SerializeObject(routers.Routes());

            string configPath = RegistryHelper.GetString(Registry.LocalMachine, Constants.RegsitryKey, "", "ConfigPath");

            File.WriteAllText(Path.Combine(configPath, Constants.RoutesConfigFileName), routesText);
        }