public static async Task <WriteableBitmap> GenerateQRCodeAsync(string content, MyColor darkColor, MyColor lightColor = null) { if (darkColor == null) { throw new ArgumentNullException(nameof(darkColor)); } var payload = new PayloadGenerator.Url(content ?? string.Empty); byte[] GetRGB(MyColor c) => new[] { c.R, c.G, c.B }; using (var generator = new QRCodeGenerator()) using (var data = generator.CreateQrCode(payload.ToString(), ECCLevel.Q)) using (var code = new BitmapByteQRCode(data)) using (var stream = new InMemoryRandomAccessStream()) using (var writer = new DataWriter(stream.GetOutputStreamAt(0))) { var darkRGB = GetRGB(darkColor); var lightRGB = lightColor == null ? new[] { Byte.MaxValue, Byte.MaxValue, Byte.MaxValue, } : GetRGB(lightColor); writer.WriteBytes(code.GetGraphic(20, darkRGB, lightRGB)); await writer.StoreAsync(); var bitmap = new WriteableBitmap(1024, 1024); await bitmap.SetSourceAsync(stream); return(bitmap); } }
public async Task <CreateRetrospectiveCommandResponse> Handle(CreateRetrospectiveCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } string?HashOptionalPassphrase(string?plainText) { return(!String.IsNullOrEmpty(plainText) ? this._passphraseService.CreateHashedPassphrase(plainText) : null); } using var qrCodeGenerator = new QRCodeGenerator(); var retrospective = new Retrospective { CreationTimestamp = this._systemClock.CurrentTimeOffset, Title = request.Title, HashedPassphrase = HashOptionalPassphrase(request.Passphrase), FacilitatorHashedPassphrase = HashOptionalPassphrase(request.FacilitatorPassphrase) ?? throw new InvalidOperationException("No facilitator passphrase given"), }; this._logger.LogInformation($"Creating new retrospective with id {retrospective.UrlId}"); string retroLocation = this._urlGenerator.GenerateUrlToRetrospectiveLobby(retrospective.UrlId).ToString(); var payload = new PayloadGenerator.Url(retroLocation); var result = new CreateRetrospectiveCommandResponse( retrospective.UrlId, new QrCode(qrCodeGenerator.CreateQrCode(payload.ToString(), QRCodeGenerator.ECCLevel.L)), retroLocation); this._returnDbContext.Retrospectives.Add(retrospective); await this._returnDbContext.SaveChangesAsync(cancellationToken); return(result); }
private async Task CreateQR(int index) { this.tb2.Text = "PDU-ID: " + index; var url = string.Format(UrlTextBox.Text, index); var qrGenerator = new QRCodeGenerator(); var payload = new PayloadGenerator.Url(url); var dark = new[] { byte.MinValue, byte.MinValue, byte.MinValue }; var light = new[] { byte.MaxValue, byte.MaxValue, byte.MaxValue }; var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); var qrCode = new BitmapByteQRCode(qrCodeData); var qrCodeImage = qrCode.GetGraphic(20, dark, light); using (var stream = new InMemoryRandomAccessStream()) { using (var writer = new DataWriter(stream.GetOutputStreamAt(0))) { writer.WriteBytes(qrCodeImage); await writer.StoreAsync(); } var image = new BitmapImage(); await image.SetSourceAsync(stream); QRImage.Source = image; } }
public async Task ArmaHello(ArmaHelloMessage message) { var ua = Context.GetHttpContext().Request.Headers["User-Agent"]; if (!ua.Any(u => u.Contains("cTabExtension/1."))) { _logger.LogWarning($"ArmaHello was not sent by Extension, but by '{string.Join(", ", ua)}'"); return; } var state = _service.GetOrCreateStateBySteamIdAndKey(message.SteamId, message.Key, new Uri(Context.GetHttpContext().Request.GetEncodedUrl()).DnsSafeHost); Context.Items[nameof(PlayerState)] = state; Context.Items[nameof(ConnectionKind)] = ConnectionKind.Arma; Interlocked.Increment(ref state.ActiveArmaConnections); await Groups.AddToGroupAsync(Context.ConnectionId, state.ArmaChannelName); var uri = _publicUri.GetPublicAdress(Context.GetHttpContext()); var generator = new PayloadGenerator.Url(new Uri(new Uri(uri), "/?t=" + state.Token).AbsoluteUri); var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(generator.ToString(), QRCodeGenerator.ECCLevel.Q); var data = $"[['{new QrFontCode(qrCodeData).GetString().Replace("\n", "','")}'],'{uri}']"; await Clients.Caller.SendAsync("Callback", "Connected", data); await _tacMapService.UpdateTacMapInterconnect(state); }
private byte[] GetQrCodeBytes(string url) { var payload = new PayloadGenerator.Url(url); var qrCode = new BitmapByteQRCode(_qrGenerator.CreateQrCode(payload)); var bytes = qrCode.GetGraphic(3); return(bytes); }
public void url_should_add_http() { var url = "code-bude.net"; var generator = new PayloadGenerator.Url(url); generator.ToString().ShouldBe("http://code-bude.net"); }
public static Bitmap GenBitmapFromUrl(string msg) { var payload = new PayloadGenerator.Url(msg); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); return(qrCodeImage); }
public static string GenStringFromUrl(string msg) { var payload = new PayloadGenerator.Url(msg); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); Base64QRCode qrCode = new Base64QRCode(qrCodeData); string qrCodeImageAsBase64 = qrCode.GetGraphic(20); return(qrCodeImageAsBase64); }
public static byte[] GenPngByteFromUrl(string msg) { var payload = new PayloadGenerator.Url(msg); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); PngByteQRCode qrCode = new PngByteQRCode(qrCodeData); byte[] qrCodeAsPngByteArr = qrCode.GetGraphic(20); return(qrCodeAsPngByteArr); }
public Bitmap CreateWithoutImage(string url) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); PayloadGenerator.Url payload = new PayloadGenerator.Url(url); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload.ToString(), QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, true); return(qrCodeImage); }
// use URL payload (opens the specified url) private void button6_Click(object sender, EventArgs e) { var payload = new PayloadGenerator.Url("https://rcb.co.il"); var qrCodeData = new QRCodeGenerator().CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); var qrCode = new QRCode(qrCodeData); var qrCodeImage = qrCode.GetGraphic(20); qrCodeImage.Save(string.Format(QR_OUTPUT_TEMPLATE, "6"), ImageFormat.Jpeg); pictureBox1.Image = qrCodeImage; }
public Bitmap QRGenerate(string url) { PayloadGenerator.Url generator = new PayloadGenerator.Url(url); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); return(qrCodeImage); }
public IActionResult GetQrCodeForJoiningGame(GameId gameId) { var qrGenerator = new QRCodeGenerator(); var host = Request.Host; var payload = new PayloadGenerator.Url($"{host}/gameControl/{gameId}/Anonymous"); var qrCodeData = qrGenerator.CreateQrCode(payload); var qrCode = new SvgQRCode(qrCodeData); var qrCodeText = qrCode.GetGraphic(10); var qrCodeBytes = Encoding.UTF8.GetBytes(qrCodeText); return(File(qrCodeBytes, "image/svg+xml")); }
public IActionResult Join(Guid gameId) { var generator = new PayloadGenerator.Url($"{Request.Scheme}://{Request.Host}{Request.PathBase}/client/{gameId}"); var payload = generator.ToString(); var qrGenerator = new QRCodeGenerator(); var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); var qrCode = new SvgQRCode(qrCodeData); var qrCodeAsSvg = qrCode.GetGraphic(5); return(Content(qrCodeAsSvg, "image/svg+xml; charset=utf-8")); }
private Bitmap renderQRCode() { string url = Request.Url.ToString(); PayloadGenerator.Url myUrl = new PayloadGenerator.Url(url); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(myUrl.ToString(), QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); //Bitmap qrCodeImage = qrCode.GetGraphic(20); Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkRed, Color.PaleGreen, true); return(qrCodeImage); }
public string GenerateQrCode(string actionName, string docNumber) { string text = $"https://edoc.ady.az/History/{actionName}?documentId={docNumber}"; PayloadGenerator.Url generator = new PayloadGenerator.Url(text); string payload = generator.ToString(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeAsBitmap = qrCode.GetGraphic(20); qrCodeAsBitmap.Save(HttpContext.Current.Server.MapPath($"/Template/{docNumber}.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg); return(HttpContext.Current.Server.MapPath($"/Template/{docNumber}.jpeg")); }
private Bitmap GenerateQRCode() { PayloadGenerator.Url lcUrl; String lcPayLoad; QRCodeGenerator lcQRCodeGenerator; QRCodeData lcQRCodeData; QRCode lcQRCode; lcUrl = new PayloadGenerator.Url(clUrl); lcPayLoad = lcUrl.ToString(); lcQRCodeGenerator = new QRCodeGenerator(); lcQRCodeData = lcQRCodeGenerator.CreateQrCode(lcPayLoad, QRCodeGenerator.ECCLevel.Q); lcQRCode = new QRCode(lcQRCodeData); return(lcQRCode.GetGraphic(clPixelPerModule)); }
public void OnGet() { Guid guid; if (!string.IsNullOrEmpty(Id) && Guid.TryParse(Id, out guid)) { GroupId = guid.ToString(); QRUrl = Request.Scheme + "://" + Request.Host + "/" + GroupId; var qrGenerator = new QRCodeGenerator(); var urlPayload = new PayloadGenerator.Url(QRUrl); var qrCodeData = qrGenerator.CreateQrCode(urlPayload, QRCodeGenerator.ECCLevel.Q); var qrCode = new Base64QRCode(qrCodeData); QRCode = qrCode.GetGraphic(4); } }
internal static byte[] GetQrImageDataForUrl(string url, ImageFormat imageFormat) { PayloadGenerator.Url payload = new PayloadGenerator.Url(url); QRCodeGenerator qrCodeGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); var qrBitmap = qrCode.GetGraphic(20); byte[] data; using (var stream = new MemoryStream()) { qrBitmap.Save(stream, imageFormat); data = stream.ToArray(); } return(data); }
private static void Generate(int i, AsymmetricKeyParameter privKey, AsymmetricKeyParameter pubKey) { (var voucherOtc, var voucherPassword) = GenerateVouchers(privKey, pubKey); var qrGenerator = new QRCodeGenerator(); using (var outDoc = new PdfDocument()) { outDoc.Info.Title = "WOM vouchers"; var outPage = outDoc.AddPage(); using (var gfx = XGraphics.FromPdfPage(outPage)) { var xfont = new XFont("Open Sans", 30, XFontStyle.Bold, XPdfFontOptions.UnicodeDefault); gfx.DrawString($"Vouchers {i}", xfont, XBrushes.Black, new XRect(0, 0, outPage.Width, outPage.Height * 0.1), XStringFormats.Center); gfx.DrawString(voucherPassword, xfont, XBrushes.Black, new XRect(0, outPage.Height * 0.75, outPage.Width, outPage.Height * 0.25), XStringFormats.Center); var payloadGenerator = new PayloadGenerator.Url(string.Format("https://wom.social/vouchers/{0:D}", voucherOtc)); var qrData = qrGenerator.CreateQrCode(payloadGenerator); using (var pngData = new PngByteQRCode(qrData)) { var pngBytes = pngData.GetGraphic(20); using (var pngByteStream = new MemoryStream(pngBytes)) { using (var qrImage = XImage.FromStream(pngByteStream)) { var w = outPage.Width * 0.8; var h = outPage.Height * 0.6; var finalSize = (w <= h) ? w : h; gfx.DrawImage(qrImage, (outPage.Width - finalSize) / 2f, outPage.Height * 0.2, finalSize, finalSize); } } } outDoc.Save($"output-{i}.pdf"); } } }
private async Task DoLogin() { var idReq = new TLRequestExportLoginToken() { ApiHash = TdConfig.api_hash, ApiId = TdConfig.api_id, ExceptIds = new TLVector <int>(Array.Empty <int>()) }; var clid = await Static.tgClient.SendRequestAsync <TLAbsLoginToken>(idReq); var link = $"tg://login?token={Base64Url.Encode(clid.Serialize())}"; // Generate QR var payload = new PayloadGenerator.Url(link); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20, System.Drawing.Color.White, System.Drawing.Color.Black, true); // Tizen stupid qrCodeImage.Save("_TempQR.png"); QrImage.Source = ImageSource.FromFile("_TempQR.png"); File.Delete("_TempQR.png"); }
internal static void GetBody(EmendamentiDto emendamento, AttiDto atto, IEnumerable <FirmeDto> firme, PersonaDto currentUser, bool enableQrCode, ref string body) { try { var firmeDtos = firme.ToList(); body = body.Replace("{lblTitoloEMView}", emendamento.N_EM); if (string.IsNullOrEmpty(emendamento.EM_Certificato)) { //EM TEMPORANEO var bodyTemp = GetTemplate(TemplateTypeEnum.FIRMA); GetBodyTemporaneo(emendamento, atto, ref bodyTemp); body = body.Replace("{ltEMView}", bodyTemp); body = body.Replace("{ltTestoModificabile}", "").Replace("{TESTOMOD_COMMENTO_START}", "<!--") .Replace("{TESTOMOD_COMMENTO_END}", "-->"); body = body.Replace("{lblFattoProprioDa}", "").Replace("{FATTOPROPRIO_COMMENTO_START}", "<!--") .Replace("{FATTOPROPRIO_COMMENTO_END}", "-->"); } else { body = body.Replace("{ltEMView}", emendamento.EM_Certificato); #region Emendamento Fatto Proprio Da body = emendamento.UIDPersonaProponenteOLD.HasValue ? body.Replace("{lblFattoProprioDa}", $"L'emendamento ritirato è stato fatto proprio da {emendamento.PersonaProponente.DisplayName}") .Replace("{FATTOPROPRIO_COMMENTO_START}", string.Empty) .Replace("{FATTOPROPRIO_COMMENTO_END}", string.Empty) : body.Replace("{lblFattoProprioDa}", string.Empty) .Replace("{FATTOPROPRIO_COMMENTO_START}", "<!--") .Replace("{FATTOPROPRIO_COMMENTO_END}", "-->"); #endregion #region Testo Modificabile body = !string.IsNullOrEmpty(emendamento.TestoEM_Modificabile) ? body.Replace("{ltTestoModificabile}", emendamento.TestoEM_Modificabile) .Replace("{TESTOMOD_COMMENTO_START}", string.Empty) .Replace("{TESTOMOD_COMMENTO_END}", string.Empty) : body.Replace("{ltTestoModificabile}", string.Empty) .Replace("{TESTOMOD_COMMENTO_START}", "<!--") .Replace("{TESTOMOD_COMMENTO_END}", "-->"); #endregion } #region Firme if (emendamento.IDStato >= (int)StatiEnum.Depositato) { //DEPOSITATO body = body.Replace("{lblDepositoEMView}", firmeDtos.Any(s => s.ufficio) ? "Emendamento Depositato d'ufficio" : $"Emendamento Depositato il {Convert.ToDateTime(emendamento.DataDeposito):dd/MM/yyyy HH:mm}"); var firmeAnte = firmeDtos.Where(f => f.Timestamp <= Convert.ToDateTime(emendamento.DataDeposito)); var firmePost = firmeDtos.Where(f => f.Timestamp > Convert.ToDateTime(emendamento.DataDeposito)); if (firmeAnte.Any()) { body = body.Replace("{radGridFirmeView}", GetFirmatariEM(firmeAnte)) .Replace("{FIRMEANTE_COMMENTO_START}", string.Empty) .Replace("{FIRMEANTE_COMMENTO_END}", string.Empty); } else { body = body.Replace("{radGridFirmeView}", string.Empty) .Replace("{FIRME_COMMENTO_START}", "<!--").Replace("{FIRME_COMMENTO_END}", "-->"); } var TemplatefirmePOST = @"<div> <div style='width:100%;'> <h5>Firme dopo il deposito</h5> </div> <div style='text-align:left'> {firme} </div> </div>"; if (firmePost.Any()) { body = body.Replace("{radGridFirmePostView}", TemplatefirmePOST.Replace("{firme}", GetFirmatariEM(firmePost))) .Replace("{FIRME_COMMENTO_START}", string.Empty) .Replace("{FIRME_COMMENTO_END}", string.Empty); } else { body = body.Replace("{radGridFirmePostView}", string.Empty) .Replace("{FIRME_COMMENTO_START}", "<!--").Replace("{FIRME_COMMENTO_END}", "-->"); } } else { //FIRMATO MA NON DEPOSITATO var firmatari = GetFirmatariEM(firmeDtos); if (!string.IsNullOrEmpty(firmatari)) { body = body.Replace("{lblDepositoEMView}", string.Empty); body = body.Replace("{radGridFirmeView}", firmatari) .Replace("{FIRMEANTE_COMMENTO_START}", string.Empty) .Replace("{FIRMEANTE_COMMENTO_END}", string.Empty); body = body.Replace("{radGridFirmePostView}", string.Empty) .Replace("{FIRME_COMMENTO_START}", "<!--") .Replace("{FIRME_COMMENTO_END}", "-->"); } else { body = body.Replace("{lblDepositoEMView}", string.Empty); body = body.Replace("{FIRMEANTE_COMMENTO_START}", "<!--") .Replace("{FIRMEANTE_COMMENTO_END}", "-->"); body = body.Replace("{radGridFirmePostView}", string.Empty) .Replace("{FIRME_COMMENTO_START}", "<!--") .Replace("{FIRME_COMMENTO_END}", "-->"); } } #endregion body = body.Replace("{lblNotePubblicheEMView}", !string.IsNullOrEmpty(emendamento.NOTE_Griglia) ? $"Note: {emendamento.NOTE_Griglia}" : string.Empty) .Replace("{NOTE_PUBBLICHE_COMMENTO_START}", !string.IsNullOrEmpty(emendamento.NOTE_Griglia) ? string.Empty : "<!--").Replace( "{NOTE_PUBBLICHE_COMMENTO_END}", !string.IsNullOrEmpty(emendamento.NOTE_Griglia) ? string.Empty : "-->"); if (currentUser != null) { if (currentUser.CurrentRole == RuoliIntEnum.Segreteria_Assemblea && !string.IsNullOrEmpty(emendamento.NOTE_EM)) { body = body.Replace("{lblNotePrivateEMView}", $"Note Riservate: {emendamento.NOTE_EM}").Replace("{NOTEPRIV_COMMENTO_START}", string.Empty).Replace("{NOTEPRIV_COMMENTO_END}", string.Empty); } else { body = body.Replace("{lblNotePrivateEMView}", string.Empty) .Replace("{NOTEPRIV_COMMENTO_START}", "<!--") .Replace("{NOTEPRIV_COMMENTO_END}", "-->"); } } else { body = body.Replace("{lblNotePrivateEMView}", string.Empty) .Replace("{NOTEPRIV_COMMENTO_START}", "<!--") .Replace("{NOTEPRIV_COMMENTO_END}", "-->"); } var textQr = string.Empty; if (enableQrCode) { var nameFileQrCode = $"QR_{emendamento.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.png"; //QRCODE var qrFilePathComplete = Path.Combine(AppSettingsConfiguration.CartellaTemp, nameFileQrCode); //QRCODE var qrLink = $"{AppSettingsConfiguration.urlPEM_ViewEM}{emendamento.UID_QRCode}"; var qrGenerator = new QRCodeGenerator(); var urlPayload = new PayloadGenerator.Url(qrLink); var qrData = qrGenerator.CreateQrCode(urlPayload, QRCodeGenerator.ECCLevel.Q); var qrCode = new QRCode(qrData); using (var qrCodeImage = qrCode.GetGraphic(20)) { qrCodeImage.Save(qrFilePathComplete); } textQr = $"<img src=\"{qrFilePathComplete}\" style=\"height:100px; width:100px; border=0;\" />"; } body = body.Replace("{QRCode}", textQr); } catch (Exception e) { Log.Error("GetBodyPDF", e); throw e; } }