Beispiel #1
0
 private void btnOpenServer_Click(object sender, EventArgs e)
 {
     client    = new ConsumerClient(tbServer.Text);
     producter = new ProducterClient(tbServer.Text);
     client.MessageRecieved += client_MessageRecieved;
     client.Start();
 }
Beispiel #2
0
        public void ConfigureDIService(IServiceCollection services)
        {
            //Permission handler
            services.AddScoped <IAuthorizationHandler, PermissionAuthorizationHandler>();

            services.AddTransient <IUserService, UserService>();
            services.AddTransient <ILandLordUserService, LandLordUserService>();
            services.AddTransient <IEstateManagerUserService, EstateManagerUserService>();

            services.AddSingleton <IProducerClient <BusMessage> >(service =>
            {
                var topics         = Configuration.GetSection("Kafka").GetValue <string>("Topics").ToString().Split(",");
                var env            = service.GetRequiredService <IHostingEnvironment>();
                var producerClient = new ProducerClient <BusMessage>(env, Configuration);
                return(producerClient);
            });

            services.AddSingleton <IConsumerClient <BusMessage> >(service =>
            {
                var topics         = Configuration.GetSection("Kafka").GetValue <string>("Topics").ToString().Split(",");
                var env            = service.GetRequiredService <IHostingEnvironment>();
                var consumerClient = new ConsumerClient <BusMessage>(env, Configuration);
                //consumerClient.Subscribe(topics.ToList());
                return(consumerClient);
            });

            services.AddTransient <Func <List <BusHandler> > >(cont =>
                                                               () =>
            {
                List <BusHandler> handlers = new List <BusHandler>();
                var scope   = cont.GetRequiredService <IServiceProvider>().CreateScope();
                var handler = scope.ServiceProvider.GetRequiredService <AuthHandler>();

                handlers.Add((message) => {
                    if (message.BusMessageType == (int)BusMessageTypes.NEW_USER)
                    {
                        handler.HandleCreateMarketerUser(message);
                        handler.HandleCreateTruckOwnerUser(message);
                    }
                });

                return(handlers);
            });

            services.AddMediatR(typeof(Startup));
            //services.AddTransient(p => BuildMediator());
            services.AddScoped <ImanageExceptionAttribute>();
            services.AddSingleton <BoundedMessageChannel <BusMessage> >();
            services.AddHostedService <EvenHubProcessorService>();
            services.AddHostedService <EventHubReaderService>();
            services.AddScoped <ImanageExceptionAttribute>();
            services.AddScoped <IDbContext, ImanageAuthDbContext>();
            services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
            services.AddScoped(typeof(IRepository <>), typeof(EntityRepository <>));
            services.AddTransient <AuthHandler>();
        }
Beispiel #3
0
 private void FrmMain_Load(object sender, EventArgs e)
 {
     /*CtrlWaiting waiting = new CtrlWaiting("权限加载中...",() =>
      * {
      *  try
      *  {
      *      PrivateMgr.LoadPrivates();
      *  }
      *  catch (Exception ex)
      *  {
      *      WinInfoHelper.ShowInfoWindow(this, "权限加载异常:"+ex.Message);
      *  }
      *
      * });
      * waiting.ShowDialog(this);*/
     try
     {
         tsslStateUser.Text = UserInfoHelper.UserInfo.USER_NAME;
         DatabaseConfigClass config = SysConfig.GetSqlServerServerConfig();
         if (config != null)
         {
             tsmiServerIp.Text = config.serverName;
         }
     }
     catch (Exception ex)
     {
         log.Error("读取配置异常:", ex);
     }
     smtNavigate.Main = this;
     try
     {
         if (PrivateMgr.FUN_POINTS.Contains(SYS_FUN_POINT.REAL_ALARM_DETECT))
         {
             Maticsoft.BLL.SMT_DATADICTIONARY_INFO dicBll = new Maticsoft.BLL.SMT_DATADICTIONARY_INFO();
             var configs = dicBll.GetModelList("DATA_TYPE='ALARM_INFO' and DATA_KEY='ALARM_SERVER'");
             if (configs.Count > 0)
             {
                 log.Info("报警服务器地址为:" + configs[0].DATA_VALUE);
                 consumerClient = new ConsumerClient(configs[0].DATA_VALUE);
                 consumerClient.MessageRecieved += consumerClient_MessageRecieved;
                 consumerClient.Start();
             }
             else
             {
                 log.Error("没有报警服务器地址,请在数据库中配置报警服务地址!其中 DATA_TYPE='ALARM_INFO' and DATA_KEY='ALARM_SERVER' DATA_VALUE为配置值,如:192.168.1.1:56010");
             }
         }
     }
     catch (Exception ex)
     {
         log.Error("报警接收初始化异常:", ex);
     }
 }
Beispiel #4
0
        internal ProCampaignService(string locale, string environement = null)
        {
            var key = ProCampaignKeyRepository.GetApiKey(locale, environement);

            if (key == null)
            {
                throw new Exception("Configuration failed Key not found");
            }

            var secret = ProCampaignKeyRepository.GetApiSecret(locale, environement);

            this._apiSecret      = !string.IsNullOrEmpty(secret) ? secret : string.Empty;
            this._apiKey         = key;
            this._consumerClient = new ConsumerClient(APIKey, APISecret);
        }
        public static void Run()
        {
            var server = new ProducerClient();
            var client = new ConsumerClient();

            // Kick off server.
            var serverTask = Task.Run(async() =>
            {
                await server.RunAsync();
            });

            // Kick off client.
            var clientTask = Task.Run(async() =>
            {
                // Similarly, client to server communication could happen on a
                // separate command channel passed into the server.
                await client.RunAsync(server.EventsChannel);
            });

            Task.WaitAll(serverTask, clientTask);
            Console.WriteLine("Shutting down runner");
        }