private void ReadEntry() { EntryContent content = (EntryContent)m_reader.ReadByte(); switch (content) { case EntryContent.Empty: m_entryQueue.Enqueue(new Object()); break; case EntryContent.Boolean: bool boolvalue = (m_reader.ReadByte() == 1); m_entryQueue.Enqueue(boolvalue); break; case EntryContent.Byte: byte bytevalue = m_reader.ReadByte(); m_entryQueue.Enqueue(bytevalue); break; case EntryContent.Integer: Int16 intvalue = m_reader.ReadInt16(); m_entryQueue.Enqueue(intvalue); break; case EntryContent.String: String strvalue = ReadString(); m_entryQueue.Enqueue(strvalue); break; default: throw new ParserException("Error reading CGT: unknown entry-content type"); } }
/* public methods */ public bool MoveNext() { try { EntryContent content = (EntryContent)m_reader.ReadByte(); if (content == EntryContent.Multi) { m_entryQueue.Clear(); int count = m_reader.ReadInt16(); for (int n = 0; n < count; n++) { ReadEntry(); } return(true); } else { return(false); } } catch (IOException) { return(false); } }
public async Task <string> UploadConvertedArticleEntry(EntryContent entryContent, string convertedContent) { if (string.IsNullOrWhiteSpace(convertedContent)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(convertedContent)); } return(await UploadArticleEntry(entryContent, convertedContent, BlobStorageContainer.TRANSLATED_ARTICLE_ENTRIES_CONTAINER)); }
private async Task <string> UploadArticleEntry(EntryContent entryContent, string content, BlobStorageContainer storageContainer) { if (entryContent == null) { throw new ArgumentNullException(nameof(entryContent)); } var contentBase64 = StringUtilities.ToBase64(content); return(await _blobstore.PersistArticleEntryAsync(storageContainer, entryContent.ArticleId, entryContent.Id, contentBase64)); }
public async Task <string> UploadMarkdownArticleEntry(EntryContent entryContent, ArticleEntry articleEntry) { if (articleEntry == null) { throw new ArgumentNullException(nameof(articleEntry)); } if (string.IsNullOrWhiteSpace(articleEntry.Content)) { return(null); } return(await UploadArticleEntry(entryContent, articleEntry.Content, BlobStorageContainer.MARKDOWN_ARTICLE_ENTRIES_CONTAINER)); }
private async Task <EntryContent> CreateNewEntryFor(Article article, ArticleEntry entry) { var entryContent = new EntryContent { ArticleId = article.Id, Created = _clock.Now, }; await _context.Add(entryContent); await _context.SaveChanges(); return(entryContent); }
private async Task <string> ConvertAndPersistEntryContent(EntryContent latestEntry) { if (!latestEntry.Persisted.HasValue || string.IsNullOrWhiteSpace(latestEntry.BlobUrl)) { throw new Exception($"Entry content {latestEntry.Id} has not been persisted"); } var mdContentUrl = StringUtilities.FromBase64(latestEntry.BlobUrl); var convertedContent = await _bogMarkdownConverter.ConvertArticle(latestEntry.ArticleId, mdContentUrl); var storageUrl = await _uploadArticleEntryCoordinator.UploadConvertedArticleEntry(latestEntry, convertedContent); await UpdateConvertedBlobUrl(latestEntry, storageUrl); return(storageUrl); }
private void SeedTestData(BlogApiDbContext dbContext) { if (!dbContext.Blogs.Any()) { using (var transaction = dbContext.Database.BeginTransaction()) { try { var testBlog = new Blog() { Id = Guid.Parse("8724c4c5-7956-484a-896b-f379fdbc7d8c") }; dbContext.Add(testBlog); var article = new Article() { Id = Guid.Parse("1b6ee39d-87f2-4e07-94fd-b18c09136acb"), BlogId = testBlog.Id, Author = "Test Guy", Created = _clock.Now }; dbContext.Add(article); var entry = new EntryContent() { Id = Guid.Parse("78889afc-9baa-4d3f-ae84-61fade9bc82f"), ArticleId = article.Id, Created = _clock.Now }; dbContext.Add(entry); dbContext.SaveChanges(); transaction.Commit(); } catch (Exception ex) { _logger.LogError(LogEvenIdsValueObject.EnitityFramework, $"Could not see data: {ex}"); transaction.Rollback(); } } } }
private async Task <EntryMedia> CreateNewEntryMediaFor(EntryContent entryContent, ArticleEntryMediaRequest entryMediaRequest) { var entryMedia = new EntryMedia(); entryMedia.FileName = entryMediaRequest.FileName; entryMedia.ContentType = entryMediaRequest.ContentType; entryMedia.BlobFileName = Guid.NewGuid(); entryMedia.EntryContentId = entryContent.Id; entryMedia.MD5Base64Hash = entryMediaRequest.MD5Base64Hash; entryMedia.Created = _clock.Now; await _context.Add(entryMedia); await _context.SaveChanges(); return(entryMedia); }
// ALL ENTRIES. private List <EntryContent> getEntries() { try { List <EntryControl> controlList = new List <EntryControl>(); List <EntryContent> contentList = new List <EntryContent>(); EntryControl entry1 = new EntryControl(LABEL1, label1Box); controlList.Add(entry1); EntryControl entry2 = new EntryControl(LABEL2, label2Box); controlList.Add(entry2); EntryControl entry3 = new EntryControl(LABEL3, label3Box); controlList.Add(entry3); EntryControl entry4 = new EntryControl(LABEL4, label4Box); controlList.Add(entry4); EntryControl entry5 = new EntryControl(LABEL5, label5Box); controlList.Add(entry5); foreach (var control in controlList) { if (control.textBox.Visible == true && control.textBox.Text == string.Empty) { // Return empty list control.textBox.Focus(); contentList = new List <EntryContent>(); return(contentList); } else if (control.textBox.Visible == true && control.textBox.Text != string.Empty) { EntryContent sampleEntry = new EntryContent(control.label.Text, control.textBox.Text); contentList.Add(sampleEntry); } } return(contentList); } catch (Exception ex) { string msg = "Issue occured while retrieving entered entries. Contact system admin." + System.Environment.NewLine + ex.Message; System.Windows.Forms.MessageBox.Show(msg, "Error 03"); return(new List <EntryContent>()); } }
public async Task <EntryContent> MarkUploadSuccess(EntryContent entryContent, string uploadUrl) { if (entryContent == null) { throw new ArgumentNullException(nameof(entryContent)); } if (string.IsNullOrWhiteSpace(uploadUrl)) { throw new ArgumentNullException(nameof(uploadUrl)); } _context.Attach(entryContent); entryContent.Persisted = _clock.Now; entryContent.BlobUrl = StringUtilities.ToBase64(uploadUrl); await _context.SaveChanges(); return(entryContent); }
private ArticleEntryResponse MapEntryResponse(EntryContent result) { var links = new List <Link> { new Link { Relation = LinkRelValueObject.ARTICLE, Href = Url.Action("GetArticle", "Article", new { id = result.ArticleId }) }, new Link { Relation = LinkRelValueObject.SELF, Href = Url.Action(nameof(GetLatestArticleEntry), new { articleId = result.ArticleId }) }, new Link { Relation = LinkRelValueObject.MEDIA, Href = Url.Action("UploadMediaContent", "EntryMedia", new { entryId = result.Id }) }, }; if (!string.IsNullOrWhiteSpace(result.BlobUrl)) { var mdBlobUrl = StringUtilities.FromBase64(result.BlobUrl); links.Add(new Link { Relation = LinkRelValueObject.MD_BLOB_URL, Href = mdBlobUrl }); } if (!string.IsNullOrWhiteSpace(result.ConvertedBlobUrl)) { var convertedBlobUrl = StringUtilities.FromBase64(result.ConvertedBlobUrl); links.Add(new Link { Relation = LinkRelValueObject.BLOB_URL, Href = convertedBlobUrl }); } return(new ArticleEntryResponse { Id = result.Id, ArticleId = result.ArticleId, Created = result.Created, Persisted = result.Persisted, Links = links.ToArray(), }); }
public EntryContent Build() { var entryContent = new EntryContent { Id = Id, ArticleId = ArticleId, Article = Article, Created = Created, EntryMedia = EntryMedia, Persisted = Persisted, BlobUrl = BlobUrl, ConvertedBlobUrl = ConvertedBlobUrl, }; foreach (var entryMedia in EntryMedia) { entryMedia.EntryContentId = entryContent.Id; entryMedia.EntryContent = entryContent; } return(entryContent); }
// 'PRINT BARCODE' CLICKED: PRINT INDEX BARCODES SHEETS FOR SELECTED INDEXES. protected void printBarcode_Click(object sender, EventArgs e) { try { // First check whether any checkbox was checked bool boxChecked = false; foreach (GridViewRow row in indexesGridView.Rows) { CheckBox chxBox = row.FindControl("cbSelect") as CheckBox; if (chxBox.Checked) { boxChecked = true; } } if (boxChecked == false) { string msg = "To print barcode, please select at least one index"; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + msg + "');", true); return; } // Hide all current html. unprintedIndexesPanel.Visible = false; if (!Page.IsValid) { return; } // Creating index barcode webpage Response.Write("<div id = 'pageToPrint' style = 'margin-top:-50px;'>"); foreach (GridViewRow row in indexesGridView.Rows) { var indexString = row.Cells[3].Text; var imgBarCode = row.FindControl("imgBarCode") as Image; CheckBox chxBox = row.FindControl("cbSelect") as CheckBox; List <EntryContent> allEntriesList = new List <EntryContent>(); if (chxBox.Checked) { if (row.RowType == DataControlRowType.DataRow) { // Get barcode Image string urlString = @"ShowCode39BarCode.ashx?code={0}&ShowText=1&Height=50"; imgBarCode.ImageUrl = string.Format(urlString, indexString.PadLeft(8, '0')); // Get operator's entries using (SqlConnection con = Helper.ConnectionObj) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT LABEL1, VALUE1, LABEL2, VALUE2, LABEL3, VALUE3," + " LABEL4, VALUE4, LABEL5, VALUE5 FROM JOB_CONFIG_INDEX" + " INNER JOIN INDEX_DATA ON JOB_CONFIG_INDEX.JOB_ID = INDEX_DATA.JOB_ID" + " WHERE INDEX_DATA.BARCODE = @indexString"; cmd.Parameters.AddWithValue("@indexString", indexString); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { int i = 0; while (reader.Read()) { int count = reader.FieldCount; while (i < count - 1) { if (reader.GetValue(i) != DBNull.Value && reader.GetValue(i + 1) != DBNull.Value) { EntryContent content = new EntryContent((string)reader.GetValue(i), (string)reader.GetValue(i + 1)); allEntriesList.Add(content); } i = i + 2; } } ViewState["allEntriesList"] = allEntriesList; } else { // Handle this } } } } // Write to index page Response.Write( "<div>" + "<div style='font-size:25px; font-weight:500;'>" + "<img src='" + imgBarCode.ImageUrl + "' height='160px' width='500px' style='margin-top:0px; '> " + "</div>" + "<div style='font-size:25px; font-weight:500; text-align:right;' >" + "<img src='" + imgBarCode.ImageUrl + "' height='160px' width='500px' style='margin-top:250px; margin-right:-180px;' class='rotate'> " + "</div>" + "</div>" + "<table style='margin-top:250px; margin-bottom:580px; margin-left:40px;'>" + "<tr>" + "<td style='font-size:25px; font-weight:500;'> Index String: </td>" + "<td style='font-size:25px; font-weight:500; padding-left:15px;'>" + indexString.ToUpper() + "</td>" + "</tr>" ); foreach (var entry in allEntriesList) { string label = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(entry.labelText.ToLower()); Response.Write( "<tr>" + "<td style='font-size:25px; font-weight:500;'>" + label + ":" + "</td>" + "<td style='font-size:25px; font-weight:500; padding-left:15px;'>" + entry.text.ToUpper() + "</td>" + "</tr>" ); } Response.Write( "<tr>" + "<td style='font-size:25px; font-weight:500;'>Date Created: </td>" + "<td style='font-size:25px; font-weight:500; padding-left:15px;'>" + DateTime.Now + "</td>" + "</tr>" + "</table>" + "</div>" ); } else { if (row.RowType == DataControlRowType.DataRow) { var indexBarcode = row.Cells[3].Text; imgBarCode.ImageUrl = ""; } } } } Response.Write("</div>"); } catch (Exception ex) { string msg = "Issue occured while attempting to setup for printing. Contact system admin." + Environment.NewLine + ex.Message; System.Windows.Forms.MessageBox.Show(msg, "Error 26"); } try { // Print generated Index sheets wepages, clear & get unprinted indexes again. ClientScript.RegisterStartupScript(this.GetType(), "PrintOperation", "printing();", true); } catch (Exception ex) { string msg = "Issue occured while attempting to print. Contact system admin." + Environment.NewLine + ex.Message; System.Windows.Forms.MessageBox.Show(msg, "27"); } }
/// <summary> /// 解压缩单个文件 /// </summary> /// <param name="OrgFile">zip文件</param> /// <param name="DestPath">目标文件夹</param> /// <param name="Entry">要解压的文件信息</param> /// <param name="Password">密码</param> /// <returns></returns> public static bool UnZipFile(string OrgFile, string DestPath, EntryContent Entry, string Password = "") { try { if (!File.Exists(OrgFile)) { return(false); } if (Entry.Name == null) { return(false); } else if (Entry.Name.Trim() == "") { return(false); } else if (!Entry.IsFile) { return(false); } if (!Directory.Exists(DestPath)) { Directory.CreateDirectory(DestPath); } ZipInputStream s = null; ZipEntry theEntry = null; string fileName; FileStream streamWriter = null; try { s = new ZipInputStream(File.OpenRead(OrgFile)); s.Password = Password; while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.Name != String.Empty) { if (theEntry.Name == Entry.Name && theEntry.IsFile && theEntry.Size != 0) { fileName = Path.Combine(DestPath, theEntry.Name); FileInfo fi = new FileInfo(fileName); if (!System.IO.Directory.Exists(fi.DirectoryName)) { System.IO.Directory.CreateDirectory(fi.DirectoryName); } streamWriter = File.Create(fileName); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } } finally { if (streamWriter != null) { streamWriter.Close(); streamWriter = null; } if (theEntry != null) { theEntry = null; } if (s != null) { s.Close(); s = null; } GC.Collect(); GC.Collect(1); } return(true); } catch (Exception ex) { ErrMsg = ex.Message; return(false); } }
/// <summary> /// 获取ZIP文件下所有文件信息 /// </summary> /// <param name="OrgFile">zip文件</param> /// <param name="Password">密码</param> /// <param name="Key">搜索条件</param> /// <returns>文件信息</returns> public static EntryContent[] ZipContent(string OrgFile, string Password = "", string Key = "") { List <ZipEntry> EntryList = new List <ZipEntry>(); try { if (File.Exists(OrgFile)) { ZipInputStream s = new ZipInputStream(File.OpenRead(OrgFile)); s.Password = Password; ZipEntry theEntry = null; try { while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.Name != String.Empty && theEntry.Name != null) { if (Key.Trim() != "") { if (IsMatch(theEntry.Name, Key)) { EntryList.Add(theEntry); } } else { EntryList.Add(theEntry); } } } } finally { if (s != null) { s.Close(); s = null; } GC.Collect(); GC.Collect(1); } } } catch (Exception ex) { ErrMsg = ex.Message; } if (EntryList.Count > 0) { EntryContent[] res = new EntryContent[EntryList.Count]; int index = 0; foreach (ZipEntry Entry in EntryList) { res[index] = new EntryContent(); res[index].Name = Entry.Name; res[index].Size = Entry.Size; res[index].CompressedSize = Entry.CompressedSize; res[index].IsFile = Entry.IsFile; res[index].IsDirectory = Entry.IsDirectory; res[index].DateTime = Entry.DateTime; res[index].Crc = Entry.Crc; index++; } return(res); } else { return(null); } }
protected override ValueTask <IOutgoingPacket> RestorePacket(int packetId) { EntryContent content = base[packetId].Content; return(new(new FromMemoryOutgoingPacket(content.Storage.Payload, (QualityOfService)(content._state & QoSState.QosMask), packetId))); }
private async Task UpdateConvertedBlobUrl(EntryContent latestEntry, string storageUrl) { latestEntry.ConvertedBlobUrl = StringUtilities.ToBase64(storageUrl); _context.Attach(latestEntry); await _context.SaveChanges(); }
public async Task FindsEntryAsExpected(Article[] articles, Guid articleIdToFind, EntryContent expectedResult = null) { var mockContext = new MockBlogApiDbContextFixture().WithQuery(articles); var dbMock = mockContext.Mock; var strategy = new GetLatestArticleEntryStrategyFixture { Context = mockContext.Build() }.Build(); var result = await strategy.FindLatestEntry(articleIdToFind); dbMock.Verify(ctx => ctx.Query <Article>(It.IsAny <string[]>())); if (expectedResult == null) { Assert.Null(result); return; } Assert.Equal(expectedResult, result); }