예제 #1
0
        private static void Register()
        {
            Serilog.ILogger serilog = new LoggerConfiguration()
                                      .Enrich.FromLogProxy()
                                      .Destructure.UsingAttributes()
                                      .WriteTo.Seq(EnvVars.SeqAddress())
                                      .CreateLogger();
            Log.Logger = serilog;

            var builder = new ContainerBuilder();

            // SSL gRPC
            var caCrt          = File.ReadAllText(EnvVars.CaCrtPath());
            var sslCredentials = new SslCredentials(caCrt);

            var registrationEngineGrpcChannel = new Channel(
                EnvVars.Target(@"RegistrationEngineHost", @"RegistrationEnginePort"),
                sslCredentials);

            // Create MagicOnion dynamic client proxy
            var registrationEngineGrpcClient = TrackingProxy.Create <IRegistrationEngineGrpc>(registrationEngineGrpcChannel);

            var registrationEngine = LogProxy.Create <IRegistrationEngine>(new RegistrationEngineClient(registrationEngineGrpcClient), serilog, LogType.All);

            builder.RegisterInstance <Serilog.ILogger>(serilog);
            builder.RegisterInstance <IRegistrationEngine>(registrationEngine);
            builder.RegisterType <MembershipManager>().As <IMembershipManager>();
            IContainer container = builder.Build();

            // Set up the service locator
            ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container));

            GrpcEnvironment.SetLogger(new ConsoleLogger());
        }
예제 #2
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            IEnumerable <EndpointResourceDescription> endpoints = Context.CodePackageActivationContext.GetEndpoints()
                                                                  .Where(endpoint => endpoint.Protocol == EndpointProtocol.Http || endpoint.Protocol == EndpointProtocol.Https);

            return(endpoints.Select(endpoint =>
                                    new ServiceInstanceListener(serviceContext =>
                                                                new KestrelCommunicationListener(serviceContext, typeof(IRestApi).Name, (url, listener) =>
            {
                ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                return new WebHostBuilder()
                .UseKestrel(options =>
                {
                    if (endpoint.Protocol == EndpointProtocol.Http)
                    {
                        options.Listen(IPAddress.Any, endpoint.Port);
                    }
                    else if (endpoint.Protocol == EndpointProtocol.Https)
                    {
                        options.Listen(IPAddress.Any, endpoint.Port, listenOptions => listenOptions.UseHttps(GetCertificate(_ApiCertThumbprint)));
                    }
                })
                .ConfigureServices(
                    services => services
                    .AddTransient(typeof(IMembershipManager), _ => TrackingProxy.ForMicroservice <IMembershipManager>())
                    .AddSingleton(typeof(ILogger), _Logger)
                    .AddSingleton(serviceContext))
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseStartup <Startup>()
                .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                .UseUrls(url)
                .Build();
            }))));
        }
예제 #3
0
        public static IWebHost BuildWebHost(ILogger serilog)
        {
            // SSL gRPC
            var caCrt          = File.ReadAllText(EnvVars.CaCrtPath());
            var sslCredentials = new SslCredentials(caCrt);

            var membershipManagerGrpcChannel = new Channel(
                EnvVars.Target(@"MembershipManagerHost", @"MembershipManagerPort"),
                sslCredentials);

            // Create MagicOnion dynamic client proxy
            var membershipManagerGrpcClient = TrackingProxy.Create <IMembershipManagerGrpc>(membershipManagerGrpcChannel);

            var membershipManager = LogProxy.Create <IMembershipManager>(new MembershipManagerClient(membershipManagerGrpcClient), serilog, LogType.All);

            var restApiLogger = serilog;

            return(new WebHostBuilder()
                   .UseKestrel(options =>
            {
                options.Listen(
                    IPAddress.Any,
                    EnvVars.LocalPort(@"RestApiPort"),
                    listenOptions => listenOptions.UseHttps(EnvVars.ServerPfxPath(), EnvVars.CrtPassword()));
            })
                   .ConfigureServices(
                       services => services
                       .AddSingleton <IMembershipManager>(membershipManager)
                       .AddSingleton <ILogger>(serilog))
                   .UseContentRoot(Directory.GetCurrentDirectory())
                   .UseStartup <Startup>()
                   .Build());
        }
예제 #4
0
        public MembershipManager(
            StatelessServiceContext context,
            ILogger logger)
            : base(context)
        {
            _Logger = logger ?? throw new ArgumentNullException(nameof(logger));
            var registrationEngine = TrackingProxy.ForComponent <IRegistrationEngine>(this);

            _Impl = LogProxy.Create <IMembershipManager>(new Impl.MembershipManager(registrationEngine, logger), logger, LogType.All);
            _Logger.Information("Constructed");
        }
        public RegistrationEngine(
            StatelessServiceContext context,
            ILogger logger)
            : base(context)
        {
            _Logger = logger ?? throw new ArgumentNullException(nameof(logger));
            var userAccess = TrackingProxy.ForComponent <IUserAccess>(this);

            _Impl = LogProxy.Create <IRegistrationEngine>(new Impl.RegistrationEngine(userAccess, logger), logger, LogType.All);
            _Logger.Information("Constructed");
        }
예제 #6
0
        private void Display(string text, TrackingProxy.PhoneNumber ph)
        {
            if (ph == null)
                return;

            Console.Write(text);
            Console.WriteLine(": {0}-{1}-{2}-{3} x {4}", ph.CountryCode, ph.AreaCode, ph.Phone, ph.Extension);
        }
예제 #7
0
        private void Display(TrackingProxy.Address adr)
        {
            if (adr == null)
                return;

            Util.Print("Name", adr.Name);
            Util.Print("Company", adr.Company);
            Util.Print("Department", adr.Department);
            Util.Print("StreetNumber", adr.StreetNumber);
            Util.Print("StreetSuffix", adr.StreetSuffix);
            Util.Print("StreetName", adr.StreetName);
            Util.Print("StreetType", adr.StreetType);
            Util.Print("StreetDirection", adr.StreetDirection);
            Util.Print("Suite", adr.Suite);
            Util.Print("Floor", adr.Floor);
            Util.Print("StreetAddress2", adr.StreetAddress2);
            Util.Print("StreetAddress3", adr.StreetAddress3);
            Util.Print("City", adr.City);
            Util.Print("Province", adr.Province);
            Util.Print("Country", adr.Country);
            Util.Print("PostalCode", adr.PostalCode);
            Display("PhoneNumber", adr.PhoneNumber);
            Display("FaxNumber", adr.FaxNumber);
        }
예제 #8
0
        private void Display(TrackingProxy.ResponseInformation respInf)
        {
            if (respInf == null)
                return;

            int i = 0;
            if (respInf.Errors != null && respInf.Errors.Length > 0)
            {
                foreach (TrackingProxy.Error error in respInf.Errors)
                {
                    i++;
                    Util.Print("Error", i);
                    Util.Push();
                    Util.Print("Error code", error.Code);
                    Util.Print("Error description", error.Description);
                    Util.Print("Additional Information", error.AdditionalInformation);
                    Util.Pop();
                }
            }

            i = 0;
            if (respInf.InformationalMessages != null && respInf.InformationalMessages.Length > 0)
            {
                foreach (TrackingProxy.InformationalMessage msg in respInf.InformationalMessages)
                {
                    i++;
                    Util.Print("InformationalMessage", i);
                    Util.Push();
                    Util.Print("", msg.Code);
                    Util.Print("message", msg.Message);
                    Util.Pop();
                }
            }
        }
예제 #9
0
 static IMembershipManager GetProxy()
 {
     return(TrackingProxy.ForMicroservice <IMembershipManager>());
 }