public MQTTDataTransport() { _config = new MQTTConfig(); _startWait = new AutoResetEvent(false); _connectWait = new AutoResetEvent(false); _subscribers = new Dictionary <string, IMessageHandler>(); _publishers = new List <IDisposable>(); }
public StaticDiscovery(MQTTConfig config) { _config = config; if (_config.IsBroker) { return; } _brokerIP = IPAddress.Parse(_config.BrokerIPAddress); }
/// <summary> /// 加载配置 /// </summary> public void LoadSettings() { MQTTConfig config = new MQTTConfig(); config.HostName = ConfigurationManager.AppSettings["Mqtt_Server"]; config.Port = int.Parse(ConfigurationManager.AppSettings["Mqtt_Port"]); config.UserName = ConfigurationManager.AppSettings["Mqtt_User"]; config.Password = ConfigurationManager.AppSettings["Mqtt_Password"]; config.DefaultExchangeName = ConfigurationManager.AppSettings["Mqtt_Exchange"]; ILogWrite _log = ServiceLocator.Current.GetInstance <ILogWrite>(); rabbitMQClientHandler = new RabbitMQClientHandler(config, _log); rabbitMQClientHandler.Connect();//连接 ExchangeName = config.DefaultExchangeName; DispatchQueue = ConfigurationManager.AppSettings["Mqtt_DispatchQueue"]; DispatchRouteKey = ConfigurationManager.AppSettings["Mqtt_DispatchRouteKey"]; List <RabbitQueueBind> list = new List <RabbitQueueBind>(); list.Add(new RabbitQueueBind() { ExchangeName = ExchangeName, QueueName = DispatchQueue, RouteKey = DispatchRouteKey }); StatusQueue = ConfigurationManager.AppSettings["Mqtt_StatusQueue"]; StatusRouteKey = ConfigurationManager.AppSettings["Mqtt_StatusRouteKey"]; list.Add(new RabbitQueueBind() { ExchangeName = ExchangeName, QueueName = StatusQueue, RouteKey = StatusRouteKey }); rabbitMQClientHandler.ExchangeAndQueueInitial(ExchangeName, ExchangeType.Topic, list); //初始化交换机和队列的绑定关系 rabbitMQClientHandler.RabbitmqMessageConsume(DispatchQueue); //订阅队列:派送队列 rabbitMQClientHandler.MessageReceivedRaised += RabbitMQClientHandler_MessageReceivedRaised; }
static void Main(string[] args) { mqtt = MQTTConfig.LerConfig(); bd = BDConfig.LerConfig(); switch (bd.Tipo) { case TipoBD.SQLServer: ServidorSQLServer(bd); break; case TipoBD.PostgreSQL: ServidorPostgreSQL(bd); break; case TipoBD.MySQL: ServidorMySQL(bd); break; case TipoBD.MongoDB: ServidorMongoDB(bd); break; } ServidorMQTT(mqtt); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { EconomyMainContext.WorkWithDb = Convert.ToBoolean(Configuration.GetValue <bool>("UseDatabase")); if (EconomyMainContext.WorkWithDb) { // Check Provider and get ConnectionString if (Configuration["Provider"] == "SQLite") { var constr = Configuration.GetConnectionString("SQLite"); if (!string.IsNullOrEmpty(constr)) { var file = constr.Split('='); if (file.Length > 0) { var f = file[1]; if (!FileHelpers.IsFileExists(f)) { var appdataFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); var destFolder = Path.Combine(appdataFolder, "VEFramework"); FileHelpers.CheckOrCreateTheFolder(destFolder); var defaultDbFile = Path.Combine(destFolder, "veframeworkdb.db"); constr = "Data Source=" + defaultDbFile; if (!FileHelpers.IsFileExists(defaultDbFile)) { var loc = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DDL", "veframeworkdb.db"); var destLoc = Path.Combine(destFolder, "veframeworkdb.db"); if (!FileHelpers.CopyFile(loc, destLoc)) { throw new Exception("Cannot copy default SQLite Db and configured file does not exists!"); } } } } } services.AddDbContext <DbEconomyContext>(options => options.UseSqlite(constr)); var optionsBuilder = new DbContextOptionsBuilder <DbEconomyContext>(); optionsBuilder.UseSqlite(constr); EconomyMainContext.DbService = new DbConnectorService(new DbEconomyContext(optionsBuilder.Options)); } else if (Configuration["Provider"] == "MSSQL") { services.AddDbContext <DbEconomyContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MSSQL"))); var optionsBuilder = new DbContextOptionsBuilder <DbEconomyContext>(); optionsBuilder.UseSqlServer(Configuration.GetConnectionString("MSSQL")); EconomyMainContext.DbService = new DbConnectorService(new DbEconomyContext(optionsBuilder.Options)); } else if (Configuration["Provider"] == "PostgreSQL") { services.AddDbContext <DbEconomyContext>(options => options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); var optionsBuilder = new DbContextOptionsBuilder <DbEconomyContext>(); optionsBuilder.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")); EconomyMainContext.DbService = new DbConnectorService(new DbEconomyContext(optionsBuilder.Options)); } // Exception else { throw new ArgumentException("Not a valid database type"); } EconomyMainContext.DbLoaded = true; } services .AddControllers(o => o.Filters.Add(new HttpResponseExceptionFilter())) .AddNewtonsoftJson(o => { o.UseMemberCasing(); //generates identical javascript and c# names o.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Include; //easier javascript work with ".Include" if (Environment.IsDevelopment()) { o.SerializerSettings.Formatting = Formatting.Indented; } }); var config = new MQTTConfig(); Configuration.GetSection("MQTT").Bind(config); services .AddHostedMqttServer(mqttServer => mqttServer .WithConnectionValidator(c => { if (c.Username != config.User) { return; } if (c.Password != config.Pass) { return; } c.ReasonCode = MqttConnectReasonCode.Success; }) .WithoutDefaultEndpoint()) .AddMqttConnectionHandler() .AddConnections(); services.AddSwaggerGen(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => { if (TimeSpan.TryParse(Configuration["LoginExpiration"], out var span)) { options.ExpireTimeSpan = span; } }); }
public AutoDiscovery(MQTTConfig config) { _config = config; _selfAddress = IPUtils.GetLocalIP(); }