public async Task Run([CosmosDBTrigger(
                                   DatabaseName,
                                   CollectionName,
                                   ConnectionStringSetting = ConnectionString,
                                   LeaseCollectionName = LeaseCollectionName,
                                   LeaseCollectionPrefix = LeaseCollectionPrefix,
                                   CreateLeaseCollectionIfNotExists = true
                                   )] IReadOnlyList <Document> documents,
                              ILogger log)
        {
            try
            {
                foreach (var document in documents)
                {
                    var changeFeedMessageModel = new ChangeFeedMessageModel()
                    {
                        Document   = document,
                        IsCustomer = true
                    };

                    _loggerHelper.LogInformationMessage(log, Guid.NewGuid(), string.Format("Attempting to send document id: {0} to service bus queue", document.Id));
                    await _serviceBusClient.SendChangeFeedMessageAsync(document, changeFeedMessageModel);
                }
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(log, Guid.NewGuid(), "Error when trying to send message to service bus queue", ex);
            }
        }
Example #2
0
        private async Task SendToStoredProc(ChangeFeedMessageModel documentModel, ILogger log)
        {
            _loggerHelper.LogMethodEnter(log);

            if (documentModel == null)
            {
                _loggerHelper.LogInformationMessage(log, CorrelationId, "document model is null");
                return;
            }

            var          resourceName  = GetResourceName(documentModel);
            var          commandText   = "Change_Feed_Insert_Update_" + resourceName;
            const string parameterName = "@Json";

            if (string.IsNullOrWhiteSpace(resourceName))
            {
                _loggerHelper.LogInformationMessage(log, CorrelationId, "resource Name is null");
                return;
            }

            try
            {
                _loggerHelper.LogInformationMessage(log, CorrelationId, "attempting to insert document into SQL");
                await _sqlServerProvider.UpsertResource(documentModel.Document, log, commandText, parameterName);
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(log, Guid.NewGuid(), "Error when trying to insert & update change feed request into SQL", ex);
                throw;
            }

            _loggerHelper.LogMethodExit(log);
        }
Example #3
0
        public async Task SendChangeFeedMessageAsync(Document document, ChangeFeedMessageModel changeFeedMessageModel)
        {
            if (_changeFeedQueueName == null)
            {
                throw new ArgumentNullException(nameof(_changeFeedQueueName));
            }

            if (_serviceBusConnectionString == null)
            {
                throw new ArgumentNullException(nameof(_serviceBusConnectionString));
            }

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (changeFeedMessageModel == null)
            {
                throw new ArgumentNullException(nameof(changeFeedMessageModel));
            }

            var queueClient = new QueueClient(_serviceBusConnectionString, _changeFeedQueueName);

            var msg = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(changeFeedMessageModel)))
            {
                ContentType = "application/json",
                MessageId   = document.Id + " " + DateTime.UtcNow
            };

            await queueClient.SendAsync(msg);
        }
Example #4
0
 private static string GetResourceName(ChangeFeedMessageModel documentModel)
 {
     if (documentModel.IsAction)
     {
         return("dss-actions");
     }
     else if (documentModel.IsActionPlan)
     {
         return("dss-actionplans");
     }
     else if (documentModel.IsAddress)
     {
         return("dss-addresses");
     }
     else if (documentModel.IsAdviserDetail)
     {
         return("dss-adviserdetails");
     }
     else if (documentModel.IsCollection)
     {
         return("dss-collections");
     }
     else if (documentModel.IsContact)
     {
         return("dss-contacts");
     }
     else if (documentModel.IsCustomer)
     {
         return("dss-customers");
     }
     else if (documentModel.IsDiversity)
     {
         return("dss-diversity");
     }
     else if (documentModel.IsEmploymentProgression)
     {
         return("dss-employmentprogressions");
     }
     else if (documentModel.IsGoal)
     {
         return("dss-goals");
     }
     else if (documentModel.IsInteraction)
     {
         return("dss-interactions");
     }
     else if (documentModel.IsLearningProgression)
     {
         return("dss-learningprogressions");
     }
     else if (documentModel.IsOutcome)
     {
         return("dss-outcomes");
     }
     else if (documentModel.IsSession)
     {
         return("dss-sessions");
     }
     else if (documentModel.IsSubscription)
     {
         return("dss-subscriptions");
     }
     else if (documentModel.IsTransfer)
     {
         return("dss-transfers");
     }
     else if (documentModel.IsWebChat)
     {
         return("dss-webchats");
     }
     else if (documentModel.IsDigitalIdentity)
     {
         return("dss-digitalidentities");
     }
     else
     {
         return(string.Empty);
     }
 }