private void handleInspectBlockSelection(BlockType blockType) { placementType = PlacementType.BlockPlacement; placementMode = PlacementMode.Manage; manageObjectList.Clear(); UIElement selectedItem = null; foreach (var item in BlockType.lookup) { var newItem = new BlockListItem(item.Value); if (item.Value == blockType) { selectedItem = newItem; } manageObjectList.AddElement(newItem); } if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftControl) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightControl)) { manageObjectList.SelectElement(selectedItem); placeView.OnClick(placeObjectAtPosition); } else { manageObjectList.ScrollToElement(selectedItem); } }
/// <inheritdoc /> public virtual string GetSearchableText(BlockListItem blockListItem, string culture = null, string segment = null) { StringBuilder sb = new StringBuilder(); using (TextWriter writer = new StringWriter(sb)) WriteBlockListItem(writer, blockListItem, culture, segment); return(sb.ToString()); }
/// <inheritdoc /> public virtual void WriteBlockListItem(TextWriter writer, BlockListItem blockListItem, string culture = null, string segment = null) { if (blockListItem == null) { return; } WriteElement(writer, blockListItem.Content, culture, segment); }
public object ResolveBlockList(BlockListItem blockListItem, Dictionary <string, object> options = null) { var converter = _blockConverters.FirstOrDefault( x => x.EditorAlias.Equals(blockListItem.Content.ContentType.Alias)); return(converter?.Convert(blockListItem.Content) ?? $"No converter implemented for: {blockListItem.Content.ContentType.Alias}"); }
/// <summary> /// Renders the specified item and adds the specified list to the ViewDataDictionary for context. /// </summary> /// <param name="htmlHelper"></param> /// <param name="item">Block list item to be rendered</param> /// <param name="list">The block list the item is a part of</param> /// <param name="viewPath">Path to where the block list items partial view is located</param> /// <returns></returns> public static void RenderBlockListItem(this HtmlHelper helper, BlockListItem item, BlockListModel list = null, string viewPath = "/Views/Partials/Blocks/", ViewDataDictionary viewData = null) { var rendering = GetBlockListItemData(item, list, viewPath, viewData); if (rendering != null) { helper.RenderAction(rendering.ActionName, rendering.ControllerName, rendering.RouteValues); } }
/// <summary> /// Renders the specified item and adds the specified list to the ViewDataDictionary for context. /// </summary> /// <param name="htmlHelper"></param> /// <param name="item">Block list item to be rendered</param> /// <param name="list">The block list the item is a part of</param> /// <param name="viewPath">Path to where the block list items partial view is located</param> /// <returns></returns> public static HtmlString BlockListItem(this HtmlHelper helper, BlockListItem item, BlockListModel list = null, string viewPath = "/Views/Partials/Blocks/", ViewDataDictionary viewData = null) { var rendering = GetBlockListItemData(item, list, viewPath, viewData); if (rendering == null) { return(new HtmlString(string.Empty)); } return(helper.Action(rendering.ActionName, rendering.ControllerName, rendering.RouteValues)); }
/// <summary> /// 新增黑名单 /// </summary> /// <param name="item"></param> /// <returns></returns> public async Task <bool> AddBlockListItem(BlockListItem item) { try { using (var configClient = new BlockListConfigClient()) { var configResult = await configClient.AddBlockListItemAsync(item); configResult.ThrowIfException(true); return(configResult.Result); } } catch (Exception ex) { _logger.Error($"新增黑名单失败 {item.BlockValue}", ex); return(false); } }
public JsonResult DeleteById(BlockListItem item) { using (var client = new BlockListConfigClient()) { var blackModel = new BlockListItem { PKID = item.PKID, UpdateBy = User.Identity.Name }; var result = client.DeleteBlockListItemByPkid(blackModel); if (result.Success) { if (result.Result) { ConfigLogManager.AddCommonConfigLogInfo(new CommonConfigLogModel { ObjectId = $"{item.BlockType}-{item.BlockValue}", BeforeValue = JsonConvert.SerializeObject(item), ObjectType = $"{item.BlockSystem}BlockListLog", Creator = User.Identity.Name, Remark = $"删除黑名单{(BlockListType)item.BlockType}-{item.BlockValue}" }); } return(Json(new { Status = 1, Success = result.Result }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Status = -1, ErrorMsg = result.ErrorMessage }, JsonRequestBehavior.AllowGet)); } } }
public JsonResult Add(BlockListItem item) { using (var client = new BlockListConfigClient()) { item.UpdateBy = User.Identity.Name; var result = client.AddBlockListItem(item); if (result.Success) { if (result.Result) { ConfigLogManager.AddCommonConfigLogInfo(new CommonConfigLogModel { ObjectId = $"{item.BlockType}-{item.BlockValue}", AfterValue = JsonConvert.SerializeObject(item), ObjectType = $"{item.BlockSystem}BlockListLog", Creator = User.Identity.Name, Remark = $"新增黑名单{(BlockListType)item.BlockType}-{item.BlockValue}" }); } return(Json(new { Status = 1, Success = result.Result }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Status = -1, ErrorMsg = result.ErrorMessage }, JsonRequestBehavior.AllowGet)); } } }
/// <inheritdoc /> public override object?ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object?inter, bool preview) { // NOTE: The intermediate object is just a JSON string, we don't actually convert from source -> intermediate since source is always just a JSON string using (_proflog.DebugDuration <BlockListPropertyValueConverter>( $"ConvertPropertyToBlockList ({propertyType.DataType.Id})")) { var value = (string?)inter; // Short-circuit on empty values if (string.IsNullOrWhiteSpace(value)) { return(BlockListModel.Empty); } BlockEditorData converted = _blockListEditorDataConverter.Deserialize(value); if (converted.BlockValue.ContentData.Count == 0) { return(BlockListModel.Empty); } IEnumerable <BlockListLayoutItem>?blockListLayout = converted.Layout?.ToObject <IEnumerable <BlockListLayoutItem> >(); if (blockListLayout is null) { return(BlockListModel.Empty); } // Get configuration BlockListConfiguration?configuration = propertyType.DataType.ConfigurationAs <BlockListConfiguration>(); if (configuration is null) { return(null); } var blockConfigMap = configuration.Blocks.ToDictionary(x => x.ContentElementTypeKey); // Convert the content data var contentPublishedElements = new Dictionary <Guid, IPublishedElement>(); foreach (BlockItemData data in converted.BlockValue.ContentData) { if (!blockConfigMap.ContainsKey(data.ContentTypeKey)) { continue; } IPublishedElement?element = _blockConverter.ConvertToElement(data, referenceCacheLevel, preview); if (element == null) { continue; } contentPublishedElements[element.Key] = element; } // If there are no content elements, it doesn't matter what is stored in layout if (contentPublishedElements.Count == 0) { return(BlockListModel.Empty); } // Convert the settings data var settingsPublishedElements = new Dictionary <Guid, IPublishedElement>(); var validSettingsElementTypes = blockConfigMap.Values.Select(x => x.SettingsElementTypeKey) .Where(x => x.HasValue).Distinct().ToList(); foreach (BlockItemData data in converted.BlockValue.SettingsData) { if (!validSettingsElementTypes.Contains(data.ContentTypeKey)) { continue; } IPublishedElement?element = _blockConverter.ConvertToElement(data, referenceCacheLevel, preview); if (element is null) { continue; } settingsPublishedElements[element.Key] = element; } // Cache constructors locally (it's tied to the current IPublishedSnapshot and IPublishedModelFactory) var blockListItemActivator = new BlockListItemActivator(_blockConverter); var list = new List <BlockListItem>(); foreach (BlockListLayoutItem layoutItem in blockListLayout) { // Get the content reference var contentGuidUdi = (GuidUdi?)layoutItem.ContentUdi; if (contentGuidUdi is null || !contentPublishedElements.TryGetValue(contentGuidUdi.Guid, out IPublishedElement? contentData)) { continue; } if (!blockConfigMap.TryGetValue( contentData.ContentType.Key, out BlockListConfiguration.BlockConfiguration? blockConfig)) { continue; } // Get the setting reference IPublishedElement?settingsData = null; var settingGuidUdi = (GuidUdi?)layoutItem.SettingsUdi; if (settingGuidUdi is not null) { settingsPublishedElements.TryGetValue(settingGuidUdi.Guid, out settingsData); } // This can happen if they have a settings type, save content, remove the settings type, and display the front-end page before saving the content again // We also ensure that the content types match, since maybe the settings type has been changed after this has been persisted if (settingsData is not null && (!blockConfig.SettingsElementTypeKey.HasValue || settingsData.ContentType.Key != blockConfig.SettingsElementTypeKey)) { settingsData = null; } // Create instance (use content/settings type from configuration) BlockListItem layoutRef = blockListItemActivator.CreateInstance(blockConfig.ContentElementTypeKey, blockConfig.SettingsElementTypeKey, contentGuidUdi, contentData, settingGuidUdi, settingsData); list.Add(layoutRef); } return(new BlockListModel(list)); } }
private void refreshListAndSelectId(int newId) { placementMode = PlacementMode.Manage; manageObjectList.Clear(); UIElement selectedItem = null; switch (placementType) { case PlacementType.BlockPlacement: foreach (var item in BlockType.lookup) { var newItem = new BlockListItem(item.Value); if (item.Value.ID == newId) { selectedItem = newItem; } manageObjectList.AddElement(newItem); } break; case PlacementType.AmbientObjectPlacement: foreach (var item in AmbientObjectType.lookup) { var newItem = new AmbientObjectListItem(item.Value); if (item.Value.ID == newId) { selectedItem = newItem; } manageObjectList.AddElement(newItem); } break; case PlacementType.AmbientHitableObjectPlacement: foreach (var item in AmbientHitableObjectType.lookup) { var newItem = new AmbientHitableObjectListItem(item.Value); if (item.Value.ID == newId) { selectedItem = newItem; } manageObjectList.AddElement(newItem); } break; case PlacementType.LivingEntityPlacement: foreach (var item in LivingEntityType.lookup) { var newItem = new LivingEntityListItem(item.Value); if (item.Value.ID == newId) { selectedItem = newItem; } manageObjectList.AddElement(newItem); } break; } manageObjectList.SelectElement(selectedItem); }
public async Task <ActionResult> ImportExcel(string blockSystem) { var files = Request.Files; if (files == null || files.Count <= 0) { return(Json(new { code = 1, status = false, msg = "请先选择文件上传" })); } var file = files[0]; if (file.ContentType != "application/vnd.ms-excel" && file.ContentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { return(Json(new { code = 1, status = false, msg = "文件格式不正确, 请上传Excel文件" })); } var blockDict = new Dictionary <string, BlockListItem>(); using (var stream = file.InputStream) { // 读取Excel表格数据 var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); var workBook = new XSSFWorkbook(new MemoryStream(buffer)); var sheet = workBook.GetSheetAt(0); for (var rowIndex = sheet.FirstRowNum + 1; rowIndex <= sheet.LastRowNum; rowIndex++) { var row = sheet.GetRow(rowIndex); if (row != null) { var blockTypeName = GetCellStringValue(row.GetCell(0)); if (string.IsNullOrEmpty(blockTypeName) || !TypeName2TypeId.ContainsKey(blockTypeName)) { return(Json(new { code = 1, status = false, msg = $"第{rowIndex + 1}行黑名单类型不正确" })); } var tempOutParameter = new Guid(); var blockValue = GetCellStringValue(row.GetCell(1)); if (blockTypeName.Equals("用户Id") && !Guid.TryParse(blockValue, out tempOutParameter)) { return(Json(new { code = 1, status = false, msg = $"第{rowIndex + 1}行用户Id应为Guid格式" })); } try { // 避免导入重复记录 if (!blockDict.ContainsKey(blockValue)) { blockDict[blockValue] = new BlockListItem { BlockSystem = blockSystem, BlockType = GetTypeIdByTypeName(blockTypeName), BlockValue = blockValue, BlockBeginTime = row.GetCell(2)?.DateCellValue, BlockEndTime = row.GetCell(3)?.DateCellValue, Reason = GetCellStringValue(row.GetCell(4)), Remark = GetCellStringValue(row.GetCell(5)), UpdateBy = User.Identity.Name }; } } catch (InvalidOperationException) { return(Json(new { code = 1, status = false, msg = $"第{rowIndex + 1}行时间格式不正确" })); } } } } if (blockDict.Any()) { // 将黑名单列表入库 var configService = new BlockListConfigService(); foreach (var item in blockDict) { await configService.AddBlockListItem(item.Value); } return(Json(new { code = 1, status = true })); } return(Json(new { code = 1, status = false, msg = "导入数据不能为空" })); }
public void Data_Item_Removed_If_Removed_From_Config() { BlockListPropertyValueConverter editor = CreateConverter(); // The data below expects that ContentKey1 + ContentKey2 + SettingsKey1 + SettingsKey2 exist but only ContentKey2 exists so // the data should all be filtered. var config = new BlockListConfiguration { Blocks = new[] { new BlockListConfiguration.BlockConfiguration { ContentElementTypeKey = _contentKey2, SettingsElementTypeKey = null } } }; IPublishedPropertyType propertyType = GetPropertyType(config); IPublishedElement publishedElement = Mock.Of <IPublishedElement>(); string json = @" { layout: { '" + Constants.PropertyEditors.Aliases.BlockList + @"': [ { 'contentUdi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D', 'settingsUdi': 'umb://element/1F613E26CE274898908A561437AF5100' }, { 'contentUdi': 'umb://element/0A4A416E547D464FABCC6F345C17809A', 'settingsUdi': 'umb://element/63027539B0DB45E7B70459762D4E83DD' } ] }, contentData: [ { 'contentTypeKey': '" + _contentKey1 + @"', 'udi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D' }, { 'contentTypeKey': '" + _contentKey2 + @"', 'udi': 'umb://element/E05A034704424AB3A520E048E6197E79' }, { 'contentTypeKey': '" + _contentKey2 + @"', 'udi': 'umb://element/0A4A416E547D464FABCC6F345C17809A' } ], settingsData: [ { 'contentTypeKey': '" + _settingKey1 + @"', 'udi': 'umb://element/63027539B0DB45E7B70459762D4E83DD' }, { 'contentTypeKey': '" + _settingKey2 + @"', 'udi': 'umb://element/1F613E26CE274898908A561437AF5100' }, { 'contentTypeKey': '" + _settingKey2 + @"', 'udi': 'umb://element/BCF4BA3DA40C496C93EC58FAC85F18B9' } ], }"; var converted = editor.ConvertIntermediateToObject(publishedElement, propertyType, PropertyCacheLevel.None, json, false) as BlockListModel; Assert.IsNotNull(converted); Assert.AreEqual(1, converted.Count); BlockListItem item0 = converted[0]; Assert.AreEqual(Guid.Parse("0A4A416E-547D-464F-ABCC-6F345C17809A"), item0.Content.Key); Assert.AreEqual("Test2", item0.Content.ContentType.Alias); Assert.IsNull(item0.Settings); }
public void Get_Data_From_Layout_Item() { BlockListPropertyValueConverter editor = CreateConverter(); BlockListConfiguration config = ConfigForMany(); IPublishedPropertyType propertyType = GetPropertyType(config); IPublishedElement publishedElement = Mock.Of <IPublishedElement>(); string json = @" { layout: { '" + Constants.PropertyEditors.Aliases.BlockList + @"': [ { 'contentUdi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D', 'settingsUdi': 'umb://element/1F613E26CE274898908A561437AF5100' }, { 'contentUdi': 'umb://element/0A4A416E547D464FABCC6F345C17809A', 'settingsUdi': 'umb://element/63027539B0DB45E7B70459762D4E83DD' } ] }, contentData: [ { 'contentTypeKey': '" + _contentKey1 + @"', 'udi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D' }, { 'contentTypeKey': '" + _contentKey2 + @"', 'udi': 'umb://element/E05A034704424AB3A520E048E6197E79' }, { 'contentTypeKey': '" + _contentKey2 + @"', 'udi': 'umb://element/0A4A416E547D464FABCC6F345C17809A' } ], settingsData: [ { 'contentTypeKey': '" + _settingKey1 + @"', 'udi': 'umb://element/63027539B0DB45E7B70459762D4E83DD' }, { 'contentTypeKey': '" + _settingKey2 + @"', 'udi': 'umb://element/1F613E26CE274898908A561437AF5100' }, { 'contentTypeKey': '" + _settingKey2 + @"', 'udi': 'umb://element/BCF4BA3DA40C496C93EC58FAC85F18B9' } ], }"; var converted = editor.ConvertIntermediateToObject(publishedElement, propertyType, PropertyCacheLevel.None, json, false) as BlockListModel; Assert.IsNotNull(converted); Assert.AreEqual(2, converted.Count); BlockListItem item0 = converted[0]; Assert.AreEqual(Guid.Parse("1304E1DD-AC87-4396-84FE-8A399231CB3D"), item0.Content.Key); Assert.AreEqual("Test1", item0.Content.ContentType.Alias); Assert.AreEqual(Guid.Parse("1F613E26CE274898908A561437AF5100"), item0.Settings.Key); Assert.AreEqual("Setting2", item0.Settings.ContentType.Alias); BlockListItem item1 = converted[1]; Assert.AreEqual(Guid.Parse("0A4A416E-547D-464F-ABCC-6F345C17809A"), item1.Content.Key); Assert.AreEqual("Test2", item1.Content.ContentType.Alias); Assert.AreEqual(Guid.Parse("63027539B0DB45E7B70459762D4E83DD"), item1.Settings.Key); Assert.AreEqual("Setting1", item1.Settings.ContentType.Alias); }
internal static BlockListItemRendering GetBlockListItemData(BlockListItem item, BlockListModel list, string viewPath, ViewDataDictionary viewData) { if (item == null) { return(null); } var contentTypeAlias = item.Content?.ContentType.Alias; if (contentTypeAlias.IsNullOrWhiteSpace()) { return(null); } var rendering = new BlockListItemRendering(); var controllerName = $"{contentTypeAlias}Surface"; if (!viewPath.IsNullOrWhiteSpace()) { viewPath = viewPath.EnsureEndsWith("/"); } rendering.RouteValues = new { blockListItem = item, blockListItemContext = new BlockListItemContext(item, list), blockListItemContentTypeAlias = contentTypeAlias, blockListItemViewPath = viewPath }; if (SurfaceControllerHelper.SurfaceControllerExists(controllerName, contentTypeAlias, cacheResult: true)) { rendering.ControllerName = controllerName; rendering.ActionName = contentTypeAlias; } else { //// See if a default surface controller has been registered var defaultController = BlockListCurrent.DefaultBlockListMvcControllerType; if (defaultController != null) { var defaultControllerName = defaultController.Name.Substring(0, defaultController.Name.LastIndexOf("Controller")); rendering.ControllerName = defaultControllerName; // Try looking for an action named after the content type alias if (string.IsNullOrWhiteSpace(contentTypeAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, contentTypeAlias, true)) { rendering.ActionName = contentTypeAlias; } // else, just go with a default action name else { rendering.ActionName = "Index"; } } else { // fall back to using the default default controller rendering.ControllerName = "DefaultBlockListMvcSurface"; rendering.ActionName = "Index"; } } return(rendering); }
public BlockListItemContext(BlockListItem item, BlockListModel list) { Item = item; List = list; }