本文整理汇总了C#中Rock.Model.BinaryFileService类的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileService类的具体用法?C# BinaryFileService怎么用?C# BinaryFileService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryFileService类属于Rock.Model命名空间,在下文中一共展示了BinaryFileService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes this instance.
/// </summary>
public void Execute()
{
using ( var rockContext = new RockContext() )
{
var binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( BinaryFileGuid );
if ( binaryFile != null )
{
string guidAsString = BinaryFileGuid.ToString();
// If any attribute still has this file as a default value, don't delete it
if ( new AttributeService( rockContext ).Queryable().Any( a => a.DefaultValue == guidAsString ) )
{
return;
}
// If any attribute value still has this file as a value, don't delete it
if ( new AttributeValueService( rockContext ).Queryable().Any( a => a.Value == guidAsString ) )
{
return;
}
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
}
}
}
示例2: gBinaryFile_Delete
/// <summary>
/// Handles the Delete event of the gBinaryFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gBinaryFile_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = binaryFileService.Get( e.RowKeyId );
if ( binaryFile != null )
{
string errorMessage;
if ( !binaryFileService.CanDelete( binaryFile, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
Guid guid = binaryFile.Guid;
bool clearDeviceCache = binaryFile.BinaryFileType.Guid.Equals( Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid() );
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
if ( clearDeviceCache )
{
Rock.CheckIn.KioskDevice.FlushAll();
Rock.CheckIn.KioskLabel.Flush( guid );
}
}
BindGrid();
}
示例3: Get
public IHttpActionResult Get(int seriesId)
{
var rockContext = new RockContext();
var contentItemService = new ContentChannelService(rockContext);
var d = new DotLiquid.Context();
ContentChannel contentItem = null;
var attrService = new AttributeService(rockContext);
var dailyItems = new List<MessageArchiveItem>();
var ids = rockContext.Database.SqlQuery<int>("exec GetMessageArchivesBySeriesId @seriesId", new SqlParameter("seriesId", seriesId)).ToList();
contentItem = contentItemService.Get(11);
var items = contentItem.Items.Where(a => ids.Contains(a.Id)).ToList();
foreach (var item in items)
{
item.LoadAttributes(rockContext);
var link = GetVimeoLink(item.GetAttributeValue("VideoId"));
var newItem = new MessageArchiveItem();
newItem.Id = item.Id;
// newItem.Content = item.Content;
newItem.Content = DotLiquid.StandardFilters.StripHtml(item.Content).Replace("\n\n", "\r\n\r\n");
newItem.Date = DateTime.Parse(item.GetAttributeValue("Date")).ToShortDateString();
newItem.Speaker = item.GetAttributeValue("Speaker");
newItem.SpeakerTitle = item.GetAttributeValue("SpeakerTitle");
newItem.Title = item.Title;
newItem.VimeoLink = link;
var notesAttr = item.Attributes["MessageNotes"];
var binaryFile = new BinaryFileService(new RockContext()).Get(notesAttr.Id);
if (binaryFile != null)
newItem.Notes = binaryFile.Url;
var talkAttr = item.Attributes["TalkItOver"];
binaryFile = new BinaryFileService(new RockContext()).Get(talkAttr.Id);
if (binaryFile != null)
newItem.TalkItOver = binaryFile.Url;
dailyItems.Add(newItem);
}
return Ok(dailyItems.AsQueryable());
}
示例4: Save
/// <summary>
/// Saves the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="personId">The person identifier.</param>
/// <returns></returns>
public override bool Save( FinancialTransactionImage item, int? personId )
{
// ensure that the BinaryFile.IsTemporary flag is set to false for any BinaryFiles that are associated with this record
BinaryFileService binaryFileService = new BinaryFileService( this.RockContext );
var binaryFile = binaryFileService.Get( item.BinaryFileId );
if ( binaryFile != null && binaryFile.IsTemporary )
{
binaryFile.IsTemporary = false;
}
return base.Save( item, personId );
}
示例5: SetEditValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="configurationValues"></param>
/// <param name="value">The value.</param>
public override void SetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues, string value )
{
var fileUploader = control as Rock.Web.UI.Controls.FileUploader;
if ( fileUploader != null )
{
var binaryFile = new BinaryFileService( new RockContext() ).Get( value.AsGuid() );
if (binaryFile != null)
{
fileUploader.BinaryFileId = binaryFile.Id;
}
}
}
示例6: FormatValue
/// <summary>
/// Returns the field's current value(s)
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="value">Information about the value</param>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
/// <returns></returns>
public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
{
var binaryFileGuid = value.AsGuidOrNull();
if ( binaryFileGuid.HasValue )
{
var binaryFileService = new BinaryFileService( new RockContext() );
var binaryFileInfo = binaryFileService.Queryable().Where( a => a.Guid == binaryFileGuid.Value )
.Select( s => new
{
s.FileName,
s.MimeType,
s.Guid
} )
.FirstOrDefault();
if ( binaryFileInfo != null )
{
if ( condensed )
{
return binaryFileInfo.FileName;
}
else
{
var filePath = System.Web.VirtualPathUtility.ToAbsolute( "~/GetFile.ashx" );
// NOTE: Flash and Silverlight might crash if we don't set width and height. However, that makes responsive stuff not work
string htmlFormat = @"
<video
src='{0}?guid={1}'
class='js-media-video'
type='{2}'
controls='controls'
style='width:100%;height:100%;'
width='100%'
height='100%'
preload='auto'
>
</video>
<script>
Rock.controls.mediaPlayer.initialize();
</script>
";
var html = string.Format( htmlFormat, filePath, binaryFileInfo.Guid, binaryFileInfo.MimeType );
return html;
}
}
}
// value or binaryfile was null
return null;
}
示例7: GetEditValue
/// <summary>
/// Reads new values entered by the user for the field
/// </summary>
/// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
/// <param name="configurationValues"></param>
/// <returns></returns>
public override string GetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues )
{
var fileUploader = control as Rock.Web.UI.Controls.FileUploader;
if ( fileUploader != null )
{
var binaryFile = new BinaryFileService( new RockContext() ).Get( fileUploader.BinaryFileId ?? 0 );
if ( binaryFile != null )
{
return binaryFile.Guid.ToString();
}
}
return null;
}
示例8: FormatValue
/// <summary>
/// Returns the field's current value(s)
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="value">Information about the value</param>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
/// <returns></returns>
public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
{
var binaryFileGuid = value.AsGuidOrNull();
if ( binaryFileGuid.HasValue )
{
var binaryFileService = new BinaryFileService( new RockContext() );
var binaryFileInfo = binaryFileService.Queryable().Where( a => a.Guid == binaryFileGuid.Value )
.Select( s => new
{
s.FileName,
s.MimeType,
s.Guid
} )
.FirstOrDefault();
if ( binaryFileInfo != null )
{
if ( condensed )
{
return binaryFileInfo.FileName;
}
else
{
var filePath = System.Web.VirtualPathUtility.ToAbsolute( "~/GetFile.ashx" );
string htmlFormat = @"
<audio
src='{0}?guid={1}'
class='img img-responsive js-media-audio'
type='{2}'
controls
>
</audio>
<script>
Rock.controls.mediaPlayer.initialize();
</script>
";
var html = string.Format( htmlFormat, filePath, binaryFileInfo.Guid, binaryFileInfo.MimeType );
return html;
}
}
}
// value or binaryfile was null
return null;
}
示例9: FormatValue
/// <summary>
/// Returns the field's current value(s)
/// </summary>
/// <param name="parentControl">The parent control.</param>
/// <param name="value">Information about the value</param>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
/// <returns></returns>
public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
{
string formattedValue = string.Empty;
int id = int.MinValue;
if (Int32.TryParse( value, out id ))
{
var result = new BinaryFileService( new RockContext() )
.Queryable()
.Select( f => new { f.Id, f.FileName } )
.Where( f => f.Id == id )
.FirstOrDefault();
if ( result != null )
{
formattedValue = result.FileName;
}
}
return base.FormatValue( parentControl, formattedValue, null, condensed );
}
示例10: gBinaryFile_Delete
/// <summary>
/// Handles the Delete event of the gBinaryFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gBinaryFile_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = binaryFileService.Get( e.RowKeyId );
if ( binaryFile != null )
{
string errorMessage;
if ( !binaryFileService.CanDelete( binaryFile, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
}
BindGrid();
}
示例11: GetDailyItem
public TheDailyItem GetDailyItem(int id)
{
var rockContext = new RockContext();
var contentItemService = new ContentChannelItemService(rockContext);
ContentChannelItem i = null;
var attrService = new AttributeService(rockContext);
var dailyItem = new TheDailyItem();
i = contentItemService.Get(id);
if (i != null)
{
i.LoadAttributes();
i.Content = DotLiquid.StandardFilters.StripHtml(i.Content).Replace("\n\n", "\r\n\r\n");
var attributes = i.Attributes;
var pdfAttr = i.Attributes["PDF"];
var binaryFile = new BinaryFileService(new RockContext()).Get(pdfAttr.Id);
var pdfUrl = binaryFile.Url;
var scriptureAttr = i.Attributes["ScriptureCards"];
binaryFile = new BinaryFileService(new RockContext()).Get(scriptureAttr.Id);
var scriptureUrl = binaryFile.Url;
dailyItem = (new TheDailyItem { Id = i.Id, Title = i.Title, Content = i.Content, DailyPDF = pdfUrl, ScriptiureCards = scriptureUrl });
}
return dailyItem;
}
示例12: 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;
}
}
}
}
示例13: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
{
errorMessages = new List<string>();
var mergeFields = GetMergeFields( action );
BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );
var benevolenceRequest = benevolenceRequestService.Get( GetAttributeValue( action, "BenevolenceRequest", true ).AsGuid() );
if (benevolenceRequest == null )
{
var errorMessage = "Benevolence request could not be found.";
errorMessages.Add( errorMessage );
action.AddLogEntry( errorMessage, true );
return false;
}
var binaryFile = new BinaryFileService(rockContext).Get(GetAttributeValue( action, "Document", true ).AsGuid());
if ( binaryFile == null )
{
action.AddLogEntry( "The document to add to the benevolence request was not be found.", true );
return true; // returning true here to allow the action to run 'successfully' without a document. This allows the action to be easily used when the document is optional without a bunch of action filter tests.
}
BenevolenceRequestDocument requestDocument = new BenevolenceRequestDocument();
benevolenceRequest.Documents.Add( requestDocument );
requestDocument.BinaryFileId = binaryFile.Id;
rockContext.SaveChanges();
action.AddLogEntry( "Added document to the benevolence request." );
return true;
}
示例14: lbPrintAttendanceRoster_Click
/// <summary>
/// Handles the Click event of the lbPrintAttendanceRoster control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void lbPrintAttendanceRoster_Click( object sender, EventArgs e )
{
// NOTE: lbPrintAttendanceRoster is a full postback since we are returning a download of the roster
nbPrintRosterWarning.Visible = false;
var rockContext = new RockContext();
Dictionary<int, object> mergeObjectsDictionary = new Dictionary<int, object>();
if ( _attendees != null )
{
var personIdList = _attendees.Select( a => a.PersonId ).ToList();
var personList = new PersonService( rockContext ).GetByIds( personIdList );
foreach ( var person in personList.OrderBy( a => a.LastName ).ThenBy( a => a.NickName ) )
{
mergeObjectsDictionary.AddOrIgnore( person.Id, person );
}
}
var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );
mergeFields.Add( "Group", this._group );
var mergeTemplate = new MergeTemplateService( rockContext ).Get( this.GetAttributeValue( "AttendanceRosterTemplate" ).AsGuid() );
if ( mergeTemplate == null )
{
this.LogException( new Exception( "No Merge Template specified in block settings" ) );
nbPrintRosterWarning.Visible = true;
nbPrintRosterWarning.Text = "Unable to print Attendance Roster";
return;
}
MergeTemplateType mergeTemplateType = mergeTemplate.GetMergeTemplateType();
if ( mergeTemplateType == null )
{
this.LogException( new Exception( "Unable to determine Merge Template Type" ) );
nbPrintRosterWarning.Visible = true;
nbPrintRosterWarning.Text = "Error printing Attendance Roster";
return;
}
BinaryFile outputBinaryFileDoc = null;
var mergeObjectList = mergeObjectsDictionary.Select( a => a.Value ).ToList();
outputBinaryFileDoc = mergeTemplateType.CreateDocument( mergeTemplate, mergeObjectList, mergeFields );
// set the name of the output doc
outputBinaryFileDoc = new BinaryFileService( rockContext ).Get( outputBinaryFileDoc.Id );
outputBinaryFileDoc.FileName = _group.Name + " Attendance Roster" + Path.GetExtension( outputBinaryFileDoc.FileName ?? "" ) ?? ".docx";
rockContext.SaveChanges();
if ( mergeTemplateType.Exceptions != null && mergeTemplateType.Exceptions.Any() )
{
if ( mergeTemplateType.Exceptions.Count == 1 )
{
this.LogException( mergeTemplateType.Exceptions[0] );
}
else if ( mergeTemplateType.Exceptions.Count > 50 )
{
this.LogException( new AggregateException( string.Format( "Exceptions merging template {0}. See InnerExceptions for top 50.", mergeTemplate.Name ), mergeTemplateType.Exceptions.Take( 50 ).ToList() ) );
}
else
{
this.LogException( new AggregateException( string.Format( "Exceptions merging template {0}. See InnerExceptions", mergeTemplate.Name ), mergeTemplateType.Exceptions.ToList() ) );
}
}
var uri = new UriBuilder( outputBinaryFileDoc.Url );
var qry = System.Web.HttpUtility.ParseQueryString( uri.Query );
qry["attachment"] = true.ToTrueFalse();
uri.Query = qry.ToString();
Response.Redirect( uri.ToString(), false );
Context.ApplicationInstance.CompleteRequest();
}
示例15: masterPage_OnSave
//.........这里部分代码省略.........
page.LayoutId = ddlLayout.SelectedValueAsInt().Value;
int? orphanedIconFileId = null;
page.IconCssClass = tbIconCssClass.Text;
page.PageDisplayTitle = cbPageTitle.Checked;
page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked;
page.PageDisplayIcon = cbPageIcon.Checked;
page.PageDisplayDescription = cbPageDescription.Checked;
page.DisplayInNavWhen = ddlMenuWhen.SelectedValue.ConvertToEnumOrNull<DisplayInNavWhen>() ?? DisplayInNavWhen.WhenAllowed;
page.MenuDisplayDescription = cbMenuDescription.Checked;
page.MenuDisplayIcon = cbMenuIcon.Checked;
page.MenuDisplayChildPages = cbMenuChildPages.Checked;
page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;
page.RequiresEncryption = cbRequiresEncryption.Checked;
page.EnableViewState = cbEnableViewState.Checked;
page.IncludeAdminFooter = cbIncludeAdminFooter.Checked;
page.OutputCacheDuration = tbCacheDuration.Text.AsIntegerOrNull() ?? 0;
page.Description = tbDescription.Text;
page.HeaderContent = ceHeaderContent.Text;
// update PageContexts
foreach ( var pageContext in page.PageContexts.ToList() )
{
contextService.Delete( pageContext );
}
page.PageContexts.Clear();
foreach ( var control in phContext.Controls )
{
if ( control is RockTextBox )
{
var tbContext = control as RockTextBox;
if ( !string.IsNullOrWhiteSpace( tbContext.Text ) )
{
var pageContext = new PageContext();
pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' );
pageContext.IdParameter = tbContext.Text;
page.PageContexts.Add( pageContext );
}
}
}
// save page and it's routes
if ( page.IsValid )
{
rockContext.SaveChanges();
// remove any routes that were deleted
foreach (var deletedRouteId in deletedRouteIds )
{
var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == deletedRouteId );
if ( existingRoute != null )
{
RouteTable.Routes.Remove( existingRoute );
}
}
// ensure that there aren't any other extra routes for this page in the RouteTable
foreach (var routeTableRoute in RouteTable.Routes.OfType<Route>().Where(a => a.PageId() == page.Id))
{
if ( !editorRoutes.Any( a => a == routeTableRoute.Url ) )
{
RouteTable.Routes.Remove( routeTableRoute );
}
}
// Add any routes that were added
foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) )
{
if ( addedRoutes.Contains( pageRoute.Route ) )
{
RouteTable.Routes.AddPageRoute( pageRoute );
}
}
if ( orphanedIconFileId.HasValue )
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedIconFileId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
}
}
Rock.Web.Cache.PageCache.Flush( page.Id );
string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true );
}
}
}