Esempio 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);
            }
        }
Esempio 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);
            }
        }
        /// <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);
            }
        }