本文整理汇总了C#中AsyncSubject类的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject类的具体用法?C# AsyncSubject怎么用?C# AsyncSubject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncSubject类属于命名空间,在下文中一共展示了AsyncSubject类的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: 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;
}
示例3: 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);
}
示例4: UploadPictureAsyncBasicTest
public void UploadPictureAsyncBasicTest()
{
Flickr f = TestData.GetAuthInstance();
var w = new AsyncSubject<FlickrResult<string>>();
byte[] imageBytes = TestData.TestImageBytes;
var s = new MemoryStream(imageBytes);
s.Position = 0;
string title = "Test Title";
string desc = "Test Description\nSecond Line";
string tags = "testtag1,testtag2";
f.UploadPictureAsync(s, "Test.jpg", title, desc, tags, false, false, false, ContentType.Other, SafetyLevel.Safe, HiddenFromSearch.Visible,
r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
if (result.HasError)
{
throw result.Error;
}
Assert.IsNotNull(result.Result);
Console.WriteLine(result.Result);
// Clean up photo
f.PhotosDelete(result.Result);
}
示例5: 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();
}
}
示例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: 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.");
}
示例8: JobHost
public JobHost()
{
// Job container.
Jobs = new Dictionary<string, Job>();
// Signal
_shutdownSignal = new AsyncSubject<Unit>();
_shutdownSignal.OnNext(Unit.Default);
}
示例9: 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();
}
示例10: CreateConnectableObservables
static IEnumerable<Task> CreateConnectableObservables()
{
var subject = new AsyncSubject<Unit>();
yield return Observable.Defer(() => Observable.Start(() => Unit.Default))
.Multicast(subject)
.RefCount()
.ToTask();
}
示例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: 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();
}
示例13: Infinite
public void Infinite()
{
var scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(
OnNext(70, 1),
OnNext(110, 2),
OnNext(220, 3),
OnNext(270, 4),
OnNext(340, 5),
OnNext(410, 6),
OnNext(520, 7),
OnNext(630, 8),
OnNext(710, 9),
OnNext(870, 10),
OnNext(940, 11),
OnNext(1020, 12)
);
var subject = default(AsyncSubject<int>);
var subscription = default(IDisposable);
var results1 = scheduler.CreateObserver<int>();
var subscription1 = default(IDisposable);
var results2 = scheduler.CreateObserver<int>();
var subscription2 = default(IDisposable);
var results3 = scheduler.CreateObserver<int>();
var subscription3 = default(IDisposable);
scheduler.ScheduleAbsolute(100, () => subject = new AsyncSubject<int>());
scheduler.ScheduleAbsolute(200, () => subscription = xs.Subscribe(subject));
scheduler.ScheduleAbsolute(1000, () => subscription.Dispose());
scheduler.ScheduleAbsolute(300, () => subscription1 = subject.Subscribe(results1));
scheduler.ScheduleAbsolute(400, () => subscription2 = subject.Subscribe(results2));
scheduler.ScheduleAbsolute(900, () => subscription3 = subject.Subscribe(results3));
scheduler.ScheduleAbsolute(600, () => subscription1.Dispose());
scheduler.ScheduleAbsolute(700, () => subscription2.Dispose());
scheduler.ScheduleAbsolute(800, () => subscription1.Dispose());
scheduler.ScheduleAbsolute(950, () => subscription3.Dispose());
scheduler.Start();
results1.Messages.AssertEqual(
);
results2.Messages.AssertEqual(
);
results3.Messages.AssertEqual(
);
}
示例14: 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.");
}
示例15: 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();
}