示例#1
0
        public static PdfPage ConvertToDL16(this PdfPage page, UrlGenerator generator, int offset, string functionDirectory)
        {
            var type   = LabelTypes.DL16;
            var width  = 282;
            var height = 95;

            var marginTop    = 36;
            var marginLeft   = 13;
            var marginRight  = 7;
            var marginBottom = 1;

            var logoWidth      = 92;
            var logoOffsetLeft = 3;
            var logoOffsetTop  = 94;

            var qrCodeSize       = 100;
            var qrCodeImageSize  = 500;
            var qrCodeOffsetLeft = 63;
            var qrCodeOffsetTop  = 97;

            var subheadingWidth      = 80;
            var subheadingOffsetLeft = 159;
            var subheadingOffsetTop  = 88;

            var cameraIconSize = 15;
            var cameraIconLeft = 248;
            var cameraIconTop  = 26;

            var idOffsetLeft = 250;
            var idOffsetTop  = 85;

            var footer3Text = "Do not remove. Reduce graffiti.\nPrint your own at pottymouth.io";
            var footer3Left = 265;
            var footer3Top  = 85;

            gfx = XGraphics.FromPdfPage(page);

            var rectangles = GetRectangles(width, height, (int)type, marginTop, marginBottom, marginLeft, marginRight);

            // Use this for debugging margins
            // gfx.DrawRectangles(pen, rectangles.ToArray());

            var totalSquaresAvailable = rectangles.Count;
            var numberOfSquresToPrint = generator.ToUri().Count;

            for (var i = 0; i < numberOfSquresToPrint; i++)
            {
                var squareToPrint = (offset + i) % totalSquaresAvailable;

                DrawQrCode(qrCodeImageSize, qrCodeSize, qrCodeOffsetLeft, qrCodeOffsetTop, rectangles[squareToPrint], generator.ToUri()[i], functionDirectory + iconPath);
                DrawImage(rectangles[squareToPrint], logoWidth, logoOffsetLeft, logoOffsetTop, functionDirectory + LogoImagePath);
                DrawImage(rectangles[squareToPrint], subheadingWidth, subheadingOffsetLeft, subheadingOffsetTop, functionDirectory + DigitalGraffitiWallPath);
                DrawImage(rectangles[squareToPrint], cameraIconSize, cameraIconLeft, cameraIconTop, functionDirectory + CameraImagePath);
                WriteCaption(generator.Guids[i].ToString().Substring(0, 6), idOffsetLeft, idOffsetTop, rectangles[squareToPrint], XBrushes.Black);
                WriteCaption(footer3Text, footer3Left, footer3Top, rectangles[squareToPrint], XBrushes.Gray, 5);
            }

            return(page);
        }
示例#2
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "api/sample")] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            var host = req.GetHost();

            var queryLogo = req.GetQueryValue("logo");

            var isBool = Boolean.TryParse(queryLogo, out bool hasLogo);

            if (!isBool && queryLogo != null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            var generator = new UrlGenerator(new Uri(host + path), 1);

            var uri = generator.ToUri().First();

            var bitmap = new QrCode().GenerateImage(uri, 50);

            var wallId = generator.Guids.First().ToString("N");

            byte[] hmac;

            var key = SampleAESKey.Key;

            hmac = AES.EncryptStringToBytes_Aes(wallId, key);

            var ms = new MemoryStream();

            if (hasLogo)
            {
                var logoPath = context.FunctionAppDirectory + LOGO_DIR;
                var logo     = new Logo(logoPath);

                ms.Position = 0;

                var qrCodeWithLogo = logo.Image.AppendImage(Image.FromStream(ms), 100, 100);
                ms = new MemoryStream();
                qrCodeWithLogo.Save(ms, ImageFormat.Jpeg);
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new ByteArrayContent(ms.ToArray());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaType);
            response.Headers.Add("Access-Control-Expose-Headers", HeaderName);
            response.Headers.Add(HeaderName, AES.ByteToString(hmac));

            return(response);
        }
