コード例 #1
0
ファイル: RequestLoader.cs プロジェクト: sanlonezhang/ql
        private void LoadAssembly(Stream stream, AssemblyPart assemblyPart, Action <Assembly> callback)
        {
            Assembly a = null;

            try
            {
                Stream assemblyStream = Application.GetResourceStream(
                    new StreamResourceInfo(stream, null),
                    new Uri(assemblyPart.Source, UriKind.Relative)).Stream;
                a = assemblyPart.Load(assemblyStream);

                if (callback != null)
                {
                    callback(a);
                }
            }
            catch (NullReferenceException)
            {
                WebClient wc = new WebClient();
                wc.OpenReadCompleted += (s, e) =>
                {
                    if (e.Error == null)
                    {
                        a = assemblyPart.Load(e.Result);
                    }

                    if (callback != null)
                    {
                        callback(a);
                    }
                };
                wc.OpenReadAsync(new Uri(assemblyPart.Source, UriKind.RelativeOrAbsolute));
            }
        }
コード例 #2
0
ファイル: AssemblyPartTest.cs プロジェクト: ynkbt/moon
        public void UserThread()
        {
            // created out of the thread
            AssemblyPart ap = new AssemblyPart();

            bool   complete = false;
            bool   status   = false;
            int    tid      = Thread.CurrentThread.ManagedThreadId;
            Thread t        = new Thread(() => {
                try {
                    Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, tid, "ManagedThreadId");

                    Assert.Throws <UnauthorizedAccessException> (delegate {
                        new AssemblyPart();
                    }, "ctor");
                    Assert.Throws <UnauthorizedAccessException> (delegate {
                        Assert.AreEqual(String.Empty, ap.Source, "Source");
                    }, "Source");

                    Assert.IsNull(ap.Load(Stream.Null), "Load(Stream.Null)");

                    Assert.IsNotNull(ap.Load(GetLibraryStream()), "Load");
                    status = true;
                }
                finally {
                    complete = true;
                    Assert.IsTrue(status, "Success");
                }
            });

            t.Start();
            EnqueueConditional(() => complete);
            EnqueueTestComplete();
        }
コード例 #3
0
ファイル: AssemblyPartTest.cs プロジェクト: ynkbt/moon
        public void LoadNewAssemblyPartFromFixedLengthStream()
        {
            AssemblyPart ap = new AssemblyPart();

            Assert.IsNull(ap.Load(GetLibraryFixedStream(0)), "0");
            Assert.IsNull(ap.Load(GetLibraryFixedStream(1)), "1");
            Assert.IsNull(ap.Load(GetLibraryFixedStream(10)), "10");
            Assert.IsNull(ap.Load(GetLibraryFixedStream(100)), "100");
            Assert.IsNull(ap.Load(GetLibraryFixedStream(1000)), "1000");
        }
コード例 #4
0
ファイル: AssemblyPartTest.cs プロジェクト: ynkbt/moon
        public void Defaults()
        {
            AssemblyPart ap = new AssemblyPart();

            Assert.AreEqual(String.Empty, ap.Source, "Source");

            ap.Source = "../../../bad.dll";
            Assert.AreEqual("../../../bad.dll", ap.Source, "Source/relative");

            Assert.Throws <NullReferenceException> (delegate {
                ap.Load(null);
            }, "Load(null)");
            Assert.IsNull(ap.Load(Stream.Null));
        }
