本文整理汇总了C#中Rock.Model.CommunicationService.GetMediumDataValue方法的典型用法代码示例。如果您正苦于以下问题:C# CommunicationService.GetMediumDataValue方法的具体用法?C# CommunicationService.GetMediumDataValue怎么用?C# CommunicationService.GetMediumDataValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.CommunicationService
的用法示例。
在下文中一共展示了CommunicationService.GetMediumDataValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHtmlPreview
/// <summary>
/// Gets the HTML preview.
/// </summary>
/// <param name="communication">The communication.</param>
/// <param name="person">The person.</param>
/// <returns></returns>
public override string GetHtmlPreview( Model.Communication communication, Person person )
{
var rockContext = new RockContext();
// Requery the Communication object
communication = new CommunicationService( rockContext ).Get( communication.Id );
var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
var mergeValues = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( null );
if ( person != null )
{
mergeValues.Add( "Person", person );
var recipient = communication.Recipients.Where( r => r.PersonAlias != null && r.PersonAlias.PersonId == person.Id ).FirstOrDefault();
if ( recipient != null )
{
// Add any additional merge fields created through a report
foreach ( var mergeField in recipient.AdditionalMergeValues )
{
if ( !mergeValues.ContainsKey( mergeField.Key ) )
{
mergeValues.Add( mergeField.Key, mergeField.Value );
}
}
}
}
string message = communication.GetMediumDataValue( "Message" );
return message.ResolveMergeFields( mergeValues );
}
示例2: Send
/// <summary>
/// Sends the specified communication.
/// </summary>
/// <param name="communication">The communication.</param>
/// <exception cref="System.NotImplementedException"></exception>
public override void Send( Rock.Model.Communication communication )
{
using ( var rockContext = new RockContext() )
{
// Requery the Communication object
communication = new CommunicationService( rockContext )
.Queryable( "CreatedByPersonAlias.Person" )
.FirstOrDefault( c => c.Id == communication.Id );
if ( communication != null &&
communication.Status == Model.CommunicationStatus.Approved &&
communication.Recipients.Where( r => r.Status == Model.CommunicationRecipientStatus.Pending ).Any() &&
( !communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value.CompareTo( RockDateTime.Now ) <= 0 ) )
{
var currentPerson = communication.CreatedByPersonAlias.Person;
var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
var globalConfigValues = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( currentPerson );
// From - if none is set, use the one in the Organization's GlobalAttributes.
string fromAddress = communication.GetMediumDataValue( "FromAddress" );
if ( string.IsNullOrWhiteSpace( fromAddress ) )
{
fromAddress = globalAttributes.GetValue( "OrganizationEmail" );
}
string fromName = communication.GetMediumDataValue( "FromName" );
if ( string.IsNullOrWhiteSpace( fromName ) )
{
fromName = globalAttributes.GetValue( "OrganizationName" );
}
// Resolve any possible merge fields in the from address
fromAddress = fromAddress.ResolveMergeFields( globalConfigValues, currentPerson );
fromName = fromName.ResolveMergeFields( globalConfigValues, currentPerson );
MailMessage message = new MailMessage();
message.From = new MailAddress( fromAddress, fromName );
// Reply To
string replyTo = communication.GetMediumDataValue( "ReplyTo" );
if ( !string.IsNullOrWhiteSpace( replyTo ) )
{
message.ReplyToList.Add( new MailAddress( replyTo ) );
}
CheckSafeSender( message, globalAttributes );
// CC
string cc = communication.GetMediumDataValue( "CC" );
if ( !string.IsNullOrWhiteSpace( cc ) )
{
foreach ( string ccRecipient in cc.SplitDelimitedValues() )
{
message.CC.Add( new MailAddress( ccRecipient ) );
}
}
// BCC
string bcc = communication.GetMediumDataValue( "BCC" );
if ( !string.IsNullOrWhiteSpace( bcc ) )
{
foreach ( string bccRecipient in bcc.SplitDelimitedValues() )
{
message.Bcc.Add( new MailAddress( bccRecipient ) );
}
}
message.IsBodyHtml = true;
message.Priority = MailPriority.Normal;
using ( var smtpClient = GetSmtpClient() )
{
// Add Attachments
string attachmentIds = communication.GetMediumDataValue( "Attachments" );
if ( !string.IsNullOrWhiteSpace( attachmentIds ) )
{
var binaryFileService = new BinaryFileService( rockContext );
foreach ( string idVal in attachmentIds.SplitDelimitedValues() )
{
int binaryFileId = int.MinValue;
if ( int.TryParse( idVal, out binaryFileId ) )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
message.Attachments.Add( new Attachment( binaryFile.ContentStream, binaryFile.FileName ) );
}
}
}
}
var historyService = new HistoryService( rockContext );
var recipientService = new CommunicationRecipientService( rockContext );
//.........这里部分代码省略.........
示例3: Send
/// <summary>
/// Sends the specified communication.
/// </summary>
/// <param name="communication">The communication.</param>
/// <exception cref="System.NotImplementedException"></exception>
public override void Send( Rock.Model.Communication communication )
{
using ( var rockContext = new RockContext() )
{
// Requery the Communication
communication = new CommunicationService( rockContext ).Get( communication.Id );
if ( communication != null &&
communication.Status == CommunicationStatus.Approved &&
communication.Recipients.Any(r => r.Status == CommunicationRecipientStatus.Pending) &&
( !communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value.CompareTo( RockDateTime.Now ) <= 0 ) )
{
// Remove all non alpha numeric from fromValue
string fromValue = communication.GetMediumDataValue( "NoReply_FromValue" );
//Ensure that the fromValue is correct
fromValue = new string( fromValue.ToCharArray().Where( c => char.IsLetterOrDigit( c ) || char.IsWhiteSpace( c ) ).Take( 11 ).ToArray() ) ;
string senderGuid = communication.GetMediumDataValue( "SenderGuid" );
if ( !string.IsNullOrWhiteSpace( fromValue ) && !string.IsNullOrWhiteSpace( senderGuid ) )
{
string accountSid = GetAttributeValue( "SID" );
string authToken = GetAttributeValue( "Token" );
if (string.IsNullOrWhiteSpace(accountSid) || string.IsNullOrWhiteSpace(authToken))
{
throw new Exception("Either SID or Token not provided");
}
var twilio = new TwilioRestClient( accountSid, authToken );
var historyService = new HistoryService( rockContext );
int personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
int communicationEntityTypeId = EntityTypeCache.Read( "Rock.Model.Communication" ).Id;
int communicationCategoryId = CategoryCache.Read( Rock.SystemGuid.Category.HISTORY_PERSON_COMMUNICATIONS.AsGuid(), rockContext ).Id;
var sender = new PersonService( rockContext ).Get( senderGuid.AsGuid() );
var mergeFields = GlobalAttributesCache.GetMergeFields( null );
if ( sender != null )
{
mergeFields.Add( "Sender", sender );
}
bool recipientFound = true;
while ( recipientFound )
{
var recipient = Rock.Model.Communication.GetNextPending( communication.Id, rockContext );
if ( recipient != null )
{
try
{
var phoneNumber = recipient.PersonAlias.Person.PhoneNumbers
.FirstOrDefault(p => p.IsMessagingEnabled);
if ( phoneNumber != null )
{
// Create merge field dictionary
var mergeObjects = recipient.CommunicationMergeValues( mergeFields );
string message = communication.GetMediumDataValue( "NoReply_Message" );
string footer = GetAttributeValue( "footer" );
if ( communication.GetMediumDataValue( "NoReply_AppendUserInfo" ).AsBoolean() && !string.IsNullOrEmpty( footer ) )
{
message += "\n " + footer;
}
else
{
message += "\n This message was sent on behalf of {{ GlobalAttribute.OrganizationName }} from a no reply number.";
}
message = message.ReplaceWordChars();
message = message.ResolveMergeFields( mergeObjects );
string twilioNumber = phoneNumber.Number;
if ( !string.IsNullOrWhiteSpace( phoneNumber.CountryCode ) )
{
twilioNumber = "+" + phoneNumber.CountryCode + phoneNumber.Number;
}
var globalAttributes = GlobalAttributesCache.Read();
if (globalAttributes == null)
{
throw new Exception("Error getting Global Attributes");
}
string callbackUrl = globalAttributes.GetValue( "PublicApplicationRoot" ) + "Webhooks/Twilio.ashx";
var response = twilio.SendMessage( fromValue, twilioNumber, message, callbackUrl );
if (response != null)
{
recipient.Status = GetCommunicationRecipientStatus(response);
recipient.TransportEntityTypeName = GetType().FullName;
recipient.UniqueMessageId = response.Sid;
try
{
historyService.Add(new History
{
CreatedByPersonAliasId = communication.SenderPersonAliasId,
//.........这里部分代码省略.........
示例4: Send
/// <summary>
/// Sends the specified communication.
/// </summary>
/// <param name="communication">The communication.</param>
/// <exception cref="System.NotImplementedException"></exception>
public override void Send( Rock.Model.Communication communication )
{
var rockContext = new RockContext();
// Requery the Communication
communication = new CommunicationService( rockContext ).Get( communication.Id );
if ( communication != null &&
communication.Status == Model.CommunicationStatus.Approved &&
communication.Recipients.Where( r => r.Status == Model.CommunicationRecipientStatus.Pending ).Any() &&
( !communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value.CompareTo( RockDateTime.Now ) <= 0 ) )
{
string fromPhone = string.Empty;
string fromValue = communication.GetMediumDataValue( "FromValue" );
int fromValueId = int.MinValue;
if ( int.TryParse( fromValue, out fromValueId ) )
{
fromPhone = DefinedValueCache.Read( fromValueId, rockContext ).Value;
}
if ( !string.IsNullOrWhiteSpace( fromPhone ) )
{
string accountSid = GetAttributeValue( "SID" );
string authToken = GetAttributeValue( "Token" );
var twilio = new TwilioRestClient( accountSid, authToken );
var historyService = new HistoryService( rockContext );
var recipientService = new CommunicationRecipientService( rockContext );
var personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
var communicationEntityTypeId = EntityTypeCache.Read( "Rock.Model.Communication" ).Id;
var communicationCategoryId = CategoryCache.Read( Rock.SystemGuid.Category.HISTORY_PERSON_COMMUNICATIONS.AsGuid(), rockContext ).Id;
var globalConfigValues = GlobalAttributesCache.GetMergeFields( null );
bool recipientFound = true;
while ( recipientFound )
{
var recipient = recipientService.Get( communication.Id, CommunicationRecipientStatus.Pending ).FirstOrDefault();
if ( recipient != null )
{
try
{
var phoneNumber = recipient.PersonAlias.Person.PhoneNumbers
.Where( p => p.IsMessagingEnabled )
.FirstOrDefault();
if ( phoneNumber != null )
{
// Create merge field dictionary
var mergeObjects = recipient.CommunicationMergeValues( globalConfigValues );
string message = communication.GetMediumDataValue( "Message" );
message = message.ResolveMergeFields( mergeObjects );
string twilioNumber = phoneNumber.Number;
if ( !string.IsNullOrWhiteSpace( phoneNumber.CountryCode ) )
{
twilioNumber = "+" + phoneNumber.CountryCode + phoneNumber.Number;
}
var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
string callbackUrl = globalAttributes.GetValue( "PublicApplicationRoot" ) + "Webhooks/Twilio.ashx";
var response = twilio.SendMessage( fromPhone, twilioNumber, message, callbackUrl );
recipient.Status = CommunicationRecipientStatus.Delivered;
recipient.TransportEntityTypeName = this.GetType().FullName;
recipient.UniqueMessageId = response.Sid;
try
{
historyService.Add( new History
{
CreatedByPersonAliasId = communication.SenderPersonAliasId,
EntityTypeId = personEntityTypeId,
CategoryId = communicationCategoryId,
EntityId = recipient.PersonAlias.PersonId,
Summary = "Sent SMS message.",
Caption = message.Truncate( 200 ),
RelatedEntityTypeId = communicationEntityTypeId,
RelatedEntityId = communication.Id
} );
}
catch (Exception ex)
{
ExceptionLogService.LogException( ex, null );
}
}
else
{
recipient.Status = CommunicationRecipientStatus.Failed;
recipient.StatusNote = "No Phone Number with Messaging Enabled";
}
}
//.........这里部分代码省略.........
示例5: GetHtmlPreview
/// <summary>
/// Gets the HTML preview.
/// </summary>
/// <param name="communication">The communication.</param>
/// <param name="person">The person.</param>
/// <returns></returns>
public override string GetHtmlPreview( Model.Communication communication, Person person )
{
var rockContext = new RockContext();
StringBuilder sbContent = new StringBuilder();
var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
var mergeValues = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( null );
// Requery the Communication object
communication = new CommunicationService( rockContext ).Get( communication.Id );
mergeValues.Add( "Communication", communication );
if ( person != null )
{
mergeValues.Add( "Person", person );
var recipient = communication.Recipients.Where( r => r.PersonAlias != null && r.PersonAlias.PersonId == person.Id ).FirstOrDefault();
if ( recipient != null )
{
// Add any additional merge fields created through a report
foreach ( var mergeField in recipient.AdditionalMergeValues )
{
if ( !mergeValues.ContainsKey( mergeField.Key ) )
{
mergeValues.Add( mergeField.Key, mergeField.Value );
}
}
}
}
// Body
string htmlContent = communication.GetMediumDataValue( "HtmlMessage" );
sbContent.Append( Email.ProcessHtmlBody( communication, globalAttributes, mergeValues ) );
// Attachments
StringBuilder sbAttachments = new StringBuilder();
string attachmentIds = communication.GetMediumDataValue( "Attachments" );
if ( !string.IsNullOrWhiteSpace( attachmentIds ) )
{
sbContent.Append( "<br/><br/>" );
var binaryFileService = new BinaryFileService( rockContext );
foreach ( string idVal in attachmentIds.SplitDelimitedValues() )
{
int binaryFileId = int.MinValue;
if ( int.TryParse( idVal, out binaryFileId ) )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
sbContent.AppendFormat( "<a target='_blank' href='{0}GetFile.ashx?id={1}'>{2}</a><br/>",
System.Web.VirtualPathUtility.ToAbsolute( "~" ), binaryFile.Id, binaryFile.FileName );
}
}
}
}
return sbContent.ToString();
}