public async Task <bool> RegisterUnit(PushUri pushUri) { string deviceId = pushUri.DeviceId.GetHashCode().ToString(); List <PushRegistrationDescription> usersDevices = null; try { usersDevices = await _unitNotificationProvider.GetRegistrationsByUUID(pushUri.PushLocation); } catch (TimeoutException) { } if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(string.Format("unitId:{0}", pushUri.UnitId.ToString())))) { await _unitNotificationProvider.RegisterPush(pushUri); } else { await _unitNotificationProvider.UnRegisterPushByUUID(pushUri.PushLocation); await _unitNotificationProvider.RegisterPush(pushUri); } return(true); }
public async Task UnRegisterPushByUserDeviceId(PushUri pushUri) { var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureNotificationHub_PushUrl); var registrations = await hubClient.GetRegistrationsByTagAsync(string.Format("userId:{0}", pushUri.UserId), 50); // Step 1: Remove the devices that have a hashed deviceId try { List <Task> tasksWithHashedDeviceId = registrations.Where(x => x.Tags.Contains(pushUri.DeviceId.GetHashCode().ToString())).Select(registration => hubClient.DeleteRegistrationAsync(registration)).ToList(); await Task.WhenAll(tasksWithHashedDeviceId.ToArray()); } catch { } // Step 2: Remove the devices that have a non-hashsed device id (the old style) try { List <Task> tasksWithNormalDeviceId = registrations.Where(x => x.Tags.Contains(pushUri.DeviceId)).Select(registration => hubClient.DeleteRegistrationAsync(registration)).ToList(); await Task.WhenAll(tasksWithNormalDeviceId.ToArray()); } catch { } // Step 3: Remove the devices that have that PushUriId try { List <Task> tasksWithHashedDeviceId = registrations.Where(x => x.Tags.Contains(string.Format("pushUriId:{0}", pushUri.PushUriId))).Select(registration => hubClient.DeleteRegistrationAsync(registration)).ToList(); await Task.WhenAll(tasksWithHashedDeviceId.ToArray()); } catch (Exception ex) { Framework.Logging.LogException(ex, string.Format("PushUriId: {0}", pushUri.PushUriId)); } }
public async Task <bool> Register(PushUri pushUri) { if (pushUri == null || String.IsNullOrWhiteSpace(pushUri.DeviceId)) { return(false); } string deviceId = pushUri.DeviceId.GetHashCode().ToString(); // We just store the full Device Id in the PushUri object, the hashed version is for Azure //var existingPushUri = _pushUriService.GetPushUriByPlatformDeviceId((Platforms)pushUri.PlatformType, pushUri.DeviceId); List <PushRegistrationDescription> usersDevices = null; try { usersDevices = await _notificationProvider.GetRegistrationsByUserId(pushUri.UserId); } catch (TimeoutException) { } //if (existingPushUri == null) // pushUri = _pushUriService.SavePushUri(pushUri); if (usersDevices == null || !usersDevices.Any(x => x.Tags.Contains(deviceId))) { await _notificationProvider.RegisterPush(pushUri); } return(true); }
public async Task <bool> UnRegisterUnit(PushUri pushUri) { await _unitNotificationProvider.UnRegisterPushByUserDeviceId(pushUri); _pushUriService.DeleteAllPushUrisByPlatformDevice((Platforms)pushUri.PlatformType, pushUri.DeviceId); return(true); }
public async Task <ActionResult <DeviceRegistrationResult> > RegisterDevice([FromBody] DeviceRegistrationInput registrationInput, CancellationToken cancellationToken) { if (this.ModelState.IsValid) { var result = new DeviceRegistrationResult(); try { if (registrationInput == null) { return(BadRequest()); } var push = new PushUri(); push.UserId = UserId; push.PlatformType = registrationInput.Plt; if (!String.IsNullOrWhiteSpace(registrationInput.Uri)) { push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri); } else if (registrationInput.Plt == (int)Platforms.Android) { push.PushLocation = "Android"; } else if (registrationInput.Plt == (int)Platforms.iPhone || registrationInput.Plt == (int)Platforms.iPad) { push.PushLocation = "Apple"; } push.DeviceId = registrationInput.Did; push.Uuid = registrationInput.Id; push.DepartmentId = DepartmentId; CqrsEvent registerUnitPushEvent = new CqrsEvent(); registerUnitPushEvent.Type = (int)CqrsEventTypes.PushRegistration; registerUnitPushEvent.Data = ObjectSerialization.Serialize(push); await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent); result.Sfl = true; result.Id = push.PushUriId; return(result); } catch (Exception ex) { result.Sfl = false; Framework.Logging.LogException(ex); return(result); } } return(BadRequest()); }
public PushUri SavePushUri(PushUri pushUri) { if (pushUri.PushUriId == 0) { var uri = GetPushUriByPlatformDeviceId((Platforms)pushUri.PlatformType, pushUri.DeviceId); if (uri != null) { return(uri); } } pushUri.CreatedOn = DateTime.UtcNow; _pushUriRepository.SaveOrUpdate(pushUri); return(pushUri); }
public async Task UnRegisterPush(PushUri pushUri) { var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureNotificationHub_PushUrl); var registrations = await hubClient.GetRegistrationsByTagAsync(string.Format("userId:{0}", pushUri.UserId), 50); foreach (var registration in registrations) { if (pushUri.PlatformType == (int)Platforms.Windows8 || pushUri.PlatformType == (int)Platforms.WindowsPhone7 || pushUri.PlatformType == (int)Platforms.WindowsPhone8) { var winReg = registration as WindowsRegistrationDescription; if (winReg != null && winReg.ChannelUri == pushUri.ChannelUri) { await hubClient.DeleteRegistrationAsync(registration); } } else if (pushUri.PlatformType == (int)Platforms.Android) { var androidReg = registration as GcmRegistrationDescription; if (androidReg != null && androidReg.GcmRegistrationId == pushUri.DeviceId) { await hubClient.DeleteRegistrationAsync(registration); } } else if (pushUri.PlatformType == (int)Platforms.iPad || pushUri.PlatformType == (int)Platforms.iPhone) { var iosReg = registration as AppleRegistrationDescription; if (iosReg != null && iosReg.DeviceToken == pushUri.DeviceId) { await hubClient.DeleteRegistrationAsync(registration); } } } }
public async Task RegisterPush(PushUri pushUri) { if (String.IsNullOrWhiteSpace(pushUri.DeviceId)) { return; } var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureNotificationHub_PushUrl); var tagsWithHashedDeviceId = new List <string>(new string[] { string.Format("userId:{0}", pushUri.UserId), string.Format("platform:{0}", pushUri.PlatformType), string.Format("deviceId:{0}", pushUri.DeviceId.GetHashCode()) }); if (pushUri.DepartmentId > 0) { tagsWithHashedDeviceId.Add(string.Format("departmentId:{0}", pushUri.DepartmentId)); } CollectionQueryResult <RegistrationDescription> registrations = null; try { registrations = hubClient.GetRegistrationsByTagAsync(string.Format("deviceId:{0}", pushUri.DeviceId.GetHashCode()), 50).Result; } catch { // So this just fails, like whenever it wants. I would rather people get 2 or 3 push messages for a fire then none. } // Loop through all Azure registrations for this Hashed DeviceId and remove them if (registrations != null) { foreach (var registration in registrations) { try { await hubClient.DeleteRegistrationAsync(registration); } catch (Exception ex) { Framework.Logging.LogException(ex); } } } if (pushUri.PlatformType == (int)Platforms.WindowsPhone7 || pushUri.PlatformType == (int)Platforms.WindowsPhone8) { try { var result = await hubClient.CreateMpnsNativeRegistrationAsync(pushUri.PushLocation, tagsWithHashedDeviceId.ToArray()); } catch (ArgumentException ex) { Framework.Logging.LogException(ex, string.Format("Device Information: {0} {1} {2} {3}", tagsWithHashedDeviceId[0], tagsWithHashedDeviceId[1], tagsWithHashedDeviceId[2], tagsWithHashedDeviceId[3])); } } else if (pushUri.PlatformType == (int)Platforms.Windows8) { try { var result = await hubClient.CreateWindowsNativeRegistrationAsync(pushUri.PushLocation, tagsWithHashedDeviceId.ToArray()); } catch (ArgumentException ex) { Framework.Logging.LogException(ex, string.Format("Device Information: {0} {1} {2} {3}", tagsWithHashedDeviceId[0], tagsWithHashedDeviceId[1], tagsWithHashedDeviceId[2], tagsWithHashedDeviceId[3])); } } else if (pushUri.PlatformType == (int)Platforms.Android) { try { var result = await hubClient.CreateGcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); } catch (ArgumentException ex) { Framework.Logging.LogException(ex, string.Format("Device Information: {0} {1} {2} {3}", tagsWithHashedDeviceId[0], tagsWithHashedDeviceId[1], tagsWithHashedDeviceId[2], tagsWithHashedDeviceId[3])); } } else if (pushUri.PlatformType == (int)Platforms.iPad || pushUri.PlatformType == (int)Platforms.iPhone) { try { var result = await hubClient.CreateAppleNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); } catch (ArgumentException ex) { Framework.Logging.LogException(ex, string.Format("Device Information: {0} {1} {2} {3}", tagsWithHashedDeviceId[0], tagsWithHashedDeviceId[1], tagsWithHashedDeviceId[2], tagsWithHashedDeviceId[3])); } } }
public void DeletePushUri(PushUri pushUri) { _pushUriRepository.DeleteOnSubmit(pushUri); }
public async Task RegisterPush(PushUri pushUri) { if (String.IsNullOrWhiteSpace(pushUri.DeviceId)) { return; } if (pushUri.UnitId.HasValue) { var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureUnitNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureUnitNotificationHub_PushUrl); var unitTags = new string[] { string.Format("pushUriId:{0}", pushUri.PushUriId), string.Format("deviceId:{0}", pushUri.DeviceId.GetHashCode()), // Device Id is the registration token string.Format("unitId:{0}", pushUri.UnitId), string.Format("uuid:{0}", pushUri.PushLocation), string.Format("did:{0}", pushUri.DepartmentId) }; CollectionQueryResult <RegistrationDescription> registrations = null; try { registrations = await hubClient.GetRegistrationsByTagAsync(string.Format("deviceId:{0}", pushUri.DeviceId.GetHashCode()), 50); } catch { // So this just fails, like whenever it wants. I would rather people get 2 or 3 push messages for a fire then none. } // Loop through all Azure registrations for this Hashed DeviceId and remove them if (registrations != null) { foreach (var registration in registrations) { try { await hubClient.DeleteRegistrationAsync(registration); } catch (Exception ex) { Framework.Logging.LogException(ex); } } } if (pushUri.PlatformType == (int)Platforms.UnitWin) { try { var result = await hubClient.CreateMpnsNativeRegistrationAsync(pushUri.PushLocation, unitTags); } catch (ArgumentException ex) { } } else if (pushUri.PlatformType == (int)Platforms.UnitAndroid) { try { var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, unitTags); } catch (ArgumentException ex) { } } else if (pushUri.PlatformType == (int)Platforms.UnitIOS) { try { var result = await hubClient.CreateAppleNativeRegistrationAsync(pushUri.DeviceId, unitTags); } catch (ArgumentException ex) { } } } }
public static bool ProcessSystemQueueItem(CqrsEvent qi) { bool success = true; if (qi != null) { switch ((CqrsEventTypes)qi.Type) { case CqrsEventTypes.None: break; case CqrsEventTypes.UnitLocation: UnitLocation unitLocation = null; try { unitLocation = ObjectSerialization.Deserialize <UnitLocation>(qi.Data); } catch (Exception ex) { } if (unitLocation != null) { IUnitsService unitService; try { unitService = Bootstrapper.GetKernel().Resolve <IUnitsService>(); unitService.AddUnitLocation(unitLocation); } catch (Exception ex) { } finally { unitService = null; } } break; case CqrsEventTypes.PushRegistration: PushUri data = null; try { data = ObjectSerialization.Deserialize <PushUri>(qi.Data); } catch (Exception ex) { } if (data != null) { var pushService = Bootstrapper.GetKernel().Resolve <IPushService>(); var resgriterResult = pushService.Register(data).Result; pushService = null; } break; case CqrsEventTypes.UnitPushRegistration: PushRegisterionEvent unitData = null; try { unitData = ObjectSerialization.Deserialize <PushRegisterionEvent>(qi.Data); } catch (Exception ex) { } if (unitData != null) { PushUri pushUri = new PushUri(); pushUri.PushUriId = unitData.PushUriId; pushUri.UserId = unitData.UserId; pushUri.PlatformType = unitData.PlatformType; pushUri.PushLocation = unitData.PushLocation; pushUri.DepartmentId = unitData.DepartmentId; pushUri.UnitId = unitData.UnitId; pushUri.DeviceId = unitData.DeviceId; pushUri.Uuid = unitData.Uuid; var pushService = Bootstrapper.GetKernel().Resolve <IPushService>(); var unitResult = pushService.RegisterUnit(pushUri).Result; pushService = null; } break; case CqrsEventTypes.StripeChargeSucceeded: var succeededCharge = Stripe.Mapper <StripeCharge> .MapFromJson(qi.Data); if (succeededCharge != null) { var paymentProviderService = Bootstrapper.GetKernel().Resolve <IPaymentProviderService>(); paymentProviderService.ProcessStripePayment(succeededCharge); } break; case CqrsEventTypes.StripeChargeFailed: var failedCharge = Stripe.Mapper <StripeCharge> .MapFromJson(qi.Data); if (failedCharge != null) { var paymentProviderService = Bootstrapper.GetKernel().Resolve <IPaymentProviderService>(); paymentProviderService.ProcessStripeChargeFailed(failedCharge); } break; case CqrsEventTypes.StripeChargeRefunded: var refundedCharge = Stripe.Mapper <StripeCharge> .MapFromJson(qi.Data); if (refundedCharge != null) { var paymentProviderService = Bootstrapper.GetKernel().Resolve <IPaymentProviderService>(); paymentProviderService.ProcessStripeSubscriptionRefund(refundedCharge); } break; case CqrsEventTypes.StripeSubUpdated: var updatedSubscription = Stripe.Mapper <StripeSubscription> .MapFromJson(qi.Data); if (updatedSubscription != null) { var paymentProviderService = Bootstrapper.GetKernel().Resolve <IPaymentProviderService>(); paymentProviderService.ProcessStripeSubscriptionUpdate(updatedSubscription); } break; case CqrsEventTypes.StripeSubDeleted: var deletedSubscription = Stripe.Mapper <StripeSubscription> .MapFromJson(qi.Data); if (deletedSubscription != null) { var paymentProviderService = Bootstrapper.GetKernel().Resolve <IPaymentProviderService>(); paymentProviderService.ProcessStripeSubscriptionCancellation(deletedSubscription); } break; case CqrsEventTypes.ClearDepartmentCache: int departmentId; if (int.TryParse(qi.Data, out departmentId)) { var userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); //var departmentSettingsService = Bootstrapper.GetKernel().Resolve<IDepartmentSettingsService>(); var subscriptionService = Bootstrapper.GetKernel().Resolve <ISubscriptionsService>(); //var scheduledTasksService = Bootstrapper.GetKernel().Resolve<IScheduledTasksService>(); var departmentService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); var actionLogsService = Bootstrapper.GetKernel().Resolve <IActionLogsService>(); var customStatesService = Bootstrapper.GetKernel().Resolve <ICustomStateService>(); var usersService = Bootstrapper.GetKernel().Resolve <IUsersService>(); subscriptionService.ClearCacheForCurrentPayment(departmentId); departmentService.InvalidateDepartmentUsersInCache(departmentId); departmentService.InvalidateDepartmentInCache(departmentId); departmentService.InvalidatePersonnelNamesInCache(departmentId); userProfileService.ClearAllUserProfilesFromCache(departmentId); usersService.ClearCacheForDepartment(departmentId); actionLogsService.InvalidateActionLogs(departmentId); customStatesService.InvalidateCustomStateInCache(departmentId); departmentService.InvalidateDepartmentMembers(); userProfileService = null; subscriptionService = null; departmentService = null; actionLogsService = null; customStatesService = null; usersService = null; } else { } break; case CqrsEventTypes.NewChatMessage: NewChatNotificationEvent newChatEvent = null; if (qi != null && !String.IsNullOrWhiteSpace(qi.Data)) { try { newChatEvent = ObjectSerialization.Deserialize <NewChatNotificationEvent>(qi.Data); } catch (Exception ex) { } if (newChatEvent != null) { var userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>(); var usersService = Bootstrapper.GetKernel().Resolve <IUsersService>(); if (newChatEvent != null && newChatEvent.RecipientUserIds != null && newChatEvent.RecipientUserIds.Count > 0) { List <UserProfile> profiles = new List <UserProfile>(); if (newChatEvent.RecipientUserIds.Count == 1) { profiles.Add(userProfileService.GetProfileByUserId(newChatEvent.RecipientUserIds.First())); } else { profiles.AddRange(userProfileService.GetSelectedUserProfiles(newChatEvent.RecipientUserIds)); } var sendingUserProfile = userProfileService.GetProfileByUserId(newChatEvent.SendingUserId); var chatResult = communicationService.SendChat(newChatEvent.Id, newChatEvent.SendingUserId, newChatEvent.GroupName, newChatEvent.Message, sendingUserProfile, profiles).Result; } userProfileService = null; communicationService = null; usersService = null; } } break; case CqrsEventTypes.TroubleAlert: TroubleAlertEvent troubleAlertEvent = null; try { troubleAlertEvent = ObjectSerialization.Deserialize <TroubleAlertEvent>(qi.Data); } catch (Exception ex) { } if (troubleAlertEvent != null && troubleAlertEvent.DepartmentId.HasValue) { var userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>(); var usersService = Bootstrapper.GetKernel().Resolve <IUsersService>(); var departmentService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); var unitsService = Bootstrapper.GetKernel().Resolve <IUnitsService>(); var departmentGroupService = Bootstrapper.GetKernel().Resolve <IDepartmentGroupsService>(); var callsService = Bootstrapper.GetKernel().Resolve <ICallsService>(); var departmentSettingsService = Bootstrapper.GetKernel().Resolve <IDepartmentSettingsService>(); var geoLocationProvider = Bootstrapper.GetKernel().Resolve <IGeoLocationProvider>(); var admins = departmentService.GetAllAdminsForDepartment(troubleAlertEvent.DepartmentId.Value); var unit = unitsService.GetUnitById(troubleAlertEvent.UnitId); List <UserProfile> profiles = new List <UserProfile>(); Call call = null; string departmentNumber = ""; string callAddress = "No Call Address"; string unitAproxAddress = "Unknown Unit Address"; departmentNumber = departmentSettingsService.GetTextToCallNumberForDepartment(troubleAlertEvent.DepartmentId.Value); if (admins != null) { profiles.AddRange(userProfileService.GetSelectedUserProfiles(admins.Select(x => x.Id).ToList())); } if (unit != null) { if (unit.StationGroupId.HasValue) { var groupAdmins = departmentGroupService.GetAllAdminsForGroup(unit.StationGroupId.Value); if (groupAdmins != null) { profiles.AddRange(userProfileService.GetSelectedUserProfiles(groupAdmins.Select(x => x.UserId).ToList())); } } if (troubleAlertEvent.CallId.HasValue && troubleAlertEvent.CallId.GetValueOrDefault() > 0) { call = callsService.GetCallById(troubleAlertEvent.CallId.Value); if (!String.IsNullOrEmpty(call.Address)) { callAddress = call.Address; } else if (!String.IsNullOrEmpty(call.GeoLocationData)) { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { callAddress = geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } } if (!String.IsNullOrWhiteSpace(troubleAlertEvent.Latitude) && !String.IsNullOrWhiteSpace(troubleAlertEvent.Longitude)) { unitAproxAddress = geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(troubleAlertEvent.Latitude), double.Parse(troubleAlertEvent.Longitude)); } communicationService.SendTroubleAlert(troubleAlertEvent, unit, call, departmentNumber, troubleAlertEvent.DepartmentId.Value, callAddress, unitAproxAddress, profiles); } } break; case CqrsEventTypes.AuditLog: AuditEvent auditEvent = null; try { auditEvent = ObjectSerialization.Deserialize <AuditEvent>(qi.Data); } catch (Exception ex) { } if (auditEvent != null) { var auditLogsRepository = Bootstrapper.GetKernel().Resolve <IGenericDataRepository <AuditLog> >(); var userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var profile = userProfileService.GetProfileByUserId(auditEvent.UserId); var auditLog = new AuditLog(); auditLog.DepartmentId = auditEvent.DepartmentId; auditLog.UserId = auditEvent.UserId; auditLog.LogType = (int)auditEvent.Type; switch (auditEvent.Type) { case AuditLogTypes.DepartmentSettingsChanged: auditLog.Message = string.Format("{0} updated the department settings", profile.FullName.AsFirstNameLastName); var compareLogic = new CompareLogic(); ComparisonResult auditCompareResult = compareLogic.Compare(auditEvent.Before, auditEvent.After); auditLog.Data = auditCompareResult.DifferencesString; break; case AuditLogTypes.UserAdded: if (auditEvent.After != null && auditEvent.After.GetType().BaseType == typeof(IdentityUser)) { var newProfile = userProfileService.GetProfileByUserId(((IdentityUser)auditEvent.After).UserId); auditLog.Message = string.Format("{0} added new user {1}", profile.FullName.AsFirstNameLastName, newProfile.FullName.AsFirstNameLastName); auditLog.Data = $"New UserId: {newProfile.UserId}"; } break; case AuditLogTypes.UserRemoved: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(UserProfile)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} removed user {(((UserProfile)auditEvent.Before).FullName.AsFirstNameLastName)}"; auditLog.Data = "No Data"; } break; case AuditLogTypes.GroupAdded: if (auditEvent.After != null && auditEvent.After.GetType() == typeof(DepartmentGroup)) { if (((DepartmentGroup)auditEvent.After).Type.HasValue && ((DepartmentGroup)auditEvent.After).Type.Value == (int)DepartmentGroupTypes.Station) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} added station group {((DepartmentGroup)auditEvent.After).Name}"; } else { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} added organizational group {((DepartmentGroup)auditEvent.After).Name}"; } auditLog.Data = $"GroupId: {((DepartmentGroup)auditEvent.After).DepartmentGroupId}"; } break; case AuditLogTypes.GroupRemoved: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(DepartmentGroup)) { auditLog.Message = string.Format("{0} removed group {1}", profile.FullName.AsFirstNameLastName, ((DepartmentGroup)auditEvent.Before).Name); auditLog.Data = "No Data"; } break; case AuditLogTypes.GroupChanged: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(DepartmentGroup) && auditEvent.After != null && auditEvent.After.GetType() == typeof(DepartmentGroup)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} updated group {((DepartmentGroup)auditEvent.After).Name}"; var compareLogicGroup = new CompareLogic(); ComparisonResult resultGroup = compareLogicGroup.Compare(auditEvent.Before, auditEvent.After); auditLog.Data = resultGroup.DifferencesString; } break; case AuditLogTypes.UnitAdded: if (auditEvent.After != null && auditEvent.After.GetType() == typeof(Unit)) { auditLog.Message = string.Format("{0} added unit {1}", profile.FullName.AsFirstNameLastName, ((Unit)auditEvent.After).Name); auditLog.Data = $"UnitId: {((Unit)auditEvent.After).UnitId}"; } break; case AuditLogTypes.UnitRemoved: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(Unit)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} removed unit {((Unit)auditEvent.Before).Name}"; auditLog.Data = "No Data"; } break; case AuditLogTypes.UnitChanged: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(Unit) && auditEvent.After != null && auditEvent.After.GetType() == typeof(Unit)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} updated unit {((Unit)auditEvent.After).Name}"; var compareLogicUnit = new CompareLogic(); ComparisonResult resultUnit = compareLogicUnit.Compare(auditEvent.Before, auditEvent.After); auditLog.Data = resultUnit.DifferencesString; } break; case AuditLogTypes.ProfileUpdated: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(UserProfile) && auditEvent.After != null && auditEvent.After.GetType() == typeof(UserProfile)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} updated the profile for {((UserProfile)auditEvent.After).FullName.AsFirstNameLastName}"; var compareLogicProfile = new CompareLogic(); ComparisonResult resultProfile = compareLogicProfile.Compare(auditEvent.Before, auditEvent.After); auditLog.Data = resultProfile.DifferencesString; } break; case AuditLogTypes.PermissionsChanged: if (auditEvent.Before != null && auditEvent.Before.GetType() == typeof(Permission) && auditEvent.After != null && auditEvent.After.GetType() == typeof(Permission)) { auditLog.Message = $"{profile.FullName.AsFirstNameLastName} updated the department permissions"; var compareLogicProfile = new CompareLogic(); ComparisonResult resultProfile = compareLogicProfile.Compare(auditEvent.Before, auditEvent.After); auditLog.Data = resultProfile.DifferencesString; } break; } if (String.IsNullOrWhiteSpace(auditLog.Data)) { auditLog.Data = "No Data"; } if (!String.IsNullOrWhiteSpace(auditLog.Message)) { auditLog.LoggedOn = DateTime.UtcNow; auditLogsRepository.SaveOrUpdate(auditLog); } } break; default: throw new ArgumentOutOfRangeException(); } } return(success); }
public async Task <DeviceRegistrationResult> RegisterUnitDevice([FromBody] DeviceRegistrationInput registrationInput) { if (this.ModelState.IsValid) { var result = new DeviceRegistrationResult(); try { if (registrationInput == null) { throw HttpStatusCode.BadRequest.AsException(); } var push = new PushUri(); push.UserId = UserId; push.PlatformType = registrationInput.Plt; push.PushLocation = registrationInput.Id; push.DepartmentId = DepartmentId; if (!String.IsNullOrWhiteSpace(registrationInput.Uri)) { push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri); } push.DeviceId = registrationInput.Did; if (registrationInput.Uid != 0) { push.UnitId = registrationInput.Uid; } try { push = _pushUriService.SavePushUri(push); } catch { } PushRegisterionEvent pushRegisterionEvent = new PushRegisterionEvent(); pushRegisterionEvent.PushUriId = push.PushUriId; pushRegisterionEvent.UserId = UserId; pushRegisterionEvent.PlatformType = registrationInput.Plt; pushRegisterionEvent.PushLocation = registrationInput.Id; pushRegisterionEvent.DepartmentId = DepartmentId; pushRegisterionEvent.DeviceId = registrationInput.Did; pushRegisterionEvent.Uuid = registrationInput.Id; if (registrationInput.Uid != 0) { pushRegisterionEvent.UnitId = registrationInput.Uid; } CqrsEvent registerUnitPushEvent = new CqrsEvent(); registerUnitPushEvent.Type = (int)CqrsEventTypes.UnitPushRegistration; registerUnitPushEvent.Data = ObjectSerialization.Serialize(pushRegisterionEvent); await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent); //await _pushService.RegisterUnit(push); result.Sfl = true; result.Id = push.PushUriId; return(result); } catch (Exception ex) { result.Sfl = false; Framework.Logging.LogException(ex); return(result); } } throw HttpStatusCode.BadRequest.AsException(); }
public void UnRegisterNotificationOnly(PushUri pushUri) { _notificationProvider.UnRegisterPushByUserDeviceId(pushUri); }
public async Task <bool> UnRegisterUnit(PushUri pushUri) { await _unitNotificationProvider.UnRegisterPushByUserDeviceId(pushUri); return(true); }