本文整理汇总了C#中Rock.Model.BinaryFileService.LoadAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileService.LoadAttributes方法的具体用法?C# BinaryFileService.LoadAttributes怎么用?C# BinaryFileService.LoadAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.BinaryFileService
的用法示例。
在下文中一共展示了BinaryFileService.LoadAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
/// <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;
}
示例2: Read
/// <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;
}