/// <summary> /// 申请500M的存储空间 /// </summary> /// <returns></returns> public static bool IncreaseQuotaTo() { //如果本函数代码断点调试将不能正常执行。申请缓存对话框将不能阻塞。 long StorageSpace = 200 * 1024 * 1024; //申请空间大小 long IncreaseSpace = 100 * 1024 * 1024; //增量空间 long MinAvailableFreeSpace = 10 * 1024 * 1024; //最小可用空间 try { lock (lockStorageObject) { using (System.IO.IsolatedStorage.IsolatedStorageFile file = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForSite()) { if (file.Quota < StorageSpace) { return(file.IncreaseQuotaTo(StorageSpace)); } else if (file.AvailableFreeSpace < MinAvailableFreeSpace) { return(file.IncreaseQuotaTo(file.Quota + IncreaseSpace)); } } } return(true); } catch (System.IO.IsolatedStorage.IsolatedStorageException) { return(false); } }
/// <summary> /// Performs an increase in space for saving files in Isolated Storage /// </summary> /// <param name="iso"></param> /// <param name="requiredSpace">The required space of a a file in bytes</param> /// <returns></returns> public static IsolatedStorageIncreaseRespond IncreaseIsoStorage(this IsolatedStorageFile iso, long requiredSpace) { IsolatedStorageIncreaseRespond respond; DebugManager.LogData("Requesting an increase in Isolated Storage: +" + string.Format("{0:#,###0}", requiredSpace)); if (iso.IsEnoughSpaceInIsoStorage(requiredSpace)) { DebugManager.LogTrace("Request for increase in Isolated Storage is not needed."); respond = IsolatedStorageIncreaseRespond.NotNeeded; } else { // request more space for Isolated Storage if (!iso.IncreaseQuotaTo(iso.Quota + requiredSpace)) { DebugManager.LogTrace("Request for increase in Isolated Storage has been declined by the user."); respond = IsolatedStorageIncreaseRespond.Declined; } else { DebugManager.LogTrace("Request for increase in Isolated Storage has been accepted by the user."); respond = IsolatedStorageIncreaseRespond.Accepted; } } return(respond); }
public AssemblyStorageService() { Store = IsolatedStorageFile.GetUserStoreForApplication(); Store.IncreaseQuotaTo(20971520); if (!Store.DirectoryExists("Modules")) Store.CreateDirectory("Modules"); }
private bool CheckIfEnoughSpaceLeft(IsolatedStorageFile store, long size) { bool enoughSpaceLeft = false; var handle = new ManualResetEvent(false); Deployment.Current.Dispatcher.BeginInvoke(() => { try { // Request size. Int64 spaceRequired = size; Int64 available = store.AvailableFreeSpace; // If available space is less than // what is requested, try to increase. if (available < spaceRequired) { spaceRequired = spaceRequired - available; // Request more quota space. if (!store.IncreaseQuotaTo(store.Quota + spaceRequired + 1)) { // The user clicked NO to the // host's prompt to approve the quota increase. enoughSpaceLeft = false; } else { // The user clicked YES to the // host's prompt to approve the quota increase. enoughSpaceLeft = true; } } enoughSpaceLeft = true; } catch (Exception) { // Handle that store could not be accessed. enoughSpaceLeft = false; } if (!enoughSpaceLeft) { this.DialogViewService.MessageBoxOk(NewDownload.DownloadRequirementsFailed, string.Format(NewDownload.NotEnoughFreeSpace, this.Tag)); } handle.Set(); }); handle.WaitOne(); return enoughSpaceLeft; }