示例#3
0
        public static PdfPage ConvertToDL8(this PdfPage page, UrlGenerator generator, int offset, string functionDirectory)
        {
            var type             = LabelTypes.DL8;
            var width            = 270;
            var height           = 182;
            var logoWidth        = 140;
            var logoOffsetLeft   = 35;
            var logoOffsetTop    = 160;
            var marginTop        = 41;
            var marginLeft       = 18;
            var marginRight      = 18;
            var marginBottom     = 10;
            var qrCodeSize       = 178;
            var qrCodeImageSize  = 500;
            var qrCodeOffsetTop  = 190;
            var qrCodeOffsetLeft = 80;

            gfx = XGraphics.FromPdfPage(page);

            var pen = new XPen(XColors.Black);

            var rectangles = GetRectangles(width, height, (int)type, marginTop, marginBottom, marginLeft, marginRight);

            gfx.DrawRectangles(pen, rectangles.ToArray());

            var totalSquaresAvailable = rectangles.Count;
            var numberOfSquresToPrint = generator.ToUri().Count;

            for (var i = 0; i < numberOfSquresToPrint; i++)
            {
                var squareToPrint = (offset + i) % totalSquaresAvailable;

                DrawQrCode(qrCodeImageSize, qrCodeSize, qrCodeOffsetLeft, qrCodeOffsetTop, rectangles[squareToPrint], generator.ToUri()[i], functionDirectory + iconPath);
                DrawImage(rectangles[squareToPrint], logoWidth, logoOffsetLeft, logoOffsetTop, functionDirectory + LogoImagePath);
            }

            return(page);
        }
示例#4
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "api/generate")] HttpRequestMessage req, TraceWriter log)
        {
            if (IsAuthenticated)
            {
                auth = req.GetAuthInfoAsync(log).Result;
            }

            log.Info("Is Authenticated: " + IsAuthenticated);

            var queryTracked = req.GetQueryValue("tracked");

            var title = req.GetQueryValue("title");

            var queryLogo = req.GetQueryValue("logo");

            var queryLatitude = req.GetQueryValue("latitude");

            var queryLongitude = req.GetQueryValue("longitude");

            var queryWallToken = req.GetQueryValue("wallToken");

            var wallToken = DecryptWallToken(queryWallToken);

            var isTracked = Boolean.TryParse(queryTracked, out bool tracked);

            var logoParsed = Boolean.TryParse(queryTracked, out bool hasLogo);

            var isLatitude = double.TryParse(queryLatitude, out double latitude);

            var isLongitude = double.TryParse(queryLongitude, out double longitude);

            var isWallId = Guid.TryParse(wallToken, out Guid wallId);

            //There's no validation on the values
            if (!isTracked || !logoParsed || (!isLatitude && queryLatitude != null) || (!isLongitude && queryLongitude != null) || !isWallId)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            var wallPath = string.Format($"{wallId.ToString("N")}/wall");

            var wallblob = BlobStorage.GetBlob(Constants.BlobContainerNames.Wall, wallPath);

            var contents = new WallEntity(new Message {
                Text = Constants.Default.Wall.WelcomeMessage, Username = Constants.Default.Wall.User
            });

            var json = JsonConvert.SerializeObject(contents);

            wallblob.UploadText(json);

            var wall = new Walls(wallId.ToString("N"), latitude, longitude, title);

            TableStorage.Insert(Constants.TableNames.Walls, wall);

            var host = req.GetHost();

            var generator = new UrlGenerator(new Uri(host + path), 1);

            var uri = generator.ToUri().First();

            var bitmap = new QrCode().GenerateImage(uri, 50);

            var qrCodePath = string.Format($"{wallId.ToString("N")}/qrCode");

            var container = BlobStorage.GetContainer(Constants.BlobContainerNames.Wall);

            var qrCodeBlob = container.GetBlockBlobReference(qrCodePath);

            qrCodeBlob.Properties.ContentType = "image/jpeg";

            var ms = new MemoryStream();

            bitmap.Save(ms, ImageFormat.Jpeg);

            qrCodeBlob.UploadFromStream(ms);

            log.Info("Image uploaded to: " + qrCodeBlob.Uri.AbsoluteUri);

            if (tracked && IsAuthenticated)
            {
                var name   = auth.GetClaim(ClaimTypes.Name).Value;
                var nameId = auth.GetClaim(ClaimTypes.NameIdentifier).Value;
                var user   = new Users(name, nameId);
                TableStorage.Insert(Constants.TableNames.Users, user);

                var trackedWall = new Tracked(nameId, wallId.ToString("N"));
                TableStorage.Insert(Constants.TableNames.Tracked, trackedWall);
            }

            if (tracked)
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { Created = DateTime.UtcNow, WallId = wallId.ToString("N") }));
            }
            else
            {
                return(req.CreateResponse(HttpStatusCode.OK, new { Created = DateTime.UtcNow }));
            }
        }