コード例 #5
0
ファイル: AssemblyHelpers.cs プロジェクト: w04301706/NLog
        /// <summary>
        /// Load from url
        /// </summary>
        /// <param name="assemblyFileName">file or path, including .dll</param>
        /// <param name="baseDirectory">basepath, optional</param>
        /// <returns></returns>
        public static Assembly LoadFromPath(string assemblyFileName, string baseDirectory = null)
        {
            string fullFileName = baseDirectory == null ? assemblyFileName : Path.Combine(baseDirectory, assemblyFileName);

            InternalLogger.Info("Loading assembly file: {0}", fullFileName);
#if NETSTANDARD1_5
            try
            {
                var assemblyName = System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName(fullFileName);
                return(Assembly.Load(assemblyName));
            }
            catch (Exception ex)
            {
                // this doesn't usually work
                InternalLogger.Warn(ex, "Fallback to AssemblyLoadContext.Default.LoadFromAssemblyPath for file: {0}", fullFileName);
                return(System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(fullFileName));
            }
#elif SILVERLIGHT && !WINDOWS_PHONE
            var      stream       = Application.GetResourceStream(new Uri(assemblyFileName, UriKind.Relative));
            var      assemblyPart = new AssemblyPart();
            Assembly assembly     = assemblyPart.Load(stream.Stream);
            return(assembly);
#else
            Assembly asm = Assembly.LoadFrom(fullFileName);
            return(asm);
#endif
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        void TLYC1_TileClick(object sender, TileClickEventArgs e)
        {
            ma       = e.Tile.Name.ToString();
            tentitle = e.Tile.Header.ToString();
            var WbClnt = new WebClient();//Tao WebClient

            WbClnt.OpenReadCompleted += (a, b) =>
            {
                if (b.Error == null)
                {
                    AssemblyPart assmbpart = new AssemblyPart();
                    Assembly     assembly  = assmbpart.Load(b.Result);
                    Object       Obj       = assembly.CreateInstance("HPA.Announcement" + "." + "ViewAnnouncement"); //Truy xuat file dll
                    if (Obj != null)                                                                                 //Neu co file dll thi tao ChildWindow
                    {
                        ChildWindow child = (ChildWindow)assembly.CreateInstance("HPA.Announcement" + "." + "ViewAnnouncement");
                        child.Width  = (double)HtmlPage.Window.Eval("screen.availWidth") - 100;
                        child.Height = (double)HtmlPage.Window.Eval("screen.availHeight") - 100;
                        child.Show();
                    }
                    else
                    {
                        MessageBox.Show("Page not exist");
                    }                                          //Khong ton tai page thi bao loi
                }
                else
                {
                    MessageBox.Show("Page not exist");
                }                                          //Khong ton tai file dll thi bao loi
            };
            WbClnt.OpenReadAsync(new Uri("http://localhost:10511/Control/" + "HPA.Announcement" + ".dll", UriKind.Absolute));
        }
コード例 #8
0
        private void CreateChildPage(string asb, string cls)
        {
            var WbClnt = new WebClient();//Tao WebClient

            WbClnt.OpenReadCompleted += (a, b) =>
            {
                if (b.Error == null)
                {
                    AssemblyPart assmbpart = new AssemblyPart();
                    Assembly     assembly  = assmbpart.Load(b.Result);
                    Object       Obj       = assembly.CreateInstance(asb + "." + cls); //Truy xuat file dll
                    if (Obj != null)                                                   //Neu co file dll thi tao ChildWindow
                    {
                        ChildWindow child = (ChildWindow)assembly.CreateInstance(asb + "." + cls);
                        child.Width  = (double)HtmlPage.Window.Eval("screen.availWidth") - 100;
                        child.Height = (double)HtmlPage.Window.Eval("screen.availHeight") - 100;
                        child.Show();
                    }
                    else
                    {
                        MessageBox.Show("Page not exist");
                    }                                          //Khong ton tai page thi bao loi
                }
                else
                {
                    MessageBox.Show("Page not exist");
                }                                          //Khong ton tai file dll thi bao loi
            };
            WbClnt.OpenReadAsync(new Uri("http://localhost:10511/Control/" + asb + ".dll", UriKind.Absolute));
        }
コード例 #9
0
        private void btnEmployeeID_DefaultButtonClick(object sender, RoutedEventArgs e)
        {
            var WbClnt = new WebClient();//Tao WebClient

            WbClnt.OpenReadCompleted += (a, b) =>
            {
                if (b.Error == null)
                {
                    AssemblyPart assmbpart = new AssemblyPart();
                    Assembly     assembly  = assmbpart.Load(b.Result);
                    Object       Obj       = assembly.CreateInstance("HPA.Common" + "." + "Find"); //Truy xuat file dll
                    if (Obj != null)                                                               //Neu co file dll thi tao ChildWindow
                    {
                        ChildWindow child = (ChildWindow)assembly.CreateInstance("HPA.Common" + "." + "Find");
                        child.Closed -= GetEMPID;//nhan ket qua tra ve tu childwindow
                        child.Closed += GetEMPID;
                        child.Show();
                        //if (child.DialogResult==true)
                        //{ txtMNV.Text = EMPID; }
                        //else { txtMNV.Text = "null"; }
                    }
                    else
                    {
                        MessageBox.Show("Page not exist");
                    }                                          //Khong ton tai page thi bao loi
                }
                else
                {
                    MessageBox.Show("Page not exist");
                }                                          //Khong ton tai file dll thi bao loi
            };
            WbClnt.OpenReadAsync(new Uri("http://localhost:10511/Control/" + "HPA.Common" + ".dll", UriKind.Absolute));
        }
コード例 #10
0
        void LoadXap(FileInfo File)
        {
            using (FileStream stream = File.OpenRead())
            {
                System.Windows.Resources.StreamResourceInfo Info = new System.Windows.Resources.StreamResourceInfo(stream, "application/binary");
                StreamResourceInfo     resource         = System.Windows.Application.GetResourceStream(Info, new Uri("AppManifest.xaml", UriKind.Relative));
                string                 resourceManifest = new StreamReader(resource.Stream).ReadToEnd();
                IEnumerable <XElement> assemblyParts    = XDocument.Parse(resourceManifest).Root.Element("Deployment").Element("Deployment.Parts").Elements("AssemblyPart");

                foreach (XElement element in assemblyParts)
                {
                    // 取出 AssemblyPart 的 Source 指定的 dll
                    string source = element.Attribute("Source").Value;
                    string xName  = source.Substring(0, source.Length - 4);

                    AssemblyPart       assemblyPart = new AssemblyPart();
                    StreamResourceInfo streamInfo   = System.Windows.Application.GetResourceStream(Info, new Uri(source, UriKind.Relative));

                    System.Reflection.Assembly assembly = null;
                    try
                    {
                        assembly = assemblyPart.Load(streamInfo.Stream);
                    }
                    catch { }

                    if (assembly != null)
                    {
                        LoadAssembly(assembly);
                    }
                }
            }
        }
コード例 #11
0
        private static void LoadAssemblyFromStream(Stream sourceStream, AssemblyPart assemblyPart)
        {
            Stream assemblyStream = Application.GetResourceStream(new StreamResourceInfo(sourceStream, null),
                                                                  new Uri(assemblyPart.Source, UriKind.Relative)).Stream;

            assemblyPart.Load(assemblyStream);
        }
コード例 #12
0
        private void WidgetXAP_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            WidgetConfig config = (WidgetConfig)e.UserState;

            string[] asmClass = config.ClassName.Split(';');
            if (asmClass.Length < 2)
            {
                return;
            }

            List <AssemblyPart> currentParts = Deployment.Current.Parts.ToList();

            StreamResourceInfo xapStreamInfo   = new StreamResourceInfo(e.Result, "application/binary");
            string             appManifest     = new StreamReader(Application.GetResourceStream(xapStreamInfo, new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd();
            XElement           deploymentRoot  = XDocument.Parse(appManifest).Root;
            List <XElement>    deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList();

            Assembly widgetAssembly = null;

            foreach (XElement deployPart in deploymentParts)
            {
                string             source        = deployPart.Attribute("Source").Value; // Assembly Name
                StreamResourceInfo asmStreamInfo = Application.GetResourceStream(xapStreamInfo, new Uri(source, UriKind.Relative));

                if (currentParts.FirstOrDefault(part => part.Source.Equals(source, StringComparison.CurrentCulture)) == null)
                {
                    AssemblyPart assemblyPart = new AssemblyPart();

                    if (source.Equals(asmClass[0], StringComparison.CurrentCultureIgnoreCase))
                    {
                        widgetAssembly = assemblyPart.Load(asmStreamInfo.Stream);
                    }
                    else
                    {
                        assemblyPart.Load(asmStreamInfo.Stream);
                    }

                    Deployment.Current.Parts.Add(assemblyPart);
                }
            }

            if (widgetAssembly != null)
            {
                WidgetBase widget = widgetAssembly.CreateInstance(asmClass[1]) as WidgetBase;
                SetWidgetProperties(widget, config);
            }
        }
コード例 #13
0
        private void webClient_OpenReadCompleted(object sender,
                                                 OpenReadCompletedEventArgs e)
        {
            AssemblyPart assemblypart = new AssemblyPart();

            assemblypart.Load(e.Result);
            txt.Text = "Assembly downloaded. You can now use it.";
        }
コード例 #14
0
        private static Assembly LoadAssembly(string assemblyPath)
        {
            var sri      = Application.GetResourceStream(new Uri(assemblyPath, UriKind.Relative));
            var myPart   = new AssemblyPart();
            var assembly = myPart.Load(sri.Stream);

            return(assembly);
        }
コード例 #15
0
        private Assembly LoadAssemblyFromXap(string relativeUri, Stream xapPackageStream)
        {
            StreamResourceInfo xapPackageSri = new StreamResourceInfo(xapPackageStream, null);
            StreamResourceInfo assemblySri   = Application.GetResourceStream(xapPackageSri, new Uri(relativeUri, UriKind.Relative));
            AssemblyPart       assemblyPart  = new AssemblyPart();

            return(assemblyPart.Load(assemblySri.Stream));
        }
コード例 #16
0
        private static void LoadToAssemblyPart(Stream assemblyStream, string name)
        {
            var part = new AssemblyPart {
                Source = name
            };
            var assembly = part.Load(assemblyStream);

            LoadedAssemblies.Add(name, assembly);
        }
コード例 #17
0
        public static Assembly ToAssembly(this FileInfo file)
        {
            AssemblyPart part = new AssemblyPart();

            using (var stream = file.OpenRead())
            {
                return(part.Load(stream));
            }
        }
コード例 #18
0
ファイル: Page.xaml.cs プロジェクト: Plankankul/Silverlight
        public Assembly LoadAssemblyFromXap(string relativeUriString, Stream xapPackageStream)
        {
            Uri uri = new Uri(relativeUriString, UriKind.Relative);
            StreamResourceInfo xapPackageSri = new StreamResourceInfo(xapPackageStream, null);
            StreamResourceInfo assemblySri   = Application.GetResourceStream(xapPackageSri, uri);

            AssemblyPart assemblyPart = new AssemblyPart();
            Assembly     a            = assemblyPart.Load(assemblySri.Stream);

            return(a);
        }
コード例 #19
0
ファイル: AssemblyHelper.cs プロジェクト: yicong/Catel
        /// <summary>
        /// Registers the assemblies from a xap file stream. The assemblies are added to a local
        /// cache which will be used by the <see cref="GetLoadedAssemblies()"/> method.
        /// </summary>
        /// <param name="xapStream">The xap stream.</param>
        /// <param name="registerInBackground">If <c>true</c>, the assembly will be loaded in the background.</param>
        /// <returns>List of assemblies in the xap files.</returns>
        /// <remarks>
        /// This method requires that the xap stream contains an <c>AppManifest.xaml</c>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="xapStream"/> is <c>null</c>.</exception>
        public static void RegisterAssembliesFromXap(Stream xapStream, bool registerInBackground = false)
        {
            Argument.IsNotNull("xapStream", xapStream);

            try
            {
                string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(xapStream, null),
                                                                                    new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd();

                var deploy = XDocument.Parse(appManifest).Root;

                var parts = (from assemblyParts in deploy.Elements().Elements()
                             select assemblyParts).ToList();

                foreach (var xe in parts)
                {
                    string source     = xe.Attribute("Source").Value;
                    var    asmPart    = new AssemblyPart();
                    var    streamInfo = Application.GetResourceStream(new StreamResourceInfo(xapStream, "application/binary"), new Uri(source, UriKind.Relative));

                    var assembly = asmPart.Load(streamInfo.Stream);
                    if ((assembly != null) && !_externalAssemblies.Contains(assembly))
                    {
                        _externalAssemblies.Add(assembly);

                        var action = new Action(() =>
                        {
                            Log.Debug("Initializing types for assembly '{0}'", assembly.FullName);

                            TypeCache.InitializeTypes(false, assembly);

                            RegisterAssemblyWithVersionInfo(assembly);

                            Log.Debug("Initialized types for assembly '{0}'", assembly.FullName);
                        });

                        if (registerInBackground)
                        {
                            TaskHelper.RunAndWait(new [] { action });
                        }
                        else
                        {
                            action();
                        }
                    }
                }
            }
            catch (Exception)
            {
                // TODO: Add logging?
            }
        }
コード例 #20
0
 public virtual ICommandAssembly Add(string name, byte[] contents, IKnownTypeHolder knownTypeHolder)
 {
     if (!list.ContainsKey(name))
     {
         using (var memoryStream = new MemoryStream(contents))
         {
             var      part     = new AssemblyPart();
             Assembly assembly = part.Load(memoryStream);
             list[name] = new CommandAssembly(assembly, knownTypeHolder);
         }
     }
     return(list[name]);
 }
コード例 #21
0
ファイル: AssemblyLoader.cs プロジェクト: sanlonezhang/ql
        void client_DownloadAssemblyCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            //加载到内存
            AssemblyPart assemblyPart = new AssemblyPart();
            Assembly     assembly     = assemblyPart.Load(e.Result);

            Interlocked.Increment(ref loaded);

            if (loaded == count && this.m_callback != null)
            {
                m_callback();
            }
        }
コード例 #22
0
        static void OpenReadCompletedHandler(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                // need to handle the error
                return;
            }

            StreamResourceInfo info = Application.GetResourceStream(
                new StreamResourceInfo(e.Result, null),
                new Uri("AppManifest.xaml", UriKind.Relative));

            string    appManifest = new StreamReader(info.Stream).ReadToEnd();
            XmlReader xReader     = XmlReader.Create(new StringReader(appManifest));
            Type      objType     = null;

            while (xReader.Read())
            {
                if (xReader.IsStartElement("AssemblyPart"))
                {
                    xReader.MoveToAttribute("Source");
                    if (xReader.ReadAttributeValue())
                    {
                        StreamResourceInfo asmInfo   = new StreamResourceInfo(e.Result, "application/binary");
                        StreamResourceInfo asmStream = Application.GetResourceStream(asmInfo, new Uri(xReader.Value, UriKind.Relative));
                        AssemblyPart       part      = new AssemblyPart();
                        Assembly           asm       = part.Load(asmStream.Stream);

                        foreach (Type t in asm.GetTypes())
                        {
                            if (t.IsDefined(typeof(CharacterHostAttribute), false))
                            {
                                objType = t;
                            }
                        }
                    }
                }
            }

            if (objType != null)
            {
                _temp.Add(typeof(CharacterHostAttribute), Activator.CreateInstance(objType));
            }

            if (LoadCompleted != null)
            {
                LoadCompleted(null, EventArgs.Empty);
            }
        }
