本文整理汇总了C#中IObservable.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# IObservable.Subscribe方法的具体用法?C# IObservable.Subscribe怎么用?C# IObservable.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObservable
的用法示例。
在下文中一共展示了IObservable.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CMTPoint
public CMTPoint(double ttm_, CMT cmt_, /*int series_,*/ IObservable<alglib.spline1dinterpolant> fitProvider_)
{
TimeToMaturity = ttm_;
//Series = series_;
m_parent = cmt_;
m_disp = fitProvider_.Subscribe(OnNext);
}
示例2: Leader
public Leader(IElection election,
IHartbeatTimer hartbeat,
IObservable<AppendEntryResultMessage> reply,
IObserver<AppendEntryMessage> append,
IObserver<ClientResultMessage> clientReply,
IObservable<ClientMessage> client,
ILogReplication logReplication,
Nodes nodes,
ILoggerFactory loggerFactory,
RaftOptions options,
ServerIdentifier serverIdentifier)
{
_isDispose = false;
_hartbeat = hartbeat;
_append = append;
_clientReply = clientReply;
_client = client;
_logReplication = logReplication;
_nodes = nodes;
_options = options;
_serverIdentifier = serverIdentifier;
_election = election;
_logger = loggerFactory.CreateLogger(nameof(Leader) + " " + serverIdentifier);
if (_options.UseLogging)
_logger.LogInformation($"{nameof(ServerStateType.Leader)}");
// Reinitialized after election
NextIndex = new ConcurrentDictionary<ServerIdentifier, int>();
MatchIndex = new ConcurrentDictionary<ServerIdentifier, int>();
_hartbeat.Leader(SendHartbeat);
_replyDispose = reply.Subscribe(EntryReplyMessageRecived);
_clientReplyDispose = client.Subscribe(ClientMessageRecived);
}
示例3: Execute
public IObservable<TestResult> Execute(IObservable<TestMethod> tests)
{
return Observable.Create(
(IObserver<TestResult> observer) =>
{
tests.Subscribe(
onNext: test =>
{
try
{
var declaringType = test.Method.DeclaringType;
var instance = Activator.CreateInstance(declaringType);
test.Method.Invoke(instance, test.Parameters);
observer.OnNext(new TestResult(test.Uri, test.Method));
}
catch (Exception ex)
{
observer.OnNext(new TestResult(test.Uri, test.Method, ex));
}
},
onError:observer.OnError,
onCompleted:observer.OnCompleted);
return Disposable.Empty;
});
}
示例4: Display
public void Display(IObservable<TestResult> results)
{
results.Subscribe(
onNext: result =>
{
Console.WriteLine("\n{0}.{1} for {2} : {3}",
result.Test.DeclaringType.FullName,
result.Test.Name,
result.Uri,
result.Success ? "Success" : "Failed");
if (!result.Success)
{
Console.Error.WriteLine(result.Exception);
Failures.Add(string.Format("\n{0}.{1} for {2}\n{3}",
result.Test.DeclaringType.FullName,
result.Test.Name,
result.Uri.AbsoluteUri,
result.Exception.Message));
}
Count++;
},
onError: WriteMessage,
onCompleted: WriteMessage);
}
示例5: DeadCountersDetector
public DeadCountersDetector(IObservable<LogEventArgs> observableEvents, Settings settings)
{
_observableEvents = observableEvents;
_settings = settings;
_observableEvents.Subscribe(UpdateCounterFreshnessTime);
}
示例6: WindowController
public WindowController(IObservable<LoadData> controls)
{
InitializeComponent();
disposable = controls.Subscribe(c => Load(c.View),
Close
);
}
示例7: Subscribe
public IDisposable Subscribe(IObservable<string> observable)
{
return observable.Subscribe(d =>
{
var bytes = Encoding.ASCII.GetBytes(d);
_client.Send(bytes, bytes.Length);
});
}
示例8: Activate
public static IDisposable Activate(this IAlertDialogFactory @this, IObservable<bool> observable, string text)
{
return observable.Subscribe(x => {
if (x)
@this.Show(text);
else
@this.Hide();
});
}
示例9: TrayIcon
public TrayIcon(IObservable<ITrayNotification> notifications) {
InitializeComponent();
Application.Current.Exit += (sender, args) => TaskbarIcon.Dispose();
_notificationQueue = new ConcurrentQueue<ITrayNotification>();
// TODO: Just attach through ViewModel instead...
notifications.Subscribe(x => {
_notificationQueue.Enqueue(x);
ProcessNotificationQueue();
});
}
示例10: BurnScrap
public void BurnScrap(IObservable<FileSystemEntity> source)
{
_subscription = source.Subscribe(entity =>
{
if (entity.File != null)
entity.File.Delete();
else
entity.Directory.Delete(true);
});
}
示例11: GameStateService
public GameStateService(ObservableTimerService timerService)
{
if (timerService == null) throw new ArgumentNullException();
_timerService = timerService;
_timeSequence = _timerService.GetTimerSequence(100*1000, 1000);
_timeSubscription = _timeSequence.Subscribe(newTime => ClockTime = newTime / 1000);
Direction = true;
}
示例12: ObservableCommand
public ObservableCommand(IObservable<bool> canExecuteObservable, Func<object, Task> action)
{
this.action = action;
canExecuteSubscription = canExecuteObservable.Subscribe(b =>
{
latest = b;
RaiseCanExecuteChanged();
});
}
示例13: RepositoryPrincipalFactory
public RepositoryPrincipalFactory(
IQueryable<IUserRoles> loadRoles,
IObservable<Lazy<IUserRoles>> roleChanges)
{
Contract.Requires(loadRoles != null);
Contract.Requires(roleChanges != null);
this.LoadRoles = loadRoles;
Subscription = roleChanges.Subscribe(_ => RefreshCache());
RefreshCache();
}
示例14: immediately_completes_when_subscribed_to_with_no_scheduler
public void immediately_completes_when_subscribed_to_with_no_scheduler()
{
obs = Observable.Empty<int>();
bool completed = false;
using (obs.Subscribe(x => { }, () => completed = true))
{
Assert.IsTrue(completed);
}
}
示例15: Trigger
public Trigger(Func<Task> action, IObservable<Input> trigger)
{
Disposable = trigger.Subscribe(async input =>
{
var prev = Interlocked.CompareExchange(ref Latch, 1, 0);
if (0 != prev)
return;
await action();
Latch = 0;
});
}