简体   繁体   English

Silverlight IsolatedStorageFile.IncreaseQuotaTo

[英]Silverlight IsolatedStorageFile.IncreaseQuotaTo

Msdn doc for IsolatedStorageFile.IncreaseQuotaTo states that: IsolatedStorageFile.IncreaseQuotaTo Msdn文档指出:

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. 当您调用IncreaseQuotaTo方法时,Silverlight中的公共语言运行库将显示一个对话框,供用户批准请求。 If the user declines the request, this method returns false and the quota remains the same size. 如果用户拒绝该请求,则此方法返回false,并且配额保持不变。

How does Silverlight know that the method was called from a user-initiated event like a button click and not from some other thread? Silverlight如何知道该方法是从用户启动的事件(如按钮单击)而不是其他某个线程中调用的?

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. 当用户首次访问我的应用程序时,我会进行一些文件的自动下载,但是我不希望用户按“下载”,然后当我检测到需要更多空间时,请调用“增加配额”,并出现“ Silverlight对话框”,要求更多空间。

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. 我想自动开始下载(不是用户启动的),并且如果我检测到需要更多空间,请调用IncreaseQuota,因此出现“ Silverlight对话框”。 (No user pressing download). (没有用户按下载)。

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 似乎msdn doc在与“事件概述”相关的部分中指定了用户启动的事件,但是IsolatedStorageFile.IncreaseQuotaTo文档和事件概述之间没有链接。

So a user initiated event according to the definition is: 因此,根据定义,用户启动的事件为:

Silverlight enforces that certain operations are only permitted in the context of a handler that handles a user-initiated event. Silverlight强制要求仅在处理用户启动事件的处理程序的上下文中允许某些操作。 The following is a list of such operations: 以下是此类操作的列表:

Setting IsFullScreen. 设置IsFullScreen。

Showing certain dialogs. 显示某些对话框。 This includes SaveFileDialog, OpenFileDialog, and the print dialog displayed by PrintDocument.Print. 这包括SaveFileDialog,OpenFileDialog和PrintDocument.Print显示的打印对话框。

Navigating from a HyperlinkButton. 从HyperlinkBut​​ton导航。

Accessing the primary Clipboard API. 访问主要的剪贴板API。

Silverlight user-initiated events include the mouse events (such as MouseLeftButtonDown), and the keyboard events (such as KeyDown). Silverlight用户启动的事件包括鼠标事件(例如MouseLeftButtonDown)和键盘事件(例如KeyDown)。 Events of controls that are based on such events (such as Click) are also considered user-initiated. 基于此类事件的控件的事件(例如Click)也被认为是用户启动的。

API calls that require user initiation should be called as soon as possible in an event handler. 需要用户启动的API调用应在事件处理程序中尽快调用。 This is because the Silverlight user initiation concept also requires that the calls occur within a certain time window after the event occurrence. 这是因为Silverlight用户启动概念还要求在事件发生后的特定时间范围内进行调用。 In Silverlight 4, this time window is approximately one second. 在Silverlight 4中,此时间窗口约为一秒钟。

User-initiated event restrictions also apply to usages of JavaScript API for Silverlight. 用户启动的事件限制也适用于JavaScript API for Silverlight的用法。

When Silverlight is in full-screen mode, some input events are deliberately limited for security reasons, although this can be mitigated for out-of-browser applications using elevated trust. 当Silverlight处于全屏模式时,出于安全原因,故意限制了某些输入事件,尽管使用增强的信任度可以减轻浏览器外应用程序的负担。 For more information, see Full-Screen Support. 有关更多信息,请参见全屏支持。

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. 尽管我在“操作”列表中没有看到“ IncreaseQuotaTo”,但我猜想它们只是忘记了,因为其行为/限制与文档中所述的相同。

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: 我很想知道Silverlight如何确切地知道用户发起的事件是什么,但是在挖掘.net框架源代码后,我陷入了死胡同:

if ((browserService == null) || !browserService.InPrivateMode())
{
    //..
}
return false; //means that IncreaseQuota will fail

where browser.IsInPrivateMode is: 其中browser.IsInPrivateMode是:

[SecuritySafeCritical]
public bool InPrivateMode()
{
    bool privateMode = false;
    return (NativeMethods.SUCCEEDED(UnsafeNativeMethods.DOM_InPrivateMode(this._browserServiceHandle, out privateMode)) && privateMode);
}

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. DOM_InPrivateMode在DllImport [“ agcore”]中,根据微软的说法,这是机密的:(因此,看来我不会很快发现他们如何检测用户发起的事件。

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. 仔细考虑一下,我猜微软不希望用户在浏览器中打开许多选项卡,然后装腔作势:我会自动调用GrowthQuotaTo。

The IncreaseQuotaTo is a browser modal dialog. GrowthQuotaTo是浏览器模式对话框。 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 :). 因此,如果用户现在已经从我的页面移至google.com的标签,并且如果我能够延迟调用CallingQuotaTo,则用户可能会认为google.com要求更多存储空间:)。

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. 因此,总的来说,考虑到这一点,我开始明白为什么他们要像这样实现它,以及为什么存在这些限制。

The documentation isn't incomplete. 文档并不完整。

If I do this... button_click(..) { new UserControl() } ... Does this still count as a user initiated event? 如果我这样做... button_click(..) { new UserControl() } ...这是否仍算作用户启动的事件?

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? IOW是鼠标悬停在用户事件上吗? 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). 如果您提示用户并且他们接受,则存储将在两次访问之间为您的应用程序保留,这意味着您无需在他们下次使用控件时再次提示他们,配额仍会比上一次增加(除非用户已故意删除它,可以通过右键单击Silverlight控件,然后转到“应用程序存储”选项卡来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM