public async Task ExecuteAsync(AddPageDirectoryCommand command, IExecutionContext executionContext) { Normalize(command); var parentDirectory = await GetParentDirectoryAsync(command); await ValidateIsUniqueAsync(command, executionContext); var pageDirectory = new PageDirectory(); pageDirectory.Name = command.Name; pageDirectory.UrlPath = command.UrlPath; pageDirectory.ParentPageDirectory = parentDirectory; _entityAuditHelper.SetCreated(pageDirectory, executionContext); _dbContext.PageDirectories.Add(pageDirectory); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); await _pageDirectoryStoredProcedures.UpdatePageDirectoryClosureAsync(); scope.QueueCompletionTask(() => OnTransactionComplete(pageDirectory.PageDirectoryId)); await scope.CompleteAsync(); } command.OutputPageDirectoryId = pageDirectory.PageDirectoryId; }
private static void ValidateNotRootDirectory(PageDirectory pageDirectory) { if (!pageDirectory.ParentPageDirectoryId.HasValue) { throw ValidationErrorException.CreateWithProperties("Cannot delete the root page directory.", nameof(pageDirectory.PageDirectoryId)); } }
private async Task MapInheritedRules(PageDirectory dbPageDirectory, PageDirectoryAccessRuleSetDetails result, IExecutionContext executionContext) { var dbInheritedRules = await _dbContext .PageDirectoryClosures .AsNoTracking() .Include(d => d.AncestorPageDirectory) .ThenInclude(d => d.AccessRules) .Include(d => d.AncestorPageDirectory) .ThenInclude(d => d.PageDirectoryPath) .FilterByDescendantId(dbPageDirectory.PageDirectoryId) .FilterNotSelfReferencing() .Where(d => d.DescendantPageDirectoryId == dbPageDirectory.PageDirectoryId && d.AncestorPageDirectory.AccessRules.Any()) .OrderByDescending(d => d.Distance) .ToListAsync(); result.InheritedAccessRules = new List <InheritedPageDirectoryAccessDetails>(); foreach (var dbInheritedRule in dbInheritedRules) { var inheritedDirectory = new InheritedPageDirectoryAccessDetails(); inheritedDirectory.PageDirectory = _pageDirectoryMicroSummaryMapper.Map(dbInheritedRule.AncestorPageDirectory); await _entityAccessDetailsMapper.MapAsync(dbInheritedRule.AncestorPageDirectory, inheritedDirectory, executionContext, (dbRule, rule) => { rule.PageDirectoryId = dbRule.PageDirectoryId; rule.PageDirectoryAccessRuleId = dbRule.PageDirectoryAccessRuleId; }); result.InheritedAccessRules.Add(inheritedDirectory); } }
private PageDirectoryRoute MapRoute(PageDirectory dbDirectory) { MissingIncludeException.ThrowIfNull(dbDirectory, d => d.PageDirectoryLocales); MissingIncludeException.ThrowIfNull(dbDirectory, d => d.AccessRules); var route = new PageDirectoryRoute(); route.Name = dbDirectory.Name; route.PageDirectoryId = dbDirectory.PageDirectoryId; route.ParentPageDirectoryId = dbDirectory.ParentPageDirectoryId; route.UrlPath = dbDirectory.UrlPath; route.LocaleVariations = dbDirectory .PageDirectoryLocales .Select(d => new PageDirectoryRouteLocale() { LocaleId = d.LocaleId, UrlPath = d.UrlPath }) .ToList(); route.AccessRuleSets = new List <EntityAccessRuleSet>(); var accessRuleSet = _entityAccessRuleSetMapper.Map(dbDirectory); if (accessRuleSet != null) { route.AccessRuleSets.Add(accessRuleSet); } // FullUrlPaths set elsewhere return(route); }
public WebCommand(IPageNavigator navigator, List <IActionCommand> actionCommands, Route route, PageDirectory page) { _navigator = navigator; _actionCommands = actionCommands; _route = route; _page = page; }
public void NaviagteTo(PageDirectory page) { switch (page) { case PageDirectory.Basket: HttpContext.Current.Response.Redirect("/Views/Basket/Basket.aspx"); break; default: throw new ApplicationException("Cannot navigate to " + page); } }
public void NavigateTo(PageDirectory page) { switch (page) { case PageDirectory.Basket: HttpContCurrent.Response.Redirect("/Views/BasketProducx"); break; default: throw new ApplicationException("Cannot navigate to" + page.ToString()); } }
public void NaviagteTo(PageDirectory page) { switch (page) { case PageDirectory.Basket: HttpContext.Current.Response.Redirect("/Views/Basket/Basket.aspx"); break; default: throw new ApplicationException("Cannot navigate to " + page.ToString()); } }
/// <summary> /// 修改操作 /// </summary> /// <param name="name"></param> void ModifyOperator(string name) { TreeViewItem item = this.tvPageManager.SelectedItem as TreeViewItem; var cmd = new CtrlPlatformCommandInfo(); cmd.CommandName = ConstantCollection.CommandName_MixedCommand; cmd.ExecSql = new List <CtrlExecSQLCmd>(); Dictionary <String, Object> dict = new Dictionary <string, Object>(); if (item.Tag is PageDirectory) { PageDirectory pd = item.Tag as PageDirectory; pd.NodeName = name; //-->修改当前选中目录 string sql = string.Format("update PageDirectory set NodeName = '{0}' where ID = {1}", pd.NodeName, pd.ID); var exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.ExecuteNonQuery, sql, "PageDirectory", this.Name, "ModifyOperator"); cmd.ExecSql.Add(exec); cmd.TempValue = Wrapper.SetXmlValue("PageDirectory", "ModifyOperator", new KeyValuePair <String, Object>[] { new KeyValuePair <String, Object>("IsDirectory", true), new KeyValuePair <String, Object>("ControlName", item.Name), new KeyValuePair <String, Object>("ID", pd.ID), new KeyValuePair <String, Object>("NewValue", name) }); } else if (item.Tag is PageDirectorySub) { //-->修改当前选中的页面 PageDirectorySub pds = item.Tag as PageDirectorySub; pds.PageName = name; string sql = string.Format("update PageDirectorySub set PageName = '{0}' where id = {1}", pds.PageName, pds.ID); var exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.ExecuteNonQuery, sql, "PageDirectorySub", this.Name, "ModifyOperator"); cmd.ExecSql.Add(exec); dict.Add("IsDirectory", false); dict.Add("ID", pds.ID); cmd.TempValue = Wrapper.SetXmlValue("PageDirectorySub", "ModifyOperator", new KeyValuePair <String, Object>[] { new KeyValuePair <String, Object>("IsDirectory", false), new KeyValuePair <String, Object>("ControlName", item.Name), new KeyValuePair <String, Object>("ID", pds.ID), new KeyValuePair <String, Object>("NewValue", name) }); } this.SendToService(cmd, this); }
private void CheckPageDirectoryIsActive(PageDirectory pageDirectory, Dictionary <int, PageDirectory> allPageDirectories) { if (!pageDirectory.IsActive) { throw new PropertyValidationException("The selected page directory is not active and cannot be used.", nameof(pageDirectory.PageDirectoryId)); } if (pageDirectory.ParentPageDirectoryId.HasValue) { var parentDirectory = allPageDirectories.GetOrDefault(pageDirectory.ParentPageDirectoryId.Value); EntityNotFoundException.ThrowIfNull(parentDirectory, pageDirectory.ParentPageDirectoryId); CheckPageDirectoryIsActive(pageDirectory.ParentPageDirectory, allPageDirectories); } }
/// <summary> /// Determines if the page is within the specified directory path. Does /// not return true if it is in a subdirectory of the specified directory path. /// </summary> public bool IsInDirectory(string directoryPath) { if (PageDirectory == null) { return(false); } if (Locale == null) { return(PageDirectory.MatchesPath(directoryPath)); } return(PageDirectory.MatchesPath(directoryPath, Locale.LocaleId)); }
/// <summary> /// 删除操作 /// </summary> /// <param name="name"></param> void DeleteOperator(string name) { TreeViewItem item = this.tvPageManager.SelectedItem as TreeViewItem; var cmd = new CtrlPlatformCommandInfo(); cmd.CommandName = ConstantCollection.CommandName_MixedCommand; cmd.ExecSql = new List <CtrlExecSQLCmd>(); if (item.Tag is PageDirectory) { //-->判断是否还有子项 //-->有子项不让其删除 if (0 < item.Items.Count) { Wrapper.ShowDialog("此目录下还有子项,请先删除子项"); return; } PageDirectory pd = item.Tag as PageDirectory; //-->删除当前选中目录 string sql = string.Format("delete from PageDirectory where ID = {0}", pd.ID); //cmd.SqlSentence.Add(sql); var exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.ExecuteNonQuery, sql, "PageDirectory", this.Name, "DeleteOperator"); cmd.ExecSql.Add(exec); cmd.TempValue = Wrapper.SetXmlValue("PageDirectory", "DeleteOperator", new KeyValuePair <String, Object>[] { new KeyValuePair <String, Object>("ControlName", item.Name) }); } else if (item.Tag is PageDirectorySub) { //-->删除当前选中的页面 PageDirectorySub pds = item.Tag as PageDirectorySub; string sql = string.Format("delete from PageDirectorySub where ID= '{0}'", pds.ID); var exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.ExecuteNonQuery, sql, "PageDirectorySub", this.Name, "DeleteOperator"); cmd.ExecSql.Add(exec); cmd.TempValue = Wrapper.SetXmlValue("PageDirectorySub", "DeleteOperator", new KeyValuePair <String, Object>[] { new KeyValuePair <String, Object>("ControlName", item.Name) }); } this.SendToService(cmd, this); }
/// <summary> /// /// </summary> /// <param name="cmd"></param> public void ProcessInitCurrentNodeDirectory(CtrlPlatformCommandInfo cmd) { //-->找着父节点的控件 string controlName = cmd.TempValue.GetAttributeValue("ParentControlID"); TreeViewItem item = tvPageManager.FindName(controlName) as TreeViewItem; if (null == item) { return; } item.Items.Clear(); PageDirectory pd = item.Tag as PageDirectory; pd.IsSendCommand = true; _InitDirectory(cmd, item); }
/// <summary> /// 增加页面 /// </summary> /// <param name="name"></param> void AddPage(string name) { TreeViewItem item = this.tvPageManager.SelectedItem as TreeViewItem; if (null == item) { Wrapper.ShowDialog("请选择目录"); return; } PageDirectory pd = item.Tag as PageDirectory; if (null == pd) { Wrapper.ShowDialog("请选择目录"); return; } var cmd = new CtrlPlatformCommandInfo(); cmd.CommandName = ConstantCollection.CommandName_MixedCommand; cmd.ExecSql = new List <CtrlExecSQLCmd>(); PageDirectorySub sds = new PageDirectorySub(); sds.PageDirectoryId = pd.ID; sds.PageName = name; sds.PageGuid = Wrapper.GuidValue; string sql = string.Format("insert into PageDirectorySub(PageDirectoryId,PageGuid,PageName,CreateDate)values("); sql += string.Format("{0},", sds.PageDirectoryId); sql += string.Format("'{0}',", sds.PageGuid); sql += string.Format("'{0}',", sds.PageName); sql += string.Format("NOW())"); var exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.ExecuteNonQuery, sql, "PageDirectorySub", this.Name, "AddPage"); cmd.ExecSql.Add(exec); sql = string.Format("select * from PageDirectorySub t where t.PageGuid = '{0}'", sds.PageGuid); exec = new CtrlExecSQLCmd(CtrlExecSqlCmdType.Query, sql, "PageDirectorySub", this.Name, "AddPage"); cmd.ExecSql.Add(exec); cmd.ParamCollection = sds.ToXElement(); cmd.TempValue = Wrapper.SetXmlValue("AddPage", "AddPage", new KeyValuePair <String, Object>[] { new KeyValuePair <String, Object>("ParentID", pd.ID), new KeyValuePair <String, Object>("ControlName", item.Name) }); this.SendToService(cmd, this); }
private async Task <bool> HasDependencies(PageDirectory pageDirectory) { if (await _dbContext .PageDirectories .AsNoTracking() .Where(w => w.ParentPageDirectoryId == pageDirectory.PageDirectoryId) .AnyAsync()) { return(true); } return(await _dbContext .Pages .AsNoTracking() .Where(p => p.PageDirectoryId == pageDirectory.PageDirectoryId) .AnyAsync()); }
public void NavigateTo(PageDirectory page) { switch (page) { case PageDirectory.Home: HttpContext.Current.Server.Transfer("~/Views/Home/Home.aspx"); break; case PageDirectory.Users: HttpContext.Current.Server.Transfer("~/Views/Users/UserList.aspx"); break; case PageDirectory.Package: HttpContext.Current.Server.Transfer("~/Views/Packages/PackageDetails.aspx"); break; } }
void btnRefresh_Click(object sender, RoutedEventArgs e) { TreeViewItem item = this.SelectedItem as TreeViewItem; if (null != item && item.Tag is PageDirectory) { PageDirectory pd = item.Tag as PageDirectory; pd.IsSendCommand = false; //-->发送命令获取下面所有目录及文件 //-->获取目录的查询语句; //-->获取文件的查询语句 InitCurrentNodeDirectory(pd.ID, item.Name); } else { InitDirectory(0); } }
public void NavigateTo(PageDirectory page) { switch (page) { case PageDirectory.Home: HttpContext.Current.Server.Transfer("~/Views/Home/Home.aspx"); break; case PageDirectory.Users: HttpContext.Current.Server.Transfer("~/Views/Users/UserList.aspx"); break; case PageDirectory.Package: HttpContext.Current.Server.Transfer("~/Views/Packages/PackageDetail.aspx"); break; case PageDirectory.MissingPage: HttpContext.Current.Server.Transfer("~/Views/Shared/404.aspx"); break; } }
public PageDirectoryMicroSummary Map(PageDirectory pageDirectory) { if (pageDirectory == null) { return(null); } MissingIncludeException.ThrowIfNull(pageDirectory, c => c.PageDirectoryPath); var result = new PageDirectoryMicroSummary() { Depth = pageDirectory.PageDirectoryPath.Depth, FullUrlPath = "/" + pageDirectory.PageDirectoryPath.FullUrlPath, Name = pageDirectory.Name, PageDirectoryId = pageDirectory.PageDirectoryId, ParentPageDirectoryId = pageDirectory.ParentPageDirectoryId }; return(result); }
public async Task ExecuteAsync(AddPageDirectoryCommand command, IExecutionContext executionContext) { // Custom Validation await ValidateIsUniqueAsync(command, executionContext); var pageDirectory = new PageDirectory(); pageDirectory.Name = command.Name; pageDirectory.UrlPath = command.UrlPath; pageDirectory.ParentPageDirectoryId = command.ParentPageDirectoryId; _entityAuditHelper.SetCreated(pageDirectory, executionContext); _dbContext.PageDirectories.Add(pageDirectory); await _dbContext.SaveChangesAsync(); _transactionScopeFactory.QueueCompletionTask(_dbContext, _cache.Clear); command.OutputPageDirectoryId = pageDirectory.PageDirectoryId; }
/// <summary> /// /// </summary> /// <param name="cmd"></param> public void ProcessInitDirectory(CtrlPlatformCommandInfo cmd) { InitDirectoryParam = cmd; this.tvPageManager.Items.Clear(); this.tviRoot.Items.Clear(); TreeViewItem root = new TreeViewItem(); root.Expanded += root_Expanded; root.Collapsed += root_Expanded; PageDirectory _pd = new PageDirectory(); _pd.ID = 0; _pd.NodeName = "页面管理器"; root.Tag = _pd; root.IsExpanded = true; root.Header = _pd.NodeName; root.Name = string.Format("tvi_{0}", _pd.ID); this.tvPageManager.Items.Add(root); _InitDirectory(cmd, root); }
public void NavigateTo(PageDirectory page) { switch (page) { case PageDirectory.Home: HttpContext.Current.Server.Transfer("~/views/Home/Index.aspx"); break; case PageDirectory.ProductDetail: HttpContext.Current.Server.Transfer("~/views/Product/ProductDetail.aspx"); break; case PageDirectory.CategoryProducts: HttpContext.Current.Server.Transfer("~/views/Product/CategoryProducts.aspx"); break; case PageDirectory.MissingPage: HttpContext.Current.Server.Transfer("~/views/Shared/404.aspx"); break; } }
private PageDirectoryRoute MapRoute(PageDirectory dbDirectory) { var route = new PageDirectoryRoute(); route.Name = dbDirectory.Name; route.PageDirectoryId = dbDirectory.PageDirectoryId; route.ParentPageDirectoryId = dbDirectory.ParentPageDirectoryId; route.UrlPath = dbDirectory.UrlPath; route.LocaleVariations = dbDirectory .PageDirectoryLocales .Select(d => new PageDirectoryRouteLocale() { LocaleId = d.LocaleId, UrlPath = d.UrlPath }) .ToList(); // FullUrlPaths set elsewhere return(route); }
void tvi_Expanded(object sender, RoutedEventArgs e) { TreeViewItem item = sender as TreeViewItem; if (item.Tag is PageDirectory) { PageDirectory pd = item.Tag as PageDirectory; if (!pd.IsSendCommand) { //-->发送命令获取下面所有目录及文件 //-->获取目录的查询语句; //-->获取文件的查询语句 InitCurrentNodeDirectory(pd.ID, item.Name); } } else if (item.Tag is PageDirectorySub) { //-->打开文件 OpenPageInfoEventArgs oe = new OpenPageInfoEventArgs(); oe.PageDirectorySub = item.Tag as PageDirectorySub; _OpenPageInfoMethod(this, oe); } }
private IEnumerable <string> GetChangedPathProperties(UpdatePageDirectoryCommand command, PageDirectory pageDirectory) { if (command.UrlPath != pageDirectory.UrlPath) { yield return(nameof(pageDirectory.UrlPath)); } if (command.ParentPageDirectoryId != pageDirectory.ParentPageDirectoryId) { yield return(nameof(pageDirectory.ParentPageDirectoryId)); } }
private async Task ValidateUrlPropertiesAllowedToChange(UpdatePageDirectoryCommand command, PageDirectory pageDirectory) { var props = GetChangedPathProperties(command, pageDirectory); if (props.Any() && await HasDependencies(pageDirectory)) { throw new PropertyValidationException("This directory is in use and the url cannot be changed", props.First()); } }