// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { if (!Configuration.GetSection("Scheduler").Get <SchedulerOptions>().Disabled) { services.AddHostedService <TimedHostedService>(); } string settings = Configuration.GetSection("Database").Get <DatabaseOptions>().Settings; string type = Configuration.GetSection("Database").Get <DatabaseOptions>().Type; Console.WriteLine("Database type: " + type); Console.WriteLine("Connecting: " + settings); DbConnection connection; if (string.IsNullOrEmpty(type)) { //Gurux.DLMS.AMI DB is defined elsewhere. connection = null; } if (string.Compare(type, "Oracle", true) == 0) { connection = new OracleConnection(settings); } else if (string.Compare(type, "MSSQL", true) == 0) { connection = new SqlConnection(settings); } else if (string.Compare(type, "MySQL", true) == 0) { connection = new MySql.Data.MySqlClient.MySqlConnection(settings); } else if (string.Compare(type, "SQLite", true) == 0) { connection = new SQLiteConnection(settings); } else { throw new Exception("Invalid connection type. " + type); } if (connection != null) { connection.Open(); GXHost h = new GXHost() { Connection = new GXDbConnection(connection, null) }; if (!h.Connection.TableExist <GXDevice>()) { Console.WriteLine("Creating tables."); h.Connection.CreateTable <GXSystemError>(false, false); h.Connection.CreateTable <GXDeviceTemplate>(false, false); h.Connection.CreateTable <GXDevice>(false, false); h.Connection.CreateTable <GXObjectTemplate>(false, false); h.Connection.CreateTable <GXAttributeTemplate>(false, false); h.Connection.CreateTable <GXObject>(false, false); h.Connection.CreateTable <GXAttribute>(false, false); h.Connection.CreateTable <GXValue>(false, false); h.Connection.CreateTable <GXTask>(false, false); h.Connection.CreateTable <GXError>(false, false); h.Connection.CreateTable <GXSchedule>(false, false); h.Connection.CreateTable <GXScheduleToAttribute>(false, false); h.Connection.CreateTable <GXSchedulerInfo>(false, false); h.Connection.CreateTable <GXReaderInfo>(false, false); h.Connection.CreateTable <GXDeviceToReader>(false, false); AddSchedule(); } else { h.Connection.UpdateTable <GXSystemError>(); h.Connection.UpdateTable <GXError>(); h.Connection.UpdateTable <GXReaderInfo>(); h.Connection.UpdateTable <GXObjectTemplate>(); h.Connection.UpdateTable <GXAttributeTemplate>(); h.Connection.UpdateTable <GXDeviceTemplate>(); h.Connection.UpdateTable <GXObject>(); h.Connection.UpdateTable <GXAttribute>(); h.Connection.UpdateTable <GXDevice>(); } h.Connection.Insert(GXInsertArgs.Insert(new GXSystemError() { Generation = DateTime.Now, Error = "Service started: " + ServerAddress }));; Console.WriteLine("Service started: " + ServerAddress); services.AddScoped <GXHost>(q => { return(h); }); } services.Configure <ReaderOptions>(Configuration.GetSection("Reader")); if (!Configuration.GetSection("Scheduler").Get <SchedulerOptions>().Disabled) { services.AddHostedService <TimedHostedService>(); } if (Configuration.GetSection("Reader").Get <ReaderOptions>().Threads != 0) { services.AddHostedService <ReaderService>(); } services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public ScheduleController(GXHost value) { host = value; }
public DeviceController(GXHost value) { host = value; }
public TestController(GXHost value) { host = value; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #if !NETCOREAPP2_0 && !NETCOREAPP2_1 services.AddControllers(); #endif//!NETCOREAPP2_0 && !NETCOREAPP2_1 DatabaseOptions db = Configuration.GetSection("Database").Get <DatabaseOptions>(); string settings = db.Settings; string type = db.Type; bool disabled = db.Disabled; if (disabled) { Console.WriteLine("Database service is disabled."); } else { Console.WriteLine("Database type: " + type); Console.WriteLine("Connecting: " + settings); } DbConnection connection; if (disabled || string.IsNullOrEmpty(type)) { //Gurux.DLMS.AMI DB is defined elsewhere. connection = null; } else if (string.Compare(type, "Oracle", true) == 0) { connection = new OracleConnection(settings); } else if (string.Compare(type, "MSSQL", true) == 0) { connection = new SqlConnection(settings); } else if (string.Compare(type, "MySQL", true) == 0) { connection = new MySql.Data.MySqlClient.MySqlConnection(settings); } else if (string.Compare(type, "SQLite", true) == 0) { connection = new SQLiteConnection(settings); } else { throw new Exception("Invalid connection type. " + type); } if (connection != null) { connection.Open(); GXHost h = new GXHost() { Connection = new GXDbConnection(connection, null) }; h.Connection.OnSqlExecuted += Connection_OnSqlExecuted; if (!h.Connection.TableExist <GXDevice>()) { Console.WriteLine("Creating tables."); h.Connection.CreateTable <GXSystemError>(false, false); h.Connection.CreateTable <GXDeviceTemplate>(false, false); h.Connection.CreateTable <GXDevice>(false, false); h.Connection.CreateTable <GXObjectTemplate>(false, false); h.Connection.CreateTable <GXAttributeTemplate>(false, false); h.Connection.CreateTable <GXObject>(false, false); h.Connection.CreateTable <GXAttribute>(false, false); h.Connection.CreateTable <GXValue>(false, false); h.Connection.CreateTable <GXTask>(false, false); h.Connection.CreateTable <GXError>(false, false); h.Connection.CreateTable <GXSchedule>(false, false); h.Connection.CreateTable <GXScheduleToAttribute>(false, false); h.Connection.CreateTable <GXSchedulerInfo>(false, false); h.Connection.CreateTable <GXReaderInfo>(false, false); h.Connection.CreateTable <GXDeviceToReader>(false, false); h.Connection.CreateTable <GXDeviceLog>(false, false); AddSchedule(h.Connection); } else { h.Connection.UpdateTable <GXSystemError>(); h.Connection.UpdateTable <GXError>(); h.Connection.UpdateTable <GXReaderInfo>(); h.Connection.UpdateTable <GXObjectTemplate>(); h.Connection.UpdateTable <GXAttributeTemplate>(); h.Connection.UpdateTable <GXDeviceTemplate>(); h.Connection.UpdateTable <GXObject>(); h.Connection.UpdateTable <GXAttribute>(); h.Connection.UpdateTable <GXDevice>(); if (!h.Connection.TableExist <GXDeviceLog>()) { h.Connection.CreateTable <GXDeviceLog>(false, false); } else { h.Connection.UpdateTable <GXDeviceLog>(); } } h.Connection.Insert(GXInsertArgs.Insert(new GXSystemError() { Generation = DateTime.Now, Error = "Service started: " + ServerAddress }));; Console.WriteLine("Service started: " + ServerAddress); services.AddScoped <GXHost>(q => { return(h); }); } services.Configure <ListenerOptions>(Configuration.GetSection("Listener")); ListenerOptions listener = Configuration.GetSection("Listener").Get <ListenerOptions>(); if (!listener.Disabled) { services.AddHostedService <GXListenerService>(); } else { Console.WriteLine("Listener service is disabled."); } services.Configure <NotifyOptions>(Configuration.GetSection("Notify")); NotifyOptions n = Configuration.GetSection("Notify").Get <NotifyOptions>(); if (!n.Disabled && n.Port != 0) { services.AddHostedService <GXNotifyService>(); } else { Console.WriteLine("Notify service is disabled."); } services.Configure <SchedulerOptions>(Configuration.GetSection("Scheduler")); SchedulerOptions s = Configuration.GetSection("Scheduler").Get <SchedulerOptions>(); if (!s.Disabled) { services.AddHostedService <GXSchedulerService>(); } else { Console.WriteLine("Scheduler service is disabled."); } services.Configure <ReaderOptions>(Configuration.GetSection("Reader")); ReaderOptions r = Configuration.GetSection("Reader").Get <ReaderOptions>(); Console.WriteLine("Reader trace level is " + r.TraceLevel); Console.WriteLine("Listener trace level is " + listener.TraceLevel); if (r.Threads != 0 && !r.Disabled) { services.AddHostedService <ReaderService>(); } else { Console.WriteLine("Reader '" + r.Name + "' ID: " + r.Id); } #if NETCOREAPP2_0 || NETCOREAPP2_1 services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); #endif //NETCOREAPP2_0 || NETCOREAPP2_1 }
public TemplateController(GXHost value) { host = value; }
public InfoController(GXHost value) { sqlSettings = value.Connection.Builder.Settings.Type.ToString(); Helpers.UpdateRestMessageTypes(MessageMap); }
public ObjectController(GXHost value) { host = value; }
public SystemErrorController(GXHost value) { host = value; }
public TaskController(GXHost value, IHostApplicationLifetime applicationLifetime) { host = value; _cancellationToken = applicationLifetime.ApplicationStopping; }
public ReaderController(GXHost value) { host = value; }
public ValueController(GXHost value) { host = value; }
public ErrorController(GXHost value) { host = value; }
public TaskController(GXHost value) { host = value; }