public static Page Load(int PageNo, int FrameNo, ICarousel Carousel = null, DateTime?LastSeen = null) { var item = PageCache.GetPage(PageNo, FrameNo); if (item == null) { item = new Page(); using (var con = new MySqlConnection(DBOps.ConnectionString)) { con.Open(); string sql = @"SELECT * FROM page WHERE @PageFrameNo>=FromPageFrameNo AND @PageFrameNo<=ToPageFrameNo ORDER BY FromPageFrameNo,ToPageFrameNo LIMIT 1;"; var cmd = new MySqlCommand(sql, con); decimal pageFrameNo = PageNo + (Convert.ToDecimal(FrameNo) / 100m); cmd.Parameters.AddWithValue("PageFrameNo", pageFrameNo); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { item.Read(rdr); break; } } if (item.PageID > 0) { item.Templates = Templates.LoadForPage(item.PageID, con); item.Routing = Routes.LoadForPage(item.PageID, con); item.Zones = Zones.LoadForPage(item.PageID, con); item.Compose(LastSeen); new TSEncoder().Encode(ref item); } } } if (item.PageNo != PageNo || item.FrameNo != FrameNo) { var page = item.PageRange.FirstOrDefault(p => p.PageNo == PageNo && p.FrameNo == FrameNo); if (page != null) { page.PageRange.Clear(); page.PageRange.AddRange(item.PageRange); page.Templates.Clear(); page.Templates.AddRange(item.Templates); page.Compose(); var nextPage = page.PageRange.FirstOrDefault(p => p.PageNo == page.NextPageNo && p.FrameNo == page.NextFrameNo); if (nextPage == null) { page.Routing.AddOrUpdate((byte)RouteKeys.Enter, Options.MainIndexPageNo, Options.MainIndexFrameNo); page.Routing.AddOrUpdate((byte)RouteKeys.K0, Options.MainIndexPageNo, Options.MainIndexFrameNo); } else { page.Routing.AddOrUpdate((byte)RouteKeys.Enter, page.NextPageNo, page.NextFrameNo); page.Routing.AddOrUpdate((byte)RouteKeys.K0, page.NextPageNo, page.NextFrameNo); } item = page; } } if (Carousel != null) { Carousel.Create(item); } return(item); }
public void Encode(ref Page Page) { if (Page == null || Page.TeleSoftwareID == null || Page.TeleSoftwareID <= 0) { return; } var file = TSFile.Load((int)Page.TeleSoftwareID); if (file.FileSizeBytes <= 0) { return; } //using (var debug = new DebugLogger("NXtel.TSEncode")) DebugLogger debug = null; { CurrentSeq = -1; Pages = new List <Page>(); Page.PageType = PageTypes.TeleSoftware; Page.PageRangeSequence = CurrentSeq++; CurrentPageNo = Page.PageNo; CurrentFrameNo = Page.FrameNo; CurrentEscape = TelesoftEscapes.E0; CurrentPage = Page; Pages.Add(Page); CreateNewPage(); // Add header page for later string fn = (file.FileName ?? "").Trim(); if (string.IsNullOrWhiteSpace(fn)) { fn = "Telesoftware"; } fn = fn.Replace("|", "|E"); // Escape escape sequence if present in filename string contents = ""; CreateNewPage(); contents = new string(' ', 40); // Blank line for NXtel header contents += "|A"; // Start of telesoftware block CurrentChecksum = 0; contents += Checksum("|G" + CurrentPage.Frame + "|I"); // Frame letter of telesoftware block, terminated //contents += Checksum("|L"); // EOL, completing header int address = 0; foreach (byte b in file.Contents) { string newChar = EscapeChar(b); if (contents.Length + newChar.Length > PAGE_LEN) { contents += "|Z" + CurrentChecksum.ToString("D3"); CurrentPage.ConvertContentsFromString(contents); debug.LogWithoutTimestamp(""); CreateNewPage(); //newChar = EscapeChar(b); // Recalculate from TelesoftEscapes.E0 contents = new string(' ', 40); // Blank line for NXtel header contents += "|A"; // Start of telesoftware block CurrentChecksum = 0; contents += Checksum("|G" + CurrentPage.Frame + "|I"); // Frame letter of telesoftware block, terminated //contents += Checksum("|L"); // EOL, completing header contents += Checksum(newChar); } else { contents += Checksum(newChar); } debug.Log(address.ToString("X8"), b.ToString("X2") + " " + b.ToString().PadLeft(3) + " " + newChar.PadRight(6) + CurrentEscape.ToString()); address++; } contents += Checksum("|F"); contents += "|Z" + CurrentChecksum.ToString("D3"); // end of frame plus checksum CurrentPage.ConvertContentsFromString(contents); // Calculate header contents contents = new string(' ', 40); // Blank line for NXtel header contents += "|A"; // Start of telesoftware block CurrentChecksum = 0; contents += Checksum("|G" + Pages[1].Frame); // Frame letter of telesoftware block contents += Checksum("|I" + fn + "|L"); // Telesoftware filename contents += Checksum((Pages.Count - 2).ToString("D3")); // header frame count contents += "|Z"; // end of telesoftware block contents += CurrentChecksum.ToString("D3"); // header checksum Pages[1].ConvertContentsFromString(contents); Page.PageRange = new NXtelData.Pages(); Page.PageRange.AddRange(Pages); var lastPage = Pages[Pages.Count - 1]; Pages[0].ToPageNo = lastPage.PageNo; Pages[0].ToFrameNo = lastPage.FrameNo; Pages[0].Routing.AddOrUpdate((byte)RouteKeys.Enter, Pages[0].NextPageNo, Pages[0].NextFrameNo); foreach (var page in Pages) { page.PageRangeCount = Pages.Count; } PageCache.Add(Pages[0]); } }