本文整理汇总了C#中EventSource类的典型用法代码示例。如果您正苦于以下问题:C# EventSource类的具体用法?C# EventSource怎么用?C# EventSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventSource类属于命名空间,在下文中一共展示了EventSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGenericEvents
public void TestGenericEvents()
{
var a = new EventSource();
var e = new IncomingEvent<EventArgs> { Channel = "a", DataObject = new EventArgs { Id = 10 }, EventName = "foo" };
(e as IncomingEvent).Data = "{id:10}";
var events = new List<IIncomingEvent>();
a.EventEmitted += (sender, evt) =>
{
Assert.AreEqual(evt.Channel, e.Channel);
Assert.AreEqual(evt.Data, e.Data);
Assert.AreEqual(evt.EventName, e.EventName);
events.Add(evt);
};
a.GetEventSubscription<EventArgs>().EventEmitted += (sender, evt) =>
{
Assert.AreEqual(evt.Channel, e.Channel);
Assert.AreEqual(evt.Data, e.Data);
Assert.AreEqual(evt.DataObject.Id, e.DataObject.Id);
Assert.AreEqual(evt.EventName, e.EventName);
events.Add(evt);
};
a.EmitEvent(e);
Assert.AreEqual(events.Count, 2, "Event should get through twice when you have two subscriptions");
}
示例2: WhenSourceEventRaised_ThenCollectedSubscriberIsNotNotified
public void WhenSourceEventRaised_ThenCollectedSubscriberIsNotNotified()
{
var source = new EventSource();
var publisher = new EventPublisher(source);
var subscriber = new EventSubscriber();
var subscription = publisher.PropertyChanged.Subscribe(subscriber.OnChanged);
try
{
subscriber = null;
subscription.Dispose();
GC.Collect();
GC.WaitForFullGCApproach(-1);
GC.WaitForFullGCComplete(-1);
GC.WaitForPendingFinalizers();
source.RaisePropertyChanged("Foo");
Assert.Equal(0, EventSubscriber.ChangedProperties.Count);
}
finally
{
//subscription.Dispose();
}
}
示例3: TestEventSource
public TestEventSource(EventSource r)
{
if (r != null)
source = r;
else
source = new EventSource();
}
示例4: BuildSourceFromDataBaseData
public static TestEventSource BuildSourceFromDataBaseData(string idReferral)
{
using (NpgsqlConnection connection = Global.GetSqlConnection())
{
string findPatient = "SELECT is_referral_review_source_mo, referral_creation_date, planned_date, referral_out_date, referral_review_date_source_mo FROM public.referral WHERE id_referral = '" + idReferral + "'ORDER BY id_referral DESC LIMIT 1";
NpgsqlCommand person = new NpgsqlCommand(findPatient, connection);
using (NpgsqlDataReader personFromDataBase = person.ExecuteReader())
{
EventSource p = new EventSource();
while (personFromDataBase.Read())
{
if (personFromDataBase["is_referral_review_source_mo"] != DBNull.Value)
p.IsReferralReviewed = Convert.ToBoolean(personFromDataBase["is_referral_review_source_mo"]);
if (personFromDataBase["referral_creation_date"] != DBNull.Value)
p.ReferralCreateDate = Convert.ToDateTime(personFromDataBase["referral_creation_date"]);
if (personFromDataBase["planned_date"] != DBNull.Value)
p.PlannedDate = Convert.ToDateTime(personFromDataBase["planned_date"]);
if (personFromDataBase["referral_out_date"] != DBNull.Value)
p.ReferralOutDate = Convert.ToDateTime(personFromDataBase["referral_out_date"]);
if (personFromDataBase["referral_review_date_source_mo"] != DBNull.Value)
p.ReferralReviewDate = Convert.ToDateTime(personFromDataBase["referral_review_date_source_mo"]);
TestEventSource pers = new TestEventSource(p);
return pers;
}
}
}
return null;
}
示例5: OnEventSourceCreated
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (!this.Disabled)
{
this.EnableEvents(eventSource, EventLevel.LogAlways, (EventKeywords) ~0);
}
}
开发者ID:TylerAngell,项目名称:service-fabric-dotnet-management-party-cluster,代码行数:7,代码来源:BufferingEventListener.cs
示例6: OnEventSourceCreated
protected override void OnEventSourceCreated(EventSource eventSource)
{
// There is a bug in the EventListener library that causes this override to be called before the object is fully constructed.
// So if we are not constructed yet, we will just remember the event source reference. Once the construction is accomplished,
// we can decide if we want to handle a given event source or not.
// Locking on 'this' is generally a bad practice because someone from outside could put a lock on us, and this is outside of our control.
// But in the case of this class it is an unlikely scenario, and because of the bug described above,
// we cannot rely on construction to prepare a private lock object for us.
lock (this)
{
if (!this.constructed)
{
if (this.eventSourcesPresentAtConstruction == null)
{
this.eventSourcesPresentAtConstruction = new List<EventSource>();
}
this.eventSourcesPresentAtConstruction.Add(eventSource);
}
else if (!this.Disabled)
{
EnableEventSource(eventSource);
}
}
}
开发者ID:Azure-Samples,项目名称:service-fabric-dotnet-management-party-cluster,代码行数:26,代码来源:BufferingEventListener.cs
示例7: OnEventSourceCreated
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name.StartsWith("Microsoft-ApplicationInsights-", StringComparison.Ordinal))
{
this.EnableEvents(eventSource, this.logLevel, (EventKeywords)AllKeyword);
}
base.OnEventSourceCreated(eventSource);
}
示例8: Log
public void Log(EventSource eventSource, Exception exception, EventId eventId, EventLogEntryType logEntryType)
{
if (!EventLog.SourceExists(eventSource.ToString()))
{
EventLog.CreateEventSource(eventSource.ToString(), "TrainSurfer");
}
EventLog log = new EventLog();
log.Source = eventSource.ToString();
log.WriteEntry(FormatException(exception), logEntryType, (int)eventId);
}
示例9: CreateEvent
public static int CreateEvent (EventSource eventSource, EventType eventType, int actingPersonId,
int organizationId,
int geographyId, int affectedPersonId, int parameterInt, string parameterText)
{
//TODO: organizationId comes in hardcoded as 1 from a lot of places, should probably be changed based on affected person
// to the party for that country if not swedish.
return SwarmDb.GetDatabaseForWriting().CreateEvent(eventSource, eventType, actingPersonId, organizationId,
geographyId, affectedPersonId, parameterInt, parameterText);
}
示例10: WhenWeakTargetCollected_ThenWeakReferenceNotAlive
public void WhenWeakTargetCollected_ThenWeakReferenceNotAlive()
{
var source = new EventSource();
var weak = new WeakReference(source);
source = null;
GC.Collect();
Assert.False(weak.IsAlive);
}
示例11: OnEventSourceCreated
/// <summary>
/// Override this method to get a list of all the eventSources that exist.
/// </summary>
protected override void OnEventSourceCreated(EventSource eventSource)
{
// Because we want to turn on every EventSource, we subscribe to a callback that triggers
// when new EventSources are created. It is also fired when the EventListner is created
// for all pre-existing EventSources. Thus this callback get called once for every
// EventSource regardless of the order of EventSource and EventListener creation.
// For any EventSource we learn about, turn it on.
EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
}
示例12: InstallerWillWireUpSubjectToPublicMethodInInternalListenerClass
public void InstallerWillWireUpSubjectToPublicMethodInInternalListenerClass()
{
InternalListener listener = new InternalListener();
EventSource source = new EventSource();
ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();
binder.Bind(source, listener);
source.Fire();
Assert.IsTrue(listener.callbackHappened);
}
示例13: CreateActivistWithLogging
public static void CreateActivistWithLogging (Geography geo, Person newActivist, string logMessage, EventSource evtSrc, bool isPublic, bool isConfirmed, int orgId)
{
PWEvents.CreateEvent(evtSrc,
EventType.NewActivist,
newActivist.Identity,
orgId,
geo.Identity,
newActivist.Identity,
0,
string.Empty);
newActivist.CreateActivist(isPublic, isConfirmed);
PWLog.Write(newActivist, PWLogItem.Person, newActivist.Identity, PWLogAction.ActivistJoin, "New activist joined.", logMessage);
}
示例14: BuildLogger
/// <summary>
/// Initializes a new instance of the <see cref="BuildLogger"/> class.
/// </summary>
/// <param name="logger">The logger used by this instance. Can be <c>null</c>.</param>
/// <param name="eventSource">The event source.</param>
/// <exception cref="ArgumentNullException"><paramref name="eventSource"/> is <c>null</c>.</exception>
internal BuildLogger(ILogger logger, EventSource eventSource)
{
if (eventSource == null)
{
throw new ArgumentNullException("eventSource");
}
this.eventSource = eventSource;
if (logger != null)
{
Initialize(logger);
}
}
示例15: GetSchema
/// <summary>
/// Gets the <see cref="EventSchema"/> for the specified eventId and eventSource.
/// </summary>
/// <param name="eventId">The ID of the event.</param>
/// <param name="eventSource">The event source.</param>
/// <returns>The EventSchema.</returns>
public EventSchema GetSchema(int eventId, EventSource eventSource)
{
Guard.ArgumentNotNull(eventSource, "eventSource");
IReadOnlyDictionary<int, EventSchema> events;
if (!this.schemas.TryGetValue(eventSource.Guid, out events))
{
events = new ReadOnlyDictionary<int, EventSchema>(this.schemaReader.GetSchema(eventSource));
this.schemas[eventSource.Guid] = events;
}
return events[eventId];
}