public async Task <ListNotificationViewModel> GetNotificationByGroup(EntityType entityType, NotificationStatus status, string groupName, int pageindex, int pagesize) { List <NotificationType> _list_notification_type = new List <NotificationType>(); if (groupName == "Campaign") { _list_notification_type = GroupCampaign; } else if (groupName == "Payment") { _list_notification_type = GroupPayment; } else if (groupName == "Influencer") { _list_notification_type = GroupInfluencer; } var filter = new NotificationSpecification(entityType, status, _list_notification_type); var notifications = await _notificationRepository.ListPagedAsync(filter, "DateCreated_desc", pageindex, pagesize); var total = await _notificationRepository.CountAsync(filter); var list = await GetNotifications(notifications); return(new ListNotificationViewModel() { Notifications = list, Pager = new PagerViewModel(pageindex, pagesize, total) }); }
public DeadClientNotificationTask(ConnectedClientsLedger parent, string clientId, DateTime disconnectTime, NotificationSpecification specification, ClientInfo info) { _gracePeriod = Convert.ToInt32( Math.Ceiling( (disconnectTime.AddSeconds(specification.Period) - disconnectTime).TotalMilliseconds)); _parent = parent; _clientId = clientId; _specification = specification; _info = info; }
public async Task <bool> GetNotificationStatus(int profileUserId) { var spec = new NotificationSpecification(profileUserId, false); var notifications = await _notificationRepository.ListAsync(spec); if (notifications.Count > 0) { return(true); } else { return(false); } }
public async Task <ListNotificationViewModel> GetNotifications(EntityType entityType, int pageindex, int pagesize) { var filter = new NotificationSpecification(entityType); var notifications = await _notificationRepository.ListPagedAsync(filter, "DateCreated_desc", pageindex, pagesize); var total = await _notificationRepository.CountAsync(filter); var list = await GetNotifications(notifications); return(new ListNotificationViewModel() { Notifications = list, Pager = new PagerViewModel(pageindex, pagesize, total) }); }
public async Task <ListNotificationViewModel> GetNotifications(EntityType entityType, int entityId, NotificationTypeGroup?typeGroup, string daterange, string order, int page, int pagesize) { var statusArr = typeGroup.GetNotificationTypes(); var dtRange = Common.Helpers.DateRangeHelper.GetDateRange2(daterange); var filter = new NotificationSpecification(entityType, entityId, statusArr, dtRange); var notifications = await _notificationRepository.ListPagedAsync(filter, order, page, pagesize); var total = await _notificationRepository.CountAsync(filter); var list = await GetNotifications(notifications); return(new ListNotificationViewModel() { Notifications = list, Pager = new PagerViewModel(page, pagesize, total) }); }
public async Task <ListNotificationViewModel> GetNotificationByGroup(EntityType entityType, int entityId, string groupName, string daterange, int pageindex, int pagesize) { List <NotificationType> _list_notification_type = new List <NotificationType>(); if (groupName == "Campaign") { _list_notification_type = GroupCampaign; } else if (groupName == "Payment") { _list_notification_type = GroupPayment; } else if (groupName == "Influencer") { _list_notification_type = GroupInfluencer; } else if (groupName == "System") { _list_notification_type = GroupSystem; } var dtRange = Common.Helpers.DateRangeHelper.GetDateRange(daterange); var filter = new NotificationSpecification(entityType, entityId, _list_notification_type.AsEnumerable(), dtRange); var notifications = await _notificationRepository.ListPagedAsync(filter, "DateCreated_desc", pageindex, pagesize); var total = await _notificationRepository.CountAsync(filter); var list = await GetNotifications(notifications); return(new ListNotificationViewModel() { Notifications = list, Pager = new PagerViewModel(pageindex, pagesize, total) }); }
public void Execute(AnalysisExecutionContext context) { _context = context; if (context.Results.Count <= 0) { context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Canceled, 0, 0, 0)); return; } MechanicalTurkSettings settings = context.CustomField as MechanicalTurkSettings; if (settings == null) { settings = new MechanicalTurkSettings(null, 3, new decimal(0.10), 300, 1800, 75); } string key = context.Key; string secret = context.Secret; MTurkConfig config = new MTurkConfig(_serviceURL, key, secret); SimpleClient client = new SimpleClient(config); List <QualificationRequirement> requirements = new List <QualificationRequirement>(); QualificationRequirement sucRequirement = new QualificationRequirement(); sucRequirement.QualificationTypeId = MTurkSystemQualificationTypes.ApprovalRateQualification; sucRequirement.IntegerValueSpecified = true; sucRequirement.IntegerValue = settings.PercentOfSuccess; sucRequirement.Comparator = Comparator.GreaterThanOrEqualTo; requirements.Add(sucRequirement); if (settings.Locale != null) { QualificationRequirement qualReq = new QualificationRequirement(); qualReq.LocaleValue = new Locale() { Country = settings.Locale }; qualReq.Comparator = Comparator.EqualTo; qualReq.QualificationTypeId = MTurkSystemQualificationTypes.LocaleQualification; requirements.Add(qualReq); } string hitType = string.Empty; try { if (context.UseDebugMode) { TimeSpan time = TimeSpan.Zero; hitType = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state) { return(hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.", settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment nlp", requirements)); }), null, out time) as string; Console.WriteLine("MechanicalTurk: HIT type for sentiment analysis has been created. HIT type ID is: {0} Execution time is: {1}", hitType, time.TotalMilliseconds); } else { hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.", settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment, nlp", requirements); } NotificationSpecification notification = new NotificationSpecification(); notification.Transport = NotificationTransport.Email; notification.EventType = new EventType[] { EventType.AssignmentReturned }; notification.Destination = settings.Email; notification.Version = "2006-05-05"; if (settings.Email != null) { client.SetHITTypeNotification(hitType, notification, true); } else { notification.Destination = "*****@*****.**"; client.SetHITTypeNotification(hitType, notification, false); } } catch (Exception ex) { AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, 0, 0); ea.Reason = ex.Message; context.OnExecutionProgress("MechanicalTurk", ea); if (ea.Cancel) { return; } } string questionFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "SentimentTemplate.xml"); string template = File.ReadAllText(questionFile); QuestionForm formTemplate = QuestionUtil.DeserializeQuestionForm(template); int processed = 0; int failed = 0; foreach (KeyValuePair <string, ResultSet> document in context.Results) { formTemplate.Question[0].QuestionIdentifier = document.Key; formTemplate.Question[0].QuestionContent.Items[0] = Encoding.UTF8.GetString(Encoding.Default.GetBytes(document.Value.Source)); string question = QuestionUtil.SerializeQuestionForm(formTemplate); HIT hit = new HIT(); hit.Expiration = DateTime.Now.AddDays(1); hit.ExpirationSpecified = true; hit.HITGroupId = "SentimentAnalysis"; hit.HITTypeId = hitType; hit.MaxAssignments = settings.Assignments; hit.MaxAssignmentsSpecified = true; hit.Question = question; HIT serverHit = null; try { processed++; if (context.UseDebugMode) { TimeSpan time = TimeSpan.Zero; serverHit = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state) { return(client.CreateHIT(hit)); }), null, out time) as HIT; Console.WriteLine("MechanicalTurk: HIT {0} has been sent to Mechanical turk for processing. Execution time is: {1}", serverHit.HITId, time.TotalMilliseconds); } else { serverHit = client.CreateHIT(hit); } document.Value.AddOutput("MechanicalTurk", settings.Assignments, serverHit.HITId); AnalysisExecutionProgressEventArgs e = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Processed, context.Results.Count, processed, failed); context.OnExecutionProgress("MechanicalTurk", e); if (e.Cancel) { break; } } catch (Exception ex) { failed++; document.Value.AddOutput("MechanicalTurk", 0, "failed"); AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, processed, failed); ea.Reason = ex.Message; context.OnExecutionProgress("MechanicalTurk", ea); if (ea.Cancel) { break; } } } context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Success, context.Results.Count, processed, failed)); }
internal void AddClientDeathNotificationSpecification(NotificationSpecification specification) { _specifications.Add(ClientDeathNotification, specification); }
public async Task <IReadOnlyCollection <Notification> > GetCheckedNotifications(int profileUserId) { var spec = new NotificationSpecification(profileUserId, true); return(await _notificationRepository.ListAsync(spec)); }
/// <summary> /// See <a href="http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_SetHITTypeNotificationOperation.html">online documentation for this operation.</a> /// </summary> /// <param name="hitTypeId">The hit type id.</param> /// <param name="notification">The notification.</param> /// <param name="active">The active.</param> public void SetHITTypeNotification(string hitTypeId, NotificationSpecification notification, bool? active) { SetHITTypeNotificationRequest req = new SetHITTypeNotificationRequest(); req.HITTypeId = hitTypeId; req.Notification = notification; if (active.HasValue) { req.Active = active.Value; req.ActiveSpecified = true; } Proxy.SetHITTypeNotification(req); }
/// <summary> /// See <a href="http://docs.amazonwebservices.com/AWSMechTurk/2012-03-25/AWSMturkAPI/ApiReference_SendTestEventNotificationOperation.html">online documentation for this operation.</a> /// </summary> /// <param name="notification">The notification.</param> /// <param name="testEventType">Type of the test event.</param> public void SendTestEventNotification(NotificationSpecification notification, EventType ?testEventType) { SendTestEventNotificationRequest req = new SendTestEventNotificationRequest(); req.Notification = notification; if (testEventType.HasValue) { req.TestEventType = testEventType.Value; req.TestEventTypeSpecified = true; } Proxy.SendTestEventNotification(req); }
/// <summary> /// Sets up an email notification setting for the given HIT Type. /// </summary> /// <param name="hitTypeId">The hit type id.</param> /// <param name="emailAddress">The email address.</param> /// <param name="eventType">Type of the event.</param> public void SendTestEmailEventNotification(string hitTypeId, string emailAddress, EventType eventType) { NotificationSpecification spec = new NotificationSpecification(); spec.Destination = emailAddress; spec.Transport = NotificationTransport.Email; spec.Version = MTurkConstants.NotificationVersion; spec.EventType = new EventType[] { eventType }; SetHITTypeNotification(hitTypeId, spec, true); }
public void Execute(AnalysisExecutionContext context) { _context = context; if (context.Results.Count <= 0) { context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Canceled, 0, 0, 0)); return; } MechanicalTurkSettings settings = context.CustomField as MechanicalTurkSettings; if (settings == null) settings = new MechanicalTurkSettings(null, 3, new decimal(0.10), 300, 1800, 75); string key = context.Key; string secret = context.Secret; MTurkConfig config = new MTurkConfig(_serviceURL, key, secret); SimpleClient client = new SimpleClient(config); List<QualificationRequirement> requirements = new List<QualificationRequirement>(); QualificationRequirement sucRequirement = new QualificationRequirement(); sucRequirement.QualificationTypeId = MTurkSystemQualificationTypes.ApprovalRateQualification; sucRequirement.IntegerValueSpecified = true; sucRequirement.IntegerValue = settings.PercentOfSuccess; sucRequirement.Comparator = Comparator.GreaterThanOrEqualTo; requirements.Add(sucRequirement); if (settings.Locale != null) { QualificationRequirement qualReq = new QualificationRequirement(); qualReq.LocaleValue = new Locale() { Country = settings.Locale }; qualReq.Comparator = Comparator.EqualTo; qualReq.QualificationTypeId = MTurkSystemQualificationTypes.LocaleQualification; requirements.Add(qualReq); } string hitType = string.Empty; try { if (context.UseDebugMode) { TimeSpan time = TimeSpan.Zero; hitType = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state) { return hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.", settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment nlp", requirements); }), null, out time) as string; Console.WriteLine("MechanicalTurk: HIT type for sentiment analysis has been created. HIT type ID is: {0} Execution time is: {1}", hitType, time.TotalMilliseconds); } else hitType = client.RegisterHITType("Sentiment analysis", "Judge the sentiment expressed by the following text.", settings.TimeToApprove, settings.TimeToFinish, settings.Reward, "sentiment, nlp", requirements); NotificationSpecification notification = new NotificationSpecification(); notification.Transport = NotificationTransport.Email; notification.EventType = new EventType[] { EventType.AssignmentReturned }; notification.Destination = settings.Email; notification.Version = "2006-05-05"; if (settings.Email != null) client.SetHITTypeNotification(hitType, notification, true); else { notification.Destination = "*****@*****.**"; client.SetHITTypeNotification(hitType, notification, false); } } catch (Exception ex) { AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, 0, 0); ea.Reason = ex.Message; context.OnExecutionProgress("MechanicalTurk", ea); if (ea.Cancel) return; } string questionFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "SentimentTemplate.xml"); string template = File.ReadAllText(questionFile); QuestionForm formTemplate = QuestionUtil.DeserializeQuestionForm(template); int processed = 0; int failed = 0; foreach (KeyValuePair<string, ResultSet> document in context.Results) { formTemplate.Question[0].QuestionIdentifier = document.Key; formTemplate.Question[0].QuestionContent.Items[0] = Encoding.UTF8.GetString(Encoding.Default.GetBytes(document.Value.Source)); string question = QuestionUtil.SerializeQuestionForm(formTemplate); HIT hit = new HIT(); hit.Expiration = DateTime.Now.AddDays(1); hit.ExpirationSpecified = true; hit.HITGroupId = "SentimentAnalysis"; hit.HITTypeId = hitType; hit.MaxAssignments = settings.Assignments; hit.MaxAssignmentsSpecified = true; hit.Question = question; HIT serverHit = null; try { processed++; if (context.UseDebugMode) { TimeSpan time = TimeSpan.Zero; serverHit = BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state) { return client.CreateHIT(hit); }), null, out time) as HIT; Console.WriteLine("MechanicalTurk: HIT {0} has been sent to Mechanical turk for processing. Execution time is: {1}", serverHit.HITId, time.TotalMilliseconds); } else serverHit = client.CreateHIT(hit); document.Value.AddOutput("MechanicalTurk", settings.Assignments, serverHit.HITId); AnalysisExecutionProgressEventArgs e = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Processed, context.Results.Count, processed, failed); context.OnExecutionProgress("MechanicalTurk", e); if (e.Cancel) break; } catch (Exception ex) { failed++; document.Value.AddOutput("MechanicalTurk", 0, "failed"); AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, context.Results.Count, processed, failed); ea.Reason = ex.Message; context.OnExecutionProgress("MechanicalTurk", ea); if (ea.Cancel) break; } } context.OnExecutionProgress("MechanicalTurk", new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Success, context.Results.Count, processed, failed)); }