Пример #1
0
 public void Add(NotificationEvent notification)
 {
     using (var context = _provider.Provide())
     {
         context.Notifications.Add(notification);
         context.SaveChanges();
     }
 }
Пример #2
0
 public bool GetById(Guid id, out NotificationEvent notification)
 {
     using (var context = _provider.Provide())
     {
         notification = context.Notifications.FirstOrDefault(n => n.Id.Equals(id));
     }
     return notification != null;
 }
Пример #3
0
 protected override bool ShouldPublish(INotificationEventPublisher publisher, NotificationEvent message)
 {
     if (PublishFailure && !message.Result.GetValueOrDefault(false))
         return true;
     if (PublishSuccess && message.Result.GetValueOrDefault(false))
         return true;
     return false;
 }
 public void Add(NotificationEvent notification)
 {
     var filename = MakeItemFilename(notification.Id);
     lock (LockObject)
     {
         Serialiser.ToJsonInFile(filename, notification);
     }
     Logger.Debug("Stored Notification ({0}): {1}", notification.EventType, filename);
 }
Пример #5
0
        public void Publish(NotificationEvent message)
        {
            throw new NotImplementedException();
            //var data = Serialiser<NotificationEventHealthCheck>.ToXml(message);

            //var statement = SqlServerStatement.Create("INSERT INTO {0}.AgentData (", myConfig.SchemaName)
            //    .Append("TypeId,EventType,SiteId,AgentId,CheckId,")
            //    .AppendIf(() => message.Check.Result.HasValue, "Result,")
            //    .AppendIf(() => message.Check.ResultCount.HasValue, "ResultCount,")
            //    .AppendIf(() => !string.IsNullOrEmpty(message.Check.Tags), "Tags,")
            //    .Append("GeneratedOnUtc,ReceivedOnUtc,Data,")
            //    .AppendIf(() => message.MinuteBucket.HasValue, "MinuteBucket,")
            //    .AppendIf(() => message.HourBucket.HasValue, "HourBucket,")
            //    .AppendIf(() => message.DayBucket.HasValue, "DayBucket,")
            //    .Append("Version")
            //    .AppendIf(() => (message.Check.Geo != null), ",Longitude,Latitude")
            //    .Append(") VALUES (")
            //    .InsertParameter("@pTypeId", message.Check.Identity.TypeId).Append(",")
            //    .InsertParameter("@pEventType", message.EventType).Append(",")
            //    .InsertParameter("@pSiteId", message.Agent.SiteId).Append(",")
            //    .InsertParameter("@pAgentId", message.Agent.AgentId).Append(",")
            //    .InsertParameter("@pCheckId", message.Check.Identity.Name).Append(",")
            //    .InsertParameterIf(() => message.Check.Result.HasValue, "@pResult", message.Check.Result)
            //    .AppendIf(() => message.Check.Result.HasValue, ",")
            //    .InsertParameterIf(() => message.Check.ResultCount.HasValue, "@pResultCount", message.Check.ResultCount)
            //    .AppendIf(() => message.Check.ResultCount.HasValue, ",")
            //    .InsertParameterIf(() => !string.IsNullOrEmpty(message.Check.Tags), "@pTags", message.Check.Tags)
            //    .AppendIf(() => !string.IsNullOrEmpty(message.Check.Tags), ",")
            //    .InsertParameter("@pGeneratedOnUtc", message.Check.GeneratedOnUtc).Append(",")
            //    .InsertParameter("@pReceivedOnUtc", DateTime.UtcNow).Append(",")
            //    .InsertParameter("@pData", data).Append(",")
            //    .InsertParameterIf(() => message.MinuteBucket.HasValue, "@pMinuteBucket", message.MinuteBucket)
            //    .AppendIf(() => message.MinuteBucket.HasValue, ",")
            //    .InsertParameterIf(() => message.HourBucket.HasValue, "@pHourBucket", message.HourBucket)
            //    .AppendIf(() => message.HourBucket.HasValue, ",")
            //    .InsertParameterIf(() => message.DayBucket.HasValue, "@pDayBucket", message.DayBucket)
            //    .AppendIf(() => message.DayBucket.HasValue, ",")
            //    .InsertParameter("@pVersion", message.Id);

            //if (message.Check.Geo != null)
            //{
            //    statement.Append(",")
            //        .InsertParameter("@pLongitude", message.Check.Geo.Longitude).Append(",")
            //        .InsertParameter("@pLatitude", message.Check.Geo.Latitude);
            //}
            //statement.Append(")");

            //using (var cmd = SqlServerAdhocCommand.UsingSmartConnection(myConfig.ConnectionString)
            //    .WithSql(statement))
            //{
            //    cmd.ExecuteNonQuery();
            //}
        }