コード例 #23
0
        private static IEnumerable <Assembly> getAssemblies(Stream stream)
        {
            if (stream == null)
            {
                return(null);
            }

            System.Windows.Resources.StreamResourceInfo xapStreamInfo = new System.Windows.Resources.StreamResourceInfo(stream, null);
            Uri uri = new Uri("AppManifest.xaml", UriKind.Relative);

            System.Windows.Resources.StreamResourceInfo resourceStream = Application.GetResourceStream(xapStreamInfo, uri);
            if (resourceStream == null)
            {
                return(null);
            }

            List <Assembly> list = null;

            using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(resourceStream.Stream))
            {
                if (!reader.ReadToFollowing("AssemblyPart"))
                {
                    return(list);
                }
                list = new List <Assembly>();
                do
                {
                    string attribute = reader.GetAttribute("Source");
                    if (attribute != null)
                    {
                        AssemblyPart item = new AssemblyPart();
                        item.Source = attribute;

                        System.Windows.Resources.StreamResourceInfo assemblyResourceStream = Application.GetResourceStream(xapStreamInfo, new Uri(item.Source, UriKind.Relative));
                        if (assemblyResourceStream == null || assemblyResourceStream.Stream == null)
                        {
                            continue;
                        }

                        Assembly assembly = item.Load(assemblyResourceStream.Stream);
                        if (assembly != null)
                        {
                            list.Add(assembly);
                        }
                    }
                }while (reader.ReadToNextSibling("AssemblyPart"));
            }
            return(list);
        }
