Ejemplo n.º 1
0
        /// <summary>
        /// Save Reflection Recursion data in Table Storage.
        /// </summary>
        /// <param name="taskInfo">This parameter is a ViewModel.</param>
        /// <returns>Null.</returns>
        public async Task SaveRecurssionDataAsync(TaskInfo taskInfo)
        {
            _telemetry.TrackEvent("SaveRecurssionDataAsync");
            try
            {
                RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry);

                RecurssionDataEntity recurssionEntity = new RecurssionDataEntity
                {
                    RecurssionID              = taskInfo.recurssionID,
                    PartitionKey              = PartitionKeyNames.RecurssionDataTable.RecurssionDataPartition,
                    RowKey                    = taskInfo.recurrsionRowKey,
                    ReflectionRowKey          = taskInfo.reflectionRowKey,
                    QuestionRowKey            = taskInfo.questionRowKey,
                    ReflectionID              = taskInfo.reflectionID,
                    RecursstionType           = taskInfo.recurssionType,
                    CustomRecurssionTypeValue = taskInfo.customRecurssionTypeValue,
                    CreatedDate               = DateTime.Now,
                    ExecutionDate             = taskInfo.executionDate,
                    ExecutionTime             = taskInfo.executionTime,
                    RecurssionEndDate         = taskInfo.executionDate.AddDays(60),
                    NextExecutionDate         = taskInfo.nextExecutionDate,
                    ScheduleId                = taskInfo.scheduleId
                };
                await recurssionDataRepository.CreateOrUpdateAsync(recurssionEntity);
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save Edit Recursion Data Async.
        /// </summary>
        /// <param name="reflection">reflection.</param>
        /// <returns>.</returns>
        public async Task SaveEditRecurssionDataAsync(RecurssionScreenData reflection)
        {
            try
            {
                _telemetry.TrackEvent("SaveEditRecurssionDataAsync");
                ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry);
                RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry);
                var reflectiondata = await reflectionDataRepository.GetReflectionData(reflection.RefID);

                var recurssion = await recurssionDataRepository.GetRecurssionData(reflectiondata.RecurrsionID);

                ReflectionDataEntity reflectionDataEntity = new ReflectionDataEntity();
                RecurssionDataEntity recurssionDataEntity = new RecurssionDataEntity();
                var reflectionid = Guid.NewGuid();
                var recurrsionid = Guid.NewGuid();
                reflectionDataEntity = reflectiondata;
                reflectionDataEntity.ReflectionID   = reflectionid;
                reflectionDataEntity.RefCreatedDate = DateTime.Now;
                reflectionDataEntity.RecurrsionID   = recurrsionid;
                reflectionDataEntity.RowKey         = Guid.NewGuid().ToString();
                await reflectionDataRepository.CreateAsync(reflectionDataEntity);

                recurssionDataEntity = recurssion;
                recurssionDataEntity.ReflectionID              = reflectionid;
                recurssionDataEntity.CreatedDate               = DateTime.Now;
                recurssionDataEntity.RecurssionID              = recurrsionid;
                recurssionDataEntity.RecursstionType           = reflection.RecurssionType;
                recurssionDataEntity.CustomRecurssionTypeValue = reflection.CustomRecurssionTypeValue;
                recurssionDataEntity.RowKey            = Guid.NewGuid().ToString();
                recurssionDataEntity.NextExecutionDate = reflection.NextExecutionDate;
                await recurssionDataRepository.CreateAsync(recurssionDataEntity);

                recurssion.NextExecutionDate = null;
                await recurssionDataRepository.CreateOrUpdateAsync(recurssion);
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the calculated next execution date time.
        /// </summary>
        /// <param name="recurssionEntity">recurssionEntity.</param>
        /// <returns>Calculated next execution date time.</returns>
        public DateTime?GetCalculatedNextExecutionDateTimeAsync(RecurssionDataEntity recurssionEntity)
        {
            _telemetry.TrackEvent("UpdateRecurssionDataNextExecutionDateTimeAsync");
            DateTime?calculatedNextExecutionDate = null;

            try
            {
                DateTime nextExecutionDate = Convert.ToDateTime(recurssionEntity.NextExecutionDate);
                RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry);

                switch (recurssionEntity.RecursstionType.ToLower().Trim())
                {
                case "daily":
                    DateTime?nextExecutionDay = DateTime.Now.AddDays(1);
                    calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextExecutionDay ? nextExecutionDay : null;
                    break;

                case "every weekday":
                    DateTime?nextWeekDay = GetNextWeekday();
                    calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextWeekDay ? nextWeekDay : null;
                    break;

                case "weekly":
                    DateTime?nextWeeklyday = GetNextWeeklyday(nextExecutionDate.DayOfWeek);
                    calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextWeeklyday ? nextWeeklyday : null;
                    break;

                case "monthly":
                    DateTime?nextMonthlyday = nextExecutionDate.AddMonths(1);
                    calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextMonthlyday ? nextMonthlyday : null;
                    break;

                case "does not repeat":
                    calculatedNextExecutionDate = null;
                    break;

                case "custom":
                    if (recurssionEntity.CustomRecurssionTypeValue.Contains("week"))
                    {
                        var selectedweeks = new List <string>();
                        weekdays.ForEach(x =>
                        {
                            if (recurssionEntity.CustomRecurssionTypeValue.Contains(x))
                            {
                                selectedweeks.Add(x);
                            }
                        });
                        if (selectedweeks.Count == 1)
                        {
                            goto case "weekly";
                        }
                        else if (selectedweeks.Count == 5 && selectedweeks.IndexOf("Saturday") == -1 && selectedweeks.IndexOf("Sunday") == -1)
                        {
                            goto case "every weekday";
                        }
                        else
                        {
                            var weekindex = selectedweeks.IndexOf(nextExecutionDate.DayOfWeek.ToString());
                            if ((weekindex + 1) < selectedweeks.Count)
                            {
                                int      addDays             = weekdays.IndexOf(selectedweeks[weekindex + 1]) - weekdays.IndexOf(selectedweeks[weekindex]);
                                DateTime?nextcustomweeklyday = DateTime.Now.AddDays(addDays);
                                calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextcustomweeklyday ? nextcustomweeklyday : null;
                            }
                        }

                        break;
                    }

                    if (recurssionEntity.CustomRecurssionTypeValue.Contains("month"))
                    {
                        if (recurssionEntity.CustomRecurssionTypeValue.Contains("Day"))
                        {
                            goto case "monthly";
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        DateTime?nextcustomdailyday = DateTime.Now.AddDays(1);
                        calculatedNextExecutionDate = recurssionEntity.RecurssionEndDate >= nextcustomdailyday ? nextcustomdailyday : null;
                        break;
                    }

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex);
            }
            return(calculatedNextExecutionDate);
        }
        /// <summary>
        /// RunJob.
        /// </summary>
        /// <param name="state">state.</param>
        private async void RunJob(object state)
        {
            _telemetry.TrackEvent("RunJob");
            try
            {
                ChannelAccount   channelAccount = new ChannelAccount(_configuration["MicrosoftAppId"]);
                Attachment       attachment     = new Attachment();
                TeamsChannelData channelData    = new TeamsChannelData()
                {
                    Notification = new NotificationInfo(true)
                };
                RecurssionDataRepository recurssionDataRepository = new RecurssionDataRepository(_configuration, _telemetry);
                ReflectionDataRepository reflectionDataRepository = new ReflectionDataRepository(_configuration, _telemetry);
                QuestionsDataRepository  questiondatarepository   = new QuestionsDataRepository(_configuration, _telemetry);

                var recurssionData = await recurssionDataRepository.GetAllRecurssionData();

                foreach (RecurssionDataEntity recurssionDataEntity in recurssionData)
                {
                    var reflectionData = await reflectionDataRepository.GetReflectionData(recurssionDataEntity.ReflectionID);

                    var question = await questiondatarepository.GetQuestionData(reflectionData.QuestionID);

                    TaskInfo taskInfo = new TaskInfo();
                    taskInfo.question     = question.Question;
                    taskInfo.postCreateBy = reflectionData.CreatedBy;
                    taskInfo.privacy      = reflectionData.Privacy;
                    taskInfo.reflectionID = reflectionData.ReflectionID;
                    var        newPostCard           = _cardHelper.CreateNewReflect(taskInfo);
                    Attachment newPostCardAttachment = new Attachment()
                    {
                        ContentType = AdaptiveCard.ContentType,
                        Content     = newPostCard
                    };
                    var        PostCardFeedback           = _cardHelper.FeedBackCard(new Dictionary <int, List <FeedbackDataEntity> >(), taskInfo.reflectionID, taskInfo.question);;
                    Attachment PostCardFeedbackAttachment = new Attachment()
                    {
                        ContentType = AdaptiveCard.ContentType,
                        Content     = PostCardFeedback
                    };
                    var proactiveNotification = await new ProactiveMessageHelper(_configuration).SendChannelNotification(channelAccount, reflectionData.ServiceUrl, reflectionData.ChannelID, "", newPostCardAttachment);
                    if (proactiveNotification.IsSuccessful && proactiveNotification.MessageId != null)
                    {
                        reflectionData.ReflectMessageId = proactiveNotification.MessageId.Split("=")[1];
                        var feedbackproactivemessage = await new ProactiveMessageHelper(_configuration).SendChannelNotification(channelAccount, reflectionData.ServiceUrl, reflectionData.ChannelID, "", PostCardFeedbackAttachment, reflectionData.ReflectMessageId);
                        if (feedbackproactivemessage.IsSuccessful && proactiveNotification.MessageId != null)
                        {
                            reflectionData.MessageID = feedbackproactivemessage.MessageId;
                            await _dbHelper.UpdateReflectionMessageIdAsync(reflectionData);
                        }
                    }

                    var calculatedNextExecutionDateTime = _dbHelper.GetCalculatedNextExecutionDateTimeAsync(recurssionDataEntity);
                    recurssionDataEntity.NextExecutionDate = null;
                    await recurssionDataRepository.CreateOrUpdateAsync(recurssionDataEntity);

                    if (calculatedNextExecutionDateTime != null)
                    {
                        ReflectionDataEntity newreflectionDataEntity = new ReflectionDataEntity();
                        RecurssionDataEntity newRecurssionDataEntity = new RecurssionDataEntity();
                        var reflectionid = Guid.NewGuid();
                        var recurrsionid = Guid.NewGuid();
                        newreflectionDataEntity                = reflectionData;
                        newreflectionDataEntity.RowKey         = Guid.NewGuid().ToString();
                        newreflectionDataEntity.ReflectionID   = reflectionid;
                        newreflectionDataEntity.RefCreatedDate = DateTime.Now;
                        newreflectionDataEntity.RecurrsionID   = recurrsionid;
                        await reflectionDataRepository.CreateAsync(newreflectionDataEntity);

                        newRecurssionDataEntity                   = recurssionDataEntity;
                        newRecurssionDataEntity.RowKey            = Guid.NewGuid().ToString();
                        newRecurssionDataEntity.ReflectionID      = reflectionid;
                        newRecurssionDataEntity.CreatedDate       = DateTime.Now;
                        newRecurssionDataEntity.RecurssionID      = recurrsionid;
                        newRecurssionDataEntity.NextExecutionDate = calculatedNextExecutionDateTime;
                        await recurssionDataRepository.CreateAsync(newRecurssionDataEntity);
                    }
                }
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex);
            }
        }