/// <summary> /// Constructor of the copy. /// </summary> /// <param name="source">Instance of <see cref="SequenceFlowElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public SequenceFlowElement(SequenceFlowElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { if (dictToRebind == null) { _sourceRefUId = source.SourceRefUId; _targetRefUId = source.TargetRefUId; } else { _sourceRefUId = dictToRebind[source.SourceRefUId]; _targetRefUId = dictToRebind[source.TargetRefUId]; _isSourceRefInitialized = false; _isTargetRefInitialized = false; } FlowType = source.FlowType; StrokeColor = source.StrokeColor; VisualType = source.VisualType; SourceSequenceFlowPointLocalPosition = source.SourceSequenceFlowPointLocalPosition; TargetSequenceFlowPointLocalPosition = source.TargetSequenceFlowPointLocalPosition; CurveCenterPosition = source.CurveCenterPosition; IsSynchronous = source.IsSynchronous; Priority = source.Priority; StepCompletedCondition = source.StepCompletedCondition; _polylinePointPositions = new Collection <Point>(source.PolylinePointPositions); }
private bool TryScheduleNextJob(CoreCampaignSchema campaignSchema, DateTime?scheduledDate) { SetCampaignInProgress(campaignSchema.EntityId, false, scheduledDate); var jobConfig = CampaignTimeScheduler.GetNextFireTime(campaignSchema, scheduledDate); if (jobConfig.ScheduledAction == CampaignScheduledAction.Stop) { CampaignEventFacade.Stop(_userConnection, campaignSchema); return(false); } var latenessConfig = CampaignTimeScheduler.GetLatenessConfig(campaignSchema, jobConfig.Time); LogMisfiredRun(campaignSchema, latenessConfig, jobConfig.Time); if (latenessConfig.Lateness == CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements) { CampaignEventFacade.Stop(_userConnection, campaignSchema); return(false); } if (latenessConfig.Lateness == CampaignExecutionLateness.Critical || latenessConfig.Lateness == CampaignExecutionLateness.MisfiredTimeConditionElements) { jobConfig = CampaignTimeScheduler.GetNextFireTime(campaignSchema, DateTime.UtcNow); } if (jobConfig.ScheduledAction != CampaignScheduledAction.ScheduledStop) { SetCampaignNextFireTime(campaignSchema.EntityId, jobConfig.Time); } CampaignJobDispatcher.ScheduleJob(campaignSchema, jobConfig); return(true); }
/// <summary> /// Constructor for <see cref="AddCampaignParticipantElement"/>. /// </summary> /// <param name="source">Instance of <see cref="AddCampaignParticipantElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public AddCampaignParticipantElement(AddCampaignParticipantElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { IsRecurring = source.IsRecurring; RecurringFrequencyInDays = source.RecurringFrequencyInDays; Priority = source.Priority; }
/// <summary> /// Constructor for <see cref="CampaignBaseCrudObjectElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignBaseCrudObjectElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignBaseCrudObjectElement(CampaignBaseCrudObjectElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { EntityName = source.EntityName; _columnValuesJson = JsonConvert.SerializeObject(source.ColumnValues, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); }
private void StartCampaign(CoreCampaignSchema campaignSchema, DateTime scheduledFireTime) { var schemaManager = (CampaignSchemaManager)_userConnection.GetSchemaManager("CampaignSchemaManager"); ChangeStatusToActive(campaignSchema.UId); schemaManager.ActualizeCampaignSchemaInfo(campaignSchema, _userConnection); LogAction(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeCampaignStart); RunCampaign(campaignSchema, CampaignSchemaExecutionStrategy.DefaultPeriod, scheduledFireTime); }
private void RunCampaignWithInProgress(CoreCampaignSchema campaignSchema, CampaignSchemaExecutionStrategy strategy, DateTime scheduledFireTime) { var campaignStatusId = GetCampaignStatusId(campaignSchema.EntityId); if (campaignStatusId == CampaignConsts.RunCampaignStatusId) { SetCampaignInProgress(campaignSchema.EntityId, true, null); RunCampaign(campaignSchema, strategy, scheduledFireTime); } }
private void StopCampaignByScheduledDate(CoreCampaignSchema campaignSchema) { var campaignInfo = CampaignHelper.GetCampaignInfo(campaignSchema.EntityId); if (campaignInfo.CampaignStatusId == CampaignConsts.RunCampaignStatusId) { CampaignEventFacade.Finalize(_userConnection, campaignSchema); LogAction(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeStoppedBySchedule); CampaignEventFacade.Stop(_userConnection, campaignSchema); } }
/// <summary> /// Constructor of the copy. /// </summary> /// <param name="source">Instance of <see cref="ConditionalSequenceFlowElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public ConditionalSequenceFlowElement(ConditionalSequenceFlowElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { FilterId = source.FilterId; DelayInDays = source.DelayInDays; DelayUnit = source.DelayUnit; HasStartTime = source.HasStartTime; StartTime = source.StartTime; IsDelayedStart = source.IsDelayedStart; HasFilter = source.HasFilter; IsFilterChanged = source.IsFilterChanged; }
/// <summary> /// Constructor for <see cref="CampaignStartSignalElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignStartSignalElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignStartSignalElement(CampaignStartSignalElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { EntitySchemaUId = source.EntitySchemaUId; SignalEntityId = source.SignalEntityId; Signal = source.Signal; WaitingRandomSignal = source.WaitingRandomSignal; WaitingEntitySignal = source.WaitingEntitySignal; EntitySignal = source.EntitySignal; HasEntityColumnChange = source.HasEntityColumnChange; HasEntityFilters = source.HasEntityFilters; LocalizableEntityFilters = new LocalizableString(source.LocalizableEntityFilters); EntityFilters = source.EntityFilters; EntityChangedColumns = source.EntityChangedColumns; }
/// <summary> /// Schedules next campaign job if it is possible. /// </summary> /// <param name="userConnection">The user connection.</param> /// <param name="campaignSchemaUId">Unique identifier of campaign schema.</param> /// <param name="scheduledDate">Time of the previous campaign run. /// It can be null when need calculate next fire time relatively to current time.</param> /// <returns>Returns true when campaign job is scheduled.</returns> public virtual bool TryScheduleNextJob(UserConnection userConnection, Guid campaignSchemaUId, DateTime?scheduledDate) { _userConnection = userConnection; try { var schemaManager = (CampaignSchemaManager)_userConnection.GetSchemaManager(nameof(CampaignSchemaManager)); CoreCampaignSchema campaignSchema = schemaManager.GetSchemaInstance(campaignSchemaUId); return(TryScheduleNextJob(campaignSchema, scheduledDate)); } catch (Exception e) { string message = string.Format(CampaignHelper .GetLczStringValue(nameof(CampaignJobExecutor), "ScheduleNextJobError"), campaignSchemaUId); Logger.Error(message, e); return(false); } }
private void LogMisfiredRun(CoreCampaignSchema campaignSchema, CampaignExecutionLatenessConfig latenessConfig, DateTime scheduledDate) { string message; switch (latenessConfig.Lateness) { case CampaignExecutionLateness.MisfiredTimeConditionElements: { string errorText = CampaignHelper .GetLczStringValue(nameof(CampaignJobExecutor), "MisfiredTimeConditionElementError"); message = string.Format(errorText, scheduledDate.ToString("g"), TimeSpanToString(latenessConfig.LatenessTime), GetElementsNames(latenessConfig.MisfiredTimeConditionElements)); LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeSkippedElement, message); break; } case CampaignExecutionLateness.Critical: { string errorText = CampaignHelper .GetLczStringValue(nameof(CampaignJobExecutor), "MisfiredCampaignExecutionError"); message = string.Format(errorText, scheduledDate.ToString("g"), TimeSpanToString(latenessConfig.LatenessTime)); LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeSkippedRun, message); break; } case CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements: { string errorText = CampaignHelper .GetLczStringValue(nameof(CampaignJobExecutor), "CriticalExecutionLatenessError"); message = string.Format(errorText, TimeSpanToString(latenessConfig.LatenessTime), TimeSpanToString(TimeSpan.FromMinutes(campaignSchema.CriticalExecutionLateness)), GetElementsNames(latenessConfig.MisfiredTimeConditionElements)); LogError(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeCriticalLateness, message); string notificationText = CampaignHelper .GetLczStringValue(nameof(CampaignJobExecutor), "CriticalLatenessNotification"); string notification = string.Format(notificationText, campaignSchema.Caption, TimeSpanToString(TimeSpan.FromMinutes(campaignSchema.CriticalExecutionLateness))); CreateNotification(campaignSchema.EntityId, notification); break; } default: break; } }
/// <summary> /// Processes job for campaign action. /// <param name="userConnection">The user connection.</param> /// <param name="parameters">Job parameters.</param> /// </summary> public void Execute(UserConnection userConnection, IDictionary <string, object> parameters) { try { _userConnection = userConnection; var schemaUid = GetTypedParameter <Guid>("CampaignSchemaUId", parameters); var scheduledFireTime = GetTypedParameter <DateTime>("ScheduledUtcFireTime", parameters); var action = (CampaignScheduledAction)GetTypedParameter <int>("ScheduledAction", parameters); var schemaGeneratorStrategy = GetTypedParameter <CampaignSchemaExecutionStrategy>("SchemaGeneratorStrategy", parameters); var schemaManager = (CampaignSchemaManager)_userConnection.GetSchemaManager("CampaignSchemaManager"); CoreCampaignSchema campaignSchema = schemaManager.GetSchemaInstance(schemaUid); switch (action) { case CampaignScheduledAction.ScheduledStart: StartCampaign(campaignSchema, scheduledFireTime); break; case CampaignScheduledAction.Start: RunCampaign(campaignSchema, schemaGeneratorStrategy, scheduledFireTime); break; case CampaignScheduledAction.Run: RunCampaignWithInProgress(campaignSchema, schemaGeneratorStrategy, scheduledFireTime); break; case CampaignScheduledAction.Stop: CampaignEventFacade.Stop(_userConnection, campaignSchema); break; case CampaignScheduledAction.ScheduledStop: StopCampaignByScheduledDate(campaignSchema); break; default: break; } } catch (Exception ex) { string message = CampaignHelper.GetLczStringValue(nameof(CampaignJobExecutor), "ExecutionException"); Logger.Error(message, ex); throw; } }
/// <summary> /// Constructor for <see cref="CampaignTimerElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignTimerElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignTimerElement(CampaignTimerElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { ExpressionType = source.ExpressionType; StartDateTime = source.StartDateTime; UseStartDateTime = source.UseStartDateTime; EndDateTime = source.EndDateTime; UseEndDateTime = source.UseEndDateTime; PeriodStartTime = source.PeriodStartTime; PeriodEndTime = source.PeriodEndTime; ExactTime = source.ExactTime; UseExactTime = source.UseExactTime; CronExpression = source.CronExpression?.Clone() as CronExpression ?? new CronExpression(DefaultCronExpression); UseCustomTimeZone = source.UseCustomTimeZone; if (source.TimeZoneOffset != null) { TimeZoneOffset = TimeZoneInfo.FromSerializedString(source.TimeZoneOffset.ToSerializedString()); } }
private void RunCampaign(CoreCampaignSchema campaignSchema, CampaignSchemaExecutionStrategy schemaGeneratorStrategy, DateTime scheduledFireTime) { try { DateTime?stopDate = GetScheduledStopDate(campaignSchema.EntityId); var latenessConfig = CampaignTimeScheduler.GetLatenessConfig(campaignSchema, scheduledFireTime); LogMisfiredRun(campaignSchema, latenessConfig, scheduledFireTime); if (stopDate <= DateTime.UtcNow) { LogAction(campaignSchema.EntityId, CampaignConsts.CampaignLogTypeStoppedBySchedule); } if (latenessConfig.Lateness == CampaignExecutionLateness.CriticalAndMisfiredTimeConditionElements || stopDate <= DateTime.UtcNow) { CampaignEventFacade.Finalize(_userConnection, campaignSchema); CampaignEventFacade.Stop(_userConnection, campaignSchema); return; } if (latenessConfig.Lateness == CampaignExecutionLateness.NoMisfire) { campaignSchema.CampaignConfiguration["ScheduledUtcFireTime"] = scheduledFireTime; var config = new CampaignExecutionConfig { CurrentFireTime = scheduledFireTime, ExecutionStrategy = schemaGeneratorStrategy }; CampaignEngine.Run(campaignSchema, config); } else { scheduledFireTime = DateTime.UtcNow; } } catch (Exception e) { string message = CampaignHelper.GetLczStringValue(nameof(CampaignJobExecutor), "ExecutionException"); Logger.Error(message, e); } TryScheduleNextJob(campaignSchema, scheduledFireTime); }
/// <summary> /// Constructor for <see cref="MarketingEmailElement"/>. /// </summary> /// <param name="source">Instance of <see cref="MarketingEmailElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public MarketingEmailElement(MarketingEmailElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { MarketingEmailId = source.MarketingEmailId; }
private IEnumerable <CampaignLandingElement> GetLandingElements(CoreCampaignSchema schema) { return(schema.FlowElements.OfType <CampaignLandingElement>()); }
/// <summary> /// Constructor for <see cref="CampaignLandingElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignLandingElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignLandingElement(CampaignLandingElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { LandingId = source.LandingId; }
/// <summary> /// Constructor for <see cref="CampaignEventElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignEventElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignEventElement(CampaignEventElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { EventId = source.EventId; }
/// <summary> /// Constructor for <see cref="BaseCampaignAudienceElement"/>. /// </summary> /// <param name="source">Instance of <see cref="BaseCampaignAudienceElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> protected BaseCampaignAudienceElement(BaseCampaignAudienceElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { FolderId = source.FolderId; }
/// <summary> /// Constructor of the copy. /// </summary> /// <param name="source">Instance of <see cref="EmailConditionalTransitionElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public EmailConditionalTransitionElement(EmailConditionalTransitionElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { IsResponseBasedStart = source.IsResponseBasedStart; _emailResponseIdJson = JsonConvert.SerializeObject(source.EmailResponseId); _hyperlinkIdJson = JsonConvert.SerializeObject(source.HyperlinkId); _hyperlinkTrackIdJson = JsonConvert.SerializeObject(source.HyperlinkTrackId); }
/// <summary> /// Returns the list of <see cref="ExitFromCampaignElement"/> campaign audience elements. /// </summary> /// <param name="schema">Campaign schema instance.</param> /// <returns>List of concrete campaign audience elements.</returns> protected override IEnumerable <BaseCampaignAudienceElement> GetAudienceElements(CoreCampaignSchema schema) { return(schema.FlowElements.OfType <ExitFromCampaignElement>()); }
/// <summary> /// Force synchronizes all campaign participants independently from campaign fragment execution results. /// </summary> /// <param name="userConnection">An instance of <see cref="UserConnection"/>.</param> /// <param name="campaignSchema">Current instance of <see cref="CoreCampaignSchema"/>.</param> /// <returns>Count of synchronized campaign participants.</returns> public CampaignSynchronizationInfo ForceSynchronize(UserConnection userConnection, CoreCampaignSchema campaignSchema) { userConnection.CheckArgumentNull("userConnection"); campaignSchema.CheckArgumentNull("campaignSchema"); return(InternalSynchronize(userConnection, campaignSchema, true)); }
private CampaignSynchronizationInfo InternalSynchronize(UserConnection userConnection, CoreCampaignSchema campaignSchema, bool isForce) { var elementsToSync = campaignSchema.FlowElements .OfType <IFragmentSynchronizable>(); var syncInfo = new CampaignSynchronizationInfo(); foreach (var element in elementsToSync) { int synchronizedCount = 0; try { var syncManager = element.GetSyncManager(); SyncByManager(userConnection, syncManager, isForce, ref synchronizedCount); } catch (Exception ex) { syncInfo.Success = false; syncInfo.Errors.Add(ex); } finally { syncInfo.SynchronizedParticipantsCount += synchronizedCount; } } return(syncInfo); }
/// <summary> /// Creates a new instance that is a copy of the current instance. /// </summary> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> /// <returns>Copied instance of the ConditionalSequenceFlowElement.</returns> public override object Copy(Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) { return(new ConditionalSequenceFlowElement(this, dictToRebind, parentSchema)); }
/// <summary> /// Constructor for <see cref="CampaignAddObjectElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignAddObjectElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignAddObjectElement(CampaignAddObjectElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { }
/// <summary> /// Constructor for <see cref="ExitFromCampaignElement"/>. /// </summary> /// <param name="source">Instance of <see cref="ExitFromCampaignElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public ExitFromCampaignElement(ExitFromCampaignElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { IsCampaignGoal = source.IsCampaignGoal; }
/// <summary> /// Constructor for <see cref="MoveAudienceToExitElement"/>. /// </summary> /// <param name="source">Instance of <see cref="MoveAudienceToExitElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public MoveAudienceToExitElement(MoveAudienceToExitElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { IsCampaignGoal = source.IsCampaignGoal; ElementType = CampaignSchemaElementType.MoveAudience; }
/// <summary> /// Constructor for <see cref="CampaignAddEventAudienceElement"/>. /// </summary> /// <param name="source">Instance of <see cref="CampaignEventElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public CampaignAddEventAudienceElement(CampaignEventElement source, Dictionary <Guid, Guid> dictToRebind, CoreCampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { EventId = source.EventId; ElementType = CampaignSchemaElementType.AddAudience; }
/// <summary> /// Creates a new instance that is a copy of the current instance. /// </summary> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> /// <returns>Copied instance of the MarketingEmailElement.</returns> public override object Copy(Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) { return(new CampaignAddObjectElement(this, dictToRebind, parentSchema)); }
/// <summary> /// Creates a new instance that is a copy of the current instance. /// </summary> /// <param name="dictToRebind">Dictionary to rebind schema element's ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> /// <returns>Copied instance of the CampaignLandingElement.</returns> public override object Copy(Dictionary <Guid, Guid> dictToRebind, CoreCampaignSchema parentSchema) { return(new CampaignAddLandingAudienceElement(this, dictToRebind, parentSchema)); }