コード例 #1
0
        public async void CreateNewNotification(string messageBody)
        {
            var actNot = new NotificationActivity()
            {
                Id          = Guid.NewGuid().ToString(),
                MessageBody = messageBody,
                UtcTime     = DateTime.UtcNow
            };

            using (var reps = new Repositories.NotificationActivityRepository("Course"))
            {
                await reps.CreateAsync(actNot);
            }
        }
コード例 #2
0
        public static async Task Run([EventHubTrigger("activity.notification", Connection = "EventHubConnectionString")] EventData[] events, ILogger log)
        {
            var exceptions = new List <Exception>();

            foreach (EventData eventData in events)
            {
                try
                {
                    string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
                    // Replace these two lines with your processing logic.
                    log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
                    var actNot = new NotificationActivity()
                    {
                        Id          = Guid.NewGuid().ToString(),
                        MessageBody = messageBody,
                        UtcTime     = DateTime.UtcNow
                    };

                    using (var reps = new Repositories.NotificationActivityRepository())
                    {
                        await reps.CreateAsync(actNot);
                    }
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                }
            }

            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }