static void SetupJasonClient() { var reader = XmlReader.Create( Application.GetResourceStream( new Uri( "AppManifest.xaml", UriKind.Relative ) ).Stream ); var parts = new AssemblyPartCollection(); if( reader.Read() ) { reader.ReadStartElement(); if( reader.ReadToNextSibling( "Deployment.Parts" ) ) { while( reader.ReadToFollowing( "AssemblyPart" ) ) { parts.Add( new AssemblyPart() { Source = reader.GetAttribute( "Source" ) } ); } } } foreach( var part in parts ) { if( part.Source.ToLower().EndsWith( ".dll" ) ) { var stream = Application.GetResourceStream( new Uri( part.Source, UriKind.Relative ) ).Stream; var assembly = part.Load( stream ); var allTypes = assembly.GetTypes(); allTypes.Where( t => !t.IsGenericType && t.IsAttributeDefined<ServiceKnownTypeAttribute>( true ) ) .ForEach( t => ServiceKnownTypesProvider.RegisterKnownType( t ) ); } } }
public void Add() { int n = Deployment.Current.Parts.Count; AssemblyPartCollection apc = new AssemblyPartCollection(); Assert.Throws <ArgumentNullException> (delegate { apc.Add(null); }, "Add(null)"); AssemblyPart ap1 = new AssemblyPart(); ap1.Load(AssemblyPartTest.GetLibraryStream()); Assert.AreEqual(String.Empty, ap1.Source, "Source-1"); apc.Add(ap1); Assert.AreEqual(1, apc.Count, "Count-1"); AssemblyPart ap2 = new AssemblyPart(); ap2.Load(AssemblyPartTest.GetLibraryStream()); Assert.AreEqual(String.Empty, ap2.Source, "Source-2"); apc.Add(ap2); Assert.AreEqual(2, apc.Count, "Count-2"); // no side effect on deployment Assert.AreEqual(n, Deployment.Current.Parts.Count, "Deployment.Current.Parts.Count"); }
static void SetupJasonClient() { var reader = XmlReader.Create(Application.GetResourceStream(new Uri("AppManifest.xaml", UriKind.Relative)).Stream); var parts = new AssemblyPartCollection(); if (reader.Read()) { reader.ReadStartElement(); if (reader.ReadToNextSibling("Deployment.Parts")) { while (reader.ReadToFollowing("AssemblyPart")) { parts.Add(new AssemblyPart() { Source = reader.GetAttribute("Source") }); } } } foreach (var part in parts) { if (part.Source.ToLower().EndsWith(".dll")) { var stream = Application.GetResourceStream(new Uri(part.Source, UriKind.Relative)).Stream; var assembly = part.Load(stream); var allTypes = assembly.GetTypes(); allTypes.Where(t => !t.IsGenericType && t.IsAttributeDefined <ServiceKnownTypeAttribute>(true)) .ForEach(t => ServiceKnownTypesProvider.RegisterKnownType(t)); } } }
/// <summary> /// 加载所有程序集合 /// </summary> public static void LoadDll() { AssemblyPartCollection coll = Deployment.Current.Parts; foreach (var v in coll) { if (!DynLoadingAssemblyDict.ContainsKey(v.Source)) { System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(new Uri(v.Source, UriKind.RelativeOrAbsolute)); if (null == sri) { continue; } Assembly ass = v.Load(sri.Stream); DynLoadingAssemblyDict.Add(v.Source, ass); } } }
public void Add () { int n = Deployment.Current.Parts.Count; AssemblyPartCollection apc = new AssemblyPartCollection (); Assert.Throws<ArgumentNullException> (delegate { apc.Add (null); }, "Add(null)"); AssemblyPart ap1 = new AssemblyPart (); ap1.Load (AssemblyPartTest.GetLibraryStream ()); Assert.AreEqual (String.Empty, ap1.Source, "Source-1"); apc.Add (ap1); Assert.AreEqual (1, apc.Count, "Count-1"); AssemblyPart ap2 = new AssemblyPart (); ap2.Load (AssemblyPartTest.GetLibraryStream ()); Assert.AreEqual (String.Empty, ap2.Source, "Source-2"); apc.Add (ap2); Assert.AreEqual (2, apc.Count, "Count-2"); // no side effect on deployment Assert.AreEqual (n, Deployment.Current.Parts.Count, "Deployment.Current.Parts.Count"); }
public static bool ContainsDLRAssemblies(AssemblyPartCollection assemblyPartCollection) { var ret = assemblyPartCollection.Count != 0; foreach (var name in _dlrAssemblyNames) { bool found = false; foreach (AssemblyPart ap in assemblyPartCollection) { if (string.Format("{0}.dll", name) == ap.Source) { found = true; break; } } ret = ret && found; } bool langFound = false; foreach (AssemblyPart ap in assemblyPartCollection) { var rb = string.Format("{0}.dll", _languageAssemblyNames[0]); var py = string.Format("{0}.dll", _languageAssemblyNames[2]); if(ap.Source == rb || ap.Source == py) { langFound = true; break; } } return ret && langFound; }