本文整理汇总了C#中Rock.Model.BinaryFileService.ContentsToString方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileService.ContentsToString方法的具体用法?C# BinaryFileService.ContentsToString怎么用?C# BinaryFileService.ContentsToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.BinaryFileService
的用法示例。
在下文中一共展示了BinaryFileService.ContentsToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnOpen_Click
protected void btnOpen_Click( object sender, EventArgs e )
{
ceLabel.Label = "Label Contents";
btnSave.Visible = false;
int? fileId = ddlLabel.SelectedValueAsInt();
if ( fileId.HasValue )
{
hfBinaryFileId.Value = fileId.Value.ToString();
using ( var rockContext = new RockContext() )
{
var file = new BinaryFileService( rockContext ).Get( fileId.Value );
if ( file != null )
{
ceLabel.Text = file.ContentsToString();
SetLabelSize( ceLabel.Text );
ceLabel.Label = string.Format( file.FileName );
btnSave.Text = "Save " + file.FileName;
btnSave.Visible = true;
}
}
}
}
示例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 );
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;
}
示例3: OnLoad
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
if ( !Page.IsPostBack )
{
using ( var rockContext = new RockContext() )
{
int? binaryFileId = PageParameter( "BinaryFileId" ).AsIntegerOrNull();
if ( binaryFileId.HasValue )
{
hfBinaryFileId.Value = binaryFileId.Value.ToString();
pnlOpenFile.Visible = false;
btnSave.Visible = true;
btnCancel.Visible = true;
var binaryFile = new BinaryFileService( rockContext ).Get( binaryFileId.Value );
if ( binaryFile != null )
{
lTitle.Text = binaryFile.FileName;
ceLabel.Text = binaryFile.ContentsToString();
SetLabelSize( ceLabel.Text );
}
}
else
{
pnlOpenFile.Visible = true;
ddlLabel.Items.Clear();
Guid labelTypeGuid = Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid();
foreach ( var labelFile in new BinaryFileService( rockContext )
.Queryable().AsNoTracking()
.Where( f => f.BinaryFileType.Guid == labelTypeGuid )
.OrderBy( f => f.FileName ) )
{
ddlLabel.Items.Add( new ListItem( labelFile.FileName, labelFile.Id.ToString() ) );
}
ddlLabel.SelectedIndex = 0;
}
ddlDevice.Items.Clear();
var printerDeviceType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.DEVICE_TYPE_PRINTER.AsGuid() );
if ( printerDeviceType != null )
{
foreach ( var device in new DeviceService( rockContext )
.Queryable().AsNoTracking()
.Where( d =>
d.DeviceTypeValueId == printerDeviceType.Id &&
d.IPAddress != "" ) )
{
ddlDevice.Items.Add( new ListItem( device.Name, device.Id.ToString() ) );
}
if ( ddlDevice.Items.Count > 0 )
{
ddlDevice.SelectedIndex = 0;
}
}
}
SetLabelImage();
}
}