Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #4
0
        public void url_should_add_http()
        {
            var url = "code-bude.net";

            var generator = new PayloadGenerator.Url(url);

            generator.ToString().ShouldBe("http://code-bude.net");
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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"));
        }
Пример #8
0
        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);
        }
Пример #9
0
        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"));
        }
Пример #10
0
        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));
        }