/// <summary> /// Printers the has cutter. /// </summary> /// <param name="labels">The labels.</param> /// <returns></returns> private static bool PrinterHasCutter(List <CheckInLabel> labels) { bool hasCutter = false; var deviceId = labels.Select(a => a.PrinterDeviceId).FirstOrDefault(); if (deviceId != null) { KioskDevice kioskDevice = KioskDevice.Get(deviceId.GetValueOrDefault(), new List <int>()); hasCutter = kioskDevice.Device.GetAttributeValue(Rock.SystemKey.DeviceAttributeKey.DEVICE_HAS_CUTTER).AsBoolean(); } return(hasCutter); }
public PrintSessionLabelsResponse PrintSessionLabels([FromUri] string session, [FromUri] int?kioskId = null) { List <Guid?> sessionGuids; // // The session data is a comma separated list of Guid values. // try { sessionGuids = session.SplitDelimitedValues() .Select(a => { var guid = a.AsGuidOrNull(); // // Check if this is a standard Guid format. // if (guid.HasValue) { return(guid.Value); } return(GuidHelper.FromShortStringOrNull(a)); }) .ToList(); } catch { sessionGuids = null; } // // If no session guids were found or an error occurred trying to // parse them, then return an error. // if (sessionGuids == null || sessionGuids.Count == 0) { return(new PrintSessionLabelsResponse { Labels = new List <CheckInLabel>(), Messages = new List <string> { "No check-in sessions were specified." } }); } using (var rockContext = new RockContext()) { KioskDevice printer = null; // // If they specified a kiosk, attempt to load the printer for // that kiosk. // if (kioskId.HasValue && kioskId.Value != 0) { var kiosk = KioskDevice.Get(kioskId.Value, null); if ((kiosk?.Device?.PrinterDeviceId).HasValue) { // // We aren't technically loading a kiosk, but this lets us // load the printer IP address from cache rather than hitting // the database each time. // printer = KioskDevice.Get(kiosk.Device.PrinterDeviceId.Value, null); } } var attendanceService = new AttendanceService(rockContext); // // Retrieve all session label data from the database, then deserialize // it, then make one giant list of labels and finally order it. // var labels = attendanceService.Queryable() .AsNoTracking() .Where(a => sessionGuids.Contains(a.AttendanceCheckInSession.Guid)) .DistinctBy(a => a.AttendanceCheckInSessionId) .Select(a => a.AttendanceData.LabelData) .ToList() .Select(a => a.FromJsonOrNull <List <CheckInLabel> >()) .Where(a => a != null) .SelectMany(a => a) .OrderBy(a => a.PersonId) .ThenBy(a => a.Order) .ToList(); foreach (var label in labels) { // // If the label is being printed to the kiosk and client printing // is enabled and the client has specified their device // identifier then we need to update the label data to have the // new printer information. // if (label.PrintTo == PrintTo.Kiosk && label.PrintFrom == PrintFrom.Client && printer != null) { label.PrinterDeviceId = printer.Device.Id; label.PrinterAddress = printer.Device.IPAddress; } } var response = new PrintSessionLabelsResponse { Labels = labels.Where(l => l.PrintFrom == PrintFrom.Client).ToList() }; // // Update any labels to convert the relative URL path to an absolute URL // path for client printing. // if (response.Labels.Any()) { var urlRoot = Request.RequestUri.GetLeftPart(UriPartial.Authority); if (Request.Headers.Contains("X-Forwarded-Proto") && Request.Headers.Contains("X-Forwarded-Host")) { urlRoot = $"{Request.Headers.GetValues( "X-Forwarded-Proto" ).First()}://{Request.Headers.GetValues( "X-Forwarded-Host" ).First()}"; } #if DEBUG // This is extremely useful when debugging with ngrok and an iPad on the local network. // X-Original-Host will contain the name of your ngrok hostname, therefore the labels will // get a LabelFile url that will actually work with that iPad. if (Request.Headers.Contains("X-Forwarded-Proto") && Request.Headers.Contains("X-Original-Host")) { urlRoot = $"{Request.Headers.GetValues( "X-Forwarded-Proto" ).First()}://{Request.Headers.GetValues( "X-Original-Host" ).First()}"; } #endif response.Labels.ForEach(l => l.LabelFile = urlRoot + l.LabelFile); } var printFromServer = labels.Where(l => l.PrintFrom == PrintFrom.Server).ToList(); if (printFromServer.Any()) { var messages = ZebraPrint.PrintLabels(printFromServer); response.Messages = messages; } return(response); } }