Exemplo n.º 1
0
            protected override Assembly Load(AssemblyName assemblyName)
            {
                var res = DependencyContext.Default.CompileLibraries.Where(d => d.Name.Contains(assemblyName.Name)).ToList();

                if (res.Count > 0)
                {
                    return(Assembly.Load(new AssemblyName(res.First().Name)));
                }
                else
                {
                    var tempRunningAssbly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName == assemblyName.FullName);
                    if (tempRunningAssbly != null)
                    {
                        return(tempRunningAssbly);
                    }
                    var tempName  = $"{assemblyName.Name}.dll";
                    var tempName1 = $"{assemblyName.Name}.exe";
                    var dll       = dlls.FirstOrDefault(x => x.EndsWith(tempName) || x.EndsWith(tempName1));
                    if (dll != null && !assemblyName.Name.StartsWith("System."))
                    {
                        var asl = AssemblyLoader.CreateAssemblyLoader(dll);
                        return(asl);
                    }
                }
                return(Assembly.Load(assemblyName));
            }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var temp = new ConfigurationBuilder()
                       .AddJsonFile("Run.Method.NowCore.deps.json", optional: true)
                       //.AddUserSecrets("e3dfcccf-0cb3-423a-b302-e3e92e95c128")
                       //.AddEnvironmentVariables()
                       .Build();

            Console.Title = "Run Method Now core2.1";
            Console.WriteLine("starting...");
            string schemapath = Path.Combine(AppContext.BaseDirectory, SchemaInfo.FileName);

            while (!File.Exists(schemapath))
            {
                Thread.Sleep(5000);
            }
            Debug.WriteLine("starting...");
            MainSchemaInfo = JsonConvert.DeserializeObject <SchemaInfo>(File.ReadAllText(schemapath));
            string appPath = AppContext.BaseDirectory + MainSchemaInfo.AssambleName + ".dll";

            //var type = asm.GetType("MyClassLib.SampleClasses.Sample");
            MainAssembly = AssemblyLoader.CreateAssemblyLoader(appPath);
            Debug.WriteLine("main assembly loaded " + (MainAssembly != null));
            Console.WriteLine("main assembly loaded " + (MainAssembly != null));
            Type typeYouWant = MainAssembly.GetType(MainSchemaInfo.NameSpaceAndClass);

            Debug.WriteLine("main class loaded " + (typeYouWant != null));
            Console.WriteLine("main class loaded " + (typeYouWant != null));
            ConstructorInfo[] constructor      = typeYouWant.GetConstructors();
            ParameterInfo[]   classTypeParem2  = (constructor.Length != 0) ? constructor[0].GetParameters() : new ParameterInfo[0];
            object[]          createdInstance2 = (classTypeParem2.Length == 0) ? new object[0] : createInstance(classTypeParem2);
            object            instance         = (constructor.Length != 0) ? Activator.CreateInstance(typeYouWant, createdInstance2) : null;
            MethodInfo        method           = getMethod(typeYouWant);

            Debug.WriteLine("main method loaded " + (method != null));
            Console.WriteLine("main method loaded " + (method != null));
            if (method == null)
            {
                Console.WriteLine(MainSchemaInfo.MethodToRun + " method not found error");
                Console.ReadKey();
            }
            else
            {
                classTypeParem2  = method.GetParameters();
                createdInstance2 = ((classTypeParem2.Length == 0) ? new object[0] : createInstance(classTypeParem2));
                var output = method.Invoke(instance, createdInstance2);
                if (output != null)
                {
                    Debug.WriteLine("output printing in json:");
                    Console.WriteLine("output printing in json:");
                    Debug.WriteLine(JsonConvert.SerializeObject(output));
                    Console.WriteLine(JsonConvert.SerializeObject(output));
                    Thread.Sleep(5 * 1000);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Scan for new namespaces when loaded
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void NamespacesDlg_Activated(object sender, EventArgs e)
        {
            NamespaceSummaryItemCollection nsColl = project.NamespaceSummaries;
            Collection <string>            asmNS, namespaces = new Collection <string>();
            AssemblyLoader loader = null;
            string         path = null;

            // Only load them once and not at design time
            if (namespacesLoaded || this.DesignMode)
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                namespacesLoaded = true;

                try
                {
                    // Make sure we start in the project's folder so that
                    // relative paths are resolved correctly.
                    Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                                      project.Filename));

                    loader = AssemblyLoader.CreateAssemblyLoader(project);

                    // Get a list of all unique namespaces in the
                    // documentation assemblies.
                    foreach (DocumentAssembly da in project.Assemblies)
                    {
                        if (da.CommentsOnly)
                        {
                            continue;
                        }

                        try
                        {
                            path  = da.AssemblyPath;
                            asmNS = loader.GetNamespaces(path);

                            foreach (string ns in asmNS)
                            {
                                if (!namespaces.Contains(ns))
                                {
                                    namespaces.Add(ns);
                                }
                            }
                        }
                        catch (FileNotFoundException ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);

                            if (MessageBox.Show("Unable to find the assembly '" +
                                                path + "' or one of its dependencies.  You " +
                                                "may need to build it or add a dependency " +
                                                "to the project dependency list.  Do you " +
                                                "want to continue loading the remaining " +
                                                "assemblies?", Constants.AppName,
                                                MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Error) == DialogResult.No)
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    if (loader != null)
                    {
                        AssemblyLoader.ReleaseAssemblyLoader();
                    }
                }

                // The global namespace (N:) isn't always listed but we'll
                // add it as it does show up in the reflection info anyway.
                if (!namespaces.Contains(String.Empty))
                {
                    namespaces.Add(String.Empty);
                }

                // Add new namespaces to the list
                foreach (string ns in namespaces)
                {
                    if (!nsColl.Contains(ns))
                    {
                        nsColl.Add(new NamespaceSummaryItem(ns));
                    }
                }

                nsColl.Sort();

                // Load the listbox with the namespace items
                foreach (NamespaceSummaryItem nsi in nsColl)
                {
                    lbNamespaces.Items.Add(nsi, nsi.IsDocumented);
                }

                if (lbNamespaces.Items.Count == 0)
                {
                    btnDelete.Enabled = txtSummary.Enabled = false;
                }
                else
                {
                    lbNamespaces.SelectedIndex = 0;
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }