public async Task <IHttpActionResult> PostShareInterest([FromBody] InterestedShareInModel entity) { try { string authorization = Request.Headers.Authorization.Parameter; string scheme = Request.Headers.Authorization.Scheme; string user = ""; InterestedShareModel pref = new InterestedShareModel(entity); pref.UserId = await RetreiveUserId(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, "Share?symbol=" + entity.ShareSymbol)) { requestMessage.Headers.Authorization = new AuthenticationHeaderValue(scheme, authorization); HttpResponseMessage response = await _client.SendAsync(requestMessage); if (response.IsSuccessStatusCode) { string id = await response.Content.ReadAsStringAsync(); pref.ShareId = Convert.ToInt32(id); } //get shareid using the symbol _service.Add(pref); } return(Ok()); } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, "error: " + e.Message)); } }
public IActionResult Post(AAASSOSRequest sosRequest) { try { AAASSOS SOSModel = sosRequest.Adapt <AAASSOS>(); using (AAASSOSService ASService = new AAASSOSService()) { ASService.Add(SOSModel, 1, "AAAS User"); } using (NotificationService notificationService = new NotificationService()) { Notifications notificationModel = new Notifications(); notificationModel.NotificationContent = "A SOS was reported by " + SOSModel.UserContactNumber; notificationModel = notificationService.Add(notificationModel, 1, "AAAS User"); _hubContext.Clients.Group((notificationModel.SubscriberId).ToString()).PushNotification(notificationModel); } } catch (Exception ex) { Sentry.SentrySdk.CaptureException(ex); } return(Ok()); //status code 200 }
private Task CheckUpdate(UpdateChecker updateChecker, NotificationService notificationService) { return(updateChecker.CompareRelease(appVersion).ContinueWith(t => { switch (t.Result.Result) { case VersionCompareValues.NeedsUpgrade: notificationService.Add(Notifications.NeedsVersionUpgrade, new List <string>() { t.Result.LatestVersion }); break; case VersionCompareValues.Error: notificationService.Add(Notifications.VersionCheckError, new List <string>() { }, NotificationTypes.Warning); break; } })); }
private IInputDevice CreateDevice(DeviceInstance deviceInstance, List <string> uniqueIds) { try { if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid)) { return(null); } var joystick = new Joystick(directInput, deviceInstance.InstanceGuid); if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1) { joystick.Dispose(); return(null); } bool isHid = deviceInstance.IsHumanInterfaceDevice; string interfacePath = null; string uniqueIdBase; string hardwareId = null; if (isHid) { if (ignoredDeviceService.IsIgnored(joystick.Properties.InterfacePath)) { joystick.Dispose(); return(null); } interfacePath = joystick.Properties.InterfacePath; uniqueIdBase = interfacePath; hardwareId = IdHelper.GetHardwareId(interfacePath); } else { uniqueIdBase = string.Join(":", deviceInstance.ProductGuid.ToString(), deviceInstance.InstanceGuid.ToString()); } string uniqueId = IdHelper.GetUniqueId(uniqueIdBase); if (uniqueIds.Any(uid => uid == uniqueId)) { notificationService.Add(Notifications.DirectInputInstanceIdDuplication, new[] { uniqueId }, NotificationTypes.Warning); } uniqueIds.Add(uniqueId); if (currentDevices.Any(d => d.UniqueId == uniqueId)) { joystick.Dispose(); return(null); } joystick.Properties.BufferSize = 128; return(new DirectInputDevice(inputConfigManager, joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName, deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, uniqueId, hardwareId, interfacePath)); } catch (Exception ex) { logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString()); return(null); } }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var groupGuid = dataMap.Get("NotificationGroup").ToString().AsGuid(); var rockContext = new RockContext(); var group = new GroupService(rockContext).Get(groupGuid); if (group != null) { var notifications = Utility.SparkLinkHelper.SendToSpark(rockContext); if (notifications.Count == 0) { return; } var notificationService = new NotificationService(rockContext); foreach (var notification in notifications.ToList()) { if (notificationService.Get(notification.Guid) == null) { notificationService.Add(notification); } else { notifications.Remove(notification); } } rockContext.SaveChanges(); var notificationRecipientService = new NotificationRecipientService(rockContext); foreach (var notification in notifications) { foreach (var member in group.Members) { if (member.Person.PrimaryAliasId.HasValue) { var recipientNotification = new NotificationRecipient(); recipientNotification.NotificationId = notification.Id; recipientNotification.PersonAliasId = member.Person.PrimaryAliasId.Value; notificationRecipientService.Add(recipientNotification); } } } rockContext.SaveChanges(); } }
public void SearchDevices() { lock (lockObject) { IEnumerable <DeviceInstance> instances = directInput.GetDevices(); if (allDevices) { instances = instances.Where(di => di.Type != DeviceType.Keyboard && di.Type != DeviceType.Mouse).ToList(); } else { instances = instances.Where(di => di.Type == DeviceType.Joystick || di.Type == DeviceType.Gamepad || di.Type == DeviceType.FirstPerson).ToList(); } List <string> uniqueIds = new List <string>(); foreach (var instance in instances) { string instanceGuid = instance.InstanceGuid.ToString(); string productGuid = instance.ProductGuid.ToString(); if (productGuid != EmulatedSCPID) { var device = CreateDevice(instance, uniqueIds); if (device == null) { continue; } if (uniqueIds.Any(uid => uid == device.UniqueId)) { notificationService.Add(Notifications.DirectInputInstanceIdDuplication, new[] { device.UniqueId }, NotificationTypes.Warning); } var config = inputConfigManager.LoadConfig(device.UniqueId); device.InputConfiguration = config; currentDevices.Add(device); Connected?.Invoke(this, new DeviceConnectedEventArgs(device)); } } foreach (var device in currentDevices.ToArray()) { if (!uniqueIds.Any(i => i == device.UniqueId)) { currentDevices.Remove(device); device.Dispose(); Disconnected?.Invoke(this, new DeviceDisconnectedEventArgs(device)); } } } }
public IActionResult Post(AAASIncidentRequest incidentRequest) { try { AAASIncident AIModel = incidentRequest.Adapt <AAASIncident>(); using (AAASIncidentService AIService = new AAASIncidentService()) { AIService.Add(AIModel, 1, "AAAS User"); } using (NotificationService notificationService = new NotificationService()) { Notifications notificationModel = new Notifications(); notificationModel.NotificationContent = "An incident(" + AIModel.IncidentType + ") was reported by " + AIModel.UserContactNumber; notificationModel = notificationService.Add(notificationModel, 1, "AAAS User"); _hubContext.Clients.Group((notificationModel.SubscriberId).ToString()).PushNotification(notificationModel); } } catch (Exception ex) { Sentry.SentrySdk.CaptureException(ex); } return(Ok()); }
/// <summary> /// 执行定时任务 /// </summary> /// <param name="task">定时任务</param> /// <param name="executeDate">执行时间</param> public void Execute(ScheduledTaskModel task, DateTime executeDate) { if (task == null) { Log.Error("无效的定时任务。"); throw new InvalidOperationException("无效的定时任务。"); } using (var dbContext = new MissionskyOAEntities()) { #region 推送消息 var sql = @"SELECT * FROM ExpenseAuditHistory WHERE [Status]= {0} AND [CurrentAudit]={1} ;" ; //推送消息 var notification = new NotificationModel() { CreatedUserId = 0, //MessageType = NotificationType.PushMessage, MessageType = NotificationType.Email, BusinessType = BusinessType.Approving, Title = "及时提交报销申请资料", MessagePrams = "test", Scope = NotificationScope.User, CreatedTime = DateTime.Now }; var financialUserEntity = dbContext.Users.FirstOrDefault(it => it.Email != null && it.Email.ToLower().Contains(Global.FinancialEmail)); var entities = dbContext.ExpenseAuditHistories.SqlQuery(string.Format(sql, (int)OrderStatus.Approved, financialUserEntity.Id)).ToList(); //当前需要提交报销纸质资料的的报销 var users = dbContext.Users.ToList(); //所有用户 var content = string.Empty; //详细内容 entities.ForEach(expenseItem => { var user = users.FirstOrDefault(it => it.Id == expenseItem.ExpenseMain.ApplyUserId); if (user != null) { notification.Target = user.Email; notification.TargetUserIds = new List <int> { user.Id }; notification.MessageContent = "您的报销已经成功审批,请及时到财务提交报销申请纸质资料。"; NotificationService.Add(notification, Global.IsProduction); //消息推送 content = string.Format("{0},{1},报销纸质资料)", content, user.EnglishName); } }); if (!string.IsNullOrEmpty(content)) //详细内容 { content = content.Substring(1); } #endregion //更新定时间任务 ScheduledTaskService.UpdateTask(dbContext, task.Id, executeDate, content); //更新数据库 dbContext.SaveChanges(); //Log.Info(string.Format("定时任务执行成功: {0}。", task.Name)); } }
/// <summary> /// 通知 /// </summary> /// <param name="dbContext">数据库上下文</param> /// <param name="meeting">会议</param> /// <param name="type">通知类型</param> private void Notify(MissionskyOAEntities dbContext, MeetingCalendarModel meeting, MeetingNotificationType type) { if (dbContext == null || meeting == null || type == MeetingNotificationType.None) { Log.Error(string.Format("会议通知失败, 通知类型: {0}。", type)); throw new InvalidOperationException(string.Format("会议通知失败, 通知类型: {0}。", type)); } //参会者 IList <string> participants = new List <string>(); dbContext.MeetingParticipants.Where(it => it.MeetingCalendarId == meeting.Id).ToList().ForEach(it => { participants.Add(it.User.Email); //参会者 var model = new NotificationModel() { Target = it.User.Email, CreatedUserId = 0, //MessageType = NotificationType.PushMessage, MessageType = NotificationType.Email, Title = "会议开始结束通知", MessagePrams = "test", Scope = NotificationScope.User, CreatedTime = DateTime.Now, TargetUserIds = new List <int> { it.User.Id } }; if (type == MeetingNotificationType.StartNotification) { var startDate = Convert.ToDateTime(meeting.StartDate.ToShortDateString() + " " + meeting.StartTime.ToString()); model.BusinessType = BusinessType.NotifyMeetingStart; model.MessageContent = string.Format("由{0}主持的会议{1}将于{2}开始。", meeting.Host, meeting.Title, startDate); } else { var endDate = Convert.ToDateTime(meeting.EndDate.ToShortDateString() + " " + meeting.EndTime.ToString()); model.BusinessType = BusinessType.NotifyMeetingEnd; model.MessageContent = string.Format("由{0}主持的会议{1}将于{2}结束。", meeting.Host, meeting.Title, endDate); } NotificationService.Add(model, Global.IsProduction); //消息推送 }); //添加通知历史 NotificationHistory.Add(new MeetingNotificationModel() { Meeting = meeting.Id, NotifiedTime = DateTime.Now, Type = type }); #region 发送邮件 //会议纪要连接 string meetingSummaryURL = string.Format(Global.MeetingSummaryURL, meeting.Id); //邮件内容 string title = (type == MeetingNotificationType.StartNotification ? "[OA]会议开始通知" : "[OA]会议结束通知"); string body = string.Format("会议主题:{0}\r\n会议议程:{1}\r\n会议纪要:{2}", meeting.Title, meeting.MeetingContext, meetingSummaryURL); EmailClient.Send(participants, null, title, body); //发送邮件 #endregion }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute( IJobExecutionContext context ) { JobDataMap dataMap = context.JobDetail.JobDataMap; var groupGuid = dataMap.Get( "NotificationGroup" ).ToString().AsGuid(); var rockContext = new RockContext(); var group = new GroupService( rockContext ).Get( groupGuid ); if ( group != null ) { var installedPackages = InstalledPackageService.GetInstalledPackages(); var sparkLinkRequest = new SparkLinkRequest(); sparkLinkRequest.RockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId(); sparkLinkRequest.OrganizationName = GlobalAttributesCache.Value( "OrganizationName" ); sparkLinkRequest.VersionIds = installedPackages.Select( i => i.VersionId ).ToList(); sparkLinkRequest.RockVersion = VersionInfo.VersionInfo.GetRockSemanticVersionNumber(); var notifications = new List<Notification>(); var sparkLinkRequestJson = JsonConvert.SerializeObject( sparkLinkRequest ); var client = new RestClient( "https://www.rockrms.com/api/SparkLink/update" ); //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" ); var request = new RestRequest( Method.POST ); request.AddParameter( "application/json", sparkLinkRequestJson, ParameterType.RequestBody ); IRestResponse response = client.Execute( request ); if ( response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted ) { foreach ( var notification in JsonConvert.DeserializeObject<List<Notification>>( response.Content ) ) { notifications.Add( notification ); } } if ( sparkLinkRequest.VersionIds.Any() ) { client = new RestClient( "https://www.rockrms.com/api/Packages/VersionNotifications" ); //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" ); request = new RestRequest( Method.GET ); request.AddParameter( "VersionIds", sparkLinkRequest.VersionIds.AsDelimited( "," ) ); response = client.Execute( request ); if ( response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted ) { foreach ( var notification in JsonConvert.DeserializeObject<List<Notification>>( response.Content ) ) { notifications.Add( notification ); } } } if ( notifications.Count == 0 ) { return; } var notificationService = new NotificationService( rockContext); foreach ( var notification in notifications.ToList() ) { if (notificationService.Get(notification.Guid) == null ) { notificationService.Add( notification ); } else { notifications.Remove( notification ); } } rockContext.SaveChanges(); var notificationRecipientService = new NotificationRecipientService( rockContext ); foreach (var notification in notifications ) { foreach ( var member in group.Members ) { if ( member.Person.PrimaryAliasId.HasValue ) { var recipientNotification = new Rock.Model.NotificationRecipient(); recipientNotification.NotificationId = notification.Id; recipientNotification.PersonAliasId = member.Person.PrimaryAliasId.Value; notificationRecipientService.Add( recipientNotification ); } } } rockContext.SaveChanges(); } }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click(object sender, EventArgs e) { List <int> personAliasIds = null; if (rblSource.SelectedValue == "Manual Selection") { personAliasIds = PersonList.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(p => p.Split('^')[0].AsInteger()) .ToList(); } else if (rblSource.SelectedValue == "Group") { int?groupId = gpGroup.SelectedValueAsId(); var group = new GroupService(new RockContext()).Get(groupId ?? 0); if (groupId.HasValue) { personAliasIds = new GroupMemberService(new RockContext()).Queryable() .Where(m => m.GroupId == groupId.Value && m.GroupMemberStatus == GroupMemberStatus.Active) .Select(m => m.Person) .ToList() .Select(p => p.PrimaryAliasId.Value) .ToList(); } } else if (rblSource.SelectedValue == "Data View") { int?dataviewId = dvDataView.SelectedValueAsId(); if (dataviewId.HasValue) { using (var rockContext = new RockContext()) { var personService = new PersonService(rockContext); var parameterExpression = personService.ParameterExpression; var dv = new DataViewService(rockContext).Get(dataviewId.Value); List <string> errorMessages; var whereExpression = dv.GetExpression(personService, parameterExpression, out errorMessages); personAliasIds = new PersonService(rockContext) .Get(parameterExpression, whereExpression) .ToList() .Select(p => p.PrimaryAliasId.Value) .ToList(); } } } using (var rockContext = new RockContext()) { var notificationService = new NotificationService(rockContext); var notificationRecipientService = new NotificationRecipientService(rockContext); var notification = new Notification(); notification.Title = tbTitle.Text; notification.Message = ceMessage.Text; notification.SentDateTime = RockDateTime.Now; notification.IconCssClass = tbIconCssClass.Text; notification.Classification = ddlClassification.SelectedValueAsEnum <NotificationClassification>(); notificationService.Add(notification); foreach (var aliasId in personAliasIds) { notification.Recipients.Add(new NotificationRecipient { PersonAliasId = aliasId }); } rockContext.SaveChanges(); } pnlPost.Visible = false; pnlResults.Visible = true; }
/// <summary> /// 执行定时任务 /// </summary> /// <param name="task">定时任务</param> /// <param name="executeDate">执行时间</param> public void Execute(ScheduledTaskModel task, DateTime executeDate) { if (task == null) { Log.Error("无效的定时任务。"); throw new InvalidOperationException("无效的定时任务。"); } using (var dbContext = new MissionskyOAEntities()) { #region 推送消息 var sql = @"SELECT * FROM BookBorrow WHERE ISNULL([Status], 0) = {0} --借阅中 AND DATEDIFF(DAY, ReturnDate, GETDATE()) >= 0 --已到预计归还日期 ;" ; //推送消息 var notification = new NotificationModel() { CreatedUserId = 0, //MessageType = NotificationType.PushMessage, MessageType = NotificationType.Email, BusinessType = BusinessType.Approving, Title = "用户归还图书通知", MessagePrams = "test", Scope = NotificationScope.User, CreatedTime = DateTime.Now }; var entities = dbContext.BookBorrows.SqlQuery(string.Format(sql, (int)UserBorrowStatus.Borrowing)).ToList(); //当前需要归还的借阅图书 var users = dbContext.Users.ToList(); //所有用户 var content = string.Empty; //详细内容 entities.ForEach(borrow => { var user = users.FirstOrDefault(it => it.Id == borrow.UserId); var book = dbContext.Books.FirstOrDefault(it => it.Id == borrow.BookId); if (user != null && book != null) { notification.Target = user.Email; notification.TargetUserIds = new List <int> { user.Id }; notification.MessageContent = string.Format("请及时归还您借阅的图书《{0}》。", book.Name); NotificationService.Add(notification, Global.IsProduction); //消息推送 content = string.Format("{0},{1}({2})", content, user.EnglishName, book.Name); } }); if (!string.IsNullOrEmpty(content)) //详细内容 { content = content.Substring(1); } #endregion //更新定时间任务 ScheduledTaskService.UpdateTask(dbContext, task.Id, executeDate, content); //更新数据库 dbContext.SaveChanges(); //Log.Info(string.Format("定时任务执行成功: {0}。", task.Name)); } }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public virtual void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var groupGuid = dataMap.Get("NotificationGroup").ToString().AsGuid(); var rockContext = new RockContext(); var group = new GroupService(rockContext).Get(groupGuid); if (group != null) { var installedPackages = InstalledPackageService.GetInstalledPackages(); var sparkLinkRequest = new SparkLinkRequest(); sparkLinkRequest.RockInstanceId = Rock.Web.SystemSettings.GetRockInstanceId(); sparkLinkRequest.OrganizationName = GlobalAttributesCache.Value("OrganizationName"); sparkLinkRequest.VersionIds = installedPackages.Select(i => i.VersionId).ToList(); sparkLinkRequest.RockVersion = VersionInfo.VersionInfo.GetRockSemanticVersionNumber(); var notifications = new List <Notification>(); var sparkLinkRequestJson = JsonConvert.SerializeObject(sparkLinkRequest); var client = new RestClient("https://www.rockrms.com/api/SparkLink/update"); //var client = new RestClient( "http://localhost:57822/api/SparkLink/update" ); var request = new RestRequest(Method.POST); request.AddParameter("application/json", sparkLinkRequestJson, ParameterType.RequestBody); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } if (sparkLinkRequest.VersionIds.Any()) { client = new RestClient("https://www.rockrms.com/api/Packages/VersionNotifications"); //client = new RestClient( "http://localhost:57822/api/Packages/VersionNotifications" ); request = new RestRequest(Method.GET); request.AddParameter("VersionIds", sparkLinkRequest.VersionIds.AsDelimited(",")); response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) { foreach (var notification in JsonConvert.DeserializeObject <List <Notification> >(response.Content)) { notifications.Add(notification); } } } if (notifications.Count == 0) { return; } var notificationService = new NotificationService(rockContext); foreach (var notification in notifications.ToList()) { if (notificationService.Get(notification.Guid) == null) { notificationService.Add(notification); } else { notifications.Remove(notification); } } rockContext.SaveChanges(); var notificationRecipientService = new NotificationRecipientService(rockContext); foreach (var notification in notifications) { foreach (var member in group.Members) { if (member.Person.PrimaryAliasId.HasValue) { var recipientNotification = new Rock.Model.NotificationRecipient(); recipientNotification.NotificationId = notification.Id; recipientNotification.PersonAliasId = member.Person.PrimaryAliasId.Value; notificationRecipientService.Add(recipientNotification); } } } rockContext.SaveChanges(); } }
/// <summary> /// 执行定时任务 /// </summary> /// <param name="task">定时任务</param> /// <param name="executeDate">执行时间</param> public void Execute(ScheduledTaskModel task, DateTime executeDate) { if (task == null) { Log.Error("无效的定时任务。"); throw new InvalidOperationException("无效的定时任务。"); } using (var dbContext = new MissionskyOAEntities()) { #region 推送消息 var sql = @"SELECT * FROM BookBorrow WHERE ISNULL([Status], 0) = {0} --借阅中 AND DATEDIFF(DAY, ReturnDate, GETDATE()) >= 0 --已到预计归还日期 ;" ; //推送消息 var notification = new NotificationModel() { CreatedUserId = 0, MessageType = NotificationType.PushMessage, BusinessType = BusinessType.Approving, Title = "Missionsky OA Notification", MessagePrams = "test", Scope = NotificationScope.User, CreatedTime = DateTime.Now }; var entities = dbContext.BookBorrows.SqlQuery(string.Format(sql, (int)UserBorrowStatus.Borrowing)).ToList(); //当前需要归还的借阅图书 entities.ForEach(borrow => { var user = dbContext.Users.FirstOrDefault(it => it.Id == borrow.UserId); var book = dbContext.Books.FirstOrDefault(it => it.Id == borrow.BookId); if (user != null && book != null) { notification.Target = user.Email; notification.TargetUserIds = new List <int> { user.Id }; notification.MessageContent = string.Format("请及时归还您借阅的图书《{0}》。", book.Name); NotificationService.Add(notification, Global.IsProduction); //消息推送 } }); #endregion //更新定时任务 var history = new ScheduledTaskHistoryModel() { TaskId = task.Id, Result = true, Desc = task.Name, CreatedTime = executeDate }; ScheduledTaskService.UpdateTask(dbContext, history); dbContext.SaveChanges(); Log.Info(string.Format("定时任务执行成功: {0}。", task.Name)); } }