SilverlightisolatedStorageFile.IncreaseQuotaTo
IsolatedStorageFile.IncreaseQuotaTo
指出:
要增加配额,您必须致电 该方法由用户发起 事件,例如在事件处理程序中 按钮单击事件。当你打电话时 常用的IncreaseQuotaTo方法 Silverlight 中的语言运行时 呈现一个对话框供用户 批准该请求。如果用户 拒绝请求,此方法 返回 false 并且配额仍然存在 大小相同。
Silverlight 如何知道该方法是从用户启动的事件(如按钮单击)调用的,而不是从其他线程调用的?
更具体地说:什么是用户发起的事件?有什么办法可以克服这个限制吗?
另一个问题:
当用户第一次访问我的应用程序时,我会自动下载一些文件,但我不希望用户按“下载”,然后当我检测到需要更多空间时,调用IncreaseQuota 并出现“Silverlight 对话框”要求更多空间。
我想自动开始下载(不是用户启动的),如果我检测到需要更多空间,请调用IncreaseQuota,从而出现“Silverlight 对话框”。 (没有用户按下下载)。
Msdn doc for IsolatedStorageFile.IncreaseQuotaTo
states that:
To increase the quota, you must call
this method from a user-initiated
event, such as in an event handler for
a button-click event. When you call
the IncreaseQuotaTo method, the common
language runtime in Silverlight
presents a dialog box for the user to
approve the request. If the user
declines the request, this method
returns false and the quota remains
the same size.
How does Silverlight know that the method was called from a user-initiated event like a button click and not from some other thread?
More specifically: What is a user initiated event? Is there any way to overcome this limitation?
And another question:
I do some automatic downloads of files when user first accesses my application, but I don't want the user to press "Download" and then when I detect more space is needed call IncreaseQuota and have the "Silverlight dialog" appearing asking for more space.
I want to start the download automatically (not user initiated), and if I detect more space is needed, call IncreaseQuota and hence have the "Silverlight dialog" appear. (No user pressing download).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量挖掘,我确实发现了用户发起的事件是什么。似乎 msdn 文档在与“事件概述”相关的部分中指定了用户启动的事件,但 IsolatedStorageFile.IncreaseQuotaTo 和 事件概述
所以用户发起的事件根据定义是:
虽然我没有在“操作”列表中看到“IncreaseQuotaTo”,但我猜他们只是忘记了它,因为行为/限制与文档中描述的相同。
我很好奇 silverlight 到底如何知道用户启动的事件是什么,但是在深入研究 .net 框架源代码后,我陷入了死胡同:
browser.IsInPrivateMode 位于哪里:
DOM_InPrivateMode 位于 DllImport["agcore"] 中据微软称是保密的:(
所以看起来我不会很快知道他们如何检测用户发起的事件。
仔细想想,我猜微软不希望用户在浏览器中打开许多选项卡,然后噗:我自动调用IncreaseQuotaTo。
IncreaseQuotaTo 是一个浏览器模式对话框。这意味着您无法在处于活动状态时导航到其他浏览器选项卡。
因此,如果用户现在已从我的页面移动到 google.com 选项卡,并且如果我能够延迟调用 IncreaseQuotaTo,则用户可能会认为 google.com 正在请求更多存储空间:)。
这确实是一个安全漏洞。
如果他们通过页面级对话框实现这一点,那么可能会更容易被黑客攻击(或解决)。
总而言之,想到这一点,我开始明白为什么他们会这样实施以及为什么存在这些限制。
After much digging, I did find out what a user initiated event is. Seems that msdn doc specifies what a user initiated event in the section related to "events overview", but there's no link between documentation of IsolatedStorageFile.IncreaseQuotaTo and Events Overview
So a user initiated event according to the definition is:
Although I don't see "IncreaseQuotaTo" inside the list of "operations", I'm guessing they just forgot it, since the behavior/limitations are the same as the ones described in the doc.
I was curios how exactly does silverlight know what a user initiated event is but after digging through .net framework source code I've got to a dead end:
where browser.IsInPrivateMode is:
where DOM_InPrivateMode is in a DllImport["agcore"] which according to microsoft is confidential :(
So it looks like I won't find out soon how they're detecting user initiated events.
Thinking it more about it, I guess microsoft didn't want a user to have many tabs open in a browser and then poof: I call automatically IncreaseQuotaTo.
The IncreaseQuotaTo is a browser modal dialog. This means you can't navigate to other browser tabs while is active.
So if the user has now moved from my page to the tab with google.com, and if I would be able to call IncreaseQuotaTo with a delay, the user might think that google.com is asking for more storage :).
This would be a security breach indeed.
Had they implemented this with a page level dialog, then that would have been probably more easily hacked (or worked around).
So all in all, thinking of it, I'm starting to see why they implemented it like this and why these limitations exist.
该文档并非不完整。
是的。但是这一点额外的代码真正实现了什么?
我个人从未尝试过什么构成了用户事件; IOW 鼠标悬停是否被视为用户事件?这对您来说尝试起来非常简单,并且您可以尝试许多其他的事情。如果有必要,您可以有一个欢迎用户的启动屏幕弹出窗口,他们必须单击它才能关闭它,此时您可以提出请求。这可能看起来有点老套,但如果你表现得好,你就可以摆脱这样的事情。
请注意,提示是一次性的。如果您提示用户并且他们接受,则在访问之间为您的应用程序保留该存储,这意味着您不需要在下次他们使用您的控件时再次提示他们,您的配额仍比上次增加(除非用户故意删除它,他们可以通过右键单击 Silverlight 控件,然后转到“应用程序存储”选项卡来完成此操作)。
The documentation isn't incomplete.
Yes. But what has that little bit of extra code really achieved?
What i've personally never experimented with is exactly what consitutes a user event; IOW is a mouse-over considered a user event? This will be very simple for you to try, and there are a multitude of other things you can experiment with. If necessary you could have a splash screen popup that welcomes the user and they have to click on it to dismiss it, at which point you make the request. It may seem a bit corny, but you can get away with things like this if you present it well.
Note that the prompt is a one-time thing. If you prompt the user and they accept, that storage is persisted for your application between visits, which means you don't need to prompt them again the next time they use your control, your quota is still increased from last time (unless the user has deliberately deleted it, which they can do by right clicking on the Silverlight control and then going to the Application Storage tab).