本文整理汇总了C#中IListener.OnEvent方法的典型用法代码示例。如果您正苦于以下问题:C# IListener.OnEvent方法的具体用法?C# IListener.OnEvent怎么用?C# IListener.OnEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IListener
的用法示例。
在下文中一共展示了IListener.OnEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Runs simulation.
/// </summary>
/// <param name="runListener">Simulation listener.</param>
/// <param name="runInSameThread">If <c>true</c>, simulation is run in same thread like caller,
/// ie. method blocks until simulation don't finish. If <c>false</c>, simulation is
/// run in separate thread and method returns immediately.</param>
/// <remarks>
/// Simulation is run the way that trigger invokes <see cref="ILinkableComponent.GetValues">ILinkableComponent.GetValues</see>
/// method of the model it's connected to
/// at the time specified by <see cref="TriggerInvokeTime">TriggerInvokeTime</see> property.
/// If you need to use more than one listener you can use <see cref="ProxyListener">ProxyListener</see>
/// class or <see cref="ProxyMultiThreadListener">ProxyMultiThreadListener</see> if <c>runInSameThread</c> is <c>false</c>.
/// </remarks>
public void Run(IListener runListener, bool runInSameThread)
{
if (!HasTrigger())
throw (new Exception("Composition has no trigger."));
if (_running)
throw (new Exception("Simulation is already running."));
_running = true;
_runListener = runListener;
try
{
TimeStamp runToTime = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(_triggerInvokeTime));
// Create informative message
if (_runListener != null)
{
StringBuilder description = new StringBuilder();
description.Append("Starting simulation at ");
description.Append(DateTime.Now.ToString());
description.Append(",");
description.Append(" composition consists from following models:\n");
foreach (UIModel model in _models)
{
description.Append(model.ModelID);
description.Append(", ");
}
// todo: add more info?
Event theEvent = new Event(EventType.Informative);
theEvent.Description = description.ToString();
_runListener.OnEvent(theEvent);
}
_runPrepareForComputationStarted = true;
// prepare for computation
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Preparing for computation";
_runListener.OnEvent(theEvent);
}
foreach (UIModel uimodel in _models)
{
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Calling Prepare() method of model " + uimodel.ModelID;
_runListener.OnEvent(theEvent);
}
uimodel.LinkableComponent.Prepare();
}
// subscribing event listener to all models
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Subscribing proxy event listener";
_runListener.OnEvent(theEvent);
for (int i = 0; i < _runListener.GetAcceptedEventTypeCount(); i++)
foreach (UIModel uimodel in _models)
{
theEvent = new Event(EventType.Informative);
theEvent.Description = "Calling Subscribe() method with EventType." + ((EventType)i).ToString() + " of model " + uimodel.ModelID;
_runListener.OnEvent(theEvent);
for (int j = 0; j < uimodel.LinkableComponent.GetPublishedEventTypeCount(); j++)
if (uimodel.LinkableComponent.GetPublishedEventType(j) == _runListener.GetAcceptedEventType(i))
{
uimodel.LinkableComponent.Subscribe(_runListener, _runListener.GetAcceptedEventType(i));
break;
}
}
}
if (!runInSameThread)
{
// creating run thread
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Creating run thread";
//.........这里部分代码省略.........
示例2: Run
/// <summary>
/// Runs simulation.
/// </summary>
/// <param name="runListener">Simulation listener.</param>
/// <param name="runInSameThread">If <c>true</c>, simulation is run in same thread like caller,
/// ie. method blocks until simulation don't finish. If <c>false</c>, simulation is
/// run in separate thread and method returns immediately.</param>
/// <remarks>
/// Simulation is run the way that trigger invokes <see cref="ILinkableComponent.GetValues">ILinkableComponent.GetValues</see>
/// method of the model it's connected to
/// at the time specified by <see cref="TriggerInvokeTime">TriggerInvokeTime</see> property.
/// If you need to use more than one listener you can use <see cref="ProxyListener">ProxyListener</see>
/// class or <see cref="ProxyMultiThreadListener">ProxyMultiThreadListener</see> if <c>runInSameThread</c> is <c>false</c>.
/// </remarks>
public void Run(Logger logger, bool runInSameThread)
{
LoggerListener loggerListener = new LoggerListener(logger);
ProgressListener progressListener = new ProgressListener();
progressListener.ModelProgressChangedHandler += new ModelProgressChangedDelegate(delegate(ILinkableComponent linkableComponent, ITimeStamp simTime)
{
string guid = cmGuidMapping[linkableComponent];
string progress = CalendarConverter.ModifiedJulian2Gregorian(simTime.ModifiedJulianDay).ToString();
CompositionModelProgressChangedHandler(this, guid, progress);
});
ArrayList listeners = new ArrayList();
listeners.Add(loggerListener);
listeners.Add(progressListener);
ProxyListener proxyListener = new ProxyListener();
proxyListener.Initialize(listeners);
startTime = DateTime.Now;
if (_running)
throw (new Exception("Simulation is already running."));
_running = true;
_runListener = proxyListener;
try
{
TimeStamp runToTime = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(_triggerInvokeTime));
// Create informative message
if (_runListener != null)
{
StringBuilder description = new StringBuilder();
description.Append("Starting simulation at ");
description.Append(DateTime.Now.ToString());
description.Append(",");
description.Append(" composition consists from following models:\n");
foreach (Model model in _models)
{
description.Append(model.ModelID);
description.Append(", ");
}
// todo: add more info?
Event theEvent = new Event(EventType.Informative);
theEvent.Description = description.ToString();
_runListener.OnEvent(theEvent);
}
_runPrepareForComputationStarted = true;
// prepare for computation
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Preparing for computation....";
_runListener.OnEvent(theEvent);
}
// subscribing event listener to all models
if (_runListener != null)
{
Event theEvent = new Event(EventType.Informative);
theEvent.Description = "Subscribing proxy event listener....";
_runListener.OnEvent(theEvent);
for (int i = 0; i < _runListener.GetAcceptedEventTypeCount(); i++)
foreach (Model uimodel in _models)
{
theEvent = new Event(EventType.Informative);
theEvent.Description = "Calling Subscribe() method with EventType." + ((EventType)i).ToString() + " of model " + uimodel.ModelID;
_runListener.OnEvent(theEvent);
for (int j = 0; j < uimodel.LinkableComponent.GetPublishedEventTypeCount(); j++)
if (uimodel.LinkableComponent.GetPublishedEventType(j) == _runListener.GetAcceptedEventType(i))
{
uimodel.LinkableComponent.Subscribe(_runListener, _runListener.GetAcceptedEventType(i));
break;
}
}
}
if (!runInSameThread)
{
//.........这里部分代码省略.........