コード例 #24
0
ファイル: XapAnalysis.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 根据AssemblyPart信息,从XAP流中读取具体DLL信息,并加载到AppDomain中。
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <param name="assemblyPart"></param>
        private static void LoadAssemblyFromStream(Stream sourceStream, AssemblyPart assemblyPart)
        {
            StreamResourceInfo resourceStream = Application.GetResourceStream(new StreamResourceInfo(sourceStream, null),
                                                                              new Uri(assemblyPart.Source, UriKind.Relative));

            //此处有可能找不到对应的DLL 文件流
            if (resourceStream != null)
            {
                var assebblyinfo = assemblyPart.Load(resourceStream.Stream);

                Platform.Logging.Logger.Current.Log(assebblyinfo.FullName, Logging.Category.Info, Logging.Priority.Low);

                Debug.WriteLine(assebblyinfo.FullName);
            }
        }
コード例 #25
0
        /// <summary>
        /// Loads an external assmebly from the specified stream
        /// </summary>
        /// <param name="stream">Stream from which to load the assembly</param>
        private object LoadExternalAssembly(WebClient client, Stream stream)
        {
            StreamResourceInfo manifestStream = Application.GetResourceStream(new StreamResourceInfo(stream, null), new Uri("AppManifest.xaml", UriKind.Relative));
            string             appManifest    = new StreamReader(manifestStream.Stream).ReadToEnd();
            string             assemblyName   = _assemblies[client] + ".dll";
            string             typeName       = _typeNames[client];
            XmlReader          reader         = XmlReader.Create(new StringReader(appManifest));
            Assembly           asm            = null;
            object             instance       = null;

            while (reader.Read())
            {
                if (reader.IsStartElement("AssemblyPart"))
                {
                    reader.MoveToAttribute("Source");
                    reader.ReadAttributeValue();

                    if (reader.Value == assemblyName)
                    {
                        var          assemblyStream = new StreamResourceInfo(stream, "application/binary");
                        var          resourceStream = Application.GetResourceStream(assemblyStream, new Uri(reader.Value, UriKind.Relative));
                        AssemblyPart p = new AssemblyPart();
                        asm = p.Load(resourceStream.Stream);

                        break;
                    }
                }
            }

            if (asm == null)
            {
                throw new InvalidOperationException("Could not find specified assembly.");
            }

            // Instantiate an instance of the specified type
            if (!String.IsNullOrWhiteSpace(typeName))
            {
                instance = asm.CreateInstance(typeName);

                if (instance == null)
                {
                    throw new InvalidOperationException("Could not create instance of requested type.");
                }
            }

            return(instance);
        }
