public bool MoveNext() { if (m_enumerator == null) { return(false); } if (!m_enumerator.MoveNext()) { if (m_first) { m_enumerator = m_evidence.GetAssemblyEnumerator(); m_first = false; if (m_enumerator != null) { return(m_enumerator.MoveNext()); } else { return(false); } } else { return(false); } } return(true); }
public IEnumerable <EvidenceBase> GetFactorySuppliedEvidence() { if (this.m_assemblyProvidedEvidence == null) { byte[] o = (byte[])null; PEFileEvidenceFactory.GetAssemblySuppliedEvidence(this.m_peFile, JitHelpers.GetObjectHandleOnStack <byte[]>(ref o)); this.m_assemblyProvidedEvidence = new List <EvidenceBase>(); if (o != null) { Evidence evidence = new Evidence(); new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert(); try { using (MemoryStream memoryStream = new MemoryStream(o)) evidence = (Evidence) new BinaryFormatter().Deserialize((Stream)memoryStream); } catch { } CodeAccessPermission.RevertAssert(); if (evidence != null) { IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator(); while (assemblyEnumerator.MoveNext()) { if (assemblyEnumerator.Current != null) { this.m_assemblyProvidedEvidence.Add(assemblyEnumerator.Current as EvidenceBase ?? (EvidenceBase) new LegacyEvidenceWrapper(assemblyEnumerator.Current)); } } } } } return((IEnumerable <EvidenceBase>) this.m_assemblyProvidedEvidence); }
public void Merge(Evidence evidence) { if (evidence != null) { using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer)) { bool flag = false; IEnumerator hostEnumerator = evidence.GetHostEnumerator(); while (hostEnumerator.MoveNext()) { if (this.Locked && !flag) { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); flag = true; } Type key = hostEnumerator.Current.GetType(); if (this.m_evidence.ContainsKey(key)) { this.GetHostEvidenceNoLock(key); } EvidenceBase base2 = WrapLegacyEvidence(hostEnumerator.Current); this.AddHostEvidenceNoLock(base2, GetEvidenceIndexType(base2), DuplicateEvidenceAction.Merge); } IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator(); while (assemblyEnumerator.MoveNext()) { EvidenceBase base3 = WrapLegacyEvidence(assemblyEnumerator.Current); this.AddAssemblyEvidenceNoLock(base3, GetEvidenceIndexType(base3), DuplicateEvidenceAction.Merge); } } } }
public IEnumerable <EvidenceBase> GetFactorySuppliedEvidence() { if (m_assemblyProvidedEvidence == null) { byte[] serializedEvidence = null; GetAssemblySuppliedEvidence(m_peFile, JitHelpers.GetObjectHandleOnStack(ref serializedEvidence)); m_assemblyProvidedEvidence = new List <EvidenceBase>(); if (serializedEvidence != null) { Evidence deserializedEvidence = new Evidence(); // Partial trust assemblies can provide their own evidence, so make sure that we have // permission to deserialize it new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert(); try { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream(serializedEvidence)) { deserializedEvidence = (Evidence)formatter.Deserialize(ms); } } catch { /* Ignore any errors deserializing */ } CodeAccessPermission.RevertAssert(); // Enumerate the assembly evidence, ignoring any host evidence supplied. Since we // could be loading a Whidbey assembly, we need to use the old GetAssemblyEnumerator // API and deal with objects instead of EvidenceBases. if (deserializedEvidence != null) { IEnumerator enumerator = deserializedEvidence.GetAssemblyEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current != null) { // If this is a legacy evidence object, we need to wrap it before // returning it. EvidenceBase currentEvidence = enumerator.Current as EvidenceBase; if (currentEvidence == null) { currentEvidence = new LegacyEvidenceWrapper(enumerator.Current); } m_assemblyProvidedEvidence.Add(currentEvidence); } } } } } return(m_assemblyProvidedEvidence); }
public static void EvidenceCallMethods() { Evidence e = new Evidence(); e = new Evidence(new Evidence()); e.Clear(); Evidence e2 = e.Clone(); System.Collections.IEnumerator ie = e.GetAssemblyEnumerator(); ie = e.GetHostEnumerator(); e.Merge(e2); }
public void DefaultConstructor () { Evidence evidence = new Evidence (); AssertEquals ("Default constructor count should be zero", evidence.Count, 0); AssertEquals ("Default constructor host enumerator MoveNext() should be false", evidence.GetHostEnumerator().MoveNext(), false); AssertEquals ("Default constructor assembly enumerator MoveNext() should be false", evidence.GetAssemblyEnumerator().MoveNext(), false); AssertEquals ("Default constructor enumerator MoveNext() should be false", evidence.GetEnumerator().MoveNext(), false); }
internal void MergeWithNoDuplicates(Evidence evidence) { if (evidence != null) { using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer)) { IEnumerator hostEnumerator = evidence.GetHostEnumerator(); while (hostEnumerator.MoveNext()) { EvidenceBase base2 = WrapLegacyEvidence(hostEnumerator.Current); this.AddHostEvidenceNoLock(base2, GetEvidenceIndexType(base2), DuplicateEvidenceAction.SelectNewObject); } IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator(); while (assemblyEnumerator.MoveNext()) { EvidenceBase base3 = WrapLegacyEvidence(assemblyEnumerator.Current); this.AddAssemblyEvidenceNoLock(base3, GetEvidenceIndexType(base3), DuplicateEvidenceAction.SelectNewObject); } } } }
public IEnumerable<EvidenceBase> GetFactorySuppliedEvidence() { if (this.m_assemblyProvidedEvidence == null) { byte[] o = null; GetAssemblySuppliedEvidence(this.m_peFile, JitHelpers.GetObjectHandleOnStack<byte[]>(ref o)); this.m_assemblyProvidedEvidence = new List<EvidenceBase>(); if (o != null) { Evidence evidence = new Evidence(); new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert(); try { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream(o)) { evidence = (Evidence) formatter.Deserialize(stream); } } catch { } CodeAccessPermission.RevertAssert(); if (evidence != null) { IEnumerator assemblyEnumerator = evidence.GetAssemblyEnumerator(); while (assemblyEnumerator.MoveNext()) { if (assemblyEnumerator.Current != null) { EvidenceBase current = assemblyEnumerator.Current as EvidenceBase; if (current == null) { current = new LegacyEvidenceWrapper(assemblyEnumerator.Current); } this.m_assemblyProvidedEvidence.Add(current); } } } } } return this.m_assemblyProvidedEvidence; }
public IEnumerable<EvidenceBase> GetFactorySuppliedEvidence() { if (m_assemblyProvidedEvidence == null) { byte[] serializedEvidence = null; GetAssemblySuppliedEvidence(m_peFile, JitHelpers.GetObjectHandleOnStack(ref serializedEvidence)); m_assemblyProvidedEvidence = new List<EvidenceBase>(); if (serializedEvidence != null) { Evidence deserializedEvidence = new Evidence(); // Partial trust assemblies can provide their own evidence, so make sure that we have // permission to deserialize it new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert(); try { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream(serializedEvidence)) { deserializedEvidence = (Evidence)formatter.Deserialize(ms); } } catch { /* Ignore any errors deserializing */ } CodeAccessPermission.RevertAssert(); // Enumerate the assembly evidence, ignoring any host evidence supplied. Since we // could be loading a Whidbey assembly, we need to use the old GetAssemblyEnumerator // API and deal with objects instead of EvidenceBases. if (deserializedEvidence != null) { IEnumerator enumerator = deserializedEvidence.GetAssemblyEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current != null) { // If this is a legacy evidence object, we need to wrap it before // returning it. EvidenceBase currentEvidence = enumerator.Current as EvidenceBase; if (currentEvidence == null) { currentEvidence = new LegacyEvidenceWrapper(enumerator.Current); } m_assemblyProvidedEvidence.Add(currentEvidence); } } } } } return m_assemblyProvidedEvidence; }
public void GetHostAssemblyEnumerator () { object[] hostarray = { "host-1", "host-2", "host-3", "host-4" }; object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" }; Evidence evidence; IEnumerator enumerator; int i; evidence = new Evidence (hostarray, asmbarray); enumerator = evidence.GetAssemblyEnumerator (); i = 0; while (enumerator.MoveNext()) { Assert.AreEqual (enumerator.Current, asmbarray[i++]); } }
internal static void MakeResourceAssemblyEvidence( Evidence input, out Evidence output, out StrongName outputSn ) { IEnumerator eviEnumerator = input.GetHostEnumerator(); output = new Evidence(); outputSn = null; while (eviEnumerator.MoveNext()) { if (eviEnumerator.Current is StrongName) { StrongName inputSn = (StrongName)eviEnumerator.Current; outputSn = new StrongName( inputSn.PublicKey, inputSn.Name + ".resource", inputSn.Version ); output.AddHost( outputSn ); } else { output.AddHost( eviEnumerator.Current ); } } eviEnumerator = input.GetAssemblyEnumerator(); while (eviEnumerator.MoveNext()) { output.AddAssembly( eviEnumerator.Current ); } }