本文整理汇总了C#中AsyncSubject.OnNext方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject.OnNext方法的具体用法?C# AsyncSubject.OnNext怎么用?C# AsyncSubject.OnNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.OnNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: each_subscriber_is_scheduled_individually
public void each_subscriber_is_scheduled_individually()
{
ManualScheduler scheduler = new ManualScheduler();
AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);
StatsObserver<int> statsA = new StatsObserver<int>();
StatsObserver<int> statsB = new StatsObserver<int>();
subject.OnNext(1);
subject.OnNext(2);
subject.OnNext(3);
subject.OnCompleted();
subject.Subscribe(statsA);
subject.Subscribe(statsB);
scheduler.RunNext();
Assert.IsTrue(statsA.NextCalled);
Assert.IsFalse(statsB.NextCalled);
scheduler.RunNext();
Assert.IsTrue(statsB.NextCalled);
}
示例2: AsyncSubject
///<summary>
///With AsyncSubject<T> ,the subscriber will only get all the last publication made.
///Simply, AsyncSubject has a one value buffer. The publication is made only on the OnCompleted() call.
///</summary>
private static void AsyncSubject()
{
var subject = new AsyncSubject<string>();
subject.OnNext("a");
subject.OnNext("b");
subject.OnNext("c");
subject.Subscribe(Console.WriteLine);
subject.OnCompleted();
}
示例3: Run
public static void Run()
{
var subject = new AsyncSubject<string>();
subject.OnNext("a");
WriteSequenceToConsole(subject);
subject.OnNext("b");
subject.OnNext("c");
// subject.OnCompleted();
Console.ReadLine();
}
示例4: Run
public void Run()
{
ConsoleUtility.PrintSuccess(string.Format("Rx AsyncSubject example"));
var topic = new AsyncSubject<Price>();
WriteToConsole(topic);
topic.OnNext(new Price(1, 99, 100, 101));
topic.OnNext(new Price(1, 98, 99, 100));
topic.OnNext(new Price(1, 97, 98, 99));
topic.OnCompleted();
}
示例5: WriteAsync
public static IObservable<Unit> WriteAsync(this Stream This, byte[] data, int start, int length)
{
var ret = new AsyncSubject<Unit>();
try
{
This.BeginWrite(data, start, length, result =>
{
try
{
This.EndWrite(result);
ret.OnNext(Unit.Default);
ret.OnCompleted();
}
catch (Exception ex)
{
ret.OnError(ex);
}
}, null);
}
catch (Exception ex)
{
ret.OnError(ex);
}
return ret;
}
示例6: detect
private IObservable<string> detect(string text)
{
var subject = new AsyncSubject<string>();
string detectUri = String.Format(GetDetectUri(text), appId, HttpUtility.HtmlEncode(text));
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler((obj, args) =>
{
if (args.Error != null)
{
subject.OnError(args.Error);
}
else
{
if (!args.Cancelled)
{
var xdoc = XDocument.Load(args.Result);
subject.OnNext(xdoc.Root.Value);
}
subject.OnCompleted();
}
});
wc.OpenReadAsync(new Uri(detectUri));
return subject;
}
示例7: PhotosGetCountsAsyncTest
public void PhotosGetCountsAsyncTest()
{
DateTime date1 = DateTime.Today.AddMonths(-12);
DateTime date2 = DateTime.Today.AddMonths(-6);
DateTime date3 = DateTime.Today;
DateTime[] uploadDates = new DateTime[] { date1, date2, date3 };
Flickr f = TestData.GetAuthInstance();
var w = new AsyncSubject<FlickrResult<PhotoCountCollection>>();
f.PhotosGetCountsAsync(uploadDates, false, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
var counts = result.Result;
Assert.AreEqual(2, counts.Count, "Should be two counts returned.");
var count1 = counts[0];
Assert.AreEqual(date1, count1.FromDate);
Assert.AreEqual(date2, count1.ToDate);
var count2 = counts[1];
Assert.AreEqual(date2, count2.FromDate);
Assert.AreEqual(date3, count2.ToDate);
}
示例8: PhotosetsGetContextAsyncTest
public void PhotosetsGetContextAsyncTest()
{
Flickr f = TestData.GetInstance();
var photosetId = "72157626420254033"; // Beamish
var photos = f.PhotosetsGetPhotos(photosetId, 1, 100);
var firstPhoto = photos.First();
var lastPhoto = photos.Last();
var w = new AsyncSubject<FlickrResult<Context>>();
f.PhotosetsGetContextAsync(firstPhoto.PhotoId, photosetId, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
var context = result.Result;
Assert.IsNull(context.PreviousPhoto, "As this is the first photo the previous photo should be null.");
Assert.IsNotNull(context.NextPhoto, "As this is the first photo the next photo should not be null.");
w = new AsyncSubject<FlickrResult<Context>>();
f.PhotosetsGetContextAsync(lastPhoto.PhotoId, photosetId, r => { w.OnNext(r); w.OnCompleted(); });
result = w.Next().First();
Assert.IsFalse(result.HasError);
context = result.Result;
Assert.IsNull(context.NextPhoto, "As this is the last photo the next photo should be null.");
Assert.IsNotNull(context.PreviousPhoto, "As this is the last photo the previous photo should not be null.");
}
示例9: PhotosetsGeneralAsyncTest
public void PhotosetsGeneralAsyncTest()
{
Flickr f = TestData.GetAuthInstance();
var photoId1 = "7519320006"; // Tree/Write/Wall
var photoId2 = "7176125763"; // Rainbow Rose
var w = new AsyncSubject<FlickrResult<Photoset>>();
f.PhotosetsCreateAsync("Test Photoset", photoId1, r => { w.OnNext(r); w.OnCompleted(); });
var photosetResult = w.Next().First();
Assert.IsFalse(photosetResult.HasError);
var photoset = photosetResult.Result;
try
{
var w2 = new AsyncSubject<FlickrResult<NoResponse>>();
f.PhotosetsEditMetaAsync(photoset.PhotosetId, "New Title", "New Description", r => { w2.OnNext(r); w2.OnCompleted(); });
var noResponseResult = w2.Next().First();
Assert.IsFalse(noResponseResult.HasError);
var w3 = new AsyncSubject<FlickrResult<NoResponse>>();
f.PhotosetsAddPhotoAsync(photoset.PhotosetId, photoId2, r => { w3.OnNext(r); w3.OnCompleted(); });
noResponseResult = w3.Next().First();
Assert.IsFalse(noResponseResult.HasError);
}
finally
{
var w4 = new AsyncSubject<FlickrResult<NoResponse>>();
// Clean up and delete photoset
f.PhotosetsDeleteAsync(photoset.PhotosetId, r => { w4.OnNext(r); w4.OnCompleted(); });
var noResponseResult = w4.Next().First();
}
}
示例10: JobHost
public JobHost()
{
// Job container.
Jobs = new Dictionary<string, Job>();
// Signal
_shutdownSignal = new AsyncSubject<Unit>();
_shutdownSignal.OnNext(Unit.Default);
}
示例11: PhotosGetExifAsyncTest
public void PhotosGetExifAsyncTest()
{
Flickr f = TestData.GetInstance();
var w = new AsyncSubject<FlickrResult<ExifTagCollection>>();
f.PhotosGetExifAsync(TestData.PhotoId, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
}
示例12: PhotosGetContactsPhotosAsyncTest
public void PhotosGetContactsPhotosAsyncTest()
{
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
AuthInstance.PhotosGetContactsPhotosAsync(50, true, true, true, PhotoSearchExtras.All, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
Assert.IsNotNull(result.Result);
Assert.IsTrue(result.Result.Count > 0, "Should return some photos.");
}
示例13: PhotosAddTagTest
public void PhotosAddTagTest()
{
string photoId = "4499284951";
string tag = "testx";
var w = new AsyncSubject<FlickrResult<NoResponse>>();
AuthInstance.PhotosAddTagsAsync(photoId, tag, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
}
示例14: PhotosSearchAsyncBasicTest
public void PhotosSearchAsyncBasicTest()
{
var o = new PhotoSearchOptions();
o.Tags = "microsoft";
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
Instance.PhotosSearchAsync(o, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsTrue(result.Result.Total > 0);
}
示例15: JobHost
public JobHost(IJobEventContext eventContext)
{
// Job container.
Jobs = new Dictionary<string, Job>();
// Store the event context that will be used to track jobs and tasks.
_eventContext = eventContext;
// Signal
_shutdownSignal = new AsyncSubject<Unit>();
_shutdownSignal.OnNext(Unit.Default);
}