コード例 #26
0
ファイル: TypeLoader.cs プロジェクト: seva-ask/qreal
        private void GetSerializedAssembly(string file)
        {
            AssembliesContext assembliesContext = new AssembliesContext();

            assembliesContext.GetSerialiazedAssembly(file, operation =>
            {
                MemoryStream ms       = new MemoryStream(operation.Value);
                AssemblyPart part     = new AssemblyPart();
                Assembly assembly     = part.Load(ms);
                Type[] availableTypes = assembly.GetTypes();
                foreach (var availableType in availableTypes)
                {
                    Types.Add(availableType);
                }
                DecreaseReady();
            }, null);
        }
コード例 #27
0
        private void WidgetDLL_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            WidgetConfig config = (WidgetConfig)e.UserState;

            string[] asmClass = config.ClassName.Split(';');
            if (asmClass.Length < 2)
            {
                return;
            }

            AssemblyPart assemblyPart = new AssemblyPart();

            Deployment.Current.Parts.Add(assemblyPart);
            Assembly   assembly = assemblyPart.Load(e.Result);
            WidgetBase widget   = assembly.CreateInstance(asmClass[1]) as WidgetBase;

            SetWidgetProperties(widget, config);
        }
コード例 #28
0
ファイル: AssemblyHelpers.cs プロジェクト: w04301706/NLog
        /// <summary>
        /// Load from url
        /// </summary>
        /// <param name="assemblyName">name without .dll</param>
        /// <returns></returns>
        public static Assembly LoadFromName(string assemblyName)
        {
            InternalLogger.Info("Loading assembly: {0}", assemblyName);

#if NETSTANDARD1_0 || WINDOWS_PHONE
            var name = new AssemblyName(assemblyName);
            return(Assembly.Load(name));
#elif SILVERLIGHT && !WINDOWS_PHONE
            //as embedded resource
            var      assemblyFile = assemblyName + ".dll";
            var      stream       = Application.GetResourceStream(new Uri(assemblyFile, UriKind.Relative));
            var      assemblyPart = new AssemblyPart();
            Assembly assembly     = assemblyPart.Load(stream.Stream);
            return(assembly);
#else
            Assembly assembly = Assembly.Load(assemblyName);
            return(assembly);
#endif
        }
        private void LoadRichEditAssembliesFromZippedStream(Stream zipPackageStream)
        {
            StreamResourceInfo zipPackageStreamResourceInfo = new StreamResourceInfo(zipPackageStream, null);
            AssemblyPart       assemblyPart = new AssemblyPart();

            string[] assemblies = ZipUtil.GetZipContents(zipPackageStream);

            for (int i = 0; i < assemblies.Length; i++)
            {
                assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri(assemblies[i], UriKind.Relative)).Stream);
            }

            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.Xpf.RichEdit.v11.1.dll", UriKind.Relative)).Stream);
            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.Xpf.Core.v11.1.dll", UriKind.Relative)).Stream);
            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.RichEdit.v11.1.Core.dll", UriKind.Relative)).Stream);
            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.Data.v11.1.dll", UriKind.Relative)).Stream);
            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.Xpf.Ribbon.v11.1.dll", UriKind.Relative)).Stream);
            //assemblyPart.Load(Application.GetResourceStream(zipPackageStreamResourceInfo, new Uri("DevExpress.Printing.v11.1.Core.dll", UriKind.Relative)).Stream);
        }
