public static PageCollection GetPages() { if (Config.Current.sArrayValue[Enums.sArrayValue.Pages] != null) { if (Config.Current.sArrayValue[Enums.sArrayValue.Pages].Length != 0) { try { PageCollection pages = null; for (int i = 0; Config.Current.sArrayValue[Enums.sArrayValue.Pages].Length > i; i++) { if (Config.Current.sArrayValue[Enums.sArrayValue.Pages][i] == "Plugin") { pages = PluginManager.GetPages(); } { LAPP.Page p = Utility.GetPageFromString(Config.Current.sArrayValue[Enums.sArrayValue.Pages][i]); if (p != null) { pages = new PageCollection(false); pages.Add(p); } } } return(pages); } catch (Exception) { } } } return(new PageCollection(false)); }
private static PageCollection BuildReactionList(IEnumerable <Reaction> reactions, string title, string footer = null) { var pages = new PageCollection(); int count = 0; foreach (var reaction in reactions.OrderBy(x => x.Trigger).ThenBy(x => x.Id)) { if (count++ % 10 == 0) { var embed = new EmbedBuilder().WithTitle(title); if (!string.IsNullOrEmpty(footer)) { embed.WithFooter(footer); } pages.Add(embed); } pages.Last.Embed.AddField(x => x .WithName($"{reaction.Id}: {reaction.Trigger}".Truncate(EmbedBuilder.MaxTitleLength)) .WithValue(reaction.Value.Truncate(500))); } return(pages); }
public void AddTest() { PageCollection target = new PageCollection(); Page page = new Page(); target.Add(page); }
public void AddTest1() { PageCollection target = new PageCollection(); Page page = null; Assert.Throws <ArgumentNullException>(() => target.Add(page)); }
public IDictionary <long, int> ListPageForumCounts(long tenantId, IEnumerable <Page> pages, IUnitOfWork unitOfWork = null) { PageCollection pageCollection = new PageCollection(); foreach (Page page in pages) { pageCollection.Add(page); } IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork); try { string sql = _sqlManager.GetSql("Sql.ListPageForumCounts.sql"); dbm.SetSQL(sql); dbm.AddParameter("@TenantId", FieldType.BigInt, tenantId); dbm.AddTypedParameter("@Pages", FieldType.Structured, pageCollection.Count == 0 ? null : pageCollection, "cms.PageTableType"); dbm.ExecuteReader(); Dictionary <long, int> countsByPageId = new Dictionary <long, int>(); while (dbm.Read()) { long pageId = (long)dbm.DataReaderValue("PageId"); int threadCount = (int)dbm.DataReaderValue("ThreadCount"); int postCount = (int)dbm.DataReaderValue("PostCount"); countsByPageId.Add(pageId, threadCount + postCount); } return(countsByPageId); } finally { if (unitOfWork == null) { dbm.Dispose(); } } }
internal PageCollection GetPagesByCriteria(Predicate <PageIndexItem> match) { var pageCollection = new PageCollection(); _pageIndex.FindAll(match).ForEach(t => pageCollection.Add(t.PageId)); return(pageCollection); }
public static void ExtractImagesFromPDF(string password, string key, string docPath, string pagePath, PageCollection pages) { Page page = null; // NOTE: This will only get the first image it finds per page. PdfReader pdf = new PdfReader(Utility.Security.AES.DecryptFile(key, docPath)); //RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(p); try { for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++) { PdfDictionary pg = pdf.GetPageN(pageNumber); // recursively search pages, forms and groups for images. PdfObject obj = FindImageInPDFDictionary(pg); if (obj != null) { int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture)); PdfObject pdfObj = pdf.GetPdfObject(XrefIndex); PdfStream pdfStrem = (PdfStream)pdfObj; byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem); if ((bytes != null)) { using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes)) { memStream.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(memStream); // must save the file while stream is open. page = new Page(); page.Order = pages.Count; page.Save(); page.Token = Utility.Security.AES.GetToken(page.Id, password); //string path = System.IO.Path.Combine(page.Filename, String.Format(@"{0}.jpg", pageNumber)); System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1); parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0); System.Drawing.Imaging.ImageCodecInfo jpegEncoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.FormatDescription == "JPEG"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); img.Save(ms, jpegEncoder, parms); System.IO.File.WriteAllBytes(System.IO.Path.Combine(pagePath, page.Filename), SoftFluent.Samples.GED.Utility.Security.AES.EncryptStream(page.Token, ms.ToArray()).ToArray()); ms.Close(); pages.Add(page); } } } } } catch { throw; } finally { pdf.Close(); //raf.Close(); } }
public static void ExtractImagesFromPDF(string password, string key, string docPath, string pagePath, PageCollection pages) { Page page = null; // NOTE: This will only get the first image it finds per page. PdfReader pdf = new PdfReader(Utility.Security.AES.DecryptFile(key, docPath)); //RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(p); try { for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++) { PdfDictionary pg = pdf.GetPageN(pageNumber); // recursively search pages, forms and groups for images. PdfObject obj = FindImageInPDFDictionary(pg); if (obj != null) { int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture)); PdfObject pdfObj = pdf.GetPdfObject(XrefIndex); PdfStream pdfStrem = (PdfStream)pdfObj; byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem); if ((bytes != null)) { using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes)) { memStream.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(memStream); // must save the file while stream is open. page = new Page(); page.Order = pages.Count; page.Save(); page.Token = Utility.Security.AES.GetToken(page.Id, password); //string path = System.IO.Path.Combine(page.Filename, String.Format(@"{0}.jpg", pageNumber)); System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1); parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0); System.Drawing.Imaging.ImageCodecInfo jpegEncoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.FormatDescription == "JPEG"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); img.Save(ms, jpegEncoder, parms); System.IO.File.WriteAllBytes(System.IO.Path.Combine(pagePath, page.Filename), SoftFluent.Samples.GED.Utility.Security.AES.EncryptStream(page.Token, ms.ToArray()).ToArray()); ms.Close(); pages.Add(page); } } } } } catch { throw; } finally { pdf.Close(); //raf.Close(); } }
public async Task Views(ICommand command) { var settings = await _settings.Read<MediaSettings>(command.GuildId); string param = string.IsNullOrWhiteSpace(command["SongOrCategoryName"]) ? null : (string)command["SongOrCategoryName"]; List<ComebackInfo> comebacks; if (string.Compare("all", param, true) == 0) { comebacks = settings.YouTubeComebacks; } else { comebacks = settings.YouTubeComebacks.Where(x => string.Compare(x.Category, param, true) == 0).ToList(); if (comebacks.Count <= 0 && !string.IsNullOrWhiteSpace(param)) comebacks = settings.YouTubeComebacks.Where(x => x.Name.Search(param, true)).ToList(); } if (comebacks.Count <= 0) { string rec; if (settings.YouTubeComebacks.Count <= 0) rec = "Use the `views add` command."; else rec = "Try " + GetOtherCategoriesRecommendation(settings, param, true, command.Prefix) + "."; await command.ReplyError($"No comeback info has been set for this category or song. {rec}"); return; } // Get YT data var pages = new PageCollection(); var infos = new List<Tuple<ComebackInfo, YoutubeInfo>>(); foreach (var comeback in comebacks) infos.Add(Tuple.Create(comeback, await GetYoutubeInfo(comeback.VideoIds, _integrationOptions.Value.YouTubeKey))); // Compose embeds with info string recommendation = "Try also: " + GetOtherCategoriesRecommendation(settings, param, false, command.Prefix) + "."; foreach (var info in infos.OrderByDescending(x => x.Item2.PublishedAt)) { if (pages.IsEmpty || pages.Last.Embed.Fields.Count % 5 == 0) { pages.Add(new EmbedBuilder().WithTitle("YouTube")); if (!string.IsNullOrEmpty(recommendation)) pages.Last.Embed.WithFooter(recommendation); } TimeSpan timePublished = DateTime.Now.ToUniversalTime() - info.Item2.PublishedAt; pages.Last.Embed.AddField(eab => eab.WithName($":tv: {info.Item1.Name}").WithIsInline(false).WithValue( $"**Views: **{info.Item2.Views.ToString("N0", GlobalDefinitions.Culture)}\n" + $"**Likes: **{info.Item2.Likes.ToString("N0", GlobalDefinitions.Culture)}\n" + $"**Published: **{string.Format("{0}d {1}h {2}min ago", timePublished.Days, timePublished.Hours, timePublished.Minutes)}\n\n")); } await command.Reply(pages); }
internal PageCollection GetPageTreeByCriteria(Guid pageId, Predicate <PageIndexItem> match) { var pageCollection = new PageCollection(); var stack = new Stack(); int currentId; int index = 0; if (pageId == Guid.Empty) { currentId = 0; } else { PageIndexItem firstPage = GetPageIndexItem(pageId); if (firstPage == null) { throw new ArgumentException("Page with id " + pageId + " not found!"); } currentId = firstPage.FirstChild; } while (currentId > -1) { PageIndexItem item = _pageIndex[currentId]; if (match(item)) { pageCollection.Add(item.PageId); if (item.NextPage > -1) { stack.Push(item.NextPage); } currentId = item.FirstChild; } else { currentId = item.NextPage; } if ((currentId == -1) && (stack.Count > 0)) { currentId = (int)stack.Pop(); } if (index > _pageIndex.Count) { // TODO: This should never happen, to be removed.. throw new Exception("Unending whileloop detected"); } index++; } return(pageCollection); }
internal PageCollection GetPagesByCriteriaSorted(Predicate <PageIndexItem> match, SortOrder sortOrder, SortDirection sortDirection) { var pages = _pageIndex.FindAll(match); pages = SortPages(pages, sortOrder, sortDirection); var pageCollection = new PageCollection(); foreach (var page in pages) { pageCollection.Add(page.PageId); } return(pageCollection); }
public async Task ListServers(ICommand command) { var pages = new PageCollection(); foreach (var guild in _client.Guilds.OrderByDescending(x => x.MemberCount)) { if (pages.IsEmpty || pages.Last.Embed.Fields.Count % 10 == 0) { pages.Add(new EmbedBuilder()); } pages.Last.Embed.AddField(x => x .WithName(guild?.Name ?? "Unknown") .WithValue($"{guild?.Id}\n{guild?.MemberCount} members")); } await command.Reply(pages, true); }
// TODO: Cache-candidate internal PageCollection GetPagePath(Guid pageId, bool includeCurrentPage = true) { var pathList = new PageCollection(); var currentPageId = pageId; for (var i = 0; i < 10000; i++) { if (i > 0 || includeCurrentPage) { pathList.Add(currentPageId); } currentPageId = GetPageIndexItem(currentPageId).ParentId; if (currentPageId == Guid.Empty) { break; } } return(pathList); }
public ActionResult ReOrder(Guid id, string[] list) { if (list != null) { PageCollection pages = new PageCollection(); Page p = null; foreach (string idPage in list) { p = Page.Load(Guid.Parse(idPage)); p.Order = pages.Count; p.DocumentId = id; pages.Add(p); } pages.SaveAll(); } return(new HttpStatusCodeResult(200)); }
public void Load(XmlDocumentDefinition xmlDataDocument) { // If the fontpath is set, update template configuration. if (!string.IsNullOrEmpty(xmlDataDocument.FontPath)) { _configuration.SetFontPath(xmlDataDocument.FontPath, xmlDataDocument.FontPathRelative); } if (!string.IsNullOrEmpty(xmlDataDocument.Dpi)) { _dpi = Convert.ToInt32(xmlDataDocument.Dpi); } // Load metadata if (xmlDataDocument.Author != null) { _author = xmlDataDocument.Author; } if (xmlDataDocument.Subject != null) { _subject = xmlDataDocument.Subject; } if (xmlDataDocument.Title != null) { _title = xmlDataDocument.Title; } // Load fonts foreach (Font dFont in xmlDataDocument.Fonts) { var bFont = new Typography.Font(dFont.Key, _configuration.FontPath + dFont.BasePath, dFont.Encoding, dFont.IsEmbedded, dFont.DefaultFontSize); foreach (FontStyle dFontStyle in dFont.Styles) { bFont.AddStyle(new Typography.FontStyle(bFont, dFontStyle.Key, dFontStyle.File)); } Fonts.Add(bFont); } // Load colors foreach (Color color in xmlDataDocument.Colors) { var bColor = new Typography.Color(color.Key) { CMYKColor = new CMYKColor(color.CMYKColor.Cyan, color.CMYKColor.Magenta, color.CMYKColor.Yellow, color.CMYKColor.Black, color.CMYKColor.Tint), RGBColor = new RGBColor(color.RGBColor.Red, color.RGBColor.Green, color.RGBColor.Blue, color.RGBColor.Alpha) }; if (color.PMSColor != null) { bColor.PMSColor = new PMSColor(color.PMSColor.Name); } Colors.Add(bColor); } // Load pages const int pageNumber = 1; foreach (XmlPageDefinition dataPage in xmlDataDocument.Pages) { var bPage = new Page(this, dataPage.Key, dataPage.Width, dataPage.Height, dataPage.Colortype, dataPage.Bleeding, pageNumber); _staticPages.Add(bPage); // Add Elements ProcessContent(dataPage.XmlContent, bPage.Contents); } // Load pages template. foreach (XmlPageTemplateDefinition dataTemplate in xmlDataDocument.PageTemplates) { var pageTemplate = new PageTemplate(this, dataTemplate.Key, dataTemplate.Width, dataTemplate.Height, dataTemplate.Colortype, dataTemplate.Bleeding, dataTemplate.XmlLayout.VOffset.Value, dataTemplate.XmlLayout.HOffset.Value, dataTemplate.XmlLayout.Width.Value, dataTemplate.XmlLayout.Height.Value); _templates.Add(pageTemplate); // Add dynamic elements (if any) ProcessContent(dataTemplate.XmlDynamicContent, pageTemplate.DynamicContents); // Add static elements (if any) ProcessContent(dataTemplate.XmlStaticContent, pageTemplate.StaticContents); } PageSequence pageSequence = PageSequence.Parse(this, xmlDataDocument); // Create page Sequence. var pagingModule = new PagingModule(); _pages.AddRange(pagingModule.GetPages(pageSequence, _staticPages, _templates)); }
public ActionResult ReOrder(Guid id, string[] list) { if (list != null) { PageCollection pages = new PageCollection(); Page p = null; foreach (string idPage in list) { p = Page.Load(Guid.Parse(idPage)); p.Order = pages.Count; p.DocumentId = id; pages.Add(p); } pages.SaveAll(); } return new HttpStatusCodeResult(200); }
internal void OnDragMove(FrameworkElement child, Point origin, Point position) { if (child == null || dragging == null) { return; } Dispatcher.Invoke(() => { // Set up render transform to move the element child.RenderTransform = CreateTransform(position.X - dragStart.X, position.Y - dragStart.Y, DragScale, DragScale); // Get current position of the dragging operation int page = GetPageIndex(position); int cell = GetCellIndex(position); // Make sure the page is valid if (page >= 0 && page < pages.Count) { // If the cell is invalid, make it the last cell in the list Rect grid = GetGridRect(page); if (!grid.Contains(position)) { cell = (rowSize * columnSize) - 1; } // No need to update if the element is already there if (pages[page][cell] != dragging) { // Remove the element from the drag source pages[dragSourcePage].RemoveAt(dragSourceCell); // Insert it into the current position pages[page].Insert(cell, dragging); // Set new drag source dragSourcePage = page; dragSourceCell = cell; // Cascade elements from "overcrowded" pages for (int i = 0; i < pages.Count; i++) { if (pages[i].Count > rowSize * columnSize) { // Add a new page if needed if (i + 1 == pages.Count) { pages.Add(new PanoramaPanelPage()); } // Remove the last element from the page UIElement cascade = pages[i][rowSize * columnSize]; pages[i].RemoveAt(rowSize * columnSize); pages[i + 1].Insert(0, cascade); } } // Update Layout UpdateFluidLayout(true); } } }); }
// TODO: Cache-candidate internal PageCollection GetPagePath(Guid pageId, bool includeCurrentPage = true) { var pathList = new PageCollection(); var currentPageId = pageId; for (var i = 0; i < 10000; i++) { if (i > 0 || includeCurrentPage) { pathList.Add(currentPageId); } currentPageId = GetPageIndexItem(currentPageId).ParentId; if (currentPageId == Guid.Empty) { break; } } return pathList; }
internal PageCollection GetPageTreeFromPage(Guid rootPageId, Guid leafPageId, PublishState pageState) { var pageCollection = new PageCollection(); Predicate<PageIndexItem> match = GetPublishStatePredicate(pageState); var stack = new Stack(); int currentId; int index = 0; PageCollection pagePath = GetPagePath(leafPageId); if (rootPageId == Guid.Empty) { currentId = 0; } else { PageIndexItem firstPage = GetPageIndexItem(rootPageId); if (firstPage == null) { throw new ArgumentException("Page with id " + rootPageId + " not found!"); } currentId = firstPage.FirstChild; } while (currentId > -1) { PageIndexItem item = _pageIndex[currentId]; if (match(item)) { pageCollection.Add(item.PageId); if (item.NextPage > -1) { stack.Push(item.NextPage); } if (pagePath.Contains(item.PageId)) { currentId = item.FirstChild; } else { currentId = -1; } } else { currentId = item.NextPage; } if ((currentId == -1) && (stack.Count > 0)) { currentId = (int)stack.Pop(); } if (index > _pageIndex.Count) { // TODO: This should never happen, to be removed.. throw new Exception("Unending whileloop detected"); } index++; } return pageCollection; }
internal PageCollection GetPagesByCriteriaSorted(Predicate<PageIndexItem> match, SortOrder sortOrder, SortDirection sortDirection) { var pages = _pageIndex.FindAll(match); pages = SortPages(pages, sortOrder, sortDirection); var pageCollection = new PageCollection(); foreach (var page in pages) { pageCollection.Add(page.PageId); } return pageCollection; }
internal PageCollection GetPagesByCriteria(Predicate<PageIndexItem> match) { var pageCollection = new PageCollection(); _pageIndex.FindAll(match).ForEach(t => pageCollection.Add(t.PageId)); return pageCollection; }
public async Task RolesStats(ICommand command, ILogger logger) { var guild = (SocketGuild)command.Guild; IUserMessage progressMessage = null; Func <double, Task> onProgress = null; if (guild.MemberCount > 5000) { onProgress = new Func <double, Task>(async x => { if (progressMessage == null) { progressMessage = (await command.Reply($"Processing guild members... {Math.Ceiling(x * 100)}%")).First(); } else { await progressMessage.ModifyAsync(m => m.Content = $"Processing guild members... {Math.Ceiling(x * 100)}%"); } }); } var stats = _roleStatsCache.GetOrAdd(command.GuildId, x => new RoleStats(logger)); var(data, whenCached) = await stats.GetOrFillAsync(guild, MaxRoleStatsAge, onProgress); if (progressMessage != null) { await progressMessage.DeleteAsync(); } var dataAge = DateTimeOffset.UtcNow - whenCached; var pages = new PageCollection(); const int MaxLines = 30; if (command["all"].HasValue) { int count = 0; foreach (var kv in data.OrderByDescending(x => x.Value)) { if (command.Guild.EveryoneRole.Id == kv.Key) { continue; } if (count++ % MaxLines == 0) { pages.Add(new EmbedBuilder().WithTitle("All roles").WithDescription(string.Empty)); } pages.Last.Embed.Description += $"<@&{kv.Key}> — {kv.Value} user{(kv.Value != 1 ? "s" : "")}\n"; if (dataAge.HasValue) { pages.Last.Embed.WithFooter(x => x.Text = $"Results from {dataAge.Value.SimpleFormat()} ago"); } } } else { var settings = await _settings.Read <RolesSettings>(command.GuildId, false); if (settings == null || settings.AssignableRoles.Count <= 0) { await command.Reply("No self-assignable roles have been set up. For statistics of all roles use `roles stats all`."); return; } int count = 0; foreach (var kv in data.OrderByDescending(x => x.Value)) { var role = settings.AssignableRoles.FirstOrDefault(x => x.RoleId == kv.Key); if (role == null) { continue; } var guildRole = command.Guild.GetRole(role.RoleId); if (guildRole == null) { continue; } if (count++ % MaxLines == 0) { pages.Add(new EmbedBuilder().WithTitle("Assignable roles").WithDescription(string.Empty)); } pages.Last.Embed.Description += $"{guildRole.Mention} — {kv.Value} user{(kv.Value != 1 ? "s" : "")}\n"; if (dataAge.HasValue) { pages.Last.Embed.WithFooter(x => x.Text = $"Results from {dataAge.Value.SimpleFormat()} ago"); } if (role.SecondaryId != default) { pages.Last.Embed.Description += $" ┕ _Secondary_ — {data[role.SecondaryId]} users\n"; if (count % MaxLines != 0) { count++; } } } } await command.Reply(pages); }
protected PageCollection.Page AddPage(PageCollection.Page tab) { return(tabs.Add(tab)); }