Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IOptions <AppSettings> appSettingsSection)
        {
            app.UseAuthentication();

            app.UseMvc();

            //print in output
            HostHelper.OutputHostnameInfo(appSettingsSection.Value.ApplicationTitle);
        }
Ejemplo n.º 2
0
        protected override void OnStop()
        {
            var stoppedList = HostHelper.OnStop();

            var message =
                $"Service Host Stopped:{HostHelper.HostName} at [{DateTime.Now:MM-dd-yyy hh:mm.ss}] \r\n {string.Join("\r\n", stoppedList)}";

            Trace.TraceInformation(message);
        }
Ejemplo n.º 3
0
        public void GetDocumentBuilder()
        {
            var source  = GetSource();
            var context = new RunspaceContext(new PipelineContext(GetOption(), null, null, null, null, null));

            HostHelper.ImportResource(source, context);
            var actual = HostHelper.GetDocumentBuilder(context, source);

            Assert.Equal(9, actual.Length);
        }
Ejemplo n.º 4
0
        public void ReadSelector()
        {
            var context  = new RunspaceContext(new PipelineContext(GetOption(), null, null, null, null, null));
            var selector = HostHelper.GetSelector(context, GetSource()).ToArray();

            Assert.NotNull(selector);
            Assert.Equal(31, selector.Length);

            Assert.Equal("BasicSelector", selector[0].Name);
            Assert.Equal("YamlAllOf", selector[4].Name);
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Get(string message = "EventMessage")
        {
            IWindsorContainer container = new WindsorContainer(new XmlInterpreter(AppDomain.CurrentDomain.BaseDirectory + "App_Config\\castle.config"));

            //ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

            var server = new ServerManager(Constants.HubName, Constants.DefaultServerProvider);

            server.Publish("Test", new Package {
                Command = message + "Source: " + HostHelper.GetHostName()
            });

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
 private void ConnectToServer()
 {
     //尝试解析出最新的域名地址
     ThreadHelper.ThreadPoolStart(c =>
     {
         var ip = HostHelper.GetHostByName(AppConfiguartion.HostAddress);
         if (ip.IsNullOrEmpty())
         {
             return;
         }
         AppConfiguartion.ServerIPEndPoint = new IPEndPoint(IPAddress.Parse(ip), AppConfiguartion.HostPort);
     });
     _clientAgent.ConnectToServer(AppConfiguartion.ServerIPEndPoint);
 }
Ejemplo n.º 7
0
        internal protected override void SendCommand(NetworkStream nStream, byte command, string destinationHost, int destinationPort)
        {
            byte[] dstPort = HostHelper.GetPortBytes(destinationPort);
            byte[] dstIp   = { 0, 0, 0, 1 };

            byte[] userId = new byte[0];
            if (Settings.Credentials != null)
            {
                if (!String.IsNullOrEmpty(Settings.Credentials.UserName))
                {
                    userId = Encoding.ASCII.GetBytes(Settings.Credentials.UserName);
                }
            }

            byte[] dstAddr = Encoding.ASCII.GetBytes(destinationHost);

            // +----+----+----+----+----+----+----+----+----+----+....+----+----+----+....+----+
            // | VN | CD | DSTPORT |      DSTIP        | USERID       |NULL| DSTADDR      |NULL|
            // +----+----+----+----+----+----+----+----+----+----+....+----+----+----+....+----+
            //    1    1      2              4           variable       1    variable        1
            byte[] request = new byte[10 + userId.Length + dstAddr.Length];

            request[0] = VersionNumber;
            request[1] = command;
            dstPort.CopyTo(request, 2);
            dstIp.CopyTo(request, 4);
            userId.CopyTo(request, 8);
            request[8 + userId.Length] = 0x00;
            dstAddr.CopyTo(request, 9 + userId.Length);
            request[9 + userId.Length + dstAddr.Length] = 0x00;

            nStream.Write(request, 0, request.Length);

            // +----+----+----+----+----+----+----+----+
            // | VN | CD | DSTPORT |      DSTIP        |
            // +----+----+----+----+----+----+----+----+
            //    1    1      2              4
            byte[] response = new byte[8];

            nStream.Read(response, 0, 8);

            byte reply = response[1];

            // Если запрос не выполнен.
            if (reply != CommandReplyRequestGranted)
            {
                HandleCommandError(reply);
            }
        }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions <AppSettings> appSettingsSection)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //app.UseForwardedHeaders(new ForwardedHeadersOptions
            //{
            //    ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto
            //});
            //register identity server in DI
            app.UseIdentityServer();

            //print in output
            HostHelper.OutputHostnameInfo(appSettingsSection.Value.ApplicationTitle);
        }
Ejemplo n.º 9
0
        public void Init(bool threaded = true)
        {
            Environment.SetEnvironmentVariable("AppName", "Client.App");
            Global.Init(new Assembly[] { typeof(App).Assembly });
            host = Host.CreateClient();
            if (threaded)
            {
                HostHelper.RunThread(host);
            }
            else
            {
#if !UNITY_5_3_OR_NEWER
                HostHelper.Run(host);
#else
#endif
            }
        }
Ejemplo n.º 10
0
        private static async Task RequestConnectionAsync(NetworkStream nStream, byte command, string destinationHost, int destinationPort,
                                                         CancellationToken cancellationToken = default)
        {
            var aTyp    = GetAddressType(destinationHost);
            var dstAddr = GetHostAddressBytes(aTyp, destinationHost);
            var dstPort = HostHelper.GetPortBytes(destinationPort);

            // REQUEST GRANT
            // +----+-----+-------+------+----------+----------+
            // |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
            // +----+-----+-------+------+----------+----------+
            // | 1  |  1  | X'00' |  1   | Variable |    2     |
            // +----+-----+-------+------+----------+----------+
            var request = new byte[4 + dstAddr.Length + 2];

            request[0] = VersionNumber;
            request[1] = command;
            request[2] = Reserved;
            request[3] = aTyp;
            dstAddr.CopyTo(request, 4);
            dstPort.CopyTo(request, 4 + dstAddr.Length);

            await nStream.WriteAsync(request.AsMemory(0, request.Length), cancellationToken).ConfigureAwait(false);

            // READ RESPONSE
            // +----+-----+-------+------+----------+----------+
            // |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
            // +----+-----+-------+------+----------+----------+
            // | 1  |  1  | X'00' |  1   | Variable |    2     |
            // +----+-----+-------+------+----------+----------+
            var response = new byte[255];

            await nStream.ReadAsync(response.AsMemory(0, response.Length), cancellationToken).ConfigureAwait(false);

            var reply = response[1];

            if (reply != CommandReplySucceeded)
            {
                HandleCommandError(reply);
            }
        }
Ejemplo n.º 11
0
        protected override void OnStart(string[] args)
        {
            try
            {
                var startedList = HostHelper.OnStart(args);

                if (startedList.Count == 0)
                {
                    throw new Exception("No services were started");
                }

                // TODO: Send email on start up of application
                Trace.TraceInformation(
                    $"Service Host Started:{HostHelper.HostName} at [{DateTime.Now:MM-dd-yyy hh:mm.ss}] \r\n{string.Join("\r\n", startedList)}");
            }
            catch (Exception ex)
            {
                PrintError(ex);
                throw;
            }
        }