/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( RockContext rockContext, Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); if ( checkInState != null ) { var family = checkInState.CheckIn.CurrentFamily; if ( family != null ) { var commonMergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null ); var groupMemberService = new GroupMemberService( rockContext ); var familyLabels = new List<Guid>(); var people = family.GetPeople( true ); foreach ( var person in people ) { var personGroupTypes = person.GetGroupTypes( true ); var groupTypes = new List<CheckInGroupType>(); // Get Primary area group types first personGroupTypes.Where( t => checkInState.ConfiguredGroupTypes.Contains( t.GroupType.Id ) ).ToList().ForEach( t => groupTypes.Add( t ) ); // Then get additional areas personGroupTypes.Where( t => !checkInState.ConfiguredGroupTypes.Contains( t.GroupType.Id ) ).ToList().ForEach( t => groupTypes.Add( t ) ); var personLabels = new List<Guid>(); foreach ( var groupType in groupTypes ) { groupType.Labels = new List<CheckInLabel>(); var groupTypeLabels = GetGroupTypeLabels( groupType.GroupType ); var PrinterIPs = new Dictionary<int, string>(); foreach ( var labelCache in groupTypeLabels ) { foreach ( var group in groupType.GetGroups( true ) ) { foreach ( var location in group.GetLocations( true ) ) { if ( labelCache.LabelType == KioskLabelType.Family ) { if ( familyLabels.Contains( labelCache.Guid ) || personLabels.Contains( labelCache.Guid ) ) { break; } else { familyLabels.Add( labelCache.Guid ); } } else if ( labelCache.LabelType == KioskLabelType.Person ) { if ( personLabels.Contains( labelCache.Guid ) ) { break; } else { personLabels.Add( labelCache.Guid ); } } var mergeObjects = new Dictionary<string, object>(); foreach ( var keyValue in commonMergeFields ) { mergeObjects.Add( keyValue.Key, keyValue.Value ); } mergeObjects.Add( "Location", location ); mergeObjects.Add( "Group", group ); mergeObjects.Add( "Person", person ); mergeObjects.Add( "People", people ); mergeObjects.Add( "GroupType", groupType ); var groupMembers = groupMemberService.Queryable().AsNoTracking() .Where( m => m.PersonId == person.Person.Id && m.GroupId == group.Group.Id ) .ToList(); mergeObjects.Add( "GroupMembers", groupMembers ); var label = new CheckInLabel( labelCache, mergeObjects ); label.FileGuid = labelCache.Guid; label.PrintFrom = checkInState.Kiosk.Device.PrintFrom; label.PrintTo = checkInState.Kiosk.Device.PrintToOverride; if ( label.PrintTo == PrintTo.Default ) { label.PrintTo = groupType.GroupType.AttendancePrintTo; } if ( label.PrintTo == PrintTo.Kiosk ) { var device = checkInState.Kiosk.Device; if ( device != null ) { label.PrinterDeviceId = device.PrinterDeviceId; } } else if ( label.PrintTo == PrintTo.Location ) { var deviceId = location.Location.PrinterDeviceId; if ( deviceId != null ) { label.PrinterDeviceId = deviceId; } } if ( label.PrinterDeviceId.HasValue ) { if ( PrinterIPs.ContainsKey( label.PrinterDeviceId.Value ) ) { label.PrinterAddress = PrinterIPs[label.PrinterDeviceId.Value]; } else { var printerDevice = new DeviceService( rockContext ).Get( label.PrinterDeviceId.Value ); if ( printerDevice != null ) { PrinterIPs.Add( printerDevice.Id, printerDevice.IPAddress ); label.PrinterAddress = printerDevice.IPAddress; } } } groupType.Labels.Add( label ); } } } } } } return true; } return false; }
private void GetGroupTypeLabels( GroupType groupType, List<CheckInLabel> labels, int labelFileTypeId, Dictionary<string, object> mergeObjects ) { //groupType.LoadAttributes(); foreach ( var attribute in groupType.Attributes ) { if ( attribute.Value.FieldType.Guid == new Guid( SystemGuid.FieldType.BINARY_FILE ) && attribute.Value.QualifierValues.ContainsKey( "binaryFileType" ) && attribute.Value.QualifierValues["binaryFileType"].Value == labelFileTypeId.ToString() ) { string attributeValue = groupType.GetAttributeValue( attribute.Key ); if ( attributeValue != null ) { int fileId = int.MinValue; if ( int.TryParse( attributeValue, out fileId ) ) { var labelCache = KioskLabel.Read( fileId ); if ( labelCache != null ) { var checkInLabel = new CheckInLabel( labelCache, mergeObjects ); checkInLabel.FileId = fileId; labels.Add( checkInLabel ); } } } } } }
private void GetGroupTypeLabels( GroupTypeCache groupType, List<CheckInLabel> labels, Dictionary<string, object> mergeObjects ) { //groupType.LoadAttributes(); foreach ( var attribute in groupType.Attributes.OrderBy( a => a.Value.Order ) ) { if ( attribute.Value.FieldType.Guid == SystemGuid.FieldType.BINARY_FILE.AsGuid() && attribute.Value.QualifierValues.ContainsKey( "binaryFileType" ) && attribute.Value.QualifierValues["binaryFileType"].Value.Equals( SystemGuid.BinaryFiletype.CHECKIN_LABEL, StringComparison.OrdinalIgnoreCase ) ) { Guid? binaryFileGuid = groupType.GetAttributeValue( attribute.Key ).AsGuidOrNull(); if ( binaryFileGuid != null ) { var labelCache = KioskLabel.Read( binaryFileGuid.Value ); if ( labelCache != null ) { var checkInLabel = new CheckInLabel( labelCache, mergeObjects ); checkInLabel.FileGuid = binaryFileGuid.Value; labels.Add( checkInLabel ); } } } } }