コード例 #1
0
ファイル: ConsoleItem.cs プロジェクト: ByteChkR/Byt3
        public bool Run(string[] args)
        {
            AppDomainController adc = AppDomainController.Create(ConsoleTitle, new[] { Path.GetDirectoryName(LibPath) });
            object ret = adc.LoadTypeAndRunFunction(LibPath, TypeSignature, "Run", new object[] { args });

            adc.Dispose();
            return(ret == null || ret is bool b && b);
        }
コード例 #2
0
ファイル: ConsoleItem.cs プロジェクト: ByteChkR/Byt3
        public ConsoleItem(AppDomainController adc, string libPath, Type type)
        {
            LibPath  = libPath;
            FileHash = GetHash(LibPath);


            TypeSignature = type.FullName;
            try
            {
                ConsoleTitle = (string)adc.GetPropertyValue(libPath, TypeSignature, "ConsoleTitle");
            }
            catch (Exception)
            {
                ConsoleTitle = Path.GetFileNameWithoutExtension(libPath);
            }

            ConsoleKey = (string)adc.GetPropertyValue(libPath, TypeSignature, "ConsoleKey");
        }
コード例 #3
0
ファイル: ConsoleLibrary.cs プロジェクト: ByteChkR/Byt3
        public bool CheckConsoles()
        {
            bool          changed  = false;
            List <string> allFiles = Directory
                                     .GetFiles(ConsolePaths.AssemblyPath, "*Console.*", SearchOption.AllDirectories)
                                     .Select(x => x.Replace("\\", "/")).ToList();

            string[] removedFiles = FindRemovedFiles(allFiles.ToArray());
            for (int i = ConsoleEntries.Count - 1; i >= 0; i--)
            {
                if (removedFiles.Contains(ConsoleEntries[i].LibPath))
                {
                    changed = true;
                    Console.WriteLine("Removing Missing Console: " + ConsoleEntries[i].ConsoleTitle);
                    ConsoleEntries.RemoveAt(i);
                }
            }

            string[] changedFiles = FindChangedFiles(allFiles.ToArray());
            if (changedFiles.Length != 0)
            {
                changed = true;
                ConsoleEntries.Clear();
            }

            string[] addedFiles = FindAddedFiles(allFiles.ToArray());
            for (int i = 0; i < addedFiles.Length; i++)
            {
                string ext = Path.GetExtension(addedFiles[i]);
                if (!ConsoleRunner.Resolvers.ContainsKey(ext))
                {
                    Console.WriteLine("Can not find Resolver for Extension: " + ext);
                    continue;
                }

                string libPath = ConsoleRunner.Resolvers[ext]
                                 .ResolveLibrary(addedFiles[i]);
                changed = true;
                AppDomainController adc = AppDomainController.Create("LoadingAssembly_" + libPath,
                                                                     new[] { Path.GetDirectoryName(libPath) });
                try
                {
                    Type[] consoleTypes = adc.GetTypes(libPath, typeof(AConsole));
                    foreach (Type consoleType in consoleTypes)
                    {
                        ConsoleItem console = new ConsoleItem(adc, libPath, consoleType);
                        Console.WriteLine("Adding New Console: " + console.ConsoleTitle);
                        ConsoleEntries.Add(console);
                    }

                    adc.Dispose();
                }
                catch (Exception e)
                {
                    adc.Dispose();
                    throw e;
                }
            }


            return(changed);
        }