Open() public method

public Open ( ) : void
return void
示例#1
0
 protected override void OnStart(string[] args)
 {
     host.Open();
 }
示例#2
0
        static void Main(string[] args)
        {
            PrintLogo();

            PortBridgeAgentSection settings = ConfigurationManager.GetSection("portBridgeAgent") as PortBridgeAgentSection;

            if (settings != null)
            {
                serviceNamespace = settings.ServiceNamespace;
                issuerName       = settings.IssuerName;
                issuerSecret     = settings.IssuerSecret;
            }

            if (!ParseCommandLine(args))
            {
                PrintUsage();
                return;
            }

            PortBridgeClientForwarderHost host = new PortBridgeClientForwarderHost();

            if (settings != null && settings.PortMappings.Count > 0)
            {
                foreach (PortMappingElement mapping in settings.PortMappings)
                {
                    List <IPRange> firewallRules = new List <IPRange>();
                    if (mapping.FirewallRules != null && mapping.FirewallRules.Count > 0)
                    {
                        foreach (FirewallRuleElement rule in mapping.FirewallRules)
                        {
                            if (!string.IsNullOrEmpty(rule.SourceRangeBegin) &&
                                !string.IsNullOrEmpty(rule.SourceRangeEnd))
                            {
                                firewallRules.Add(new IPRange(IPAddress.Parse(rule.SourceRangeBegin), IPAddress.Parse(rule.SourceRangeEnd)));
                            }
                            else if (!string.IsNullOrEmpty(rule.Source))
                            {
                                firewallRules.Add(new IPRange(IPAddress.Parse(rule.Source)));
                            }
                        }
                    }

                    if (mapping.LocalTcpPort.HasValue)
                    {
                        if (!string.IsNullOrEmpty(mapping.LocalPipe) ||
                            !string.IsNullOrEmpty(mapping.RemotePipe))
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalTcpPort {0} defined with incompatible other settings", mapping.LocalTcpPort.Value));
                        }
                        else if (!mapping.RemoteTcpPort.HasValue)
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalTcpPort {0} does not have a matching RemoteTcpPort defined", mapping.LocalTcpPort.Value));
                        }

                        host.Forwarders.Add(new TcpClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, mapping.TargetHost, mapping.LocalTcpPort.Value, mapping.RemoteTcpPort.Value, mapping.BindTo, useHybrid, firewallRules));
                    }

                    if (!string.IsNullOrEmpty(mapping.LocalPipe))
                    {
                        if (mapping.LocalTcpPort.HasValue ||
                            mapping.RemoteTcpPort.HasValue)
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalPipe {0} defined with incompatible other settings", mapping.LocalPipe));
                        }
                        else if (string.IsNullOrEmpty(mapping.RemotePipe))
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalPipe {0} does not have a matching RemotePipe defined", mapping.LocalPipe));
                        }

                        host.Forwarders.Add(new NamedPipeClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, mapping.TargetHost, mapping.LocalPipe, mapping.RemotePipe, useHybrid));
                    }
                }
            }
            else
            {
                List <IPRange> firewallRules = new List <IPRange>();
                firewallRules.Add(new IPRange(IPAddress.Loopback));
                host.Forwarders.Add(new TcpClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, cmdlineTargetHost, fromPort, toPort, null, useHybrid, firewallRules));
            }

            if (!runOnConsole)
            {
                ServiceController sc = new ServiceController("PortBridgeAgentService");
                try
                {
                    var status = sc.Status;
                }
                catch (SystemException)
                {
                    runOnConsole = true;
                }
            }

            if (runOnConsole)
            {
                host.Open();
                Console.WriteLine("Press [ENTER] to exit.");
                Console.ReadLine();
                host.Close();
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new PortBridgeAgentService(host)
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            PrintLogo();

            PortBridgeAgentSection settings = ConfigurationManager.GetSection("portBridgeAgent") as PortBridgeAgentSection;
            if (settings != null)
            {
                serviceNamespace = settings.ServiceNamespace;
                issuerName = settings.IssuerName;
                issuerSecret = settings.IssuerSecret;
            }

            if (!ParseCommandLine(args))
            {
                PrintUsage();
                return;
            }

            PortBridgeClientForwarderHost host = new PortBridgeClientForwarderHost();
            if (settings != null && settings.PortMappings.Count > 0)
            {
                foreach (PortMappingElement mapping in settings.PortMappings)
                {
                    List<IPRange> firewallRules = new List<IPRange>();
                    if (mapping.FirewallRules != null && mapping.FirewallRules.Count > 0)
                    {
                        foreach (FirewallRuleElement rule in mapping.FirewallRules)
                        {
                            if (!string.IsNullOrEmpty(rule.SourceRangeBegin) &&
                                 !string.IsNullOrEmpty(rule.SourceRangeEnd))
                            {
                                firewallRules.Add(new IPRange(IPAddress.Parse(rule.SourceRangeBegin), IPAddress.Parse(rule.SourceRangeEnd)));
                            }
                            else if (!string.IsNullOrEmpty(rule.Source))
                            {
                                firewallRules.Add(new IPRange(IPAddress.Parse(rule.Source)));
                            }
                        }
                    }

                    if (mapping.LocalTcpPort.HasValue)
                    {
                        if ( !string.IsNullOrEmpty(mapping.LocalPipe) ||
                             !string.IsNullOrEmpty(mapping.RemotePipe))
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalTcpPort {0} defined with incompatible other settings", mapping.LocalTcpPort.Value));
                        }
                        else if (!mapping.RemoteTcpPort.HasValue)
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalTcpPort {0} does not have a matching RemoteTcpPort defined", mapping.LocalTcpPort.Value));
                        }

                        host.Forwarders.Add(new TcpClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, mapping.TargetHost, mapping.LocalTcpPort.Value, mapping.RemoteTcpPort.Value, mapping.BindTo, useHybrid, firewallRules));
                    }

                    if (!string.IsNullOrEmpty(mapping.LocalPipe))
                    {
                        if ( mapping.LocalTcpPort.HasValue ||
                             mapping.RemoteTcpPort.HasValue)
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalPipe {0} defined with incompatible other settings", mapping.LocalPipe));
                        }
                        else if (string.IsNullOrEmpty(mapping.RemotePipe))
                        {
                            throw new ConfigurationErrorsException(string.Format("LocalPipe {0} does not have a matching RemotePipe defined", mapping.LocalPipe));
                        }

                        host.Forwarders.Add(new NamedPipeClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, mapping.TargetHost, mapping.LocalPipe, mapping.RemotePipe, useHybrid));
                    }

                }
            }
            else
            {
                List<IPRange> firewallRules = new List<IPRange>();
                firewallRules.Add(new IPRange(IPAddress.Loopback));
                host.Forwarders.Add(new TcpClientConnectionForwarder(serviceNamespace, issuerName, issuerSecret, cmdlineTargetHost, fromPort, toPort, null, useHybrid, firewallRules));
            }

            if (!runOnConsole)
            {
                ServiceController sc = new ServiceController("PortBridgeAgentService");
                try
                {
                    var status = sc.Status;
                }
                catch (SystemException)
                {
                    runOnConsole = true;
                }
            }

            if (runOnConsole)
            {
                host.Open();
                Console.WriteLine("Press [ENTER] to exit.");
                Console.ReadLine();
                host.Close();
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new PortBridgeAgentService(host)
                };
                ServiceBase.Run(ServicesToRun);
            }
        }