diff --git a/Oqtane.Client/Modules/Admin/Modules/Settings.razor b/Oqtane.Client/Modules/Admin/Modules/Settings.razor index 86ddb41b..ae515412 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Settings.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Settings.razor @@ -70,7 +70,9 @@ string _permissions; string _pageId; +#pragma warning disable 649 PermissionGrid _permissionGrid; +#pragma warning restore 649 RenderFragment DynamicComponent { get; set; } object _settings; diff --git a/Oqtane.Client/Modules/Admin/Pages/Index.razor b/Oqtane.Client/Modules/Admin/Pages/Index.razor index 85f9f12f..ce546547 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Index.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Index.razor @@ -24,18 +24,18 @@ @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - private async Task DeletePage(Page Page) + private async Task DeletePage(Page page) { try { - Page.IsDeleted = true; - await PageService.UpdatePageAsync(Page); - await logger.LogInformation("Page Deleted {Page}", Page); + page.IsDeleted = true; + await PageService.UpdatePageAsync(page); + await logger.LogInformation("Page Deleted {Page}", page); NavigationManager.NavigateTo(NavigateUrl("admin/pages")); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Page {Page} {Error}", Page, ex.Message); + await logger.LogError(ex, "Error Deleting Page {Page} {Error}", page, ex.Message); AddModuleMessage("Error Deleting Page", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor index dfdbe432..bfba2d25 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ - + @@ -25,7 +25,7 @@ - @@ -33,7 +33,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -65,7 +65,7 @@ - @@ -76,7 +76,7 @@ - @@ -90,16 +90,16 @@ public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } public override string Actions { get { return "Add,Edit"; } } - int profileid = -1; - string name = ""; - string title = ""; - string description = ""; - string category = ""; - string vieworder = "0"; - string maxlength = "0"; - string defaultvalue = ""; - string isrequired = "False"; - string isprivate = "False"; + int _profileid = -1; + string _name = ""; + string _title = ""; + string _description = ""; + string _category = ""; + string _vieworder = "0"; + string _maxlength = "0"; + string _defaultvalue = ""; + string _isrequired = "False"; + string _isprivate = "False"; protected override async Task OnInitializedAsync() { @@ -107,25 +107,25 @@ { if (PageState.QueryString.ContainsKey("id")) { - profileid = Int32.Parse(PageState.QueryString["id"]); - Profile profile = await ProfileService.GetProfileAsync(profileid); + _profileid = Int32.Parse(PageState.QueryString["id"]); + Profile profile = await ProfileService.GetProfileAsync(_profileid); if (profile != null) { - name = profile.Name; - title = profile.Title; - description = profile.Description; - category = profile.Category; - vieworder = profile.ViewOrder.ToString(); - maxlength = profile.MaxLength.ToString(); - defaultvalue = profile.DefaultValue; - isrequired = profile.IsRequired.ToString(); - isprivate = profile.IsPrivate.ToString(); + _name = profile.Name; + _title = profile.Title; + _description = profile.Description; + _category = profile.Category; + _vieworder = profile.ViewOrder.ToString(); + _maxlength = profile.MaxLength.ToString(); + _defaultvalue = profile.DefaultValue; + _isrequired = profile.IsRequired.ToString(); + _isprivate = profile.IsPrivate.ToString(); } } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message); + await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", _profileid, ex.Message); AddModuleMessage("Error Loading Profile", MessageType.Error); } } @@ -135,30 +135,30 @@ try { Profile profile; - if (profileid != -1) + if (_profileid != -1) { - profile = await ProfileService.GetProfileAsync(profileid); + profile = await ProfileService.GetProfileAsync(_profileid); } else { profile = new Profile(); } - profile.Name = name; - profile.Title = title; - profile.Description = description; - profile.Category = category; - profile.ViewOrder = int.Parse(vieworder); - profile.MaxLength = int.Parse(maxlength); - profile.DefaultValue = defaultvalue; - profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired)); - profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate)); + profile.Name = _name; + profile.Title = _title; + profile.Description = _description; + profile.Category = _category; + profile.ViewOrder = int.Parse(_vieworder); + profile.MaxLength = int.Parse(_maxlength); + profile.DefaultValue = _defaultvalue; + profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); + profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); profile = await ProfileService.UpdateProfileAsync(profile); await logger.LogInformation("Profile Saved {Profile}", profile); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message); + await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); AddModuleMessage("Error Saving Profile", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Profiles/Index.razor b/Oqtane.Client/Modules/Admin/Profiles/Index.razor index b362895a..593ccca4 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Index.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Index.razor @@ -2,7 +2,7 @@ @inherits ModuleBase @inject IProfileService ProfileService -@if (Profiles == null) +@if (_profiles == null) {

