我想在我的应用程序和akavache/Akavache中使用paulcbetts/refit。
问题是根据我的逻辑,Windows Phone 不喜欢我执行以下操作:
我得到学期(从缓存中,然后获取),选择想要的学期(我将 H2014 用于测试),获取所选(许多)学期的时间表(从缓存中,然后获取,如下所示:
var defer = Observable.Defer(() =>
BlobCache.Secure.GetAndFetchLatest("Semesters", () => _api.GetSemesters())
.Select(x => x.Single(semester => semester.AbredgedName == "H2014"))
.SelectMany(currentSemester => BlobCache.Secure.GetAndFetchLatest("Schedule_" + currentSemester.AbredgedName,
() => _api.GetSchedule(currentSemester.AbredgedName)))
);
defer.Subscribe(scheduleVms => {
foreach (var activity in scheduleVms)
{
Debug.WriteLine("1 {0}", activity.Name);
}
});
Observable.Timer(TimeSpan.FromSeconds(4)).Subscribe(_ =>
{
defer.Subscribe(scheduleVms => {
foreach (var activity in scheduleVms)
{
Debug.WriteLine("2 {0}", activity.Name);
}
});
});
如果我使用 5 或更多的 TimeSpan.FromSeconds,它会做我想做的事,就好像我给了 Windows Phone 喘息的时间。否则(5岁以下),我得到的例外情况如下:
抛出异常:mscorlib.ni.dll StackTrace 中的“System.NotSupportedException”:
at MS.Internal.Modern.InternalNetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
at System.IO.Stream.<BeginEndReadAsync>b__d(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.Net.Http.DelegatingStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.Net.Http.DelegatingStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.IO.Stream.<CopyToAsyncInternal>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Refit.RequestBuilderImplementation.<>c__DisplayClass2a`1.<<buildCancellableTaskFuncForMethod>b__29>d__2c.MoveNext()
想要的行为:
- 获取缓存学期 -> 获取该学期的缓存计划,获取该学期的计划
- 获取学期 -> 获取该学期的缓存计划,获取该学期的计划
我试过了:
- 在没有 Refit 的情况下链接akavache/Akavache并且它可以工作。
- 在没有akavache/Akavache的情况下链接 GetSchedule 和 GetSemesters 的选择,它可以工作。
如果你们对工作有想法或我做错了什么,请告诉我!