如何在 Silverlight/CSLA 中创建延迟加载和缓存的集合
我正在为使用 CSLA 编写的现有桌面应用程序创建 Silverlight 前端。 我遇到麻烦的一件事是转换如下所示的类:
public class SomeCollection : Csla.ReadOnlyListBase<SomeCollection, SomeObject>
{
private static SomeCollection _list = null;
public static SomeCollection GetSomeCollection()
{
if (_list == null)
{
_list = DataPortal.FetchChild<SomeCollection>();
}
return _list;
}
}
代码中充满了“SomeCollection.GetSomeCollection()” 这在 silverlight 端不起作用,因为所有 DataPortal 访问都是异步的,因此您必须从如下所示:
public static void GetSomeCollection(EventHandler<DataPortalResult<SomeCollection>> callback)
{
DataPortal<SomeCollection> portal = new DataPortal<SomeCollection>();
portal.FetchCompleted += callback;
portal.BeginFetch();
}
当数据准备好时,回调处理程序被调用。 我当然可以缓存此结果,但与此同时任何 SomeCollection.GetSomeCollection() 调用都会失败。
我尝试阻塞直到异步调用完成,但到目前为止我还没有运气。 这不是一个很好的解决方案,但我不知道如果在加载数据之前调用 SomeCollection.GetSomeCollection() 还能做什么。 我能想到的唯一其他选择是允许 SomeCollection.GetSomeCollection() 返回 null,然后以某种方式将所有调用者转换为处理 null 返回值
有什么想法吗?
(我对 Silverlight 和 Csla 非常陌生,所以我可能会以完全错误的方式处理这个问题)
I'm creating a Silverlight front end for an existing desktop app written using CSLA. One thing that I'm having trouble with is converting classes like the following:
public class SomeCollection : Csla.ReadOnlyListBase<SomeCollection, SomeObject>
{
private static SomeCollection _list = null;
public static SomeCollection GetSomeCollection()
{
if (_list == null)
{
_list = DataPortal.FetchChild<SomeCollection>();
}
return _list;
}
}
The code is peppered with "SomeCollection.GetSomeCollection()" This won't work on the silverlight side because all DataPortal access is asyncronous, so you have to start with something like the following:
public static void GetSomeCollection(EventHandler<DataPortalResult<SomeCollection>> callback)
{
DataPortal<SomeCollection> portal = new DataPortal<SomeCollection>();
portal.FetchCompleted += callback;
portal.BeginFetch();
}
The callback handler gets called when the data is ready. I can certainly cache the result of this, but in the meantime any SomeCollection.GetSomeCollection() calls will fail.
I've tried blocking until the asynchronous call completes, but I've had no luck so far. That's not a great solution, but I don't know what else to do if SomeCollection.GetSomeCollection() is called before the data has been loaded. the only other option I can think of is to allow SomeCollection.GetSomeCollection() to return null, and then somehow convert all callers to handle null return values
Any thoughts?
(I'm super new to Silverlight and Csla, so it's possible that I'm going about this the completely wrong way)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://forums.lhotka.net/forums/thread/35585.aspx
http://forums.lhotka.net/forums/thread/35585.aspx