Ejemplo n.º 1
0
 public Program()
 {
     _bus = MassTransitConfig.ConfigureSenderBus();
     _reverseGeoCodingService = new ReverseGeoCodingService();
     _endpoint = _bus.GetSendEndpoint(new Uri(
                                          "rabbitmq://*****:*****@eagle.rmq.cloudamqp.com/zcckffbw/Teltonika.endpoint"));
 }
Ejemplo n.º 2
0
        public void StartService()
        {
            ContainerBuilder builder = new ContainerBuilder();
            var dependencyRegistrar  = new DependencyRegistrar();

            dependencyRegistrar.Register(builder);
            //_bus = DependencyRegistrar.ResolveServiceBus();
            //try
            //{
            //    _bus.StartAsync();
            //}
            //catch (Exception e)
            //{
            //    Debug.WriteLine(e.Message);
            //    _bus.StopAsync();
            //}
            try
            {
                MassTransitConfig.ConfigureReceiveBus((cfg, hst) =>
                                                      cfg.ReceiveEndpoint(hst, "Teltonika.endpoint", e =>
                                                                          e.Consumer <DenormalizerHandler>())

                                                      ).Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                //  throw;
            }
        }
Ejemplo n.º 3
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     RegisterExceptionless();
     MassTransitConfig.MassTransit_Start();
 }
Ejemplo n.º 4
0
        public Server()
        {
            _reverseGeoCodingService = new ReverseGeoCodingService();
            _bus = MassTransitConfig.ConfigureSenderBus();
            var connextion = ConfigurationManager.AppSettings["RabbitMqConnectionString"];

            _endpoint      = _bus.GetSendEndpoint(new Uri(connextion));
            _devicesParser = new DevicesParser();
        }
Ejemplo n.º 5
0
        static IContainer BuildContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ReverseGeoCodingService>();
            var bus = MassTransitConfig.ConfigureSenderBus();

            builder.RegisterInstance(bus).As <IBusControl>();
            builder.RegisterType <TeltonikaServer>();
            return(builder.Build());
        }
Ejemplo n.º 6
0
 protected void Application_Start()
 {
     log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
     GlobalConfiguration.Configuration.Filters.Add(new WebApiTrackerAttribute());
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     MassTransitConfig.MassTransit_Start();
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var busConfig = new BusConsumerStarter();
            var builder = new ContainerBuilder();
            builder.RegisterType<DbContextScopeFactory>().As<IDbContextScopeFactory>();
            builder.RegisterType<AmbientDbContextLocator>().As<IAmbientDbContextLocator>();
            builder.RegisterGeneric(typeof(EfScopeRepository<>)).As(typeof(IScopeRepository<>)).InstancePerLifetimeScope();
            Container = builder.Build();

            Container.Resolve<IAmbientDbContextLocator>();
            MassTransitConfig.ConfigureReceiveBus((cfg, hst) =>
                cfg.ReceiveEndpoint(hst, "Teltonika.endpoint", e =>
                    e.Consumer<TeltonikaedgeHandler>())

            ).Start();   //busConfig.StartConsumerBus<Tk103Handler>("Tk1003.endpoint");
        }
