protected void Application_Start() { DashboardConfig.RegisterService(RouteTable.Routes); RouteConfig.RegisterRoutes(RouteTable.Routes); ASPxWebControl.CallbackError += Application_Error; ControllerBuilder.Current.SetControllerFactory(typeof(CustomControllerFactory)); }
public PirSensorService(DashboardConfig cfg, MonitorService monitorService) { this._monitorService = monitorService; this.PirSensorPin = cfg.PirSensorPin; this.MonitorFadeoutTimeMs = (int)(cfg.MonitorFadeoutTimeMinutes * 60 * 1000); if (TimeSpan.TryParse(cfg.WakeupTime, CultureInfo.InvariantCulture, out TimeSpan wakeupTime)) { this.WakeupTime = wakeupTime; Logger.Info($"Wakeup at {this.WakeupTime}"); } else { this.WakeupTime = new TimeSpan(06, 00, 00); Logger.Warn($"Wakeup Fallback at {this.WakeupTime}"); } if (TimeSpan.TryParse(cfg.BedTime, CultureInfo.InvariantCulture, out TimeSpan bedTime)) { this.BedTime = bedTime; Logger.Info($"Bedtime at {this.BedTime}"); } else { this.BedTime = new TimeSpan(22, 00, 00); Logger.Warn($"Bedtime Fallback at {this.BedTime}"); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Bind the Appsettings.json to shiftDashboardConfig DashboardConfig shiftDashboardConfig = new DashboardConfig(); Configuration.GetSection(shiftDashboardConfig.Position).Bind(shiftDashboardConfig); services.AddSingleton <DashboardConfig>(shiftDashboardConfig); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.Configure <ForwardedHeadersOptions>(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; }); // Initialize DB Context services.AddDbContext <DashboardContext>(options => { var builder = new NpgsqlDbContextOptionsBuilder(options); builder.SetPostgresVersion(new Version(9, 6)); options.UseNpgsql(shiftDashboardConfig.ConnectionString); } ); // Shift Api Service (Need a DB Context services.AddTransient <IApiService, ApiService>(); // Schedule Tasks. services.AddQuartz(q => { // Create a "key" for the job var updateDelegateJobKey = new JobKey("UpdateDelegateJob"); // Register the job with the DI container q.AddJob <UpdateDelegateJob>(opts => opts.WithIdentity(updateDelegateJobKey)); // Create a trigger for the job // q.AddTrigger(opts => opts .ForJob(updateDelegateJobKey) .WithIdentity("UpdateDelegateJob-trigger") // give the trigger a unique name .WithCronSchedule("0 */45 * * * ?"));; // run every 45 minutes // Use a Scoped container to create jobs. I'll touch on this later q.UseMicrosoftDependencyInjectionScopedJobFactory(); }); // Add the Quartz.NET hosted service services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); services.AddControllersWithViews(); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }
/// <summary> /// Perform an automatic placement of the block. Also updates the configuration of /// the block to match where it was placed. /// </summary> /// <param name="config">The user configuration information to update.</param> /// <param name="block">The block wrapper tha tmus tbe placed.</param> /// <param name="columns">The dashboard columns in the UI.</param> private void AutoConfigBlockPlacement(DashboardConfig config, DashboardBlockWrapper block, List <DashboardColumn> columns, bool isRequired) { var shortestColumn = columns.OrderBy(c => c.Placeholder.Controls.Count).First(); if (isRequired) { block.Config.Column = columns.IndexOf(shortestColumn); block.Config.Order = 0; int i = 1; config.Blocks.Where(b => b.Column == block.Config.Column && b.BlockId != block.Config.BlockId) .ToList() .ForEach(b => b.Order = i++); columns[block.Config.Column].Placeholder.Controls.AddAt(0, block); } else { block.Config.Column = columns.IndexOf(shortestColumn); block.Config.Order = 999; int i = 0; config.Blocks.Where(b => b.Column == block.Config.Column) .ToList() .ForEach(b => b.Order = i++); columns[block.Config.Column].Placeholder.Controls.Add(block); } }
public HomeController(ILogger <HomeController> logger, DashboardConfig dashboardconfig, DashboardContext dbcontext, IApiService apiService) { _dashboardOptions = dashboardconfig; _logger = logger; _dbcontext = dbcontext; _apiService = apiService; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DashboardConfig.Config(); }
private WeatherForecast _cachedResult; // if OWM is down public WeatherService(ILogger <WeatherService> logger, DashboardConfig cfg) { this._logger = logger; this._appId = cfg?.OpenWeatherMapAppId ?? throw new InvalidDataException("DashboardConfig.OpenWeatherMapAppId is not set"); this._units = cfg?.OpenWeatherMapUnits ?? throw new InvalidDataException("DashboardConfig.OpenWeatherMapUnits is not set"); this._latitude = cfg?.WeatherLocationLatitude ?? throw new InvalidDataException("DashboardConfig.WeatherLocationLatitude is not set"); this._longitude = cfg?.WeatherLocationLongitude ?? throw new InvalidDataException("DashboardConfig.WeatherLocationLongitude is not set"); this._language = cfg?.OpenWeatherMapLang ?? throw new InvalidDataException("DashboardConfig.OpenWeatherMapLang is not set"); }
public async Task UpdateDashboard(UserId user, DashboardConfig dashboard) { var dashboardModel = new DashboardConfigModel( dashboard.Id, dashboard.Name, dashboard.Tags .Select(t => new DashboardConfigTagModel(t.Tag, t.Target)) .ToList()); await _repository.AddOrUpdateDashboard(user, dashboardModel); }
protected void Application_Start() { DashboardConfig.RegisterService(RouteTable.Routes); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); ModelBinders.Binders.DefaultBinder = new DevExpress.Web.Mvc.DevExpressEditorsBinder(); DevExpress.Web.ASPxWebControl.CallbackError += Application_Error; }
public void OpenFileName(string str) { if (str != null) { DashboardConfigBundle configBundle = JsonConvert.DeserializeObject <DashboardConfigBundle>(File.ReadAllText(str)); //dc.AddItemsToConsole(JsonConvert.SerializeObject(configBundle, Formatting.Indented)); DashboardConfig_ = configBundle.DashboardConfig_; List <IDashboardCellConfig> dashboardCellConfigs = configBundle.DashboardCellConfigs_; ClearDashboardCells(); AddDashBoardCells(dashboardCellConfigs); dc.AddItemsToConsole($"Dashboard \"{DashboardConfig_.DashboardName_}\" loaded"); } }
/// <summary> /// Saves the user configuartion about how they want their dashboard to look. /// </summary> /// <param name="config">The dashboard configuartion for the user.</param> private void SaveConfig(DashboardConfig config) { // // Explicitly set the order of the blocks. // foreach (var blockGroup in config.Blocks.GroupBy(b => b.Column)) { int order = 0; blockGroup.OrderBy(b => b.Order).ToList().ForEach(b => b.Order = order++); } SetBlockUserPreference("config", JsonConvert.SerializeObject(config)); }
public BackgroundImageService(ILogger <BackgroundImageService> logger, DashboardConfig cfg, IWebHostEnvironment env, ReverseGeoCodingService geoCodingService) { this._logger = logger; this._geoCodingService = geoCodingService ?? throw new ArgumentNullException(); this._imagesSourcePath = cfg?.BackgroundImagesPath ?? throw new InvalidDataException("DashboardConfig.BackgroundImagesPath is not set"); if (!System.IO.Directory.Exists(this._imagesSourcePath)) { throw new DirectoryNotFoundException(this._imagesSourcePath); } this._localCopyFullPath = Path.Combine(env.WebRootPath, BasePath, "background.jpg"); this._relativePath = Path.Combine(BasePath, "background.jpg"); this._nextBackgrounds = new Queue <BackgroundImage>(31); // up to one month ahead this._logger.LogInformation(nameof(BackgroundImageService) + " created"); }
public GoogleCalendarService(DashboardConfig cfg, CalendarService googleService) { Dictionary <string, string> calendars = cfg?.Calendars; if (calendars == null) { throw new InvalidDataException("DashboardConfig.Calendars is null"); } if (calendars.Count == 0) { throw new InvalidDataException("DashboardConfig.Calendars is empty"); } this._calendarIds = calendars.Keys.ToArray(); this._googleService = googleService ?? throw new ArgumentNullException(nameof(googleService)); }
public MainWindow() { InitializeComponent(); DataContext = this; // load a dashboard in the view space DashboardConfig dashboardConfig = new DashboardConfig("Dashboard"); DashboardUC_ = new DashboardUC(dashboardConfig); MainContainer.Content = DashboardUC_; //this.Title = DashboardUC_.DashboardConfig_.DashboardName_; DashboardUC_.PropertyChanged += DashboardUC__PropertyChanged; //AddSeedCells(); String fileNameStr = (String)((App)Application.Current).Properties["FilePathArgName"]; DashboardUC_.OpenFileName(fileNameStr); }
public static IServiceCollection AddConfiguration(this IServiceCollection services, out DashboardConfig config) { var builder = new ConfigurationBuilder() .AddJsonFile("./secrets.json") .AddEnvironmentVariables("DB_"); IConfigurationRoot root = builder.Build(); var dbconfig = new DashboardConfig(); ConfigurationBinder.Bind(root, dbconfig); services.AddSingleton <DashboardConfig>(dbconfig); config = dbconfig; return(services); }
/// <summary> /// Get the config for the current user on how they want their dashboard /// to look. /// </summary> /// <returns>The configuration object for the dashboard.</returns> private DashboardConfig GetConfig() { var configString = GetBlockUserPreference("config"); DashboardConfig config = null; try { config = JsonConvert.DeserializeObject <DashboardConfig>(configString); if (config == null) { config = new DashboardConfig { Layout = GetAttributeValue("DefaultLayout") }; } } catch { config = new DashboardConfig { Layout = GetAttributeValue("DefaultLayout") }; } return(config); }
public ApiService(ILogger <ApiService> logger, DashboardConfig dashboardconfig, DashboardContext dbcontext) { _dashboardOptions = dashboardconfig; _logger = logger; _dbcontext = dbcontext; }
public DashboardUC(DashboardConfig dashboardConfig) { DashboardConfig_ = dashboardConfig; DoInitialWireUp(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); // Bind the Appsettings.json to shiftDashboardConfig DashboardConfig shiftDashboardConfig = new DashboardConfig(); Configuration.GetSection(shiftDashboardConfig.Position).Bind(shiftDashboardConfig); services.AddSingleton <DashboardConfig>(shiftDashboardConfig); // Initialize DB Context services.AddDbContext <DashboardContext>(options => { var builder = new NpgsqlDbContextOptionsBuilder(options); builder.SetPostgresVersion(new Version(9, 6)); options.UseNpgsql(shiftDashboardConfig.ConnectionString); } ); // Shift Api Service (Need a DB Context services.AddTransient <IApiService, ApiService>(); // Schedule Tasks. services.AddQuartz(q => { // Create a "key" for the job var updateDelegateJobKey = new JobKey("UpdateDelegateJob"); // Register the job with the DI container q.AddJob <UpdateDelegateJob>(opts => opts.WithIdentity(updateDelegateJobKey)); // Create a trigger for the job // q.AddTrigger(opts => opts .ForJob(updateDelegateJobKey) .WithIdentity("UpdateDelegateJob-trigger") // give the trigger a unique name .WithCronSchedule("0 */45 * * * ?"));; // run every 45 minutes // Use a Scoped container to create jobs. I'll touch on this later q.UseMicrosoftDependencyInjectionScopedJobFactory(); }); // Add the Quartz.NET hosted service services.AddQuartzHostedService( q => q.WaitForJobsToComplete = true); if (services.All(x => x.ServiceType != typeof(HttpClient))) { services.AddScoped( s => { var navigationManager = s.GetRequiredService <NavigationManager>(); return(new HttpClient { BaseAddress = new Uri(navigationManager.BaseUri) }); }); } services.AddBlazorise(options => { options.ChangeTextOnKeyPress = true; }); services.AddBootstrapProviders(); services.AddFontAwesomeIcons(); }
public async Task Handle(UserId user, DashboardConfig dashboard) => await _manager.UpdateDashboard(user, dashboard);
/// <summary> /// Build and layout all the blocks onto the web page. /// </summary> /// <param name="config">User configuration data that specifies how things should be laid out.</param> private void BuildBlocks(DashboardConfig config) { var sourcePageGuid = GetAttributeValue("SourcePage").AsGuidOrNull(); if (sourcePageGuid.HasValue) { var sourcePage = PageCache.Read(sourcePageGuid.Value); if (sourcePage != null) { var blocks = GetAvailableBlocks(); Panel pnlRow = new Panel { CssClass = "row" }; List <DashboardBlockWrapper> dashboardBlocks = new List <DashboardBlockWrapper>(); bool needSave = false; phControls.Controls.Add(pnlRow); var columns = BuildColumns(config, pnlRow); foreach (var block in blocks) { DashboardBlockConfig blockConfig = null; blockConfig = config.Blocks.Where(b => b.BlockId == block.BlockId).FirstOrDefault(); if (blockConfig == null) { blockConfig = new DashboardBlockConfig(block.BlockId); blockConfig.Visible = block.DefaultVisible; config.Blocks.Add(blockConfig); needSave = true; } if (block.Required) { blockConfig.Visible = true; } if (blockConfig.Visible) { var control = TemplateControl.LoadControl(block.BlockCache.BlockType.Path); control.ClientIDMode = ClientIDMode.AutoID; var blockControl = control as RockBlock; bool canEdit = block.BlockCache.IsAuthorized(Authorization.EDIT, CurrentPerson); bool canAdministrate = block.BlockCache.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson); blockControl.SetBlock(PageCache, block.BlockCache, canEdit, canAdministrate); block.BlockCache.BlockType.SetSecurityActions(blockControl); var blockWrapper = new DashboardBlockWrapper(blockControl, block.BlockCache, blockConfig); blockWrapper.ShowDelete = !block.Required; dashboardBlocks.Add(blockWrapper); } } // // Add all the blocks that are properly layed out already. // var existingBlocks = dashboardBlocks.Where(b => b.Config.Column < columns.Count); foreach (var blockGroup in existingBlocks.GroupBy(b => b.Config.Column)) { var sortedBlocks = blockGroup.OrderBy(b => b.Config.Order); foreach (var block in sortedBlocks) { columns[block.Config.Column].Placeholder.Controls.Add(block); } } // // Add in blocks that are new or don't currently fit. // var newBlocks = dashboardBlocks.Where(b => b.Config.Column >= columns.Count); foreach (var blockGroup in newBlocks.GroupBy(b => b.Config.Column)) { var sortedBlocks = blockGroup.OrderBy(b => b.Config.Order); foreach (var block in sortedBlocks) { bool isRequired = blocks.Where(b => b.BlockId == block.Config.BlockId).First().Required; AutoConfigBlockPlacement(config, block, columns, isRequired); needSave = true; } } // // Cleanup the config for any blocks that don't exist anymore. // var missingKeys = config.Blocks .Where(b => !blocks.Where(db => b.BlockId == db.BlockId).Any()) .Select(b => b.BlockId) .ToList(); foreach (var missingKey in missingKeys) { config.Blocks.RemoveAll(b => b.BlockId == missingKey); needSave = true; } if (needSave) { SaveConfig(config); } } } }
/// <summary> /// Build the columns that will be available for use based on the user's preferences. /// </summary> /// <param name="config">The user configuration data to use.</param> /// <param name="pnlRow">The panel control that will contain the columns.</param> private List <DashboardColumn> BuildColumns(DashboardConfig config, Panel pnlRow) { List <DashboardColumn> columns = new List <DashboardColumn>(); DashboardColumn column; if (config.Layout == TWO_COLUMN) { for (int i = 0; i < 2; i++) { column = new DashboardColumn("col-md-6", i); pnlRow.Controls.Add(column.Panel); columns.Add(column); } } else if (config.Layout == FOUR_COLUMN) { for (int i = 0; i < 4; i++) { column = new DashboardColumn("col-md-3", i); pnlRow.Controls.Add(column.Panel); columns.Add(column); } } else if (config.Layout == ONE_TWO_COLUMN) { column = new DashboardColumn("col-md-6", 0); pnlRow.Controls.Add(column.Panel); columns.Add(column); for (int i = 1; i < 3; i++) { column = new DashboardColumn("col-md-3", i); pnlRow.Controls.Add(column.Panel); columns.Add(column); } } else if (config.Layout == TWO_ONE_COLUMN) { for (int i = 0; i < 2; i++) { column = new DashboardColumn("col-md-3", i); pnlRow.Controls.Add(column.Panel); columns.Add(column); } column = new DashboardColumn("col-md-6", 2); pnlRow.Controls.Add(column.Panel); columns.Add(column); } else /* THREE_COLUMN */ { for (int i = 0; i < 3; i++) { column = new DashboardColumn("col-md-4", i); pnlRow.Controls.Add(column.Panel); columns.Add(column); } } return(columns); }