internal static string GetDataDirectory(IsolatedStorageScope scope) { // This is the relevant special folder for the given scope plus "IsolatedStorage". // It is meant to replicate the behavior of the VM ComIsolatedStorage::GetRootDir(). // (note that Silverlight used "CoreIsolatedStorage" for a directory name and did not support machine scope) string dataDirectory = null; if (IsMachine(scope)) { // SpecialFolder.CommonApplicationData -> C:\ProgramData dataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); } else if (IsRoaming(scope)) { // SpecialFolder.ApplicationData -> C:\Users\Joe\AppData\Roaming dataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } else { // SpecialFolder.LocalApplicationData -> C:\Users\Joe\AppData\Local dataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); } dataDirectory = Path.Combine(dataDirectory, IsolatedStorageDirectoryName); return dataDirectory; }
internal static string GetDataDirectory(IsolatedStorageScope scope) { // This is the relevant special folder for the given scope plus "IsolatedStorage". // It is meant to replicate the behavior of the VM ComIsolatedStorage::GetRootDir(). string dataDirectory = null; if (IsMachine(scope)) { dataDirectory = ApplicationData.Current.SharedLocalFolder.Path; } else { if (!IsRoaming(scope)) { dataDirectory = ApplicationData.Current.LocalFolder.Path; } else { dataDirectory = ApplicationData.Current.RoamingFolder.Path; } } dataDirectory = Path.Combine(dataDirectory, IsolatedStorageDirectoryName); return dataDirectory; }
public void DomainIdentityIsSet(IsolatedStorageScope scope) { TestStorage storage = new TestStorage(scope); Assert.NotNull(storage.AssemblyIdentity); Assert.NotNull(storage.DomainIdentity); Assert.Throws<InvalidOperationException>(() => storage.ApplicationIdentity); }
/// <summary> /// The full root directory is the relevant special folder from Environment.GetFolderPath() plus "IsolatedStorage" /// and a set of random directory names if not roaming. /// /// Examples: /// /// User: @"C:\Users\jerem\AppData\Local\IsolatedStorage\10v31ho4.bo2\eeolfu22.f2w\" /// User|Roaming: @"C:\Users\jerem\AppData\Roaming\IsolatedStorage\" /// Machine: @"C:\ProgramData\IsolatedStorage\nin03cyc.wr0\o3j0urs3.0sn\" /// /// Identity for the current store gets tacked on after this. /// </summary> internal static string GetRootDirectory(IsolatedStorageScope scope) { if (IsRoaming(scope)) { if (string.IsNullOrEmpty(s_roamingUserRootDirectory)) { s_roamingUserRootDirectory = GetDataDirectory(scope); } return s_roamingUserRootDirectory; } if (IsMachine(scope)) { if (string.IsNullOrEmpty(s_machineRootDirectory)) { s_machineRootDirectory = GetRandomDirectory(GetDataDirectory(scope), scope); } return s_machineRootDirectory; } if (string.IsNullOrEmpty(s_userRootDirectory)) s_userRootDirectory = GetRandomDirectory(GetDataDirectory(scope), scope); return s_userRootDirectory; }
internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageScope scope) { string randomDirectory = GetExistingRandomDirectory(rootDirectory); if (string.IsNullOrEmpty(randomDirectory)) { using (Mutex m = CreateMutexNotOwned(rootDirectory)) { if (!m.WaitOne()) { throw new IsolatedStorageException(SR.IsolatedStorage_Init); } try { randomDirectory = GetExistingRandomDirectory(rootDirectory); if (string.IsNullOrEmpty(randomDirectory)) { // Someone else hasn't created the directory before we took the lock randomDirectory = Path.Combine(rootDirectory, Path.GetRandomFileName(), Path.GetRandomFileName()); CreateDirectory(randomDirectory, scope); } } finally { m.ReleaseMutex(); } } } return randomDirectory; }
internal static string GetRootDirectory(IsolatedStorageScope scope) { // The full root directory is the relevant special folder from Environment.GetFolderPath() plus "IsolatedStorage" // and a set of random directory names if not roaming. The current identity gets tacked on after this. if (IsRoaming(scope)) { if (string.IsNullOrEmpty(s_roamingUserRootDirectory)) { s_roamingUserRootDirectory = GetDataDirectory(scope); } return s_roamingUserRootDirectory; } if (IsMachine(scope)) { if (string.IsNullOrEmpty(s_machineRootDirectory)) { s_machineRootDirectory = GetDataDirectory(scope); } return s_machineRootDirectory; } if (string.IsNullOrEmpty(s_userRootDirectory)) s_userRootDirectory = GetDataDirectory(scope); return s_userRootDirectory; }
/* public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, System.Security.Policy.Evidence domainEvidence, Type domainEvidenceType, System.Security.Policy.Evidence assemblyEvidence, Type assemblyEvidenceType) { Contract.Requires(domainEvidence != null); Contract.Requires(assemblyEvidence != null); return default(IsolatedStorageFile); } */ public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, object domainIdentity, object assemblyIdentity) { Contract.Requires(domainIdentity != null); Contract.Requires(assemblyIdentity != null); return default(IsolatedStorageFile); }
// Constructor. internal IsolatedStorageFile(IsolatedStorageScope scope, String baseDirectory) { InitStore(scope, null, null); this.baseDirectory = baseDirectory; this.refCount = 1; this.closed = false; }
internal IsolatedStorageFileEnumerator(IsolatedStorageScope scope) { this.m_Scope = scope; this.m_fiop = IsolatedStorageFile.GetGlobalFileIOPerm(scope); this.m_rootDir = IsolatedStorageFile.GetRootDir(scope); this.m_fileEnum = new TwoLevelFileEnumerator(this.m_rootDir); this.Reset(); }
public IsolatedStorageSettings( bool useIsolatedStore, IsolatedStorageScope isolationScope ) { UseIsolatedStore = useIsolatedStore; _isolationScope = isolationScope; }
public IsolatedStorageFileEnumerator (IsolatedStorageScope scope, string root) { _scope = scope; // skip application-isolated storages if (Directory.Exists (root)) _storages = Directory.GetDirectories (root, "d.*"); _pos = -1; }
public void GetRandomDirectory(IsolatedStorageScope scope) { using (var temp = new TempDirectory()) { string randomDir = Helper.GetRandomDirectory(temp.Path, scope); Assert.True(Directory.Exists(randomDir)); } }
private void GetEnumerator (IsolatedStorageScope scope) { IEnumerator e = IsolatedStorageFile.GetEnumerator (scope); int n = 0; while (e.MoveNext ()) { IsolatedStorageFile isf = (IsolatedStorageFile)e.Current; CheckEnumerated (++n, scope, isf); } }
internal static void CreateDirectory(string path, IsolatedStorageScope scope) { if (Directory.Exists(path)) return; DirectoryInfo info = Directory.CreateDirectory(path); if (IsMachine(scope) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Need to emulate COMIsolatedStorage::CreateDirectoryWithDacl(), which gives the following rights: // // World / Everyone (S-1-1-0 / SECURITY_WORLD_RID) -> (FILE_GENERIC_WRITE | FILE_GENERIC_READ) & (~WRITE_DAC) // Creator Owner (S-1-3-0 / SECURITY_CREATOR_OWNER_RID) -> FILE_ALL_ACCESS // Local Admins (S-1-5-32 / SECURITY_BUILTIN_DOMAIN_RID & DOMAIN_ALIAS_RID_ADMINS) -> FILE_ALL_ACCESS // // When looking at rights through the GUI it looks like this: // // "Everyone" -> Read, Write // "Administrators" -> Full control // "CREATOR OWNER" -> Full control // // With rights applying to "This folder, subfolders, and files". No inheritance from the parent folder. // // Note that trying to reset the rules for CREATOR OWNER leaves the current directory with the actual creator's SID. // (But applies CREATOR OWNER as expected for items and subdirectories.) Setting up front when creating the directory // doesn't exhibit this behavior, but as we can't currently do that we'll take the rough equivalent for now. DirectorySecurity security = new DirectorySecurity(); // Don't inherit the existing rules security.SetAccessRuleProtection(isProtected: true, preserveInheritance: false); security.AddAccessRule(new FileSystemAccessRule( identity: new SecurityIdentifier(WellKnownSidType.WorldSid, null), fileSystemRights: FileSystemRights.Read | FileSystemRights.Write, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Allow)); security.AddAccessRule(new FileSystemAccessRule( identity: new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), fileSystemRights: FileSystemRights.FullControl, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Allow)); security.AddAccessRule(new FileSystemAccessRule( identity: new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null), fileSystemRights: FileSystemRights.FullControl, inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, propagationFlags: PropagationFlags.None, type: AccessControlType.Allow)); info.SetAccessControl(security); } }
public void InitStore_InvalidScopes(IsolatedStorageScope scope) { try { s_verifyScopeMethod.Invoke(null, new object[] { scope }); } catch (TargetInvocationException e) { Assert.IsType<ArgumentException>(e.InnerException); } }
internal static void CreateDirectory(string path, IsolatedStorageScope scope) { if (!IsMachine(scope)) { Directory.CreateDirectory(path); } else { // TODO: https://github.com/dotnet/corefx/issues/11124 // Machine scope, we need to ACL throw new NotImplementedException(); } }
private void CheckEnumerated (int n, IsolatedStorageScope scope, IsolatedStorageFile isf) { string prefix = n.ToString () + " - " + scope.ToString () + " - "; Assert.IsNotNull (isf, prefix + "IsolatedStorageFile"); Assert.IsTrue (((scope & isf.Scope) != 0), prefix + "Scope"); if ((isf.Scope & IsolatedStorageScope.Assembly) != 0) Assert.IsNotNull (isf.AssemblyIdentity, prefix + "AssemblyIdentity"); if ((isf.Scope & IsolatedStorageScope.Domain) != 0) Assert.IsNotNull (isf.DomainIdentity, prefix + "DomainIdentity"); if ((isf.Scope & IsolatedStorageScope.Application) != 0) Assert.IsNotNull (isf.ApplicationIdentity, prefix + "ApplicationIdentity"); }
public static IEnumerator GetEnumerator (IsolatedStorageScope scope) { Demand (scope); switch (scope) { case IsolatedStorageScope.User: case IsolatedStorageScope.User | IsolatedStorageScope.Roaming: case IsolatedStorageScope.Machine: break; default: string msg = Locale.GetText ("Invalid scope, only User, User|Roaming and Machine are valid"); throw new ArgumentException (msg); } return new IsolatedStorageFileEnumerator (scope, GetIsolatedStorageRoot (scope)); }
public static void Delete(string fileName, IsolatedStorageScope scope) { try { using (IsolatedStorageFile file = IsolatedStorageFile.GetStore(scope, (Type)null, (Type)null)) { if (!(string.IsNullOrEmpty(fileName) || (file.GetFileNames(fileName).Length <= 0))) { file.DeleteFile(fileName); } } } catch (Exception exception) { throw new Exception("无法在存储区内删除文件.", exception); } }
internal static void VerifyScope(IsolatedStorageScope scope) { // The only valid ones are the ones that have a helper constant defined above (c_*) if ((scope == c_Domain) || (scope == c_Assembly) || (scope == c_DomainRoaming) || (scope == c_AssemblyRoaming) || (scope == c_MachineDomain) || (scope == c_MachineAssembly) || (scope == c_AppUser) || (scope == c_AppMachine) || (scope == c_AppUserRoaming)) { return; } throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_Scope_Invalid")); }
public static void Remove(IsolatedStorageScope scope) { // The static Remove() deletes ALL IsoStores for the given scope VerifyGlobalScope(scope); string root = Helper.GetRootDirectory(scope); try { Directory.Delete(root, recursive: true); Directory.CreateDirectory(root); } catch { throw new IsolatedStorageException(SR.IsolatedStorage_DeleteDirectories); } }
protected void InitStore(IsolatedStorageScope scope, Type appEvidenceType) { #if !MOBILE if (AppDomain.CurrentDomain.ApplicationIdentity == null) { throw new IsolatedStorageException(Locale.GetText("No ApplicationIdentity available for AppDomain.")); } if (appEvidenceType == null) { // TODO - Choose evidence } #endif // no exception here because this can work without CAS storage_scope = scope; }
/// <summary> /// Initializes a new instance of the <see cref="IsoStorageConfigurationSource"/> class. /// </summary> /// <param name="scope"> /// The scope for the isolated storage file. /// </param> /// <param name="fileName"> /// Name of the file. /// </param> /// <remarks> /// If you specify invalid scope for your application, you will get an <see cref="IsolatedStorageException"/>. /// </remarks> public IsoStorageConfigurationSource( IsolatedStorageScope scope, string fileName ) { if ( scope == IsolatedStorageScope.None ) { throw new ArgumentException( Text.InvalidStorageScope ); } if ( string.IsNullOrEmpty( fileName ) ) { throw new ArgumentNullException( "fileName" ); } Scope = scope; _fileName = fileName; Load(); }
public static void Save <T>(T o, string filenameONLY = null, IsolatedStorageScope iss = IsoConst.PdFls) { try { var isoStore = IsolatedStorageFile.GetStore(iss, null, null); using (var isoStream = new IsolatedStorageFileStream(IsoHelper.GetSetFilename <T>(filenameONLY, "json"), FileMode.Create, isoStore)) { using (var streamWriter = new StreamWriter(isoStream)) { new DataContractJsonSerializer(typeof(T)).WriteObject(streamWriter.BaseStream, o); // new XmlSerializer(o.GetType()).Serialize(streamWriter, o); streamWriter.Close(); } } } catch (Exception ex) { ex.Log(); throw; } }
public void GetStore_Assembly_NonPresentDomainEvidences() { IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Assembly; IsolatedStorageFile isf = IsolatedStorageFile.GetStore(scope, typeof(StrongName), typeof(Url)); Assert.AreEqual(Int64.MaxValue, isf.MaximumSize, "MaximumSize"); Assert.AreEqual(scope, isf.Scope, "Scope"); #if !MOBILE Assert.IsTrue((isf.AssemblyIdentity is Url), "AssemblyIdentity"); // note: mono transforms the CodeBase into uppercase // for net 1.1 which uses file:// and not file:/// string codebase = Assembly.GetExecutingAssembly().CodeBase.ToUpper().Substring(8); Assert.IsTrue((isf.AssemblyIdentity.ToString().ToUpper().IndexOf(codebase) > 0), "Url"); // DomainIdentity throws a InvalidOperationException #endif Assert.IsTrue((isf.CurrentSize >= 0), "CurrentSize"); }
public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, object applicationIdentity) { Demand(scope); if (applicationIdentity == null) { throw new ArgumentNullException("applicationIdentity"); } IsolatedStorageFile storageFile = new IsolatedStorageFile(scope); storageFile._applicationIdentity = applicationIdentity; #if !MOBILE storageFile._fullEvidences = Assembly.GetCallingAssembly().UnprotectedGetEvidence(); #endif storageFile.PostInit(); return(storageFile); }
/// <summary> /// ɾ��ָ������Ĵ洢������ /// </summary> /// <param name="fileName">��ɾ�����ļ�</param> /// <param name="scope">�����洢��Χ����</param> public static void Delete(string fileName, IsolatedStorageScope scope) { try { using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(scope, null, null)) { if (!string.IsNullOrEmpty(fileName) && isoStore.GetFileNames(fileName).Length > 0) { isoStore.DeleteFile(fileName); } } } catch (Exception ex) { throw new Exception("���ڴ洢����ɾ���ļ�.", ex); } }
internal void InitStore(IsolatedStorageScope scope, object domain, object assem, object app) { PermissionSet psAllowed = (PermissionSet)null; PermissionSet psDenied = (PermissionSet)null; Evidence domainEv = (Evidence)null; Evidence assemEv = (Evidence)null; Evidence appEv = (Evidence)null; if (System.IO.IsolatedStorage.IsolatedStorage.IsApp(scope)) { EvidenceBase evidence = app as EvidenceBase ?? (EvidenceBase) new LegacyEvidenceWrapper(app); appEv = new Evidence(); appEv.AddHostEvidence <EvidenceBase>(evidence); } else { EvidenceBase evidence1 = assem as EvidenceBase ?? (EvidenceBase) new LegacyEvidenceWrapper(assem); assemEv = new Evidence(); assemEv.AddHostEvidence <EvidenceBase>(evidence1); if (System.IO.IsolatedStorage.IsolatedStorage.IsDomain(scope)) { EvidenceBase evidence2 = domain as EvidenceBase ?? (EvidenceBase) new LegacyEvidenceWrapper(domain); domainEv = new Evidence(); domainEv.AddHostEvidence <EvidenceBase>(evidence2); } } this._InitStore(scope, domainEv, (Type)null, assemEv, (Type)null, appEv, (Type)null); if (!System.IO.IsolatedStorage.IsolatedStorage.IsRoaming(scope)) { RuntimeAssembly caller = System.IO.IsolatedStorage.IsolatedStorage.GetCaller(); System.IO.IsolatedStorage.IsolatedStorage.GetControlEvidencePermission().Assert(); // ISSUE: explicit reference operation // ISSUE: variable of a reference type PermissionSet& newGrant = @psAllowed; // ISSUE: explicit reference operation // ISSUE: variable of a reference type PermissionSet& newDenied = @psDenied; caller.GetGrantSet(newGrant, newDenied); if (psAllowed == null) { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_AssemblyGrantSet")); } } this.SetQuota(psAllowed, psDenied); }
public static void Remove(IsolatedStorageScope scope) { string dir = GetIsolatedStorageRoot(scope); if (!Directory.Exists(dir)) { return; } try { Directory.Delete(dir, true); } catch (IOException) { throw new IsolatedStorageException("Could not remove storage."); } }
internal static string GetDataDirectory(IsolatedStorageScope scope) { // This is the relevant special folder for the given scope plus "IsolatedStorage". // It is meant to replicate the behavior of the VM ComIsolatedStorage::GetRootDir(). // (note that Silverlight used "CoreIsolatedStorage" for a directory name and did not support machine scope) Environment.SpecialFolder specialFolder = IsMachine(scope) ? Environment.SpecialFolder.CommonApplicationData : // e.g. C:\ProgramData IsRoaming(scope) ? Environment.SpecialFolder.ApplicationData : // e.g. C:\Users\Joe\AppData\Roaming Environment.SpecialFolder.LocalApplicationData; // e.g. C:\Users\Joe\AppData\Local string dataDirectory = Environment.GetFolderPath(specialFolder, Environment.SpecialFolderOption.Create); dataDirectory = Path.Combine(dataDirectory, IsolatedStorageDirectoryName); return(dataDirectory); }
public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) { Demand(scope); IsolatedStorageFile storageFile = new IsolatedStorageFile(scope); if ((scope & IsolatedStorageScope.Domain) != 0) { storageFile._domainIdentity = GetTypeFromEvidence(AppDomain.CurrentDomain.Evidence, domainEvidenceType); } if ((scope & IsolatedStorageScope.Assembly) != 0) { Evidence e = Assembly.GetCallingAssembly().UnprotectedGetEvidence(); storageFile._fullEvidences = e; storageFile._assemblyIdentity = GetTypeFromEvidence(e, assemblyEvidenceType); } storageFile.PostInit(); return(storageFile); }
public static IEnumerator GetEnumerator(IsolatedStorageScope scope) { Demand(scope); switch (scope) { case IsolatedStorageScope.User: case IsolatedStorageScope.User | IsolatedStorageScope.Roaming: case IsolatedStorageScope.Machine: break; default: string msg = Locale.GetText("Invalid scope, only User, User|Roaming and Machine are valid"); throw new ArgumentException(msg); } return(new IsolatedStorageFileEnumerator(scope, GetIsolatedStorageRoot(scope))); }
/// <summary> /// 删除指定区域的存储区内容 /// </summary> /// <param name="fileName">待删除的文件</param> /// <param name="scope">独立存储范围对象</param> public static void Delete(string fileName, IsolatedStorageScope scope) { try { using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(scope, null, null)) { if (!string.IsNullOrEmpty(fileName) && isoStore.GetFileNames(fileName).Length > 0) { isoStore.DeleteFile(fileName); } } } catch (Exception ex) { LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(IsolatedStorageHelper)); throw new Exception("无法在存储区内删除文件.", ex); } }
/// <summary> /// Configures the service with the <see cref="ScopeAttribute"/> value, to customize the /// store location. /// </summary> /// <param name="settings">Values to configure the service with.</param> public override void Configure(NameValueCollection settings) { base.Configure(settings); if (!String.IsNullOrEmpty(settings[ScopeAttribute])) { string[] values = settings[ScopeAttribute].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List <IsolatedStorageScope> scopes = new List <IsolatedStorageScope>(values.Length); foreach (string value in values) { string trimmed = value.Trim(); if (trimmed.Length > 0) { if (Enum.IsDefined(typeof(IsolatedStorageScope), trimmed) == false) { throw new StatePersistenceException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidIsolatedStorageStatePersistanceScope, settings[ScopeAttribute], trimmed)); } scopes.Add((IsolatedStorageScope)Enum.Parse(typeof(IsolatedStorageScope), trimmed)); } } scope = IsolatedStorageScope.None; foreach (IsolatedStorageScope tmpscope in scopes) { scope |= tmpscope; } // Try to initialize a store with the given scope. try { IsolatedStorageFile store = IsolatedStorageFile.GetStore(scope, null, null); } catch (ArgumentException aex) { throw new StatePersistenceException(String.Format( CultureInfo.CurrentCulture, Resources.InvalidIsolatedStorageStatePersistanceParsedScope, settings[ScopeAttribute]), aex); } } }
// Remove store for all identities /// <include file='doc\IsolatedStorageFile.uex' path='docs/doc[@for="IsolatedStorageFile.Remove1"]/*' /> public static void Remove(IsolatedStorageScope scope) { VerifyGlobalScope(scope); DemandAdminPermission(); String rootDir = GetRootDir(scope); new FileIOPermission( FileIOPermissionAccess.Write, rootDir).Assert(); try { Directory.Delete(rootDir, true); // Remove all sub dirs and files Directory.CreateDirectory(rootDir); // Recreate the root dir } catch (Exception) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_DeleteDirectories")); } }
private void _InitStore(IsolatedStorageScope scope, Evidence appEv, Type appEvidenceType, Evidence assemEv, Type assemblyEvidenceType) { // Input arg ckecks if (assemEv == null) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_AssemblyMissingIdentity")); } if (IsDomain(scope) && (appEv == null)) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_DomainMissingIdentity")); } VerifyScope(scope); // Security checks DemandPermission(scope); String typeHash = null, instanceHash = null; m_AssemIdentity = GetAccountingInfo( assemEv, assemblyEvidenceType, false, out typeHash, out instanceHash); m_AssemName = GetNameFromID(typeHash, instanceHash); if (IsDomain(scope)) { m_AppIdentity = GetAccountingInfo(appEv, appEvidenceType, false, out typeHash, out instanceHash); m_AppName = GetNameFromID(typeHash, instanceHash); } m_Scope = scope; }
private void _InitStore(IsolatedStorageScope scope, Evidence domainEv, Type domainEvidenceType, Evidence assemEv, Type assemblyEvidenceType, Evidence appEv, Type appEvidenceType) { System.IO.IsolatedStorage.IsolatedStorage.VerifyScope(scope); if (System.IO.IsolatedStorage.IsolatedStorage.IsApp(scope)) { if (appEv == null) { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_ApplicationMissingIdentity")); } } else { if (assemEv == null) { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_AssemblyMissingIdentity")); } if (System.IO.IsolatedStorage.IsolatedStorage.IsDomain(scope) && domainEv == null) { throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_DomainMissingIdentity")); } } System.IO.IsolatedStorage.IsolatedStorage.DemandPermission(scope); string typeName = (string)null; string instanceName = (string)null; if (System.IO.IsolatedStorage.IsolatedStorage.IsApp(scope)) { this.m_AppIdentity = System.IO.IsolatedStorage.IsolatedStorage.GetAccountingInfo(appEv, appEvidenceType, IsolatedStorageScope.Application, out typeName, out instanceName); this.m_AppName = this.GetNameFromID(typeName, instanceName); } else { this.m_AssemIdentity = System.IO.IsolatedStorage.IsolatedStorage.GetAccountingInfo(assemEv, assemblyEvidenceType, IsolatedStorageScope.Assembly, out typeName, out instanceName); this.m_AssemName = this.GetNameFromID(typeName, instanceName); if (System.IO.IsolatedStorage.IsolatedStorage.IsDomain(scope)) { this.m_DomainIdentity = System.IO.IsolatedStorage.IsolatedStorage.GetAccountingInfo(domainEv, domainEvidenceType, IsolatedStorageScope.Domain, out typeName, out instanceName); this.m_DomainName = this.GetNameFromID(typeName, instanceName); } } this.m_Scope = scope; }
public void GetStore_DomainScope_Evidences() { IsolatedStorageScope scope = IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly; Evidence de = new Evidence(); de.AddHost(new Zone(SecurityZone.Internet)); Evidence ae = new Evidence(); ae.AddHost(new Zone(SecurityZone.Intranet)); IsolatedStorageFile isf = IsolatedStorageFile.GetStore(scope, de, typeof(Zone), ae, typeof(Zone)); // Maximum size for Internet isn't (by default) Int64.MaxValue Assert.AreEqual(scope, isf.Scope, "Scope"); Assert.IsTrue((isf.AssemblyIdentity is Zone), "AssemblyIdentity"); Assert.IsTrue((isf.AssemblyIdentity.ToString().IndexOf("Intranet") > 0), "Zone - Assembly"); Assert.IsTrue((isf.DomainIdentity is Zone), "DomainIdentity"); Assert.IsTrue((isf.DomainIdentity.ToString().IndexOf("Internet") > 0), isf.DomainIdentity.ToString()); //"Zone - Domain"); Assert.IsTrue((isf.CurrentSize >= 0), "CurrentSize"); }
private void CheckEnumerated(int n, IsolatedStorageScope scope, IsolatedStorageFile isf) { string prefix = n.ToString() + " - " + scope.ToString() + " - "; Assert.IsNotNull(isf, prefix + "IsolatedStorageFile"); Assert.IsTrue(((scope & isf.Scope) != 0), prefix + "Scope"); if ((isf.Scope & IsolatedStorageScope.Assembly) != 0) { Assert.IsNotNull(isf.AssemblyIdentity, prefix + "AssemblyIdentity"); } if ((isf.Scope & IsolatedStorageScope.Domain) != 0) { Assert.IsNotNull(isf.DomainIdentity, prefix + "DomainIdentity"); } if ((isf.Scope & IsolatedStorageScope.Application) != 0) { Assert.IsNotNull(isf.ApplicationIdentity, prefix + "ApplicationIdentity"); } }
public static void Load(IDictionary d, IsolatedStorageScope scope, string filename) { d.Clear(); using (IsolatedStorageFile file = IsolatedStorageFile.GetStore(scope, (Type)null, (Type)null)) { string[] fileNames = file.GetFileNames(filename); if ((fileNames.Length > 0) && (fileNames[0] == filename)) { using (Stream stream = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, file)) { IFormatter formatter = new BinaryFormatter(); IDictionaryEnumerator enumerator = ((IDictionary)formatter.Deserialize(stream)).GetEnumerator(); while (enumerator.MoveNext()) { d.Add(enumerator.Key, enumerator.Value); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="IsolatedFileReader"/> class. /// </summary> /// <param name="scope">The scope.</param> /// <param name="fileName">Name of the file.</param> /// <param name="encoding">The encoding.</param> protected IsolatedFileReader ( IsolatedStorageScope scope, string fileName, Encoding encoding) : base(scope, fileName, FileMode.Open, FileAccess.Read) { ArgumentUtility.NotNull ( encoding, "encoding"); _reader = new StreamReader ( Stream, encoding); }
/// <summary> /// Initializes a new instance of the <see cref="IsolatedFileWriter"/> class. /// </summary> /// <param name="scope">The scope.</param> /// <param name="fileName">Name of the file.</param> /// <param name="encoding">The encoding.</param> protected IsolatedFileWriter ( IsolatedStorageScope scope, string fileName, Encoding encoding) : base(scope, fileName, FileMode.Create, FileAccess.Write) { ArgumentUtility.NotNull ( encoding, "encoding"); _writer = new StreamWriter ( Stream, encoding); }
// Helper static methods internal static String GetRootDir(IsolatedStorageScope scope) { if (IsRoaming(scope)) { if (s_RootDirRoaming == null) { s_RootDirRoaming = nGetRootDir(scope); } return(s_RootDirRoaming); } if (s_RootDirUser == null) { InitGlobalsNonRoaming(scope); } return(s_RootDirUser); }
public static IsolatedStorageFile GetStore (IsolatedStorageScope scope, Evidence domainEvidence, Type domainEvidenceType, Evidence assemblyEvidence, Type assemblyEvidenceType) { Demand (scope); bool domain = ((scope & IsolatedStorageScope.Domain) != 0); if (domain && (domainEvidence == null)) throw new ArgumentNullException ("domainEvidence"); bool assembly = ((scope & IsolatedStorageScope.Assembly) != 0); if (assembly && (assemblyEvidence == null)) throw new ArgumentNullException ("assemblyEvidence"); IsolatedStorageFile storageFile = new IsolatedStorageFile (scope); #if !MOBILE if (domain) { if (domainEvidenceType == null) { storageFile._domainIdentity = GetDomainIdentityFromEvidence (domainEvidence); } else { storageFile._domainIdentity = GetTypeFromEvidence (domainEvidence, domainEvidenceType); } if (storageFile._domainIdentity == null) throw new IsolatedStorageException (Locale.GetText ("Couldn't find domain identity.")); } if (assembly) { if (assemblyEvidenceType == null) { storageFile._assemblyIdentity = GetAssemblyIdentityFromEvidence (assemblyEvidence); } else { storageFile._assemblyIdentity = GetTypeFromEvidence (assemblyEvidence, assemblyEvidenceType); } if (storageFile._assemblyIdentity == null) throw new IsolatedStorageException (Locale.GetText ("Couldn't find assembly identity.")); } #endif storageFile.PostInit (); return storageFile; }
internal bool InitStore(IsolatedStorageScope scope, Stream domain, Stream assem, Stream app, String domainName, String assemName, String appName) { BinaryFormatter bSer; try { GetReflectionPermission().Assert(); bSer = new BinaryFormatter(); if (IsApp(scope)) { // Get the Application Info m_AppIdentity = bSer.Deserialize(app); m_AppName = appName; } else { // Get the Assem Info m_AssemIdentity = bSer.Deserialize(assem); m_AssemName = assemName; if (IsDomain(scope)) { // Get the AppDomain Info m_DomainIdentity = bSer.Deserialize(domain); m_DomainName = domainName; } } } catch { return(false); } BCLDebug.Assert(m_ValidQuota == false, "Quota should be invalid here"); m_Scope = scope; return(true); }
internal void InitStore(IsolatedStorageScope scope, Evidence appEv, Type appEvidenceType, Evidence assemEv, Type assemEvidenceType) { PermissionSet psAllowed = null, psDenied = null; if (!IsRoaming(scope)) { if (IsDomain(scope)) { psAllowed = SecurityManager.ResolvePolicy( appEv, GetExecutionPermission(), GetUnrestricted(), null, out psDenied); if (psAllowed == null) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_DomainGrantSet")); } } else { psAllowed = SecurityManager.ResolvePolicy( assemEv, GetExecutionPermission(), GetUnrestricted(), null, out psDenied); if (psAllowed == null) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_AssemblyGrantSet")); } } } _InitStore(scope, appEv, appEvidenceType, assemEv, assemEvidenceType); SetQuota(psAllowed, psDenied); }
private static void VerifyScope(IsolatedStorageScope scope) { // The only valid ones are the ones that have a helper constant defined above (c_*) switch (scope) { case IsolatedStorageScope.User | IsolatedStorageScope.Assembly: case IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain: case IsolatedStorageScope.Roaming | IsolatedStorageScope.User | IsolatedStorageScope.Assembly: case IsolatedStorageScope.Roaming | IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain: case IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly: case IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain: case IsolatedStorageScope.Application | IsolatedStorageScope.User: case IsolatedStorageScope.Application | IsolatedStorageScope.User | IsolatedStorageScope.Roaming: case IsolatedStorageScope.Application | IsolatedStorageScope.Machine: break; default: throw new ArgumentException(SR.IsolatedStorage_Scope_Invalid); } }
private static void Execute() { if (s_roaming) { s_Scope = IsolatedStorageScope.User | IsolatedStorageScope.Roaming; } else { s_Scope = IsolatedStorageScope.User; } if (s_remove) { Remove(); } if (s_list) { List(); } }
internal void InitStore(IsolatedStorageScope scope, Evidence domainEv, Type domainEvidenceType, Evidence assemEv, Type assemEvidenceType, Evidence appEv, Type appEvidenceType) { PermissionSet psAllowed = null; if (!IsRoaming(scope)) { if (IsApp(scope)) { psAllowed = SecurityManager.GetStandardSandbox(appEv); } else if (IsDomain(scope)) { psAllowed = SecurityManager.GetStandardSandbox(domainEv); } else { psAllowed = SecurityManager.GetStandardSandbox(assemEv); } } this._InitStore(scope, domainEv, domainEvidenceType, assemEv, assemEvidenceType, appEv, appEvidenceType); this.SetQuota(psAllowed, null); }
public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) { Demand(scope); IsolatedStorageFile storageFile = new IsolatedStorageFile(scope); #if !DISABLE_SECURITY if ((scope & IsolatedStorageScope.Domain) != 0) { if (domainEvidenceType == null) { domainEvidenceType = typeof(Url); } storageFile._domainIdentity = GetTypeFromEvidence(AppDomain.CurrentDomain.Evidence, domainEvidenceType); } #endif #if !DISABLE_SECURITY if ((scope & IsolatedStorageScope.Assembly) != 0) { Evidence e = Assembly.GetCallingAssembly().UnprotectedGetEvidence(); storageFile._fullEvidences = e; if ((scope & IsolatedStorageScope.Domain) != 0) { if (assemblyEvidenceType == null) { assemblyEvidenceType = typeof(Url); } storageFile._assemblyIdentity = GetTypeFromEvidence(e, assemblyEvidenceType); } else { storageFile._assemblyIdentity = GetAssemblyIdentityFromEvidence(e); } } #endif storageFile.PostInit(); return(storageFile); }
internal void InitStore(IsolatedStorageScope scope, Object app, Object assem) { Assembly callerAssembly; PermissionSet psAllowed = null, psDenied = null; Evidence appEv = null, assemEv = new Evidence(); assemEv.AddHost(assem); if (IsDomain(scope)) { appEv = new Evidence(); appEv.AddHost(app); } _InitStore(scope, appEv, null, assemEv, null); // Set the quota based on the caller, not the evidence supplied if (!IsRoaming(scope)) // No quota for roaming { callerAssembly = nGetCaller(); GetControlEvidencePermission().Assert(); callerAssembly.nGetGrantSet(out psAllowed, out psDenied); if (psAllowed == null) { throw new IsolatedStorageException( Environment.GetResourceString( "IsolatedStorage_AssemblyGrantSet")); } } // This can be called only by trusted assemblies. // This quota really does not correspond to the permissions // granted for this evidence. SetQuota(psAllowed, psDenied); }
/// <include file='doc\IsolatedStorageFile.uex' path='docs/doc[@for="IsolatedStorageFile.GetEnumerator"]/*' /> public static IEnumerator GetEnumerator(IsolatedStorageScope scope) { VerifyGlobalScope(scope); DemandAdminPermission(); return new IsolatedStorageFileEnumerator(scope); }
internal static void VerifyGlobalScope(IsolatedStorageScope scope) { if ((scope != IsolatedStorageScope.User) && (scope != (IsolatedStorageScope.User| IsolatedStorageScope.Roaming))) { throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_Scope_U_R")); } }
/// <include file='doc\IsolatedStorageFile.uex' path='docs/doc[@for="IsolatedStorageFile.GetStore"]/*' /> public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) { if (domainEvidenceType != null) DemandAdminPermission(); IsolatedStorageFile sf = new IsolatedStorageFile(); sf.InitStore(scope, domainEvidenceType, assemblyEvidenceType); sf.Init(scope); return sf; }
internal static FileIOPermission GetGlobalFileIOPerm( IsolatedStorageScope scope) { if (IsRoaming(scope)) { // no sync needed, ok to create multiple instances. if (s_PermRoaming == null) { s_PermRoaming = new FileIOPermission( FileIOPermissionAccess.AllAccess, GetRootDir(scope)); } return s_PermRoaming; } // no sync needed, ok to create multiple instances. if (s_PermUser == null) { s_PermUser = new FileIOPermission( FileIOPermissionAccess.AllAccess, GetRootDir(scope)); } return s_PermUser; }
private static void InitGlobalsNonRoaming(IsolatedStorageScope scope) { String rootDir = nGetRootDir(scope); new FileIOPermission(FileIOPermissionAccess.AllAccess, rootDir).Assert(); String rndName = GetRandomDirectory(rootDir); if (rndName == null) { // Create a random directory Mutex m = CreateMutexNotOwned(rootDir); if (!m.WaitOne()) throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init")); try { // finally... rndName = GetRandomDirectory(rootDir); // try again with lock if (rndName == null) { byte[] key = new byte[15]; Win32Native.Random(true, key , key.Length); rndName = ToBase32StringSuitableForDirName(key); Directory.CreateDirectory(rootDir + rndName); } } finally { m.ReleaseMutex(); } } s_RootDirUser = rootDir + rndName + "\\"; }
// Helper static methods internal static String GetRootDir(IsolatedStorageScope scope) { if (IsRoaming(scope)) { if (s_RootDirRoaming == null) s_RootDirRoaming = nGetRootDir(scope); return s_RootDirRoaming; } if (s_RootDirUser == null) InitGlobalsNonRoaming(scope); return s_RootDirUser; }
internal bool InitExistingStore(IsolatedStorageScope scope) { FileIOPermission fp; StringBuilder sb = new StringBuilder(); sb.Append(GetRootDir(scope)); if (IsDomain(scope)) { sb.Append(this.AppName); sb.Append(this.SeparatorExternal); // For Domain Stores, accounting is done in the domain root this.m_InfoFile = sb.ToString() + s_InfoFile; } sb.Append(this.AssemName); sb.Append(this.SeparatorExternal); if (IsDomain(scope)) { sb.Append(s_Files); } else { // For Assem Stores, accounting is done in the assem root this.m_InfoFile = sb.ToString() + s_InfoFile; sb.Append(s_AssemFiles); } sb.Append(this.SeparatorExternal); fp = new FileIOPermission( FileIOPermissionAccess.AllAccess, sb.ToString()); fp.Assert(); if (!Directory.Exists(sb.ToString())) return false; this.m_RootDir = sb.ToString(); this.m_fiop = fp; return true; }
internal void Init(IsolatedStorageScope scope) { GetGlobalFileIOPerm(scope).Assert(); StringBuilder sb = new StringBuilder(); // Create the root directory if it is not already there sb.Append(GetRootDir(scope)); if (IsDomain(scope)) { sb.Append(this.AppName); sb.Append(this.SeparatorExternal); try { Directory.CreateDirectory(sb.ToString()); // No exception implies this directory was created now // Create the Identity blob file in the root // directory. OK if there are more than one created // last one wins CreateIDFile(sb.ToString(), true); } catch (Exception) { // Ok to ignore IO exception } // For Domain Stores, accounting is done in the domain root this.m_InfoFile = sb.ToString() + s_InfoFile; } sb.Append(this.AssemName); sb.Append(this.SeparatorExternal); try { Directory.CreateDirectory(sb.ToString()); // No exception implies this directory was created now // Create the Identity blob file in the root // directory. OK if there are more than one created // last one wins CreateIDFile(sb.ToString(), false); } catch (Exception) { // Ok to ignore IO exception } if (IsDomain(scope)) { sb.Append(s_Files); } else { // For Assem Stores, accounting is done in the assem root this.m_InfoFile = sb.ToString() + s_InfoFile; sb.Append(s_AssemFiles); } sb.Append(this.SeparatorExternal); String rootDir = sb.ToString(); try { Directory.CreateDirectory(rootDir); } catch (Exception) { // Ok to ignore IO exception } this.m_RootDir = rootDir; // Use the "new" RootDirectory to create the permission. // This instance of permission is not the same as the // one we just asserted. It uses this.base.RootDirectory. m_fiop = new FileIOPermission( FileIOPermissionAccess.AllAccess, rootDir); }