Ejemplo n.º 8
0
 protected void Application_Stop()
 {
     MassTransitConfig.MassTransit_Stop();
 }
        public static IServiceCollection ConfigureBus(this IServiceCollection services, IConfiguration configuration,
                                                      string apiResourceName, Assembly assembly,
                                                      Action <IServiceCollectionConfigurator <IExternalBus> > postAction = null)
        {
            var config = new MassTransitConfig();

            configuration.Bind("MassTransitConfig", config);
            // get referenced assemblies
            var assemblies = new List <Assembly> {
                assembly
            };

            assemblies.AddRange(assembly.GetProjectReferencedAssemblies());
            // find consumers
            var types = AssemblyTypeCache.FindTypes(assemblies, TypeMetadataCache.IsConsumerOrDefinition).GetAwaiter()
                        .GetResult();
            var consumers = types.FindTypes(TypeClassification.Concrete | TypeClassification.Closed).ToArray();
            var internals = new List <Type>();
            var externals = new List <Type>();

            foreach (var type in consumers)
            {
                if (type.HasInterface <IExternalConsumer>())
                {
                    externals.Add(type);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"{type.FullName} registered into External Bus");
                }

                else
                {
                    internals.Add(type);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine($"{type.FullName} registered into Mediator");
                }
            }

            services.AddMediator(x =>
            {
                x.AddConsumers(internals.ToArray());
            });
            //services.AddMassTransit(x =>
            //{
            //    x.AddConsumers(internals.ToArray());
            //    x.AddMediator((provider, cfg) => { cfg.UseFluentValidation(); });
            //});


            services.AddMassTransit <IExternalBus>(x =>
            {
                x.AddConsumers(externals.ToArray());
                x.AddBus(provider =>
                {
                    switch (config.BusType)
                    {
                    case BusType.AzureServiceBus:
                    case BusType.ActiveMQ:
                    case BusType.AmazonSQS:
                        throw new NotImplementedException();

                    default:
                        var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
                        {
                            cfg.Host(new Uri(config.RabbitMQ.Address), h =>
                            {
                                h.Username(config.RabbitMQ.Username);
                                h.Password(config.RabbitMQ.Password);
                            });

                            cfg.ReceiveEndpoint(apiResourceName, ep => { ep.ConfigureConsumers(provider); });

                            cfg.ConnectConsumerConfigurationObserver(
                                new FluentValidationConsumerConfigurationObserver(provider));
                            //cfg.UseFluentValidation();
                        });
                        return(busControl);
                    }
                });

                postAction?.Invoke(x);
            });

            services.AddMassTransitHostedService();

            return(services);
        }
Ejemplo n.º 10
0
        protected void Application_Start()
        {
            #region add mastransit consumer

            try
            {
                MassTransitConfig.ConfigureReceiveBus((cfg, hst) =>
                                                      cfg.ReceiveEndpoint(hst, "Smartfleet.Web.endpoint", e =>
                                                                          e.Consumer <SignalRHandler>())

                                                      ).Start();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                //throw;
            }
            #endregion

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            BundleTable.EnableOptimizations = false;
            // seed user administrator and roles
            //  SeedInitialData();

            #region register different services and classes using autofac
#if DEBUG
            TelemetryConfiguration.Active.DisableTelemetry = true;
#endif
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterAssemblyTypes(typeof(MvcApplication).Assembly)
            .AsImplementedInterfaces();

            builder.RegisterModule(new AutofacWebTypesModule());
            //builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType <SmartFleetObjectContext>().As <SmartFleetObjectContext>();

            builder.RegisterType <UserStore <IdentityUser> >().As <IUserStore <IdentityUser> >();
            builder.RegisterType <RoleStore <IdentityRole> >().As <IRoleStore <IdentityRole, string> >();
            builder.RegisterType <UserManager <IdentityUser> >();
            builder.RegisterType <AuthenticationService>().As <IAuthenticationService>();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <DbContextScopeFactory>().As <IDbContextScopeFactory>();
            builder.RegisterType <ReverseGeoCodingService>().As <ReverseGeoCodingService>();
            builder.RegisterType <VehicleService>().As <IVehicleService>();
            builder.RegisterType <CustomerService>().As <ICustomerService>();

            builder.RegisterType <PositionService>().As <IPositionService>();
            builder.RegisterType <CustomerService>().As <ICustomerService>();
            builder.RegisterType <PdfService>().As <IPdfService>();
            #endregion

            #region automapper

            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new SmartFleetAdminMappings());
            });
            var mapper = mapperConfiguration.CreateMapper();
            builder.RegisterInstance(mapper).As <IMapper>();
            #endregion
            //var bus = BusControl();
            //try
            //{

            //    bus.StartAsync();
            //}
            //catch (Exception e)
            //{
            //    Debug.WriteLine(e.Message);
            //    bus.StopAsync();
            //}
            var container = builder.Build();
            var path      = Server.MapPath("/") + @"bin\microservices";
            MicroServicesLoader.Loader(path);

            //    container.Resolve<IAmbientDbContextLocator>();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            // GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver((IContainer)container);
        }