/// <summary>
        /// Publishes the specified audit event.
        /// </summary>
        /// <param name="auditEvent">The audit event.</param>
        public void Publish(AuditEvent auditEvent)
        {
            var message = Bus.CreateInstance<IAuditMessage>();

            auditEvent.SiteSubscriptionId = ServiceContext.HostSettings.AuditSiteSubscriptionId;

            message.AuditEvent = auditEvent;

            Bus.Publish(message);
        }
Esempio n. 2
0
 /// <summary>
 /// Shows the audit.
 /// </summary>
 /// <param name="auditEvent">The audit event.</param>
 /// <remarks>Note this only does something if built in Debug mode.</remarks>
 public static void ShowAudit(AuditEvent auditEvent)
 {
     #if DEBUG
     if (auditEvent == null)
     {
         throw new ArgumentNullException("auditEvent");
     }
     Output("AUDIT EVENT");
     Output(" SiteSubscriptionId: " + auditEvent.SiteSubscriptionId);
     Output(" ClientIP: " + auditEvent.ClientIP);
     Output(" DateOccurred: " + auditEvent.DateOccurred.ToLocalTime().ToString());
     Output(" SessionIdentifier: " + auditEvent.SessionIdentifier);
     Output(" SiteCollectionIdentifier: " + auditEvent.SiteCollectionIdentifier);
     Output(" SiteIdentifier: " + auditEvent.SiteIdentifier);
     Output(" Url: " + auditEvent.Url);
     Output(" UserName: "******"  AuditEntityAction: " + entity.AuditEntityAction.ToString());
             Output("  EntityIdentifier: " + entity.EntityIdentifier);
             Output("  EntityType: " + entity.EntityType);
             if (entity.AuditEntityProperties != null)
             {
                 foreach (var property in entity.AuditEntityProperties)
                 {
                     Output("   PropertyName: " + property.PropertyName);
                     if (property.NewValue == null)
                     {
                         Output("     NewValue: (null)");
                     }
                     else
                     {
                         Output("     NewValue: " + property.NewValue);
                     }
                     if (property.OriginalValue == null)
                     {
                         Output("     OriginalValue: (null)");
                     }
                     else
                     {
                         Output("     OriginalValue: " + property.OriginalValue);
                     }
                 }
             }
         }
     }
     Output("");
     #endif
 }
 private static AuditEvent CreateAuditEvent()
 {
     var userContext = new TestUserContext();
     var auditEvent = new AuditEvent();
     auditEvent.ClientIP = userContext.ClientIP;
     auditEvent.DateOccurred = DateTime.UtcNow;
     auditEvent.SessionIdentifier = userContext.SessionIdentifier;
     auditEvent.SiteCollectionIdentifier = userContext.SiteCollectionIdentifier;
     auditEvent.SiteIdentifier = userContext.SiteIdentifier;
     auditEvent.Url = userContext.Uri.ToString();
     auditEvent.UserName = userContext.UserName;
     auditEvent.AuditEntities = new Collection<AuditEntity>();
     auditEvent.AuditEntities.Add(CreateAuditEntity());
     auditEvent.AuditEntities.Add(CreateAuditEntity());
     return auditEvent;
 }
        public void publishes_event_to_bus()
        {
            //setup
            var eventToPublish = new AuditEvent();

            var mockMessage = new Mock<IAuditMessage>();
            mockMessage.SetupAllProperties();

            var mockBus = new Mock<IBus>();
            mockBus.Setup(bus => bus.CreateInstance<IAuditMessage>()).Returns(mockMessage.Object);

            var subject = new BusAuditEventPublisher();
            subject.Bus = mockBus.Object;

            //act
            subject.Publish(eventToPublish);

            //assert
            mockBus.Verify(bus => bus.Publish(It.Is<IAuditMessage>(message => message.AuditEvent == eventToPublish)), Times.Once());
        }
Esempio n. 5
0
        public void Run()
        {
            int counter = 0;
            Output("Press Enter to publish an audit event");
            while (Console.ReadLine() != null)
            {
                String subscriptionId = Guid.Empty.ToString();
                if (++counter % 2 == 0)
                {
                    subscriptionId = "7FD0769B-59C2-40EA-AA4A-F29ABA02DB6D";
                }
                Output("subscription " + subscriptionId);

                var auditEvent = new AuditEvent
                {
                    ClientIP = "127.0.0.1",
                    Url = "http://localhost",
                    UserName = "******",
                    DateOccurred = DateTime.UtcNow,
                    SiteSubscriptionId = subscriptionId,
                    AuditEntities = new Collection<AuditEntity>()
                };

                var entity = new AuditEntity { AuditEntityProperties = new Collection<AuditEntityProperty>() };
                entity.EntityIdentifier = "123";
                entity.AuditEntityAction = AuditEntityAction.Update;
                entity.EntityType = "MEDSEEK.eHealth.Framework.DAL.Common.Profile";
                entity.AuditEntityProperties.Add(new AuditEntityProperty { NewValue = "Jack", OriginalValue = "John", PropertyName = "FirstName" });
                entity.AuditEntityProperties.Add(new AuditEntityProperty { NewValue = null, OriginalValue = DateTime.Now.ToString(), PropertyName = "DateOfBirth" });
                auditEvent.AuditEntities.Add(entity);

                var message = Bus.CreateInstance<IAuditMessage>();
                message.AuditEvent = auditEvent;

                Bus.Publish(message);
                Output("Published message");
            }

            Console.ReadLine();
        }
 private static AuditEvent CreateAuditEvent()
 {
     var auditEvent = new AuditEvent();
     auditEvent.ClientIP = "127.0.0.1";
     auditEvent.DateOccurred = DateTime.UtcNow;
     auditEvent.SessionIdentifier = Guid.NewGuid().ToString();
     auditEvent.SiteCollectionIdentifier = Guid.NewGuid().ToString();
     auditEvent.SiteIdentifier = Guid.NewGuid().ToString();
     auditEvent.Url = "http://localhost";
     auditEvent.UserName = "******";
     return auditEvent;
 }