Open() public method

public Open ( ) : void
return void
Esempio n. 1
0
        static void Main(string[] args)
        {
            runOnConsole = false;
            useHybrid    = true;

            PrintLogo();

            PortBridgeSection settings = ConfigurationManager.GetSection("portBridge") as PortBridgeSection;

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

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

            PortBridgeServiceForwarderHost host = new PortBridgeServiceForwarderHost();

            if (settings != null && settings.HostMappings.Count > 0)
            {
                foreach (HostMappingElement hostMapping in settings.HostMappings)
                {
                    string targetHostAlias = hostMapping.TargetHost;
                    if (string.Equals(targetHostAlias, "localhost", StringComparison.OrdinalIgnoreCase))
                    {
                        targetHostAlias = localHostName;
                    }
                    host.Forwarders.Add(new ServiceConnectionForwarder(serviceNamespace, issuerName, issuerSecret, hostMapping.TargetHost, targetHostAlias, hostMapping.AllowedPorts, hostMapping.AllowedPipes, useHybrid));
                }
            }
            else
            {
                string targetHostAlias = localHostName;
                if (string.Equals(targetHostAlias, "localhost", StringComparison.OrdinalIgnoreCase))
                {
                    targetHostAlias = localHostName;
                }
                host.Forwarders.Add(new ServiceConnectionForwarder(serviceNamespace, issuerName, issuerSecret, "localhost", targetHostAlias, permittedPorts, string.Empty, useHybrid));
            }


            if (!runOnConsole)
            {
                ServiceController sc = new ServiceController("PortBridgeService");
                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 PortBridgeService(host)
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
Esempio n. 2
0
 protected override void OnStart(string[] args)
 {
     host.Open();
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            runOnConsole = false;
            useHybrid = true;

            PrintLogo();

            PortBridgeSection settings = ConfigurationManager.GetSection("portBridge") as PortBridgeSection;
            if (settings != null)
            {
                serviceNamespace = settings.ServiceNamespace;
                issuerName = settings.IssuerName;
                issuerSecret = settings.IssuerSecret;
                if (!string.IsNullOrEmpty(settings.LocalHostName))
                {
                    localHostName = settings.LocalHostName;
                }
            }

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

            PortBridgeServiceForwarderHost host = new PortBridgeServiceForwarderHost();
            if (settings != null && settings.HostMappings.Count > 0)
            {
                foreach (HostMappingElement hostMapping in settings.HostMappings)
                {
                    string targetHostAlias = hostMapping.TargetHost;
                    if (string.Equals(targetHostAlias, "localhost", StringComparison.OrdinalIgnoreCase))
                    {
                        targetHostAlias = localHostName;
                    }
                    host.Forwarders.Add(new ServiceConnectionForwarder(serviceNamespace, issuerName, issuerSecret, hostMapping.TargetHost, targetHostAlias, hostMapping.AllowedPorts, hostMapping.AllowedPipes, useHybrid));
                }
            }
            else
            {
                string targetHostAlias = localHostName;
                if (string.Equals(targetHostAlias, "localhost", StringComparison.OrdinalIgnoreCase))
                {
                    targetHostAlias = localHostName;
                }
                host.Forwarders.Add(new ServiceConnectionForwarder(serviceNamespace, issuerName, issuerSecret, "localhost", targetHostAlias, permittedPorts, string.Empty, useHybrid));
            }

            if (!runOnConsole)
            {
                ServiceController sc = new ServiceController("PortBridgeService");
                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 PortBridgeService(host)
                };
                ServiceBase.Run(ServicesToRun);
            }
        }