public async Task <ANotification_Notification> GetNotificationAsync(long notificationId) { using var log = BeginFunction(nameof(NotificationAdminService), nameof(GetNotificationAsync), notificationId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var mNotification = await CommunicationMicroService.GetNotificationAsync(notificationId).ConfigureAwait(false); var mUser = mNotification.ParticipantReference != null && TryParseUserId.FromParticipantReference(mNotification.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var result = Create.ANotification_Notification(mNotification, mUser); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <AAlert_AlertList> GetAlertsAsync(bool?acknowledged, int recordCount) { using var log = BeginFunction(nameof(AlertAdminService), nameof(GetAlertsAsync), acknowledged, recordCount); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var alerts = new List <AAlert_Alert>(); var mAlerts = await CommunicationMicroService.GetAlertsAsync(recordCount, acknowledged); foreach (var mAlert in mAlerts.Alerts) { var mUser = mAlert.ParticipantReference != null && TryParseUserId.FromParticipantReference(mAlert.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var alert = Create.AAlert_Alert(mAlert, mUser); alerts.Add(alert); } var result = new AAlert_AlertList() { Alerts = alerts }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <ANotification_NotificationList> GetNotificationsAsync(bool?acknowledged, int recordCount) { using var log = BeginFunction(nameof(NotificationAdminService), nameof(GetNotificationsAsync), acknowledged, recordCount); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var notifications = new List <ANotification_Notification>(); var mNotifications = await CommunicationMicroService.GetNotificationsAsync(recordCount, acknowledged).ConfigureAwait(false); foreach (var mNotification in mNotifications.Notifications) { var mUser = mNotification.ParticipantReference != null && TryParseUserId.FromParticipantReference(mNotification.ParticipantReference, out string userId) ? await UserMicroService.GetUserAsync(userId) : null; var notification = Create.ANotification_Notification(mNotification, mUser); notifications.Add(notification); } var result = new ANotification_NotificationList() { Notifications = notifications }; log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateNotification() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <CommunicationTest> >(); var user = await GetRandomUserAsync(); logger.LogInformation($"User = {user}"); var participantReference = CreateParticipantReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Participant reference = {participantReference}"); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference); logger.LogInformation($"Participant ID = {participantId}"); var topicReference = CreateTopicReference.FromUserId(user.Id); logger.LogInformation($"Topic reference = {topicReference}"); var topicFields = new Dictionary <string, string>() { { "Key1", "Value1" }, { "Key2", "Value2" } }; var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, topicFields).ConfigureAwait(false); logger.LogInformation($"Topic ID = {topicId}"); await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId); }
public async Task HandleShipmentEventAsync(MFulfillment_ShipmentEvent eventData) { using var log = BeginFunction(nameof(FulfillmentEventMicroService), nameof(HandleShipmentEventAsync), eventData); try { using var ctx = CreateQuiltContext(); switch (eventData.EventType) { case MFulfillment_ShipmentEventTypes.Process: { var fulfillableIds = new HashSet <long>(); foreach (var shipmentRequestId in eventData.ShipmentRequestIds) { var mShipmentRequest = await FullfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId).ConfigureAwait(false); foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems) { var mFulfillable = await FullfillmentMicroService.GetFulfillableByItemAsync(mShipmentRequestItem.FulfillableItemId).ConfigureAwait(false); var fulfillableId = mFulfillable.FulfillableId; if (fulfillableIds.Contains(fulfillableId)) { _ = fulfillableIds.Add(fulfillableId); if (TryParseOrderId.FromFulfillableReference(mFulfillable.FulfillableReference, out var orderId)) { var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false); var userId = ParseUserId.FromOrdererReference(mOrder.OrdererReference); var participantReference = CreateParticipantReference.FromUserId(userId); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false); var topicReference = CreateTopicReference.FromOrderId(orderId); var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, null).ConfigureAwait(false); await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId).ConfigureAwait(false); } } } } } break; } await Task.CompletedTask.ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task AcknowledgeNotificationAsync(long notificationId) { using var log = BeginFunction(nameof(NotificationAdminService), nameof(AcknowledgeNotificationAsync), notificationId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); await CommunicationMicroService.AcknowledgeNotificationAsync(notificationId).ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <Session_Data> GetSession(string userId) { using var log = BeginFunction(nameof(SessionUserService), nameof(GetSession), userId); try { //AssertIsEndUser(userId); await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); //using var ctx = QuiltContextFactory.Create(); var participantReference = CreateParticipantReference.FromUserId(userId); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false); var svcSummary = await CommunicationMicroService.GetSummaryAsync(participantId).ConfigureAwait(false); var result = new Session_Data { HasNotifications = svcSummary.HasNotifications, HasMessages = svcSummary.HasMessages }; //var ordererReference = CreateOrdererReference.FromUserId(userId); //var dbOrdererPendingOrder = ctx.OrdererPendingOrders.SingleOrDefault(r => r.Orderer.OrdererReference == ordererReference); // HACK: OrderStatus /* * result.CartItemCount = dbOrdererPendingOrder == null * ? 0 * : dbOrdererPendingOrder.Order.OrderItems.Where(r => r.OrderItemStatusTypeCode == OrderItemStatusTypes.Pending).Count(); */ log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task <ADashboard_Summary> GetDashboardDataAsync() { using var log = BeginFunction(nameof(DashboardAdminService), nameof(GetDashboardDataAsync)); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); var result = new ADashboard_Summary() { MCommunication_Dashboard = await CommunicationMicroService.GetDashboardAsync(), MDesign_Dashboard = await DesignMicroService.GetDashboardAsync(), MFulfillment_Dashboard = await FulfillmentMicroService.GetDashboardAsync(), MFunding_Dashboard = await FundingMicroService.GetDashboardAsync(), MLedger_Dashboard = await LedgerMicroService.GetDashboardAsync(), MOrder_Dashboard = await OrderMicroService.GetDashboardAsync(), MProject_Dashboard = await ProjectMicroService.GetDashboardAsync(), MSquare_Dashboard = await SquareMicroService.GetDashboardAsync(), MUser_Dashboard = await UserMicroService.GetDashboardAsync() }; //using (var ctx = QuiltContextFactory.Create()) //{ // using var conn = QuiltContextFactory.CreateConnection(); // conn.Open(); // // Order // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrder in GetDashboardOrders(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.OrderStatusType(dbOrder.OrderStatusTypeCode).Name, // Count = dbOrder.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderStatusCounts = statusCounts; // } // // Order Return Request // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderReturnRequest in GetDashboardOrderReturnRequests(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ReturnRequestStatusType(dbOrderReturnRequest.OrderReturnRequestStatusTypeCode).Name, // Count = dbOrderReturnRequest.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderReturnRequestStatusCounts = statusCounts; // } // // Order Return // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderReturn in GetDashboardOrderReturns(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ReturnStatusType(dbOrderReturn.OrderReturnStatusTypeCode).Name, // Count = dbOrderReturn.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderReturnStatusCounts = statusCounts; // } // // Order Shipment Request // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderShipmentRequest in GetDashboardOrderShipmentRequests(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ShipmentRequestStatusType(dbOrderShipmentRequest.OrderShipmentRequestStatusTypeCode).Name, // Count = dbOrderShipmentRequest.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderShipmentRequestStatusCounts = statusCounts; // } // // Order Shipment // // // { // var statusCounts = new List<Admin_Dashboard_StatusCountData>(); // foreach (var dbOrderShipment in GetDashboardOrderShipments(conn).ToList()) // { // var statusCount = new Admin_Dashboard_StatusCountData() // { // StatusName = ctx.ShipmentStatusType(dbOrderShipment.OrderShipmentStatusTypeCode).Name, // Count = dbOrderShipment.RecordCount.GetValueOrDefault() // }; // statusCounts.Add(statusCount); // } // result.OrderShipmentStatusCounts = statusCounts; // } //} log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateAlert() { const int AlertCount = 3; var logger = ServiceScope.ServiceProvider.GetService <ILogger <CommunicationTest> >(); await CommunicationMicroService.AcknowledgeAlertsAsync(); var mAlerts = await CommunicationMicroService.GetAlertsAsync(int.MaxValue, true); Assert.IsNotNull(mAlerts); var existingAlertCount = mAlerts.Alerts.Count; mAlerts = await CommunicationMicroService.GetAlertsAsync(int.MaxValue, false); Assert.IsNotNull(mAlerts); Assert.AreEqual(0, mAlerts.Alerts.Count); var alertIds = new List <long>(); for (int idx = 0; idx < AlertCount; ++idx) { var participantReference = CreateParticipantReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Participant reference = {participantReference}"); var participantId = await CommunicationMicroService.AllocateParticipantAsync(participantReference); logger.LogInformation($"Participant ID = {participantId}"); var topicReference = CreateTopicReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Topic reference = {topicReference}"); var topicFields = new Dictionary <string, string>() { { "Key1", "Value1" }, { "Key2", "Value2" } }; var topicId = await CommunicationMicroService.AllocateTopicAsync(topicReference, topicFields); logger.LogInformation($"Topic ID = {topicId}"); var exception = new Exception("Test Exception"); var alertId = await CommunicationMicroService.CreateAlert(exception, participantId, topicId); logger.LogInformation($"Alert ID = {alertId}"); alertIds.Add(alertId); var mAlert = await CommunicationMicroService.GetAlertAsync(alertId); Assert.IsNotNull(mAlert); Assert.AreEqual(alertId, mAlert.AlertId); Assert.AreEqual(participantId, mAlert.ParticipantId); Assert.AreEqual(participantReference, mAlert.ParticipantReference); Assert.AreEqual(topicId, mAlert.TopicId); Assert.AreEqual(topicReference, mAlert.TopicReference); Assert.IsNull(mAlert.AcknowledgementDateTimeUtc); } mAlerts = await CommunicationMicroService.GetAlertsAsync(int.MaxValue, false); Assert.IsNotNull(mAlerts); Assert.AreEqual(AlertCount, mAlerts.Alerts.Count); foreach (var alertId in alertIds) { var mAlert = mAlerts.Alerts.Where(r => r.AlertId == alertId).Single(); Assert.IsNotNull(mAlert); Assert.AreEqual(alertId, mAlert.AlertId); Assert.IsNull(mAlert.AcknowledgementDateTimeUtc); } await CommunicationMicroService.AcknowledgeAlertAsync(alertIds[0]); mAlerts = await CommunicationMicroService.GetAlertsAsync(int.MaxValue, false); Assert.IsNotNull(mAlerts); Assert.AreEqual(AlertCount - 1, mAlerts.Alerts.Count); Assert.IsNull(mAlerts.Alerts.Where(r => r.AlertId == alertIds[0]).FirstOrDefault()); }