// Build text using recognized layout public RecognizedText(FREngine.IFRPage frPage, int pageIndex) { Text = new List <Character>(); words = new List <Word>(); FREngine.ILayoutBlocks blocks = frPage.Layout.Blocks; lineAll = new List <CustomLine>(); listWords = new List <CustomWord>(); Page = new CustomPage(); Page.Index = pageIndex; tableIndex = 0; for (int iBlock = 0; iBlock < blocks.Count; iBlock++) { FREngine.IBlock block = blocks[iBlock]; CustomBlock csBlock = buildTextFromBlock(block, iBlock); if (csBlock != null) { csBlock.ParentIndex = pageIndex; Page.BlockItems.Add(csBlock); } } ProcessLine(); }
static BlockLoader() { var ass = Assembly.GetExecutingAssembly(); var allBlockTypes = ass.GetTypes().Where(x => !x.IsAbstract && x.GetInterfaces().Contains(typeof(IBlock))); foreach (var type in allBlockTypes) { var attrib = (BlockTypeAttribute[])type.GetCustomAttributes(typeof(BlockTypeAttribute), true); if (attrib.Length == 0) { continue; } BlockMap.Add(attrib[0].Type, (IBlock)Activator.CreateInstance(type)); } //Do something with CustomBlock... maybe load files from json to create CustomBlocks and add to BlockMap var files = Directory.GetFiles("Assets/tiles", "t_*.vox"); foreach (var file in files) { var name = Path.GetFileNameWithoutExtension(file).ToLower(); var block = new CustomBlock { Type = name }; BlockMap.Add(name, block); } }
/// Unloads the custom actions of a block public void UnloadBlock(CustomBlock block) { if (block is ITickable tickable) { chunk.world.OnTick -= tickable.OnTick; } block.OnUnload(); }
/// Loads custom actions of a block public void LoadBlock(Coord3 pos, BlockData data, CustomBlock block) { block.Setup(data, chunk, pos); block.OnLoad(); if (block is ITickable tickable) { chunk.world.OnTick -= tickable.OnTick; } }
internal static void Delete(int PortalID, string Guid) { foreach (CustomBlock item in GetAll(PortalID).Where(p => p.Guid.ToLower() == Guid.ToLower()).ToList()) { CustomBlock.Delete("where ID=@0", item.ID); } CacheFactory.Clear(CacheFactory.Keys.CustomBlock); }
public static CustomBlock GetByLocale(int PortalID, string GUID, string Locale) { CustomBlock cb = BlockFactory.GetAll(PortalID).Where(b => b.Guid.ToLower() == GUID.ToLower() && b.Locale == Locale).FirstOrDefault(); if (cb == null) { cb = BlockFactory.GetAll(PortalID).Where(b => b.Guid.ToLower() == GUID.ToLower() && b.Locale == null).FirstOrDefault(); } return(cb); }
internal static List <CustomBlock> GetAll(int PortalID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock + "ALL", PortalID); List <CustomBlock> Custom_Block = CacheFactory.Get(CacheKey); if (Custom_Block == null) { Custom_Block = CustomBlock.Query("where PortalID=@0", PortalID).ToList(); CacheFactory.Set(CacheKey, Custom_Block); } return(Custom_Block); }
internal static CustomBlock Get(int PortalID, string Name) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock, PortalID, Name); CustomBlock CustomBlock = CacheFactory.Get(CacheKey); if (CustomBlock == null) { CustomBlock = CustomBlock.Query("where PortalID=@0 and Name=@1", PortalID, Name).FirstOrDefault(); CacheFactory.Set(CacheKey, CustomBlock); } return(CustomBlock); }
public static dynamic Add(PortalSettings PortalSettings, CustomBlock CustomBlock, int ForceCount = 0) { dynamic Result = new ExpandoObject(); try { if (BlockFactory.Get(PortalSettings.PortalId, CustomBlock.Name) == null) { if (ForceCount == 0) { CustomBlock.Guid = Guid.NewGuid().ToString().ToLower(); } CustomBlock.PortalID = PortalSettings.PortalId; CustomBlock.CreatedBy = PortalSettings.UserId; CustomBlock.UpdatedBy = PortalSettings.UserId; CustomBlock.CreatedOn = DateTime.UtcNow; CustomBlock.UpdatedOn = DateTime.UtcNow; CustomBlock.Locale = PageManager.GetCultureCode(PortalSettings); BlockFactory.AddUpdate(CustomBlock); CustomBlock cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == null).FirstOrDefault(); if (cb == null) { cb = CustomBlock; cb.Locale = null; cb.ID = 0; BlockFactory.AddUpdate(cb); } Result.Status = "Success"; Result.Guid = CustomBlock.Guid; } else { if (ForceCount > 0) { CustomBlock.Name = CustomBlock.Name + ForceCount; ForceCount++; Result = Add(PortalSettings, CustomBlock, ForceCount); } else { Result.Status = "Exist"; } } } catch (Exception ex) { Result.Status = ex.Message.ToString(); DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return(Result); }
private void btnSave_Click(object sender, EventArgs e) { if (Errors()) { MessageBox.Show(_errorMessage); _errorMessage = FixedMessage; // Reset the error message return; } CustomBlock block = new CustomBlock { Name = txtName.Text, Solidity = (CustomBlockSolidity)cboSolidity.SelectedIndex, MovementSpeed = (byte)numMovementSpeed.Value, Texture = texture, TransmitsLight = chkTransmitsLight.Checked, WalkSound = (WalkSound)cboWalkSound.SelectedIndex, FullBright = chkFullBright.Checked, Shape = (byte)numSize.Value, BlockDraw = (BlockDraw)cboTransparency.SelectedIndex, FogDensity = (byte)numFogDensity.Value, FogR = btnFogColor.BackColor.R, FogG = btnFogColor.BackColor.G, FogB = btnFogColor.BackColor.B }; string json = block.ToJson(); // Bottom Top Side const string tempDir = "CBTemp/"; Directory.CreateDirectory(tempDir); var jsonWriter = File.CreateText(tempDir + "block.json"); jsonWriter.Flush(); jsonWriter.Close(); File.Move(imageLocations[0], tempDir + texture.BottomFilePath); File.Move(imageLocations[1], tempDir + texture.TopFilePath); File.Move(imageLocations[2], tempDir + texture.SideFilePath); string fileName = txtName.Text + ".gcblock"; ZipFile.CreateFromDirectory(tempDir, fileName); File.Move(fileName, "Custom Blocks/" + fileName); foreach (string file in Directory.GetFiles(tempDir)) { File.Delete(file); } Directory.Delete(tempDir); }
internal static void AddUpdate(CustomBlock CustomBlock) { if (string.IsNullOrEmpty(CustomBlock.Html)) { CustomBlock.Html = ""; } CustomBlock.Category = CustomBlock.Category.ToLower(); if (CustomBlock.ID > 0) { CustomBlock.Update(); } else { CustomBlock.Insert(); } CacheFactory.Clear(CacheFactory.Keys.CustomBlock); }
public BlockDesigner() { InitializeComponent(); _block = new CustomBlock(); Current = CustomBlock.LoadBlocks().ToArray(); // Display warning messages if close or at max amount of custom blocks if (Current.Length >= 151) { MessageBox.Show("Warning: Server cannot hold anymore custom blocks.\n" + "Custom block will not be saved."); _canSave = false; } else if (Current.Length >= 140) { MessageBox.Show("Warning: Server almost out of room for custom blocks.\n" + $"The server can only hold 151 and there are {Current.Length}" + " saved"); _canSave = true; // Allows blocks to be saved } else { _canSave = true; } _onesTaken = Current.Select(block => block.ID).Select(dummy => (int)dummy).ToList(); // Add vanilla ID's for (int x = 0; x <= 84; x++) { _onesTaken.Add(x); } _onesTaken.Add(86); for (int x = 240; x <= 249; x++) { _onesTaken.Add(x); } numID.Value = GetValidInt(); SetForeColor(); }
/// Deserialize a specific block void DeserializeBlock(BinaryReader reader, byte id, ref Block block) { if (id == (byte)ReservedBytes.Air) { return; } BlockData data; data = ResourceStore.Blocks[id]; if (data.IsCustomType || data.IsStandalone) { block = CustomBlock.Convert(id, data.dataType); var customBlock = (CustomBlock)block; customBlock.Deserialize(reader); } else { block = new Block(id); } }
private static void BuildGlobalBlockMarkup(int PortalId, int UserId, HtmlNode item) { string blockguid = item.Attributes.Where(a => a.Name == "data-guid").FirstOrDefault().Value; if (!string.IsNullOrEmpty(blockguid)) { CustomBlock customBlock = BlockManager.GetByLocale(PortalId, blockguid, GetCultureCode(PortalController.Instance.GetCurrentSettings() as PortalSettings)); if (customBlock == null) { customBlock = new CustomBlock { Guid = blockguid.ToLower(), PortalID = PortalId, Name = item.Attributes.Where(a => a.Name == "data-name").FirstOrDefault().Value, Category = item.Attributes.Where(a => a.Name == "data-category").FirstOrDefault().Value, IsGlobal = true, CreatedBy = UserId, UpdatedBy = UserId, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; string[] str = item.InnerHtml.Split(new string[] { "</style>" }, StringSplitOptions.None); if (str.Length > 1) { customBlock.Html = str[1]; customBlock.Css = str[0]; } else { customBlock.Html = str[0]; } BlockFactory.AddUpdate(customBlock); } item.InnerHtml = item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value; item.Attributes.Remove("data-category"); item.Attributes.Remove("data-name"); } }
internal static Packet MakeDefineBlock(CustomBlock customBlock) { Packet packet = new Packet(OpCode.DefineBlock); packet.Data[1] = customBlock.ID; Encoding.ASCII.GetBytes(customBlock.Name, 0, customBlock.Name.Length, packet.Data, 2); packet.Data[66] = (byte)customBlock.Solidity; packet.Data[67] = customBlock.MovementSpeed; packet.Data[68] = customBlock.Texture.TopID; packet.Data[69] = customBlock.Texture.SideID; packet.Data[70] = customBlock.Texture.BottomID; packet.Data[71] = customBlock.TransmitsLight ? (byte)0 : (byte)1; packet.Data[72] = (byte)customBlock.WalkSound; packet.Data[73] = customBlock.FullBright ? (byte)0 : (byte)1; packet.Data[74] = customBlock.Shape; packet.Data[75] = (byte)customBlock.BlockDraw; packet.Data[76] = customBlock.FogDensity; packet.Data[77] = customBlock.FogR; packet.Data[78] = customBlock.FogG; packet.Data[79] = customBlock.FogB; return(packet); }
/// <summary> /// Converts the string representation of the custom type contained in the config value into the /// proper class. /// /// The RectangleTypeConverter partial class contained in the GENERATED code has a method called "ConvertFrom". /// This "ConvertFrom" method makes a call to "ConvertFromStringToRectangle". We actually implement the /// "ConvertFromStringToRectangle" method here. /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value"></param> /// <returns></returns> private global::Samples.Configuration.ExternalTypes.CustomBlock ConvertFromStringToCustomBlock(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, string value) { var ct = new CustomBlock(); string[] values = value.Split(','); if (values.Length != 3) { throw new ArgumentException("Invalid input string"); } //H: 42, W: 314, D: 312 foreach (string val in values) { string[] keyValue = val.Split(':'); switch (keyValue[0].Trim().ToUpper()) { case "H": ct.Height = int.Parse(keyValue[1]); break; case "W": ct.Width = int.Parse(keyValue[1]); break; case "D": ct.Depth = int.Parse(keyValue[1]); break; default: throw new ArgumentException("Invalid input string"); } } return(ct); }
/// When a new block it placed, setup custom actions void CreateBlock(Coord3 pos, BlockData data, ref Block block) { UpdateBlockNeighbors(pos); if (data == null) { block = null; return; } if (!data.IsCustomType && !data.IsStandalone) { block = new Block(data.id); return; } var type = data.IsCustomType ? data.dataType : BlockDataType.StandaloneBlock; block = CustomBlock.Convert(data.id, type); var customBlock = (CustomBlock)block; LoadBlock(pos, data, customBlock); customBlock.OnPlace(); }
public static HttpResponseMessage ExportCustomBlock(int PortalID, string GUID) { HttpResponseMessage Response = new HttpResponseMessage(); CustomBlock customBlock = BlockManager.GetByLocale(PortalID, GUID, null); if (customBlock != null) { string Theme = Core.Managers.ThemeManager.GetCurrentThemeName(); ExportTemplate exportTemplate = new ExportTemplate { Guid = Guid.NewGuid().ToString(), Type = TemplateType.BlockTemplate.ToString(), UpdatedOn = DateTime.UtcNow, Templates = new List <Layout>(), ThemeName = Theme, ThemeGuid = "49A70BA1-206B-471F-800A-679799FF09DF" }; Dictionary <string, string> Assets = new Dictionary <string, string>(); Layout layout = new Layout(); layout.Blocks = new List <CustomBlock>() { customBlock }; if (layout.Blocks != null) { foreach (CustomBlock block in layout.Blocks) { if (!string.IsNullOrEmpty(block.Html)) { block.Html = PageManager.TokenizeTemplateLinks(PageManager.DeTokenizeLinks(block.Html, PortalID), false, Assets); } if (!string.IsNullOrEmpty(block.Css)) { block.Css = PageManager.DeTokenizeLinks(block.Css, PortalID); } } CacheFactory.Clear(CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock + "ALL", PortalID)); } layout.Name = customBlock.Name; layout.Content = ""; layout.SVG = ""; layout.ContentJSON = ""; layout.Style = ""; layout.StyleJSON = ""; layout.Type = ""; exportTemplate.Templates.Add(layout); string serializedExportTemplate = JsonConvert.SerializeObject(exportTemplate); if (!string.IsNullOrEmpty(serializedExportTemplate)) { byte[] fileBytes = null; using (MemoryStream memoryStream = new MemoryStream()) { using (ZipArchive zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { AddZipItem("ExportTemplate.json", Encoding.ASCII.GetBytes(serializedExportTemplate), zip); if (Assets != null && Assets.Count > 0) { foreach (KeyValuePair <string, string> asset in Assets) { string FileName = asset.Key.Replace(PageManager.ExportTemplateRootToken, ""); string FileUrl = asset.Value; if (FileUrl.StartsWith("/")) { FileUrl = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, FileUrl); } AddZipItem("Assets/" + FileName, new WebClient().DownloadData(FileUrl), zip); } } } fileBytes = memoryStream.ToArray(); } string fileName = customBlock.Name + "_BlockTemplate.zip"; Response.Content = new ByteArrayContent(fileBytes.ToArray()); Response.Content.Headers.Add("x-filename", fileName); Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); Response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; Response.StatusCode = HttpStatusCode.OK; } } return(Response); }
public static dynamic Edit(PortalSettings PortalSettings, CustomBlock CustomBlock) { dynamic Result = new ExpandoObject(); try { CustomBlock cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == PageManager.GetCultureCode(PortalSettings)).FirstOrDefault(); if (cb == null) { cb = BlockFactory.GetAll(PortalSettings.PortalId).Where(b => b.Guid.ToLower() == CustomBlock.Guid.ToLower() && b.Locale == null).FirstOrDefault(); if (cb != null) { cb.Locale = PageManager.GetCultureCode(PortalSettings); cb.ID = 0; BlockFactory.AddUpdate(cb); } } if (cb != null) { cb.Name = CustomBlock.Name; cb.Category = CustomBlock.Category; if (CustomBlock.IsGlobal && !string.IsNullOrEmpty(CustomBlock.Html)) { HtmlDocument html = new HtmlDocument(); html.LoadHtml(CustomBlock.Html); IEnumerable <HtmlNode> query = html.DocumentNode.Descendants("div"); foreach (HtmlNode item in query.ToList()) { if (item.Attributes.Where(a => a.Name == "dmid").FirstOrDefault() != null && item.Attributes.Where(a => a.Name == "mid").FirstOrDefault() != null && !string.IsNullOrEmpty(item.Attributes.Where(a => a.Name == "mid").FirstOrDefault().Value)) { int mid = int.Parse(item.Attributes.Where(a => a.Name == "mid").FirstOrDefault().Value); ModuleInfo minfo = ModuleController.Instance.GetModule(mid, Null.NullInteger, false); if (minfo != null && !minfo.AllTabs) { minfo.AllTabs = true; ModuleController.Instance.UpdateModule(minfo); List <TabInfo> listTabs = TabController.GetPortalTabs(minfo.PortalID, Null.NullInteger, false, true); foreach (TabInfo destinationTab in listTabs) { ModuleInfo module = ModuleController.Instance.GetModule(minfo.ModuleID, destinationTab.TabID, false); if (module != null) { if (module.IsDeleted) { ModuleController.Instance.RestoreModule(module); } } else { if (!PortalSettings.Current.ContentLocalizationEnabled || (minfo.CultureCode == destinationTab.CultureCode)) { ModuleController.Instance.CopyModule(minfo, destinationTab, minfo.PaneName, true); } } } } item.InnerHtml = "<div vjmod=\"true\"><app id=\"" + mid + "\"></app>"; } else if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault() != null) { if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value.ToLower() != "global") { item.InnerHtml = item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value; } } } CustomBlock.Html = html.DocumentNode.OuterHtml; } cb.Html = CustomBlock.Html; cb.Css = CustomBlock.Css; cb.IsGlobal = CustomBlock.IsGlobal; cb.UpdatedBy = PortalSettings.Current.UserId; cb.UpdatedOn = DateTime.UtcNow; BlockFactory.AddUpdate(cb); Result.Status = "Success"; Result.Guid = cb.Guid; Result.CustomBlock = cb; } else { Result.Status = "Not exist"; } } catch (Exception ex) { Result.Status = ex.Message.ToString(); DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } return(Result); }
public static void DeleteCustomBlocks(int PortalID) { CustomBlock.Delete("Where PortalID=@0", PortalID); }
public dynamic AddCustomBlock(CustomBlock CustomBlock) { return(Core.Managers.BlockManager.Add(PortalSettings, CustomBlock)); }
public dynamic EditCustomBlock(CustomBlock CustomBlock) { return(Core.Managers.BlockManager.Edit(PortalSettings, CustomBlock)); }
private CustomBlock buildTextFromBlock(FREngine.IBlock block, int iBlock) { if (block.Type == FREngine.BlockTypeEnum.BT_Table) { FREngine.ITableBlock tableBlock = block.GetAsTableBlock(); CustomTable cstable = new CustomTable(); cstable.X = tableBlock.Region.BoundingRectangle.Left; cstable.Y = tableBlock.Region.BoundingRectangle.Top; cstable.Width = tableBlock.Region.BoundingRectangle.Width; cstable.Height = tableBlock.Region.BoundingRectangle.Height; cstable.ParentIndex = Page.Index; cstable.Index = tableIndex; tableIndex++; List <CustomBlock> blockItems = new List <CustomBlock>(); for (int iCell = 0; iCell < tableBlock.Cells.Count; iCell++) { FREngine.ITableCell cell = tableBlock.Cells[iCell]; CustomBlock csBlock = buildTextFromBlock(cell.Block, iCell); if (csBlock != null) { blockItems.Add(csBlock); //blockAll.Add(csBlock); } } var rowItemsGroup = blockItems.GroupBy(x => x.Y); int iRow = 0; foreach (var item in rowItemsGroup) { CustomRow rowItem = new CustomRow() { Width = cstable.Width, Height = item.Max(x => x.Height), BlockItems = item.ToList(), X = item.Min(x => x.X), Y = item.Min(x => x.Y), Value = string.Join("\t", item.Select(x => x.Value)), Index = iRow, ParentIndex = iBlock, }; cstable.RowItems.Add(rowItem); iRow++; } cstable.Value = string.Join("\n", cstable.RowItems.Select(x => x.Value));; // //string.Join("|", cstable.BlockItems.Select(x => x.Value)); Page.TableItems.Add(cstable); return(null); } if (block.Type != FREngine.BlockTypeEnum.BT_Text) { return(null); } CustomBlock result = new CustomBlock(); FREngine.ITextBlock textBlock = block.GetAsTextBlock(); result.Index = iBlock; result.X = textBlock.Region.BoundingRectangle.Left; result.Y = textBlock.Region.BoundingRectangle.Top; result.Width = textBlock.Region.BoundingRectangle.Width; result.Height = textBlock.Region.BoundingRectangle.Height; for (int iPar = 0; iPar < textBlock.Text.Paragraphs.Count; iPar++) { FREngine.IParagraph par = textBlock.Text.Paragraphs[iPar]; result.LineItems.AddRange(buildTextFromParagraph(par, iBlock)); } result.Value = string.Join("\n", result.LineItems.Select(x => x.Value)); return(result); }