本文整理汇总了C#中AsyncSubject类的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject类的具体用法?C# AsyncSubject怎么用?C# AsyncSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncSubject类属于命名空间,在下文中一共展示了AsyncSubject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:richardszalay,项目名称:raix,代码行数:26,代码来源:AsyncSubjectFixture.cs
示例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;
}
开发者ID:jorik041,项目名称:Akavache,代码行数:27,代码来源:StreamMixins.cs
示例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);
}
开发者ID:MichaelAzar,项目名称:flickr-net,代码行数:29,代码来源:PhotosAsyncTests.cs
示例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);
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:30,代码来源:PhotosUploadTests.cs
示例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();
}
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:35,代码来源:PhotosetsAsyncTests.cs
示例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;
}
开发者ID:joeldart,项目名称:RX-Example,代码行数:25,代码来源:MainPage.xaml.cs
示例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.");
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:33,代码来源:PhotosetsAsyncTests.cs
示例8: JobHost
public JobHost()
{
// Job container.
Jobs = new Dictionary<string, Job>();
// Signal
_shutdownSignal = new AsyncSubject<Unit>();
_shutdownSignal.OnNext(Unit.Default);
}
开发者ID:Mecabot,项目名称:RedDog,代码行数:9,代码来源:JobHost.cs
示例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();
}
开发者ID:cypherwars,项目名称:ReactiveExtensions,代码行数:13,代码来源:Program.cs
示例10: CreateConnectableObservables
static IEnumerable<Task> CreateConnectableObservables()
{
var subject = new AsyncSubject<Unit>();
yield return Observable.Defer(() => Observable.Start(() => Unit.Default))
.Multicast(subject)
.RefCount()
.ToTask();
}
开发者ID:niik,项目名称:RxSpy,代码行数:9,代码来源:Program.cs
示例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);
}
开发者ID:MichaelAzar,项目名称:flickr-net,代码行数:10,代码来源:PhotosAsyncTests.cs
示例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();
}
开发者ID:pudae,项目名称:lplpl,代码行数:10,代码来源:TestAsyncSubject.cs
示例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(
);
}
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:55,代码来源:AsyncSubjectTest.cs
示例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.");
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:11,代码来源:PhotosSearchAsyncTests.cs
示例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();
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:11,代码来源:PhotosSearchAsyncTests.cs
示例16: StatsGetPhotosetDomainsAsyncTest
public void StatsGetPhotosetDomainsAsyncTest()
{
Flickr f = TestData.GetAuthInstance();
DateTime d = DateTime.Today.AddDays(-7);
var w = new AsyncSubject<FlickrResult<StatDomainCollection>>();
f.StatsGetPhotosetDomainsAsync(d, 1, 25, r => { w.OnNext(r); w.OnCompleted(); });
var result = w.Next().First();
Assert.IsFalse(result.HasError);
}
开发者ID:h4ck3rm1k3,项目名称:FlickrNet,代码行数:12,代码来源:StatsAsyncTests.cs
示例17: 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);
}
开发者ID:ericleigh007,项目名称:flickr-net,代码行数:12,代码来源:PhotosSearchAsyncTests.cs
示例18: 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();
}
开发者ID:sam-io,项目名称:dotnet-playground,代码行数:12,代码来源:Rx_3_AsyncSubject.cs
示例19: 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);
}
开发者ID:CedarLogic,项目名称:RedDog.Engine,代码行数:12,代码来源:JobHost.cs
示例20: PhotosGetRecentAsyncTest
public void PhotosGetRecentAsyncTest()
{
Flickr f = TestData.GetInstance();
var w = new AsyncSubject<FlickrResult<PhotoCollection>>();
f.PhotosGetRecentAsync(1, 50, 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.");
}
开发者ID:MichaelAzar,项目名称:flickr-net,代码行数:12,代码来源:PhotosAsyncTests.cs
注:本文中的AsyncSubject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论