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


C# CommunicationService.AsNoTracking方法代码示例

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


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

示例1: Execute

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute( IJobExecutionContext context )
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            var beginWindow = RockDateTime.Now.AddDays( 0 - dataMap.GetInt( "ExpirationPeriod" ) );
            var endWindow = RockDateTime.Now.AddMinutes( 0 - dataMap.GetInt( "DelayPeriod" ) );

            var qry = new CommunicationService( new RockContext() ).Queryable()
                .Where( c =>
                    c.Status == CommunicationStatus.Approved &&
                    c.Recipients.Where( r => r.Status == CommunicationRecipientStatus.Pending ).Any() &&
                    (
                        ( !c.FutureSendDateTime.HasValue && c.CreatedDateTime.HasValue && c.CreatedDateTime.Value.CompareTo( beginWindow ) >= 0 && c.CreatedDateTime.Value.CompareTo( endWindow ) <= 0 ) ||
                        ( c.FutureSendDateTime.HasValue && c.FutureSendDateTime.Value.CompareTo( beginWindow ) >= 0 && c.FutureSendDateTime.Value.CompareTo( endWindow ) <= 0 )
                    ) );

            foreach ( var comm in qry.AsNoTracking().ToList() )
            {
                var medium = comm.Medium;
                if ( medium != null )
                {
                    medium.Send( comm );
                }
            }
        }
开发者ID:azturner,项目名称:Rock,代码行数:28,代码来源:SendCommunications.cs

示例2: Execute

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public virtual void Execute( IJobExecutionContext context )
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            var beginWindow = RockDateTime.Now.AddDays( 0 - dataMap.GetInt( "ExpirationPeriod" ) );
            var endWindow = RockDateTime.Now.AddMinutes( 0 - dataMap.GetInt( "DelayPeriod" ) );
            var nowDate = RockDateTime.Now;

            var rockContext = new RockContext();
            var qryPendingRecipients = new CommunicationRecipientService( rockContext ).Queryable().Where( a => a.Status == CommunicationRecipientStatus.Pending );

            var qry = new CommunicationService( rockContext ).Queryable()
                .Where( c =>
                    c.Status == CommunicationStatus.Approved &&
                    qryPendingRecipients.Where( r => r.CommunicationId == c.Id ).Any() &&
                    (
                        ( !c.FutureSendDateTime.HasValue && c.CreatedDateTime.HasValue && c.CreatedDateTime.Value.CompareTo( beginWindow ) >= 0 && c.CreatedDateTime.Value.CompareTo( endWindow ) <= 0 ) ||
                        ( c.FutureSendDateTime.HasValue && c.FutureSendDateTime.Value.CompareTo( beginWindow ) >= 0 && c.FutureSendDateTime.Value.CompareTo( nowDate ) <= 0 )
                    ) );

            var exceptionMsgs = new List<string>();
            int communicationsSent = 0;

            foreach ( var comm in qry.AsNoTracking().ToList() )
            {
                try
                {
                    var medium = comm.Medium;
                    if ( medium != null && medium.IsActive )
                    {
                        medium.Send( comm );
                        communicationsSent++;
                    }
                }

                catch ( Exception ex )
                {
                    exceptionMsgs.Add( string.Format( "Exception occurred sending communication ID:{0}:{1}    {2}", comm.Id, Environment.NewLine, ex.Messages().AsDelimited( Environment.NewLine + "   " ) ) );
                    ExceptionLogService.LogException( ex, System.Web.HttpContext.Current );
                }
            }

            if ( communicationsSent > 0 )
            {
                context.Result = string.Format( "Sent {0} {1}", communicationsSent, "communication".PluralizeIf( communicationsSent > 1 ) );
            }
            else
            {
                context.Result = "No communications to send";
            }

            if ( exceptionMsgs.Any() )
            {
                throw new Exception( "One or more exceptions occurred sending communications..." + Environment.NewLine + exceptionMsgs.AsDelimited( Environment.NewLine ) );
            }

            // check for communications that have not been sent but are past the expire date. Mark them as failed and set a warning.
            var qryExpired = new CommunicationService( rockContext ).Queryable()
                .Where( c =>
                    c.Status == CommunicationStatus.Approved &&
                    qryPendingRecipients.Where( r => r.CommunicationId == c.Id ).Any() &&
                    (
                        (!c.FutureSendDateTime.HasValue && c.CreatedDateTime.HasValue && c.CreatedDateTime.Value.CompareTo( beginWindow ) < 0 ) ||
                        (c.FutureSendDateTime.HasValue && c.FutureSendDateTime.Value.CompareTo( beginWindow ) < 0 )
                    ) );

            foreach ( var comm in qryExpired.ToList() )
            {
                foreach ( var recipient in comm.Recipients.Where( r => r.Status == CommunicationRecipientStatus.Pending ) )
                {
                    recipient.Status = CommunicationRecipientStatus.Failed;
                    recipient.StatusNote = "Communication was not sent before the expire window (possibly due to delayed approval).";
                    rockContext.SaveChanges();
                }
            }
        }
开发者ID:SparkDevNetwork,项目名称:Rock,代码行数:79,代码来源:SendCommunications.cs


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