Cached Check-in Label
Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInPersonSummary" /> class.
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="schedule">The schedule.</param>
        /// <param name="groupType">Type of the group.</param>
        /// <param name="group">The group.</param>
        /// <param name="location">The location.</param>
        public CheckInPersonSummary(KioskLabel label, CheckInSchedule schedule, CheckInGroupType groupType, CheckInGroup group, CheckInLocation location)
            : this(schedule, groupType, group, location)
        {
            if (groupType != null && groupType.GroupType != null && label != null)
            {
                if (groupType.GroupType.Attributes == null)
                {
                    // shouldn't happen since GroupType is a ModelCache<,> type
                    return;
                }

                foreach (var attribute in groupType.GroupType.Attributes.OrderBy(a => a.Value.Order))
                {
                    if (attribute.Value.FieldType.Guid == SystemGuid.FieldType.LABEL.AsGuid())
                    {
                        Guid?binaryFileGuid = groupType.GroupType.GetAttributeValue(attribute.Key).AsGuidOrNull();
                        if (binaryFileGuid.HasValue && binaryFileGuid.Value == label.Guid)
                        {
                            GroupTypeConfiguredForLabel = true;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInPersonSummary" /> class.
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="schedule">The schedule.</param>
        /// <param name="groupType">Type of the group.</param>
        /// <param name="group">The group.</param>
        /// <param name="location">The location.</param>
        public CheckInPersonSummary(KioskLabel label, CheckInSchedule schedule, CheckInGroupType groupType, CheckInGroup group, CheckInLocation location)
            : this(schedule, groupType, group, location)
        {
            if (groupType != null && groupType.GroupType != null && label != null)
            {
                if (groupType.GroupType.Attributes == null)
                {
                    groupType.GroupType.LoadAttributes();
                }

                foreach (var attribute in groupType.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.GroupType.GetAttributeValue(attribute.Key).AsGuidOrNull();
                        if (binaryFileGuid.HasValue && binaryFileGuid.Value == label.Guid)
                        {
                            GroupTypeConfiguredForLabel = true;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInLabel" /> class.
        /// </summary>
        /// <param name="kioskLabel">The label.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        public CheckInLabel(KioskLabel kioskLabel, Dictionary <string, object> mergeObjects)
        {
            LabelKey  = kioskLabel.Guid.ToString();
            LabelFile = kioskLabel.Url;

            MergeFields = new Dictionary <string, string>();
            foreach (var item in kioskLabel.MergeFields)
            {
                MergeFields.Add(item.Key, item.Value.ResolveMergeFields(mergeObjects));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInLabel" /> class.
        /// </summary>
        /// <param name="kioskLabel">The label.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        public CheckInLabel(KioskLabel kioskLabel, Dictionary <string, object> mergeObjects)
        {
            LabelKey  = kioskLabel.Guid.ToString();
            LabelFile = kioskLabel.Url;
            Order     = kioskLabel.Order;

            MergeFields = new Dictionary <string, string>();
            foreach (var item in kioskLabel.MergeFields)
            {
                MergeFields.Add(item.Key, item.Value.ResolveMergeFields(mergeObjects));
                MergeFields[item.Key] = HttpUtility.HtmlDecode(MergeFields[item.Key]);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInLabel" /> class.
        /// </summary>
        /// <param name="kioskLabel">The label.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        public CheckInLabel( KioskLabel kioskLabel, Dictionary<string, object> mergeObjects )
        {
            LabelKey = kioskLabel.Guid.ToString();
            LabelFile = kioskLabel.Url;
            Order = kioskLabel.Order;

            MergeFields = new Dictionary<string, string>();
            foreach ( var item in kioskLabel.MergeFields )
            {
                MergeFields.Add( item.Key, item.Value.ResolveMergeFields( mergeObjects ) );
                MergeFields[item.Key] = HttpUtility.HtmlDecode( MergeFields[item.Key] );
            }
        }
Beispiel #6
0
 /// <summary>
 /// Sets the options.
 /// </summary>
 /// <param name="label">The label.</param>
 public void SetOptions(KioskLabel label)
 {
     _selectedOptions = new List <CheckInPersonSummary>();
     foreach (var schedule in SelectedSchedules.Where(s => s.StartTime.HasValue).OrderBy(s => s.StartTime))
     {
         var groupType = SelectedGroupTypes(schedule).FirstOrDefault();
         if (groupType != null)
         {
             var group = groupType.SelectedGroups(schedule).FirstOrDefault();
             if (group != null)
             {
                 var location = group.SelectedLocations(schedule).FirstOrDefault();
                 if (location != null)
                 {
                     _selectedOptions.Add(new CheckInPersonSummary(label, schedule, groupType, group, location));
                 }
             }
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Reads the specified label by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static KioskLabel Read( int id )
        {
            string cacheKey = KioskLabel.CacheKey( id );

            ObjectCache cache = MemoryCache.Default;
            KioskLabel label = cache[cacheKey] as KioskLabel;

            if ( label != null )
            {
                return label;
            }
            else
            {
                var file = new BinaryFileService( new RockContext() ).Get( id );
                if ( file != null )
                {
                    label = new KioskLabel();

                    label.Guid = file.Guid;
                    label.Url = string.Format( "{0}GetFile.ashx?id={1}", System.Web.VirtualPathUtility.ToAbsolute( "~" ), file.Id );
                    label.MergeFields = new Dictionary<string, string>();
                    label.FileContent = System.Text.Encoding.Default.GetString( file.Data.Content );

                    file.LoadAttributes();
                    string attributeValue = file.GetAttributeValue( "MergeCodes" );
                    if ( !string.IsNullOrWhiteSpace( attributeValue ) )
                    {
                        string[] nameValues = attributeValue.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
                        foreach ( string nameValue in nameValues )
                        {
                            string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
                            if ( nameAndValue.Length == 2 && !label.MergeFields.ContainsKey( nameAndValue[0] ) )
                            {
                                label.MergeFields.Add( nameAndValue[0], nameAndValue[1] );

                                int definedValueId = int.MinValue;
                                if ( int.TryParse( nameAndValue[1], out definedValueId ) )
                                {
                                    var definedValue = DefinedValueCache.Read( definedValueId );
                                    if ( definedValue != null )
                                    {
                                        string mergeField = definedValue.GetAttributeValue( "MergeField" );
                                        if ( mergeField != null )
                                        {
                                            label.MergeFields[nameAndValue[0]] = mergeField;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var cachePolicy = new CacheItemPolicy();
                    cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds( 60 );
                    cache.Set( cacheKey, label, cachePolicy );

                    return label;
                }
            }

            return null;
        }
Beispiel #8
0
        /// <summary>
        /// Reads the specified label by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static KioskLabel Read(int id)
        {
            string cacheKey = KioskLabel.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            KioskLabel  label = cache[cacheKey] as KioskLabel;

            if (label != null)
            {
                return(label);
            }
            else
            {
                var file = new BinaryFileService().Get(id);
                if (file != null)
                {
                    label = new KioskLabel();

                    label.Guid        = file.Guid;
                    label.Url         = string.Format("{0}GetFile.ashx?{1}", System.Web.VirtualPathUtility.ToAbsolute("~"), file.Id);
                    label.MergeFields = new Dictionary <string, string>();
                    label.FileContent = System.Text.Encoding.Default.GetString(file.Data.Content);

                    file.LoadAttributes();
                    string attributeValue = file.GetAttributeValue("MergeCodes");
                    if (!string.IsNullOrWhiteSpace(attributeValue))
                    {
                        string[] nameValues = attributeValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string nameValue in nameValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries);
                            if (nameAndValue.Length == 2 && !label.MergeFields.ContainsKey(nameAndValue[0]))
                            {
                                label.MergeFields.Add(nameAndValue[0], nameAndValue[1]);

                                int definedValueId = int.MinValue;
                                if (int.TryParse(nameAndValue[1], out definedValueId))
                                {
                                    var definedValue = DefinedValueCache.Read(definedValueId);
                                    if (definedValue != null)
                                    {
                                        string mergeField = definedValue.GetAttributeValue("MergeField");
                                        if (mergeField != null)
                                        {
                                            label.MergeFields[nameAndValue[0]] = mergeField;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var cachePolicy = new CacheItemPolicy();
                    cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
                    cache.Set(cacheKey, label, cachePolicy);

                    return(label);
                }
            }

            return(null);
        }
Beispiel #9
0
        /// <summary>
        /// Flushes the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(KioskLabel.CacheKey(id));
        }
Beispiel #10
0
        /// <summary>
        /// Reads the specified label by guid.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        /// <returns></returns>
        public static KioskLabel Read( Guid guid )
        {
            string cacheKey = KioskLabel.CacheKey( guid );

            RockMemoryCache cache = RockMemoryCache.Default;
            KioskLabel label = cache[cacheKey] as KioskLabel;

            if ( label != null )
            {
                return label;
            }
            else
            {
                using ( var rockContext = new RockContext() )
                {
                    var file = new BinaryFileService( rockContext ).Get( guid );
                    if ( file != null )
                    {
                        label = new KioskLabel();
                        label.Guid = file.Guid;
                        label.Url = string.Format( "{0}GetFile.ashx?id={1}", System.Web.VirtualPathUtility.ToAbsolute( "~" ), file.Id );
                        label.MergeFields = new Dictionary<string, string>();
                        label.FileContent = file.ContentsToString();

                        file.LoadAttributes( rockContext );

                        label.LabelType = file.GetAttributeValue( "core_LabelType" ).ConvertToEnum<KioskLabelType>();

                        string attributeValue = file.GetAttributeValue( "MergeCodes" );
                        if ( !string.IsNullOrWhiteSpace( attributeValue ) )
                        {
                            string[] nameValues = attributeValue.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
                            foreach ( string nameValue in nameValues )
                            {
                                string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
                                if ( nameAndValue.Length == 2 && !label.MergeFields.ContainsKey( nameAndValue[0] ) )
                                {
                                    label.MergeFields.Add( nameAndValue[0], nameAndValue[1] );

                                    int definedValueId = int.MinValue;
                                    if ( int.TryParse( nameAndValue[1], out definedValueId ) )
                                    {
                                        var definedValue = DefinedValueCache.Read( definedValueId );
                                        if ( definedValue != null )
                                        {
                                            string mergeField = definedValue.GetAttributeValue( "MergeField" );
                                            if ( mergeField != null )
                                            {
                                                label.MergeFields[nameAndValue[0]] = mergeField;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        cache.Set( cacheKey, label, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.Date.AddDays( 1 ) } );

                        return label;
                    }
                }
            }

            return null;
        }
Beispiel #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckInLabel" /> class.
        /// </summary>
        /// <param name="kioskLabel">The label.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        public CheckInLabel( KioskLabel kioskLabel, Dictionary<string, object> mergeObjects )
        {
            LabelKey = kioskLabel.Guid.ToString();
            LabelFile = kioskLabel.Url;

            MergeFields = new Dictionary<string, string>();
            foreach ( var item in kioskLabel.MergeFields )
            {
                MergeFields.Add( item.Key, item.Value.ResolveMergeFields( mergeObjects ) );
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckInLabel" /> class.
 /// </summary>
 /// <param name="kioskLabel">The label.</param>
 /// <param name="mergeObjects">The merge objects.</param>
 public CheckInLabel(KioskLabel kioskLabel, Dictionary <string, object> mergeObjects) :
     this(kioskLabel, mergeObjects, null)
 {
 }
Beispiel #13
0
        /// <summary>
        /// Flushes the specified guid.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        public static void Flush(Guid guid)
        {
            RockMemoryCache cache = RockMemoryCache.Default;

            cache.Remove(KioskLabel.CacheKey(guid));
        }
Beispiel #14
0
        /// <summary>
        /// Reads the specified label by guid.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        /// <returns></returns>
        public static KioskLabel Read(Guid guid)
        {
            string cacheKey = KioskLabel.CacheKey(guid);

            RockMemoryCache cache = RockMemoryCache.Default;
            KioskLabel      label = cache[cacheKey] as KioskLabel;

            if (label != null)
            {
                return(label);
            }
            else
            {
                using (var rockContext = new RockContext())
                {
                    var file = new BinaryFileService(rockContext).Get(guid);
                    if (file != null)
                    {
                        label             = new KioskLabel();
                        label.Guid        = file.Guid;
                        label.Url         = string.Format("{0}GetFile.ashx?id={1}", System.Web.VirtualPathUtility.ToAbsolute("~"), file.Id);
                        label.MergeFields = new Dictionary <string, string>();
                        label.FileContent = file.ContentsToString();

                        file.LoadAttributes(rockContext);

                        label.LabelType = file.GetAttributeValue("core_LabelType").ConvertToEnum <KioskLabelType>();

                        string attributeValue = file.GetAttributeValue("MergeCodes");
                        if (!string.IsNullOrWhiteSpace(attributeValue))
                        {
                            string[] nameValues = attributeValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string nameValue in nameValues)
                            {
                                string[] nameAndValue = nameValue.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries);
                                if (nameAndValue.Length == 2 && !label.MergeFields.ContainsKey(nameAndValue[0]))
                                {
                                    label.MergeFields.Add(nameAndValue[0], nameAndValue[1]);

                                    int definedValueId = int.MinValue;
                                    if (int.TryParse(nameAndValue[1], out definedValueId))
                                    {
                                        var definedValue = DefinedValueCache.Read(definedValueId);
                                        if (definedValue != null)
                                        {
                                            string mergeField = definedValue.GetAttributeValue("MergeField");
                                            if (mergeField != null)
                                            {
                                                label.MergeFields[nameAndValue[0]] = mergeField;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        cache.Set(cacheKey, label, new CacheItemPolicy {
                            AbsoluteExpiration = DateTimeOffset.Now.Date.AddDays(1)
                        });

                        return(label);
                    }
                }
            }

            return(null);
        }