当前位置: 首页>>代码示例>>C#>>正文


C# Rock.GetChannelDataValue方法代码示例

本文整理汇总了C#中Rock.GetChannelDataValue方法的典型用法代码示例。如果您正苦于以下问题:C# Rock.GetChannelDataValue方法的具体用法?C# Rock.GetChannelDataValue怎么用?C# Rock.GetChannelDataValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rock的用法示例。


在下文中一共展示了Rock.GetChannelDataValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessTextBody

        /// <summary>
        /// Processes the text body.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="globalAttributes">The global attributes.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        /// <returns></returns>
        public static string ProcessTextBody ( Rock.Model.Communication communication,
            Rock.Web.Cache.GlobalAttributesCache globalAttributes,
            Dictionary<string, object> mergeObjects )
        {

            string defaultPlainText = communication.GetChannelDataValue( "DefaultPlainText" );
            string plainTextBody = communication.GetChannelDataValue( "TextMessage" );

            if ( string.IsNullOrWhiteSpace( plainTextBody ) && !string.IsNullOrWhiteSpace(defaultPlainText))
            {
                plainTextBody = defaultPlainText;
            }

            return plainTextBody.ResolveMergeFields( mergeObjects );

        }
开发者ID:Ganon11,项目名称:Rock,代码行数:23,代码来源:Email.cs

