public async Task <List <ISiteFolder> > GetPageSiteFolders( int pageNumber, int pageSize, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); List <ISiteFolder> siteFolderList = new List <ISiteFolder>(); using (DbDataReader reader = await dbSiteFolder.GetPage( pageNumber, pageSize, cancellationToken)) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public async Task <bool> Save(ISiteFolder siteFolder, CancellationToken cancellationToken = default(CancellationToken)) { if (siteFolder == null) { return(false); } SiteFolder folder = SiteFolder.FromISiteFolder(siteFolder); if (folder.Guid == Guid.Empty) { folder.Guid = Guid.NewGuid(); dbContext.SiteFolders.Add(folder); } else { bool tracking = dbContext.ChangeTracker.Entries <SiteFolder>().Any(x => x.Entity.Guid == folder.Guid); if (!tracking) { dbContext.SiteFolders.Update(folder); } } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken); return(rowsAffected > 0); }
private static string GetVirtualFolderName() { if (HttpContext.Current == null) { return(String.Empty); } // find first level folder name // after site root string folderName = string.Empty; string requestPath = HttpContext.Current.Request.RawUrl.Replace("https://", string.Empty).Replace("http://", string.Empty); if (requestPath == "/") { return(folderName); } // if ( // (requestPath.IndexOf("/") > -1 && requestPath.LastIndexOf("/") > requestPath.IndexOf("/")) //|| SiteFolder.Exists(requestPath.TrimStart('/')) //) // { //requestPath = requestPath.Substring(requestPath.IndexOf("/") + 1, requestPath.Length - 1); requestPath = requestPath.TrimStart('/'); if (requestPath.IndexOf("/") > -1) { requestPath = requestPath.Substring(0, requestPath.IndexOf("/")); } //folderName = try { if (SiteFolder.Exists(requestPath)) { folderName = requestPath; } } catch (DbException) { // folderName = string.Empty; } catch (InvalidOperationException) { // occurs when db tables and procs haven't been created yet // in MS SQL // folderName = string.Empty; } //} return(folderName); }
public static SiteFolder Update(SiteFolder siteFolder) { if (!siteFolder.ParentId.HasValue) { throw new ApplicationException(FolderStrings.CanUpdateRootFolder); } return((SiteFolder)FolderFactory.Create(EntityTypeCode.SiteFolder) .CreateRepository() .Update(siteFolder)); }
public static SiteFolder Save(SiteFolder folder) { if (folder == null) { throw new ArgumentNullException(nameof(folder)); } return((SiteFolder)FolderFactory.Create(EntityTypeCode.SiteFolder) .CreateRepository() .Create(folder.ParentEntityId, folder.ParentId, folder.Name)); }
public async Task <SiteFolder> GetSiteFolder(string folderName) { using (DbDataReader reader = await dbSiteFolder.GetOne(folderName)) { if (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); return(siteFolder); } } return(null); }
public async Task <ISiteFolder> GetSiteFolder(string folderName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); using (DbDataReader reader = dbSiteFolder.GetOne(folderName)) { if (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); return(siteFolder); } } return(null); }
public async Task <Guid> GetSiteGuidByFolder(string folderName, CancellationToken cancellationToken = default(CancellationToken)) { var query = from x in dbContext.SiteFolders where x.FolderName == folderName select x ; SiteFolder folder = await query.SingleOrDefaultAsync <SiteFolder>(cancellationToken); if (folder == null) { return(Guid.Empty); } return(folder.SiteGuid); }
public async Task <List <SiteFolder> > GetAllSiteFolders() { List <SiteFolder> siteFolderList = new List <SiteFolder>(); using (DbDataReader reader = await dbSiteFolder.GetAll()) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public List <SiteFolder> GetAllSiteFoldersNonAsync() { List <SiteFolder> siteFolderList = new List <SiteFolder>(); using (DbDataReader reader = dbSiteFolder.GetAllNonAsync()) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public async Task <List <SiteFolder> > GetSiteFoldersBySite(Guid siteGuid) { List <SiteFolder> siteFolderList = new List <SiteFolder>(); using (DbDataReader reader = dbSiteFolder.GetBySite(siteGuid)) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public async Task <List <ISiteFolder> > GetAllSiteFolders(CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); List <ISiteFolder> siteFolderList = new List <ISiteFolder>(); using (DbDataReader reader = dbSiteFolder.GetAll()) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public async Task<List<ISiteFolder>> GetSiteFoldersBySite(Guid siteGuid, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); List<ISiteFolder> siteFolderList = new List<ISiteFolder>(); using (DbDataReader reader = await dbSiteFolder.GetBySite(siteGuid)) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return siteFolderList; }
public async Task <List <SiteFolder> > GetPageSiteFolders( int pageNumber, int pageSize) { List <SiteFolder> siteFolderList = new List <SiteFolder>(); using (DbDataReader reader = await dbSiteFolder.GetPage(pageNumber, pageSize)) { while (reader.Read()) { SiteFolder siteFolder = new SiteFolder(); siteFolder.LoadFromReader(reader); siteFolderList.Add(siteFolder); } } return(siteFolderList); }
public async Task <bool> EnsureSiteFolder(ISiteSettings site) { bool folderExists = await siteRepo.FolderExists(site.SiteFolderName, CancellationToken); if (!folderExists) { List <ISiteFolder> siteFolders = await siteRepo.GetSiteFoldersBySite(site.SiteGuid, CancellationToken); //delete any existing folders before creating a new one foreach (ISiteFolder f in siteFolders) { bool deleted = await siteRepo.DeleteFolder(f.Guid, CancellationToken); } //ensure the current folder mapping SiteFolder folder = new SiteFolder(); folder.FolderName = site.SiteFolderName; folder.SiteGuid = site.SiteGuid; folderExists = await siteRepo.Save(folder, CancellationToken); } return(folderExists); }
public async Task <bool> Save(SiteFolder siteFolder) { if (siteFolder == null) { return(false); } if (siteFolder.Guid == Guid.Empty) { siteFolder.Guid = Guid.NewGuid(); return(await dbSiteFolder.Add( siteFolder.Guid, siteFolder.SiteGuid, siteFolder.FolderName)); } else { return(await dbSiteFolder.Update( siteFolder.Guid, siteFolder.SiteGuid, siteFolder.FolderName)); } }
public async Task <ActionResult> SiteInfo(SiteBasicSettingsViewModel model) { // can only delete from server admin site/cannot delete server admin site if (siteManager.CurrentSite.IsServerAdminSite) { if (model.SiteGuid != siteManager.CurrentSite.SiteGuid) { model.ShowDelete = uiOptions.AllowDeleteChildSites; } } if (!ModelState.IsValid) { return(View(model)); } if (model.SiteGuid == Guid.Empty) { this.AlertDanger("oops something went wrong, site was not found.", true); return(RedirectToAction("Index")); } //model.SiteId = Site.SiteSettings.SiteId; //model.SiteGuid = Site.SiteSettings.SiteGuid; ISiteSettings selectedSite = null; if (model.SiteGuid == siteManager.CurrentSite.SiteGuid) { selectedSite = siteManager.CurrentSite; ViewData["Title"] = "Site Settings"; } else if (siteManager.CurrentSite.IsServerAdminSite) { selectedSite = await siteManager.Fetch(model.SiteGuid); ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, "{0} - Settings", selectedSite.SiteName); } if (selectedSite == null) { this.AlertDanger("oops something went wrong.", true); return(RedirectToAction("Index")); } if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { if ( ((model.SiteFolderName == null) || (model.SiteFolderName.Length == 0)) && (!selectedSite.IsServerAdminSite) ) { // only the server admin site can be without a folder ModelState.AddModelError("foldererror", "Folder name is required."); return(View(model)); } SiteFolder folder = await siteManager.GetSiteFolder(model.SiteFolderName); if ((folder != null) && (folder.SiteGuid != selectedSite.SiteGuid)) { ModelState.AddModelError("foldererror", "The selected folder name is already in use on another site."); return(View(model)); } } else if (multiTenantOptions.Mode == MultiTenantMode.HostName) { ISiteHost host; if (!string.IsNullOrEmpty(model.HostName)) { model.HostName = model.HostName.Replace("https://", string.Empty).Replace("http://", string.Empty); host = await siteManager.GetSiteHost(model.HostName); if (host != null) { if (host.SiteGuid != selectedSite.SiteGuid) { ModelState.AddModelError("hosterror", "The selected host/domain name is already in use on another site."); return(View(model)); } } else { bool hostResult = await siteManager.AddHost( selectedSite.SiteGuid, selectedSite.SiteId, model.HostName); } } selectedSite.PreferredHostName = model.HostName; } selectedSite.SiteName = model.SiteName; selectedSite.TimeZoneId = model.TimeZoneId; selectedSite.SiteFolderName = model.SiteFolderName; selectedSite.SiteIsClosed = model.IsClosed; selectedSite.SiteIsClosedMessage = model.ClosedMessage; if (layoutOptions.SelectionMode == LayoutSelectionMode.Browsing) { selectedSite.Layout = model.Layout; } bool result = await siteManager.Save(selectedSite); if ((result) && (multiTenantOptions.Mode == MultiTenantMode.FolderName)) { if (!string.IsNullOrEmpty(selectedSite.SiteFolderName)) { bool folderEnsured = await siteManager.EnsureSiteFolder(selectedSite); } } if (result) { this.AlertSuccess(string.Format("Basic site settings for <b>{0}</b> were successfully updated.", selectedSite.SiteName), true); } if ((siteManager.CurrentSite.IsServerAdminSite) //&&(Site.SiteSettings.SiteGuid != selectedSite.SiteGuid) ) { // just edited from site list so redirect there return(RedirectToAction("SiteList", new { pageNumber = model.ReturnPageNumber })); } return(RedirectToAction("Index")); }
private static SiteSettings LoadSiteSettings() { if (log.IsDebugEnabled) { log.Debug("CacheHelper.cs LoadSiteSettings"); } SiteSettings siteSettings = null; try { bool useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false); string siteFolderName; if (useFolderForSiteDetection) { siteFolderName = VirtualFolderEvaluator.VirtualFolderName(); } else { siteFolderName = string.Empty; } if (useFolderForSiteDetection) { Guid siteGuid = SiteFolder.GetSiteGuid(siteFolderName); siteSettings = new SiteSettings(siteGuid); } else { siteSettings = new SiteSettings(WebUtils.GetHostName()); } if (siteSettings.SiteId > -1) { siteSettings.SiteRoot = WebUtils.GetSiteRoot(); if (useFolderForSiteDetection) { siteSettings.SiteFolderName = siteFolderName; } SetCurrentSkinBaseUrl(siteSettings); } else { siteSettings = null; log.Error("CacheHelper failed to load siteSettings"); } } catch (System.Data.Common.DbException ex) { log.Error("Error trying to obtain siteSettings", ex); } catch (InvalidOperationException ex) { log.Error("Error trying to obtain siteSettings", ex); } catch (IndexOutOfRangeException ex) { log.Error("Error trying to obtain siteSettings", ex); } return(siteSettings); }
public async Task <ActionResult> NewSite(SiteBasicSettingsViewModel model) { ViewData["Title"] = "Create New Site"; if (!ModelState.IsValid) { return(View(model)); } bool addHostName = false; if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { if (string.IsNullOrEmpty(model.SiteFolderName)) { ModelState.AddModelError("foldererror", "Folder name is required."); return(View(model)); } SiteFolder folder = await siteManager.GetSiteFolder(model.SiteFolderName); if (folder != null) { ModelState.AddModelError("foldererror", "The selected folder name is already in use on another site."); return(View(model)); } } else { ISiteHost host; if (!string.IsNullOrEmpty(model.HostName)) { model.HostName = model.HostName.Replace("https://", string.Empty).Replace("http://", string.Empty); host = await siteManager.GetSiteHost(model.HostName); if (host != null) { ModelState.AddModelError("hosterror", "The selected host/domain name is already in use on another site."); return(View(model)); } addHostName = true; } } SiteSettings newSite = new SiteSettings(); // only the first site created by setup page should be a server admin site newSite.IsServerAdminSite = false; newSite.SiteName = model.SiteName; if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { newSite.SiteFolderName = model.SiteFolderName; } else if (addHostName) { newSite.PreferredHostName = model.HostName; } newSite.SiteIsClosed = model.IsClosed; newSite.SiteIsClosedMessage = model.ClosedMessage; //Site.SiteRepository.Save(newSite); bool result = await siteManager.CreateNewSite(newSite); result = await siteManager.CreateRequiredRolesAndAdminUser(newSite); if ((result) && (multiTenantOptions.Mode == MultiTenantMode.FolderName)) { bool folderResult = await siteManager.EnsureSiteFolder(newSite); // for folder sites we need routes that match the folder // which are normally created during app startup // can we add routes here? or do we need to force the app to recycle? // this seems to work, but we really do need to restart // so that the per folder authentication gets setup too //cloudscribe.Web.Routing.RouteRegistrar.AddDefaultRouteForNewSiteFolder(folder.FolderName); //startup.TriggerStartup(); //http://stackoverflow.com/questions/31339896/replacement-httpruntime-unloadappdomain-in-asp-net-5 } if (result && addHostName) { bool hostResult = await siteManager.AddHost( newSite.SiteGuid, newSite.SiteId, model.HostName); } if (result) { this.AlertSuccess(string.Format("Basic site settings for <b>{0}</b> were successfully created.", newSite.SiteName), true); } return(RedirectToAction("SiteList", new { pageNumber = model.ReturnPageNumber })); }
private static SiteSettings LoadSiteSettings() { if (debugLog) { log.Debug("CacheHelper.cs LoadSiteSettings"); } SiteSettings siteSettings = null; try { bool useFolderForSiteDetection = WebConfigSettings.UseFolderBasedMultiTenants; string siteFolderName; if (useFolderForSiteDetection) { siteFolderName = VirtualFolderEvaluator.VirtualFolderName(); } else { siteFolderName = string.Empty; } if (useFolderForSiteDetection) { Guid siteGuid = SiteFolder.GetSiteGuid(siteFolderName); siteSettings = new SiteSettings(siteGuid); } else { siteSettings = new SiteSettings(WebUtils.GetHostName()); } if (siteSettings.SiteId > -1) { siteSettings.ReloadExpandoProperties(); siteSettings.SiteRoot = WebUtils.GetSiteRoot(); if (useFolderForSiteDetection) { siteSettings.SiteFolderName = siteFolderName; } } else { siteSettings = null; log.Error("CacheHelper failed to load siteSettings"); } } catch (System.Data.Common.DbException ex) { log.Error("Error trying to obtain siteSettings", ex); } catch (InvalidOperationException ex) { log.Error("Error trying to obtain siteSettings", ex); } catch (IndexOutOfRangeException ex) { log.Error("Error trying to obtain siteSettings", ex); } return(siteSettings); }
internal static SiteFolderViewModel Create(SiteFolder folder, string tabId, int parentId) => Create <SiteFolderViewModel>(folder, tabId, parentId);
private static PathInfo _GetPathInfo(int id) => SiteFolder.GetPathInfo(id);
public static PathInfo GetPathInfo(int folderId) => SiteFolder.GetPathInfo(folderId);