Ejemplo n.º 1
0
        public static async Task <HttpResponseMessage> GenerateQR(HttpRequestMessage req, TraceWriter log)
        {
            log.Info("Entering function");

            // Read the json request.
            var qrRequestJson = await req.Content.ReadAsStringAsync();

            var qrRequest = JsonConvert.DeserializeObject <SimpleVCardRequest>(qrRequestJson);

            log.Info("Request was deserialized");

            // Create the vCard string
            var vCard = "BEGIN:VCARD\n";

            vCard += $"FN:{qrRequest.Name}\n";
            vCard += $"TEL;WORK;VOICE:{qrRequest.Phone}\n";
            vCard += "END:VCARD";

            log.Info("vCard was created");

            // Generate de QRCode
            QRCodeData qrCodeData = new QRCodeData(vCard);

            qrCodeData.EccLevel = EccLevel.Q;

            log.Info("data created");

            var generator = new SvgQRCode(qrCodeData);
            var svg       = generator.Create(512);

            log.Info("svg was created");

            var response = new HttpResponseMessage()
            {
                Content    = new StringContent(svg),
                StatusCode = HttpStatusCode.OK,
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/svg+xml");

            log.Info("sending response");

            return(response);
        }
Ejemplo n.º 2
0
        private static void CreateSvgFile(DirectoryInfo root, DirectoryInfo directory)
        {
            var readme = new FileInfo(Path.Combine(directory.FullName, "Readme.md"));

            if (!readme.Exists)
            {
                return;
            }

            var url = readme.FullName;

            url = url.Replace(root.FullName, string.Empty);
            url = "https://github.com/dlemstra/talks/tree/master" + url.Replace("\\", "/");

            var data = new QRCodeData(url);

            SvgQRCode code   = new SvgQRCode(data);
            var       result = code.Create(512);

            string outputFile = Path.Combine(readme.Directory.FullName, "Readme.svg");

            File.WriteAllText(outputFile, result);
        }
Ejemplo n.º 3
0
        public void Test_Create()
        {
            QRCodeData data = new QRCodeData("QRCodeCore");

            SvgQRCode qrCode = new SvgQRCode(data);
            string    actual = qrCode.Create(128);

            string excepted = @"<svg version=""1.1"" baseProfile=""full"" width=""116"" height=""116"" xmlns=""http://www.w3.org/2000/svg"">
<rect width=""100%"" height=""100%"" fill=""#fff""/>
<rect x=""16"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""16"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""20"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""24"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""28"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""32"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""36"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""40"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""44"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""44"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""44"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""44"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""44"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""68"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""48"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""68"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""52"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""44"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""56"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""44"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""60"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""64"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""68"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""72"" y=""80"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""68"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""76"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""80"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""84"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""88"" width=""4"" height=""4"" fill=""000"" />
<rect x=""84"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""64"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""68"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""88"" y=""92"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""52"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""56"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""60"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""68"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""72"" width=""4"" height=""4"" fill=""000"" />
<rect x=""92"" y=""96"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""16"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""20"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""24"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""28"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""32"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""36"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""40"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""48"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""76"" width=""4"" height=""4"" fill=""000"" />
<rect x=""96"" y=""80"" width=""4"" height=""4"" fill=""000"" />
</svg>
".Replace("\r", "").Replace("\n", "");

            actual = actual.Replace("\r", "").Replace("\n", "");
            Assert.Equal(excepted, actual);
        }