コード例 #1
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);
        }
コード例 #2
0
        public static void Run(string[] args, Dictionary <string, object> resolvers)
        {
            if (args.Length == 1 && args[0] == "reload")
            {
                if (File.Exists(ConsolePaths.RunnerConfig))
                {
                    File.Delete(ConsolePaths.RunnerConfig);
                }
                Console.WriteLine("Index File Cleared");
                return;
            }

            Resolvers = resolvers.ToDictionary(pair => pair.Key, pair => new ResolverWrapper(pair.Value));
            ConsolePaths.SetUpPaths();

            ConsoleLibrary lib = ConsoleLibrary.Load(ConsolePaths.RunnerConfig);

            if (lib.CheckConsoles())
            {
                try
                {
                    lib.Save(ConsolePaths.RunnerConfig);
                }
                catch (Exception)
                {
                }
            }

            if (args.Length != 0)
            {
                string[] consoleArgs = new string[args.Length - 1];
                Console.Write("Arguments: ");
                for (int i = 1; i < args.Length; i++)
                {
                    Console.Write(args[i] + " ");
                    consoleArgs[i - 1] = args[i];
                }

                Console.WriteLine();
                ConsoleItem item = lib.GetConsoleItem(args[0]);
                if (item != null)
                {
                    try
                    {
                        if (!item.Run(consoleArgs))
                        {
                            Console.WriteLine($"Exectuion of {args[0]} Failed.");
                            Console.ReadLine();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        if (e.InnerException != null)
                        {
                            Console.WriteLine("Inner: ");
                            Console.WriteLine(e.InnerException);
                        }

                        throw;
                    }
                }
                else
                {
                    Console.WriteLine("Can not find Console with Key: " + args[0]);
                }
            }
            else
            {
                Console.Write(lib.InstalledConsoles);
            }
        }
コード例 #3
0
ファイル: ConsoleLibrary.cs プロジェクト: ByteChkR/Byt3
 public string[] FindChangedFiles(string[] files)
 {
     return(files.Where(x => ConsoleEntries.Any(y =>
                                                y.LibPath == x && y.FileHash !=
                                                ConsoleItem.GetHash(ConsoleRunner.Resolvers[Path.GetExtension(x)].ResolveLibrary(x)))).ToArray());
 }