System.IO.IsolatedStorage.Helper.GetDefaultIdentityAndHash C# (CSharp) Méthode

GetDefaultIdentityAndHash() static private méthode

static private GetDefaultIdentityAndHash ( object &identity, string &hash, char separator ) : void
identity object
hash string
separator char
Résultat void
        internal static void GetDefaultIdentityAndHash(out object identity, out string hash, char separator)
        {
            // NetFX (desktop CLR) IsolatedStorage uses identity from System.Security.Policy.Evidence to build
            // the folder structure on disk. It would use the "best" available evidence in this order:
            //
            //  1. Publisher (Authenticode)
            //  2. StrongName
            //  3. Url (CodeBase)
            //  4. Site
            //  5. Zone
            //
            // For CoreFX StrongName and Url are the only relevant types. By default evidence for the Domain comes
            // from the Assembly which comes from the EntryAssembly(). We'll emulate the legacy default behavior
            // by pulling directly from EntryAssembly.
            //
            // Note that it is possible that there won't be an EntryAssembly, which is something NetFX doesn't
            // have to deal with and shouldn't be likely on CoreFX due to a single AppDomain. Without Evidence
            // to pull from we'd have to dig into the use case to try and find a reasonable solution should we
            // run into this in the wild.

            Assembly assembly = Assembly.GetEntryAssembly();

            if (assembly == null)
                throw new IsolatedStorageException(SR.IsolatedStorage_Init);

            AssemblyName assemblyName = assembly.GetName();
            Uri codeBase = new Uri(assembly.CodeBase);

            hash = GetNormalizedStrongNameHash(assemblyName);
            if (hash != null)
            {
                hash = "StrongName" + separator + hash;
                identity = assemblyName;
            }
            else
            {
                hash = GetNormalizedUriHash(codeBase);
                hash = "Url" + separator + hash;
                identity = codeBase;
            }
        }
    }

Usage Example

Exemple #1
0
        protected void InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
        {
            VerifyScope(scope);
            Scope = scope;

            object identity;
            string hash;

            Helper.GetDefaultIdentityAndHash(out identity, out hash, SeparatorInternal);

            if (Helper.IsApplication(scope))
            {
                _applicationIdentity = identity;
            }
            else
            {
                if (Helper.IsDomain(scope))
                {
                    _domainIdentity = identity;
                    hash            = $"{hash}{SeparatorExternal}{hash}";
                }

                _assemblyIdentity = identity;
            }

            IdentityHash = hash;
        }
All Usage Examples Of System.IO.IsolatedStorage.Helper::GetDefaultIdentityAndHash