Loading...

} @@ -10,7 +10,7 @@ else { - +
    @@ -27,25 +27,25 @@ else @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - List Profiles; + List _profiles; protected override async Task OnInitializedAsync() { - Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId); + _profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId); } - private async Task DeleteProfile(int ProfileId) + private async Task DeleteProfile(int profileId) { try { - await ProfileService.DeleteProfileAsync(ProfileId); - await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId); + await ProfileService.DeleteProfileAsync(profileId); + await logger.LogInformation("Profile Deleted {ProfileId}", profileId); AddModuleMessage("Profile Deleted", MessageType.Success); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message); + await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", profileId, ex.Message); AddModuleMessage("Error Deleting Profile", MessageType.Error); } } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor index 72409259..012a5495 100644 --- a/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor +++ b/Oqtane.Client/Modules/Admin/RecycleBin/Index.razor @@ -23,14 +23,14 @@
- @if (pages == null) + @if (_pages == null) {

No Deleted Pages

} else { - +
    @@ -49,14 +49,14 @@ }
- @if (modules == null) + @if (_modules == null) {

No Deleted Modules

} else { - +
    @@ -83,8 +83,8 @@ @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - List pages; - List modules; + List _pages; + List _modules; protected override async Task OnInitializedAsync() { @@ -101,84 +101,84 @@ private async Task Load() { - pages = await PageService.GetPagesAsync(PageState.Site.SiteId); - pages = pages.Where(item => item.IsDeleted).ToList(); + _pages = await PageService.GetPagesAsync(PageState.Site.SiteId); + _pages = _pages.Where(item => item.IsDeleted).ToList(); - modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); - modules = modules.Where(item => item.IsDeleted).ToList(); + _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); + _modules = _modules.Where(item => item.IsDeleted).ToList(); } - private async Task RestorePage(Page Page) + private async Task RestorePage(Page page) { try { - Page.IsDeleted = false; - await PageService.UpdatePageAsync(Page); - await logger.LogInformation("Page Restored {Page}", Page); + page.IsDeleted = false; + await PageService.UpdatePageAsync(page); + await logger.LogInformation("Page Restored {Page}", page); await Load(); StateHasChanged(); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", Page, ex.Message); + await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", page, ex.Message); AddModuleMessage("Error Restoring Deleted Page", MessageType.Error); } } - private async Task DeletePage(Page Page) + private async Task DeletePage(Page page) { try { - await PageService.DeletePageAsync(Page.PageId); - await logger.LogInformation("Page Permanently Deleted {Page}", Page); + await PageService.DeletePageAsync(page.PageId); + await logger.LogInformation("Page Permanently Deleted {Page}", page); await Load(); StateHasChanged(); NavigationManager.NavigateTo(NavigateUrl()); } catch (Exception ex) { - await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", Page, ex.Message); + await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", page, ex.Message); AddModuleMessage(ex.Message, MessageType.Error); } } - private async Task RestoreModule(Module Module) + private async Task RestoreModule(Module module) { try { - PageModule pagemodule = await PageModuleService.GetPageModuleAsync(Module.PageModuleId); + PageModule pagemodule = await PageModuleService.GetPageModuleAsync(module.PageModuleId); pagemodule.IsDeleted = false; await PageModuleService.UpdatePageModuleAsync(pagemodule); - await logger.LogInformation("Module Restored {Module}", Module); + await logger.LogInformation("Module Restored {Module}", module); await Load(); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", Module, ex.Message); + await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", module, ex.Message); AddModuleMessage("Error Restoring Deleted Module", MessageType.Error); } } - private async Task DeleteModule(Module Module) + private async Task DeleteModule(Module module) { try { - await PageModuleService.DeletePageModuleAsync(Module.PageModuleId); + await PageModuleService.DeletePageModuleAsync(module.PageModuleId); // check if there are any remaining module instances in the site - modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); - if (!modules.Exists(item => item.ModuleId == Module.ModuleId)) + _modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId); + if (!_modules.Exists(item => item.ModuleId == module.ModuleId)) { - await ModuleService.DeleteModuleAsync(Module.ModuleId); + await ModuleService.DeleteModuleAsync(module.ModuleId); } - await logger.LogInformation("Module Permanently Deleted {Module}", Module); + await logger.LogInformation("Module Permanently Deleted {Module}", module); await Load(); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", Module, ex.Message); + await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", module, ex.Message); AddModuleMessage("Error Permanently Deleting Module", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Register/Index.razor b/Oqtane.Client/Modules/Admin/Register/Index.razor index 40b59b89..46fdca01 100644 --- a/Oqtane.Client/Modules/Admin/Register/Index.razor +++ b/Oqtane.Client/Modules/Admin/Register/Index.razor @@ -3,31 +3,31 @@ @inject NavigationManager NavigationManager @inject IUserService UserService -@if (Message != "") +@if (_message != "") { - + }
- +
- +
- - + +
- - + +
- +
@@ -36,38 +36,40 @@ @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } } - string Message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity"; - string Username = ""; - string Password = ""; - string Confirm = ""; - string Email = ""; - string DisplayName = ""; + string _message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity"; + string _username = ""; + string _password = ""; + string _confirm = ""; + string _email = ""; + string _displayName = ""; private async Task Register() { try { - Message = ""; - if (Username != "" && Password != "" && Confirm != "" && Email != "") + _message = ""; + if (_username != "" && _password != "" && _confirm != "" && _email != "") { - if (Password == Confirm) + if (_password == _confirm) { - User user = new User(); - user.SiteId = PageState.Site.SiteId; - user.Username = Username; - user.DisplayName = (DisplayName == "" ? Username : DisplayName); - user.Email = Email; - user.Password = Password; + User user = new User + { + SiteId = PageState.Site.SiteId, + Username = _username, + DisplayName = (_displayName == "" ? _username : _displayName), + Email = _email, + Password = _password + }; user = await UserService.AddUserAsync(user); if (user != null) { - await logger.LogInformation("User Created {Username} {Email}", Username, Email); + await logger.LogInformation("User Created {Username} {Email}", _username, _email); AddModuleMessage("User Account Created. Please Check Your Email For Verification Instructions.", MessageType.Info); } else { - await logger.LogError("Error Adding User {Username} {Email}", Username, Email); + await logger.LogError("Error Adding User {Username} {Email}", _username, _email); AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error); } } @@ -83,7 +85,7 @@ } catch (Exception ex) { - await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", Username, Email, ex.Message); + await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", _username, _email, ex.Message); AddModuleMessage("Error Adding User", MessageType.Error); } } diff --git a/Oqtane.Client/Modules/Admin/Roles/Add.razor b/Oqtane.Client/Modules/Admin/Roles/Add.razor index fccd1981..e908dd1c 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Add.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Add.razor @@ -17,7 +17,7 @@ - diff --git a/Oqtane.Client/Modules/Admin/Roles/Edit.razor b/Oqtane.Client/Modules/Admin/Roles/Edit.razor index 5d884975..71bc826a 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Edit.razor @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ - @@ -25,7 +25,7 @@ - @@ -36,7 +36,7 @@ - @@ -49,40 +49,40 @@ @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - int roleid; - string name = ""; - string description = ""; - string isautoassigned = "False"; - string issystem = "False"; + int _roleid; + string _name = ""; + string _description = ""; + string _isautoassigned = "False"; + string _issystem = "False"; protected override async Task OnInitializedAsync() { try { - roleid = Int32.Parse(PageState.QueryString["id"]); - Role role = await RoleService.GetRoleAsync(roleid); + _roleid = Int32.Parse(PageState.QueryString["id"]); + Role role = await RoleService.GetRoleAsync(_roleid); if (role != null) { - name = role.Name; - description = role.Description; - isautoassigned = role.IsAutoAssigned.ToString(); - issystem = role.IsSystem.ToString(); + _name = role.Name; + _description = role.Description; + _isautoassigned = role.IsAutoAssigned.ToString(); + _issystem = role.IsSystem.ToString(); } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", roleid, ex.Message); + await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", _roleid, ex.Message); AddModuleMessage("Error Loading Role", MessageType.Error); } } private async Task SaveRole() { - Role role = await RoleService.GetRoleAsync(roleid); - role.Name = name; - role.Description = description; - role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned)); - role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem)); + Role role = await RoleService.GetRoleAsync(_roleid); + role.Name = _name; + role.Description = _description; + role.IsAutoAssigned = (_isautoassigned != null && Boolean.Parse(_isautoassigned)); + role.IsSystem = (_issystem != null && Boolean.Parse(_issystem)); try { diff --git a/Oqtane.Client/Modules/Admin/Roles/Index.razor b/Oqtane.Client/Modules/Admin/Roles/Index.razor index 79124760..29378752 100644 --- a/Oqtane.Client/Modules/Admin/Roles/Index.razor +++ b/Oqtane.Client/Modules/Admin/Roles/Index.razor @@ -2,7 +2,7 @@ @inherits ModuleBase @inject IRoleService RoleService -@if (Roles == null) +@if (_roles == null) {

Loading...

} @@ -10,7 +10,7 @@ else { - +
    @@ -27,25 +27,25 @@ else @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } - List Roles; + List _roles; protected override async Task OnParametersSetAsync() { - Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId); + _roles = await RoleService.GetRolesAsync(PageState.Site.SiteId); } - private async Task DeleteRole(Role Role) + private async Task DeleteRole(Role role) { try { - await RoleService.DeleteRoleAsync(Role.RoleId); - await logger.LogInformation("Role Deleted {Role}", Role); + await RoleService.DeleteRoleAsync(role.RoleId); + await logger.LogInformation("Role Deleted {Role}", role); StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Deleting Role {Role} {Error}", Role, ex.Message); + await logger.LogError(ex, "Error Deleting Role {Role} {Error}", role, ex.Message); AddModuleMessage("Error Deleting Role", MessageType.Error); } } -} \ No newline at end of file +} diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index 496d411f..b3692a49 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -31,7 +31,7 @@ - diff --git a/Oqtane.Client/Modules/Admin/Sites/Add.razor b/Oqtane.Client/Modules/Admin/Sites/Add.razor index 944610d1..a692d081 100644 --- a/Oqtane.Client/Modules/Admin/Sites/Add.razor +++ b/Oqtane.Client/Modules/Admin/Sites/Add.razor @@ -7,7 +7,7 @@ @inject IThemeService ThemeService @inject IUserService UserService -@if (tenants == null) +@if (_tenants == null) {

Loading...

} @@ -21,7 +21,7 @@ else + @@ -41,7 +41,7 @@ else - @@ -51,7 +51,7 @@ else + + - @if (!isinitialized) + @if (!_isinitialized) { - + @@ -101,7 +101,7 @@ else - + } @@ -113,50 +113,50 @@ else @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } } - Dictionary themes = new Dictionary(); - Dictionary panelayouts = new Dictionary(); - Dictionary containers = new Dictionary(); + Dictionary _themes = new Dictionary(); + Dictionary _panelayouts = new Dictionary(); + Dictionary _containers = new Dictionary(); - List Themes; - List tenants; - string tenantid = "-1"; - string name = ""; - string urls = ""; - string themetype = ""; - string layouttype = ""; - string containertype = ""; - bool isinitialized = true; - string username = ""; - string password = ""; + List _themeList; + List _tenants; + string _tenantid = "-1"; + string _name = ""; + string _urls = ""; + string _themetype = ""; + string _layouttype = ""; + string _containertype = ""; + bool _isinitialized = true; + string _username = ""; + string _password = ""; protected override async Task OnInitializedAsync() { - Themes = await ThemeService.GetThemesAsync(); - tenants = await TenantService.GetTenantsAsync(); - urls = PageState.Alias.Name; - themes = ThemeService.GetThemeTypes(Themes); - containers = ThemeService.GetContainerTypes(Themes); - username = Constants.HostUser; + _themeList = await ThemeService.GetThemesAsync(); + _tenants = await TenantService.GetTenantsAsync(); + _urls = PageState.Alias.Name; + _themes = ThemeService.GetThemeTypes(_themeList); + _containers = ThemeService.GetContainerTypes(_themeList); + _username = Constants.HostUser; } private async void TenantChanged(ChangeEventArgs e) { try { - tenantid = (string)e.Value; - if (tenantid != "-1") + _tenantid = (string)e.Value; + if (_tenantid != "-1") { - Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault(); + Tenant tenant = _tenants.Where(item => item.TenantId == int.Parse(_tenantid)).FirstOrDefault(); if (tenant != null) { - isinitialized = tenant.IsInitialized; + _isinitialized = tenant.IsInitialized; StateHasChanged(); } } } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Tenant {TenantId} {Error}", tenantid, ex.Message); + await logger.LogError(ex, "Error Loading Tenant {TenantId} {Error}", _tenantid, ex.Message); AddModuleMessage("Error Loading Tenant", MessageType.Error); } } @@ -165,31 +165,31 @@ else { try { - themetype = (string)e.Value; - if (themetype != "") + _themetype = (string)e.Value; + if (_themetype != "") { - panelayouts = ThemeService.GetPaneLayoutTypes(Themes, themetype); + _panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype); } else { - panelayouts = new Dictionary(); + _panelayouts = new Dictionary(); } StateHasChanged(); } catch (Exception ex) { - await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message); + await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error); } } private async Task SaveSite() { - if (tenantid != "-1" && name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype)) + if (_tenantid != "-1" && _name != "" && _urls != "" && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype)) { bool unique = true; List aliases = await AliasService.GetAliasesAsync(); - foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (aliases.Exists(item => item.Name == name)) { @@ -200,12 +200,12 @@ else { bool isvalid = true; - if (!isinitialized) + if (!_isinitialized) { User user = new User(); user.SiteId = PageState.Site.SiteId; - user.Username = username; - user.Password = password; + user.Username = _username; + user.Password = _password; user = await UserService.LoginUserAsync(user, false, false); isvalid = user.IsAuthenticated; } @@ -215,24 +215,24 @@ else ShowProgressIndicator(); aliases = new List(); - urls = urls.Replace("\n", ","); - foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + _urls = _urls.Replace("\n", ","); + foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { Alias alias = new Alias(); alias.Name = name; - alias.TenantId = int.Parse(tenantid); + alias.TenantId = int.Parse(_tenantid); alias.SiteId = -1; alias = await AliasService.AddAliasAsync(alias); aliases.Add(alias); } Site site = new Site(); - site.TenantId = int.Parse(tenantid); - site.Name = name; + site.TenantId = int.Parse(_tenantid); + site.Name = _name; site.LogoFileId = null; - site.DefaultThemeType = themetype; - site.DefaultLayoutType = (layouttype == null ? "" : layouttype); - site.DefaultContainerType = containertype; + site.DefaultThemeType = _themetype; + site.DefaultLayoutType = (_layouttype == null ? "" : _layouttype); + site.DefaultContainerType = _containertype; site = await SiteService.AddSiteAsync(site, aliases[0]); foreach (Alias alias in aliases) @@ -241,19 +241,19 @@ else await AliasService.UpdateAliasAsync(alias); } - if (!isinitialized) + if (!_isinitialized) { User user = new User(); user.SiteId = site.SiteId; - user.Username = username; - user.Password = password; + user.Username = _username; + user.Password = _password; user.Email = PageState.User.Email; user.DisplayName = PageState.User.DisplayName; user = await UserService.AddUserAsync(user, aliases[0]); if (user != null) { - Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault(); + Tenant tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid)); tenant.IsInitialized = true; await TenantService.UpdateTenantAsync(tenant); } @@ -265,7 +265,7 @@ else } else { - await logger.LogError("Invalid Password Entered For Host {Username}", username); + await logger.LogError("Invalid Password Entered For Host {Username}", _username); AddModuleMessage("Invalid Host Password", MessageType.Error); } } diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index c9b63239..e8e0c675 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -11,6 +11,7 @@ @inject IModuleService ModuleService @inject IModuleDefinitionService ModuleDefinitionService @inject ILogService LogService +@using System.Diagnostics.CodeAnalysis @implements IHandleAfterRender @DynamicComponent @@ -65,6 +66,7 @@ } } + [SuppressMessage("ReSharper", "StringIndexOfIsCultureSpecific.1")] private async Task Refresh() { Alias alias = null; diff --git a/Oqtane.Client/UI/ThemeBuilder.razor b/Oqtane.Client/UI/ThemeBuilder.razor index dd12b058..2be44081 100644 --- a/Oqtane.Client/UI/ThemeBuilder.razor +++ b/Oqtane.Client/UI/ThemeBuilder.razor @@ -1,5 +1,5 @@ @namespace Oqtane.UI -@inject IJSRuntime jsRuntime +@inject IJSRuntime JsRuntime @DynamicComponent diff --git a/Oqtane.Server/Controllers/AliasController.cs b/Oqtane.Server/Controllers/AliasController.cs index 20eeba79..dc4bf37b 100644 --- a/Oqtane.Server/Controllers/AliasController.cs +++ b/Oqtane.Server/Controllers/AliasController.cs @@ -49,11 +49,11 @@ namespace Oqtane.Controllers name = WebUtility.UrlDecode(name); List aliases = _aliases.GetAliases().ToList(); Alias alias = null; - alias = aliases.Where(item => item.Name == name).FirstOrDefault(); - if (alias == null && name.Contains("/")) + alias = aliases.FirstOrDefault(item => item.Name == name); + if (name != null && (alias == null && name.Contains("/"))) { // lookup alias without folder name - alias = aliases.Find(item => item.Name == name.Substring(0, name.IndexOf("/"))); + alias = aliases.Find(item => item.Name == name.Substring(0, name.IndexOf("/", StringComparison.Ordinal))); } if (alias == null && aliases.Count > 0) { @@ -71,27 +71,27 @@ namespace Oqtane.Controllers // POST api/ [HttpPost] [Authorize(Roles = Constants.AdminRole)] - public Alias Post([FromBody] Alias Alias) + public Alias Post([FromBody] Alias alias) { if (ModelState.IsValid) { - Alias = _aliases.AddAlias(Alias); - _logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", Alias); + alias = _aliases.AddAlias(alias); + _logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", alias); } - return Alias; + return alias; } // PUT api//5 [HttpPut("{id}")] [Authorize(Roles = Constants.AdminRole)] - public Alias Put(int id, [FromBody] Alias Alias) + public Alias Put(int id, [FromBody] Alias alias) { if (ModelState.IsValid) { - Alias = _aliases.UpdateAlias(Alias); - _logger.Log(LogLevel.Information, this, LogFunction.Update, "Alias Updated {Alias}", Alias); + alias = _aliases.UpdateAlias(alias); + _logger.Log(LogLevel.Information, this, LogFunction.Update, "Alias Updated {Alias}", alias); } - return Alias; + return alias; } // DELETE api//5 diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index ea02c5ba..4cc7ac9a 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -61,14 +61,15 @@ namespace Oqtane.Controllers { foreach (string file in Directory.GetFiles(folder)) { - files.Add(new Models.File { Name = Path.GetFileName(file), Extension = Path.GetExtension(file).Replace(".","") }); + files.Add(new Models.File {Name = Path.GetFileName(file), Extension = Path.GetExtension(file)?.Replace(".", "")}); } } } } + return files; } - + // GET: api//siteId/folderPath [HttpGet("{siteId}/{path}")] public IEnumerable Get(int siteId, string path) @@ -95,6 +96,7 @@ namespace Oqtane.Controllers HttpContext.Response.StatusCode = 401; return null; } + return files; } @@ -103,7 +105,7 @@ namespace Oqtane.Controllers public Models.File Get(int id) { Models.File file = _files.GetFile(id); - if (_userPermissions.IsAuthorized(User,PermissionNames.View, file.Folder.Permissions)) + if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions)) { return file; } @@ -118,20 +120,21 @@ namespace Oqtane.Controllers // PUT api//5 [HttpPut("{id}")] [Authorize(Roles = Constants.RegisteredRole)] - public Models.File Put(int id, [FromBody] Models.File File) + public Models.File Put(int id, [FromBody] Models.File file) { - if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, File.Folder.FolderId, PermissionNames.Edit)) + if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, file.Folder.FolderId, PermissionNames.Edit)) { - File = _files.UpdateFile(File); - _logger.Log(LogLevel.Information, this, LogFunction.Update, "File Updated {File}", File); + file = _files.UpdateFile(file); + _logger.Log(LogLevel.Information, this, LogFunction.Update, "File Updated {File}", file); } else { - _logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update File {File}", File); + _logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update File {File}", file); HttpContext.Response.StatusCode = 401; - File = null; + file = null; } - return File; + + return file; } // DELETE api//5 @@ -149,6 +152,7 @@ namespace Oqtane.Controllers { System.IO.File.Delete(filepath); } + _logger.Log(LogLevel.Information, this, LogFunction.Delete, "File Deleted {File}", file); } else @@ -164,11 +168,11 @@ namespace Oqtane.Controllers { Models.File file = null; Folder folder = _folders.GetFolder(int.Parse(folderid)); - if (folder != null && _userPermissions.IsAuthorized(User,PermissionNames.Edit, folder.Permissions)) + if (folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, folder.Permissions)) { string folderpath = GetFolderPath(folder); CreateDirectory(folderpath); - string filename = url.Substring(url.LastIndexOf("/") + 1); + string filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1); // check for allowable file extensions if (Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", ""))) { @@ -180,6 +184,7 @@ namespace Oqtane.Controllers { System.IO.File.Delete(folderpath + filename); } + client.DownloadFile(url, folderpath + filename); _files.AddFile(CreateFile(filename, folder.FolderId, folderpath + filename)); } @@ -199,9 +204,10 @@ namespace Oqtane.Controllers HttpContext.Response.StatusCode = 401; file = null; } + return file; } - + // POST api//upload [HttpPost("upload")] public async Task UploadFile(string folder, IFormFile file) @@ -213,9 +219,9 @@ namespace Oqtane.Controllers if (int.TryParse(folder, out folderid)) { Folder Folder = _folders.GetFolder(folderid); - if (Folder != null && _userPermissions.IsAuthorized(User,PermissionNames.Edit, Folder.Permissions)) + if (Folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, Folder.Permissions)) { - folderpath = GetFolderPath(Folder); + folderpath = GetFolderPath(Folder); } } else @@ -225,6 +231,7 @@ namespace Oqtane.Controllers folderpath = GetFolderPath(folder); } } + if (folderpath != "") { CreateDirectory(folderpath); @@ -232,6 +239,7 @@ namespace Oqtane.Controllers { await file.CopyToAsync(stream); } + string upload = await MergeFile(folderpath, file.FileName); if (upload != "" && folderid != -1) { @@ -252,19 +260,19 @@ namespace Oqtane.Controllers // parse the filename which is in the format of filename.ext.part_x_y string token = ".part_"; - string parts = Path.GetExtension(filename).Replace(token, ""); // returns "x_y" - int totalparts = int.Parse(parts.Substring(parts.IndexOf("_") + 1)); - filename = filename.Substring(0, filename.IndexOf(token)); // base filename - string[] fileparts = Directory.GetFiles(folder, filename + token + "*"); // list of all file parts + string parts = Path.GetExtension(filename)?.Replace(token, ""); // returns "x_y" + int totalparts = int.Parse(parts?.Substring(parts.IndexOf("_") + 1)); + filename = filename?.Substring(0, filename.IndexOf(token)); // base filename + string[] fileParts = Directory.GetFiles(folder, filename + token + "*"); // list of all file parts // if all of the file parts exist ( note that file parts can arrive out of order ) - if (fileparts.Length == totalparts && CanAccessFiles(fileparts)) + if (fileParts.Length == totalparts && CanAccessFiles(fileParts)) { // merge file parts bool success = true; using (var stream = new FileStream(Path.Combine(folder, filename + ".tmp"), FileMode.Create)) { - foreach (string filepart in fileparts) + foreach (string filepart in fileParts) { try { @@ -283,13 +291,13 @@ namespace Oqtane.Controllers // delete file parts and rename file if (success) { - foreach (string filepart in fileparts) + foreach (string filepart in fileParts) { System.IO.File.Delete(filepart); } // check for allowable file extensions - if (!Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", ""))) + if (!Constants.UploadableFiles.Contains(Path.GetExtension(filename)?.Replace(".", ""))) { System.IO.File.Delete(Path.Combine(folder, filename + ".tmp")); } @@ -300,17 +308,19 @@ namespace Oqtane.Controllers { System.IO.File.Delete(Path.Combine(folder, filename)); } + // rename file now that the entire process is completed System.IO.File.Move(Path.Combine(folder, filename + ".tmp"), Path.Combine(folder, filename)); _logger.Log(LogLevel.Information, this, LogFunction.Create, "File Uploaded {File}", Path.Combine(folder, filename)); } + merged = filename; } } // clean up file parts which are more than 2 hours old ( which can happen if a prior file upload failed ) - fileparts = Directory.GetFiles(folder, "*" + token + "*"); - foreach (string filepart in fileparts) + fileParts = Directory.GetFiles(folder, "*" + token + "*"); + foreach (string filepart in fileParts) { DateTime createddate = System.IO.File.GetCreationTime(filepart).ToUniversalTime(); if (createddate < DateTime.UtcNow.AddHours(-2)) @@ -339,7 +349,7 @@ namespace Oqtane.Controllers locked = false; } catch // file is locked by another process - { + { Thread.Sleep(1000); // wait 1 second } finally @@ -349,13 +359,16 @@ namespace Oqtane.Controllers stream.Close(); } } + attempts += 1; } + if (locked && canaccess) { canaccess = false; } } + return canaccess; } @@ -364,7 +377,7 @@ namespace Oqtane.Controllers public IActionResult Download(int id) { Models.File file = _files.GetFile(id); - if (file != null && _userPermissions.IsAuthorized(User,PermissionNames.View, file.Folder.Permissions)) + if (file != null && _userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions)) { string filepath = GetFolderPath(file.Folder) + file.Name; if (System.IO.File.Exists(filepath)) @@ -402,7 +415,7 @@ namespace Oqtane.Controllers if (!Directory.Exists(folderpath)) { string path = ""; - string[] folders = folderpath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); + string[] folders = folderpath.Split(new char[] {'\\'}, StringSplitOptions.RemoveEmptyEntries); foreach (string folder in folders) { path += folder + "\\"; @@ -422,7 +435,7 @@ namespace Oqtane.Controllers FileInfo fileinfo = new FileInfo(filepath); file.Extension = fileinfo.Extension.ToLower().Replace(".", ""); - file.Size = (int)fileinfo.Length; + file.Size = (int) fileinfo.Length; file.ImageHeight = 0; file.ImageWidth = 0; @@ -434,6 +447,7 @@ namespace Oqtane.Controllers file.ImageHeight = image.Height; file.ImageWidth = image.Width; } + stream.Close(); }