コード例 #30
0
ファイル: ModuleInstaller.xaml.cs プロジェクト: publicwmh/eas
        private void btnBrowser_Click(object sender, RoutedEventArgs e)
        {
            this.moduleList.ItemsSource = null;
            this.modules = new List <Module>();

            OpenFileDialog openfile = new OpenFileDialog();

            if (openfile.ShowDialog() == true)
            {
                string fileName = openfile.File.Name;

                if (fileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
                {
                    using (FileStream stream = openfile.File.OpenRead())
                    {
                        AssemblyPart assemblyPart           = new AssemblyPart();
                        System.Reflection.Assembly assembly = null;
                        try
                        {
                            assembly = assemblyPart.Load(stream);
                        }
                        catch { }

                        if (assembly != null)
                        {
                            LoadAssembly(assembly);
                        }
                    }
                }
                else if (fileName.EndsWith(".xap", StringComparison.CurrentCultureIgnoreCase))
                {
                    LoadXap(openfile.File);
                }
            }

            this.labelCount.Content = string.Format("已加载 {0} 个要安装的模块。", this.modules.Count);

            this.moduleList.ItemsSource = modules;
            this.btnOK.IsEnabled        = modules.Count > 0;
        }
コード例 #31
0
        private void ParseExtensionsElement(NLogXmlElement extensionsElement, string baseDirectory)
        {
            extensionsElement.AssertName("extensions");

            foreach (var addElement in extensionsElement.Elements("add"))
            {
                var prefix = addElement.GetOptionalAttribute("prefix", null);

                if (prefix != null)
                {
                    prefix = prefix + ".";
                }

                var type = StripOptionalNamespacePrefix(addElement.GetOptionalAttribute("type", null));
                if (type != null)
                {
                    configurationItemFactory.RegisterType(Type.GetType(type, true), prefix);
                }

            #if !WINDOWS_PHONE
                var assemblyFile = addElement.GetOptionalAttribute("assemblyFile", null);
                if (assemblyFile != null)
                {
                    try
                    {
            #if SILVERLIGHT
                                var si = Application.GetResourceStream(new Uri(assemblyFile, UriKind.Relative));
                                var assemblyPart = new AssemblyPart();
                                Assembly asm = assemblyPart.Load(si.Stream);
            #else

                        var fullFileName = Path.Combine(baseDirectory, assemblyFile);
                        InternalLogger.Info("Loading assembly file: {0}", fullFileName);

                        var asm = Assembly.LoadFrom(fullFileName);
            #endif
                        configurationItemFactory.RegisterItemsFromAssembly(asm, prefix);
                    }
                    catch (Exception exception)
                    {
                        if (exception.MustBeRethrown())
                        {
                            throw;
                        }

                        InternalLogger.Error("Error loading extensions: {0}", exception);
                        if (LogManager.ThrowExceptions)
                        {
                            throw new NLogConfigurationException("Error loading extensions: " + assemblyFile, exception);
                        }
                    }

                    continue;
                }

                var assemblyName = addElement.GetOptionalAttribute("assembly", null);
                if (assemblyName != null)
                {
                    try
                    {
                        InternalLogger.Info("Loading assembly name: {0}", assemblyName);
            #if SILVERLIGHT
                        var si = Application.GetResourceStream(new Uri(assemblyName + ".dll", UriKind.Relative));
                        var assemblyPart = new AssemblyPart();
                        Assembly asm = assemblyPart.Load(si.Stream);
            #else
                        var asm = Assembly.Load(assemblyName);
            #endif

                        configurationItemFactory.RegisterItemsFromAssembly(asm, prefix);
                    }
                    catch (Exception exception)
                    {
                        if (exception.MustBeRethrown())
                        {
                            throw;
                        }

                        InternalLogger.Error("Error loading extensions: {0}", exception);
                        if (LogManager.ThrowExceptions)
                        {
                            throw new NLogConfigurationException("Error loading extensions: " + assemblyName, exception);
                        }
                    }

                    continue;
                }
            #endif
            }
        }