Пример #6
0
        public UiViewsModule(ActivityTracker tracker)
            : base(BaseUrl)
        {
            _tracker = tracker;
            Get["/"] = _ => View["views/status.sshtml"];
            Get["/status"] = _ => View["views/status.sshtml"];
            Get["/activity"] = _ => View["views/activity.sshtml"];
            Get["/gallery"] = _ => View["views/gallery.sshtml"];
            Get["/configure"] = _ => View["views/configure.sshtml"];
            Get["/about"] = _ => View["views/about.sshtml"];
            Get["/tools/diagnostics"] = _ => View["views/diagnostics.sshtml"];
            Get["/tools/sendnotification"] = _ =>
            {
                var siteInfo = _tracker.StartEvent;

                var config = Container.Resolve<WebServiceActivityConfig>();

                var notification = new NotificationEvent
                {
                    AgentId = siteInfo.AgentId,
                    CheckId = "CheckId",
                    CriticalFailure = false,
                    CriticalFailureDetails = null,
                    Data = "JSON Serialised copy of this...",
                    MinuteBucket = AnalyticsBaseline.MinuteBucket,
                    HourBucket = AnalyticsBaseline.HourBucket,
                    DayBucket = AnalyticsBaseline.DayBucket,
                    DisplayUnit = "",
                    EventType = "",
                    GeneratedOnUtc = DateTime.UtcNow,
                    Id = Guid.NewGuid(),
                    Latitude = "",
                    Longitude = "",
                    Message = "Message",
                    Properties = new Properties { {"SomeProperty", "SomeValue"} },
                    Result = false,
                    ResultCount = 0,
                    SiteId = siteInfo.SiteId,
                    State = MessageStateTypes.NotSet,
                    Tags = new List<string> {"SomeTag"},
                    Version = Guid.Empty
                };
                var keys = config.ApiKeys != null ? config.ApiKeys.ToArray() : new string[0];
                var model = new SendNotificationModel(notification, keys);
                return View["views/sendnotification.sshtml", model];
            };
        }
Пример #7
0
        protected override bool ShouldPublish(INotificationEventPublisher publisher, NotificationEvent message)
        {
            if (IgnoreTheseTypes != null && IgnoreTheseTypes.Count > 0)
            {
                // don't publish if match
                if (IgnoreTheseTypes.Exists(ignoreType => System.String.CompareOrdinal(ignoreType, message.EventType) == 0))
                    return false;
                // otherwise check the publish list next....
            }

            if (PublishTheseTypes != null && PublishTheseTypes.Count > 0)
            {
                // publish only if match
                return PublishTheseTypes.Exists(publishType => System.String.CompareOrdinal(publishType, message.EventType) == 0);
            }

            // publish everything else...
            return true;
        }
Пример #8
0
        public void Consume(NotificationEvent message)
        {
            throw new NotImplementedException();
            //var statement = SQLiteStatement.Create("INSERT INTO AgentData (")
            //    .Append(
            //        "TypeId,EventType,SiteId,AgentId,CheckId,Result,ResultCount,GeneratedOnUtc,ReceivedOnUtc,Data,Tags,Version,MinuteBucket,HourBucket,DayBucket")
            //    .AppendIf(() => (message.Check.Geo != null), ",Longitude,Latitude")
            //    .Append(") VALUES (")
            //    .InsertParameter("@pTypeId", message.TypeId).Append(",")
            //    .InsertParameter("@pEventType", message.EventType).Append(",")
            //    .InsertParameter("@pSiteId", message.SiteId).Append(",")
            //    .InsertParameter("@pAgentId", message.AgentId).Append(",")
            //    .InsertParameter("@pCheckId", message.CheckId).Append(",")
            //    .InsertParameter("@pResult", message.Result).Append(",")
            //    .InsertParameter("@pResultCount", message.ResultCount).Append(",")
            //    .InsertParameter("@pGeneratedOnUtc", message.GeneratedOnUtc).Append(",")
            //    .InsertParameter("@pReceivedOnUtc", message.ReceivedOnUtc).Append(",")
            //    .InsertParameter("@pData", message.Data).Append(",")
            //    .InsertParameter("@pTags", message.Tags).Append(",")
            //    .InsertParameter("@pVersion", message.Id).Append(",")
            //    .InsertParameter("@pMinuteBucket", message.MinuteBucket).Append(",")
            //    .InsertParameter("@pHourBucket", message.HourBucket).Append(",")
            //    .InsertParameter("@pDayBucket", message.DayBucket);

            //if (message.Check.Geo != null)
            //{
            //    statement.Append(",")
            //        .InsertParameter("@pLongitude", message.Check.Geo.Longitude).Append(",")
            //        .InsertParameter("@pLatitude", message.Check.Geo.Latitude);
            //}
            //statement.Append(")");

            //using (var cmd = SQLiteAdhocCommand.UsingSmartConnection(myConfig.ConnectionString)
            //    .WithSql(statement))
            //{
            //    cmd.ExecuteNonQuery();
            //}
        }
Пример #9
0
 public void Consume(NotificationEvent message)
 {
     NotificationEvent other;
     if(!_repository.GetById(message.Id, out other))
         _repository.Add(message);
 }
Пример #10
0
 public SendNotificationModel(NotificationEvent notification, string[] apiKeys)
 {
     Notification = notification;
     ApiKeys = Serialiser.ToJson(apiKeys, false);
     Json = Serialiser.ToJson(notification, false);
 }
 public void Execute(NotificationEvent notification)
 {
     NotificationsReceived.Add(notification.Id, notification);
 }
Пример #12
0
 public void TheNotificationRequestIsConvertedToAnEvent()
 {
     var hub = new DefaultNotificationHub(new AgentConfiguration(), _filters);
     _event = hub.ConvertRequestToEvent(_request);
 }
Пример #13
0
 public void Consume(NotificationEvent message)
 {
     Publish(message);
 }
Пример #14
0
 public void Consume(NotificationEvent message)
 {
     var graph = Serialiser.ToJson(message);
     System.Console.WriteLine(graph);
 }
 public bool GetById(Guid id, out NotificationEvent notification)
 {
     notification = LoadAll().FirstOrDefault(n => n.Id.Equals(id));
     return notification != null;
 }