示例2: Send

        /// <summary>
        /// Sends the specified communication.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="CurrentPersonId">The current person id.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public override void Send( Rock.Model.Communication communication, int? CurrentPersonId )
        {
            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(DateTime.Now) > 0))
            {
                // From
                MailMessage message = new MailMessage();
                message.From = new MailAddress(
                    communication.GetChannelDataValue( "FromAddress" ),
                    communication.GetChannelDataValue( "FromName" ) );

                // Reply To
                string replyTo = communication.GetChannelDataValue( "ReplyTo" );
                if ( !string.IsNullOrWhiteSpace( replyTo ) )
                {
                    message.ReplyToList.Add( new MailAddress( replyTo ) );
                }

                // CC
                string cc = communication.GetChannelDataValue( "CC" );
                if ( !string.IsNullOrWhiteSpace( cc ) )
                {
                    foreach ( string ccRecipient in cc.SplitDelimitedValues() )
                    {
                        message.CC.Add( new MailAddress( ccRecipient ) );
                    }
                }

                // BCC
                string bcc = communication.GetChannelDataValue( "BCC" );
                if ( !string.IsNullOrWhiteSpace( bcc ) )
                {
                    foreach ( string bccRecipient in bcc.SplitDelimitedValues() )
                    {
                        message.Bcc.Add( new MailAddress( bccRecipient ) );
                    }
                }

                message.IsBodyHtml = true;
                message.Priority = MailPriority.Normal;

                // Create SMTP Client
                SmtpClient smtpClient = new SmtpClient( GetAttributeValue( "Server" ) );

                int port = int.MinValue;
                if ( int.TryParse( GetAttributeValue( "Port" ), out port ) )
                {
                    smtpClient.Port = port;
                }

                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                bool useSSL = false;
                smtpClient.EnableSsl = bool.TryParse( GetAttributeValue( "UseSSL" ), out useSSL ) && useSSL;

                string userName = GetAttributeValue( "UserName" );
                string password = GetAttributeValue( "Password" );
                if ( !string.IsNullOrEmpty( userName ) )
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = new System.Net.NetworkCredential( userName, password );
                }

                // Add Attachments
                string attachmentIds = communication.GetChannelDataValue( "Attachments" );
                if ( !string.IsNullOrWhiteSpace( attachmentIds ) )
                {
                    var binaryFileService = new BinaryFileService();

                    foreach(string idVal in attachmentIds.SplitDelimitedValues())
                    {
                        int binaryFileId = int.MinValue;
                        if (int.TryParse(idVal, out binaryFileId))
                        {
                            var binaryFile = binaryFileService.Get(binaryFileId);
                            if ( binaryFile != null )
                            {
                                Stream stream = new MemoryStream( binaryFile.Data.Content );
                                message.Attachments.Add( new Attachment( stream, binaryFile.FileName ) );
                            }
                        }
                    }
                }

                var recipientService = new CommunicationRecipientService();

                var globalConfigValues = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( null );
                
                bool recipientFound = true;
                while ( recipientFound )
                {
                    RockTransactionScope.WrapTransaction( () =>
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:Rock,代码行数:101,代码来源:SMTP.cs

示例3: ProcessHtmlBody

        /// <summary>
        /// Processes the HTML body.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="globalAttributes">The global attributes.</param>
        /// <param name="mergeObjects">The merge objects.</param>
        /// <returns></returns>
        public static string ProcessHtmlBody( Rock.Model.Communication communication,
            Rock.Web.Cache.GlobalAttributesCache globalAttributes,
            Dictionary<string, object> mergeObjects )
        {
            string htmlBody = communication.GetChannelDataValue( "HtmlMessage" );
            if ( !string.IsNullOrWhiteSpace( htmlBody ) )
            {
                // Get the unsubscribe content and add a merge field for it
                string unsubscribeHtml = communication.GetChannelDataValue( "UnsubscribeHTML" ).ResolveMergeFields( mergeObjects );
                if (mergeObjects.ContainsKey( "UnsubscribeOption"))
                {
                    mergeObjects.Add( "UnsubscribeOption", unsubscribeHtml );
                }
                else
                {
                    mergeObjects["UnsubscribeOption"] = unsubscribeHtml;
                }
                
                // Resolve merge fields
                htmlBody = htmlBody.ResolveMergeFields( mergeObjects );

                // Resolve special syntax needed if option was included in global attribute
                if ( Regex.IsMatch( htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]" ) )
                {
                    htmlBody = Regex.Replace( htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]", unsubscribeHtml );
                }

                // Add the unsubscribe option at end if it wasn't included in content
                if ( !htmlBody.Contains( unsubscribeHtml ) )
                {
                    htmlBody += unsubscribeHtml;
                }

                // Resolve any relative paths
                string publicAppRoot = globalAttributes.GetValue( "PublicApplicationRoot" ).EnsureTrailingForwardslash();
                htmlBody = htmlBody.Replace( @" src=""/", @" src=""" + publicAppRoot );
                htmlBody = htmlBody.Replace( @" href=""/", @" href=""" + publicAppRoot );
            }

            return htmlBody;

        }
开发者ID:Ganon11,项目名称:Rock,代码行数:49,代码来源:Email.cs

示例4: Send

        /// <summary>
        /// Sends the specified communication.
        /// </summary>
        /// <param name="communication">The communication.</param>
        /// <param name="CurrentPersonId">The current person id.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public override void Send( Rock.Model.Communication communication, int? CurrentPersonId )
        {
            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( DateTime.Now ) > 0 ) )
            {
                string fromPhone = string.Empty;
                string fromValue = communication.GetChannelDataValue( "FromValue" );
                int fromValueId = int.MinValue;
                if ( int.TryParse( fromValue, out fromValueId ) )
                {
                    fromPhone = DefinedValueCache.Read( fromValueId ).Description;
                }

                if ( !string.IsNullOrWhiteSpace( fromPhone ) )
                {
                    string accountSid = GetAttributeValue( "SID" );
                    string authToken = GetAttributeValue( "Token" );
                    var twilio = new TwilioRestClient( accountSid, authToken );

                    var recipientService = new CommunicationRecipientService();

                    var globalConfigValues = GlobalAttributesCache.GetMergeFields( null );

                    bool recipientFound = true;
                    while ( recipientFound )
                    {
                        RockTransactionScope.WrapTransaction( () =>
                        {
                            var recipient = recipientService.Get( communication.Id, CommunicationRecipientStatus.Pending ).FirstOrDefault();
                            if ( recipient != null )
                            {
                                string phoneNumber = recipient.Person.PhoneNumbers
                                    .Where( p => p.IsMessagingEnabled )
                                    .Select( p => p.Number )
                                    .FirstOrDefault();

                                if ( string.IsNullOrWhiteSpace( phoneNumber ) )
                                {
                                    recipient.Status = CommunicationRecipientStatus.Failed;
                                    recipient.StatusNote = "No Phone Number with Messaging Enabled";
                                }
                                else
                                {
                                    // Create merge field dictionary
                                    var mergeObjects = MergeValues( globalConfigValues, recipient );
                                    string subject = communication.Subject.ResolveMergeFields( mergeObjects );

                                    try
                                    {
                                        twilio.SendMessage( fromPhone, phoneNumber, subject );
                                        recipient.Status = CommunicationRecipientStatus.Success;
                                    }
                                    catch ( Exception ex )
                                    {
                                        recipient.Status = CommunicationRecipientStatus.Failed;
                                        recipient.StatusNote = "Twilio Exception: " + ex.Message;
                                    }
                                }
                                recipientService.Save( recipient, CurrentPersonId );
                            }
                            else
                            {
                                recipientFound = false;
                            }
                        } );
                    }
                }
            }
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:77,代码来源:Twilio.cs


注:本文中的Rock.GetChannelDataValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。