Exemplo n.º 1
0
        public static void Core()
        {
            //remove all file

            ConsoleAssistance.WriteLine(I18N.Core("Clean_CleanAll"), ConsoleColor.Yellow);
            //confirm
            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            var strDownload   = Information.WorkPath.Enter("cache").Enter("download").Path;
            var strDependency = Information.WorkPath.Enter("cache").Enter("dependency").Path;

            Console.WriteLine(I18N.Core("Clean_Deleting", "download"));
            Directory.Delete(strDownload, true);
            Directory.CreateDirectory(strDownload);

            Console.WriteLine(I18N.Core("Clean_Deleting", "dependency"));
            Directory.Delete(strDependency, true);
            Directory.CreateDirectory(strDependency);

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Exemplo n.º 2
0
        public static void Core(string packageName)
        {
            //get info
            var installFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("installed").Path);

            DirectoryInfo[] directoryList;
            if (packageName.Contains("@"))
            {
                directoryList = installFolder.GetDirectories($"{packageName}");
            }
            else
            {
                directoryList = installFolder.GetDirectories($"{packageName}@*");
            }

            if (directoryList.Count() == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                return;
            }

            //sort remove package for ensure correctly remove
            var recorder = new Record();

            recorder.Init();
            var realPackage = recorder.SortPackage((from i in directoryList select i.Name).ToList());

            recorder.Save();

            ConsoleAssistance.WriteLine(I18N.Core("Remove_RemoveList"), ConsoleColor.Yellow);
            foreach (var item in realPackage)
            {
                Console.WriteLine($"{item}");
            }

            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            //remove
            var res = RealRemove(realPackage);

            if (!res)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_OperationAborted"), ConsoleColor.Red);
                return;
            }

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("Teji server " + Information.Version, ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine("A self-host IM.");

            ConsoleAssistance.WriteLine("Init Config...");
            General.serverConfig = new ConfigManager(true);

            ConsoleAssistance.WriteLine("Init Database...");
            General.serverDatabase = new Database();
            General.serverDatabase.Open();

            ConsoleAssistance.WriteLine("Init File Pool...");
            General.FilePoolManager = new FilePool();

            ConsoleAssistance.WriteLine("Init Network...");
            General.serverNetwork = new Network();
            General.serverNetwork.StartListen();

            //circle
            string command = "";

            while (true)
            {
                var result = Console.ReadKey(true);
                if (result.Key == ConsoleKey.Tab)
                {
                    General.IsInputing = true;
                    command            = "";

                    //todo:finish display
                    ConsoleAssistance.Write("TejiServer", ConsoleColor.Green);
                    ConsoleAssistance.Write(">", ConsoleColor.Yellow);

                    command = Console.ReadLine();
                    //todo:process command
                    if (command == "exit")
                    {
                        break;
                    }
                    else
                    {
                        CommandProcessor.Process(null, command);
                    }
                    General.IsInputing = false;
                }
            }

            //close
            General.serverNetwork.Close();
            General.serverDatabase.Close();
            General.serverConfig.Save();
        }
Exemplo n.º 4
0
        public static void Core(string packageName)
        {
            //get info
            var downloadFolder   = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("download").Path);
            var dependencyFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("dependency").Path);

            var filelist = new List <string>();

            if (packageName.Contains("@"))
            {
                //special version
                filelist.AddRange(from item in downloadFolder.GetFiles($"{packageName}.zip") select item.FullName);
                filelist.AddRange(from item in dependencyFolder.GetFiles($"{packageName}.json") select item.FullName);
            }
            else
            {
                //all version
                filelist.AddRange(from item in downloadFolder.GetFiles($"{packageName}@*.zip") select item.FullName);
                filelist.AddRange(from item in dependencyFolder.GetFiles($"{packageName}@*.json") select item.FullName);
            }

            ConsoleAssistance.WriteLine(I18N.Core("Clean_FileList"), ConsoleColor.Yellow);
            foreach (var item in filelist)
            {
                Console.WriteLine($"{item}");
            }

            //confirm
            Console.WriteLine();
            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            foreach (var item in filelist)
            {
                Console.WriteLine(I18N.Core("Clean_Deleting", item));
                File.Delete(item);
            }

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("Welcome to use Subway Map Render.", ConsoleColor.Yellow);

            //load
            var globalConfig = ConfigManager.Read <ShareLib.RenderStruct.RenderSettings>(ConfigManager.RenderSettingsFile);

            ConsoleAssistance.WriteLine("Load saved render config OK.", ConsoleColor.Yellow);

            string command = "";

            while (true)
            {
                ConsoleAssistance.Write("> ", ConsoleColor.Green);
                command = Console.ReadLine();
                if (!Command.CommandProcessor(command, ref globalConfig))
                {
                    break;
                }
            }

            ConsoleAssistance.WriteLine("Thank you for your using.", ConsoleColor.Yellow);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("BPM Script Debugger", ConsoleColor.Yellow);

            //read template
            var fs2 = new StreamReader("ScriptBody.cs", Encoding.UTF8);

            General.CodeTemplate = fs2.ReadToEnd();
            fs2.Close();
            fs2.Dispose();

            //read config
            General.ConfigManager = new Config("settings.config", new Dictionary <string, string>()
            {
                { "GamePath", "" },
                { "I18N", "en-us" }
            });

            //setup script settings storage
            General.ScriptSettings = new SettingsManager();

            //================================================read circle
            string command = "";

            while (true)
            {
                ConsoleAssistance.Write($"BPMScriptDebugger ({General.CurrentAppStatus.ToString()})> ", ConsoleColor.Green);

                command = Console.ReadLine();
                if (CommandProcessor.Process(command))
                {
                    break;
                }
            }

            ConsoleAssistance.WriteLine("Debugger exit.", ConsoleColor.Yellow);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("Teji client " + Information.Version, ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine("A self-host IM.");

            General.IsInputing = false;

            ConsoleAssistance.WriteLine("Init Config...");
            General.clientConfig = new ConfigManager(false);

            ConsoleAssistance.WriteLine("Init Network...");
            General.clientNetwork = new Network();
            General.clientNetwork.ServerMessage += (str) => {
                ConsoleAssistance.WriteLine(str);
            };
            //General.clientNetwork.ConnectServer("192.168.1.102", 8181, false);
            ////cache.ConnectServer("fe80:0:5c1f:28d1:53ba:7fcd", 6161, true);

            //Console.ReadKey();
            //General.clientNetwork.SendMessage("test", "???");
            //Console.ReadKey();
            //General.clientNetwork.Close();
            //Console.ReadKey();

            //circle
            string command = "";

            while (true)
            {
                var result = Console.ReadKey(true);
                if (result.Key == ConsoleKey.Tab)
                {
                    General.IsInputing = true;
                    command            = "";

                    //todo:finish display
                    ConsoleAssistance.Write("TejiConsole", ConsoleColor.Green);
                    ConsoleAssistance.Write("@???", ConsoleColor.Green);
                    ConsoleAssistance.Write(": ", ConsoleColor.Yellow);
                    ConsoleAssistance.Write("/", ConsoleColor.Magenta);
                    ConsoleAssistance.Write(" >", ConsoleColor.Yellow);


                    command = Console.ReadLine();
                    //todo:process command
                    if (command == "exit")
                    {
                        break;
                    }
                    else
                    {
                        CommandProcessor.Process(command);
                    }
                    General.IsInputing = false;
                }
            }

            //close
            General.clientNetwork.Close();
            General.clientConfig.Save();
        }
Exemplo n.º 8
0
        public static void Core(string packageName)
        {
            Console.WriteLine(I18N.Core("Install_CollectingPackageInfo"));

            //=================================================================pre-process
            //name is legal
            var packageDbConn = new Database();

            packageDbConn.Open();

            var reader = (from _i in packageDbConn.CoreDbContext.package
                          where _i.name == (packageName.Contains("@") ? packageName.Split('@', StringSplitOptions.None)[0] : packageName)
                          select _i).ToList();

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NoMatchedPackage"), ConsoleColor.Red);
                return;
            }
            packageName = GetVersionNatrually(packageName, packageDbConn);

            //is installed ?
            var installFolder = new DirectoryInfo(Information.WorkPath.Enter("cache").Enter("installed").Path);

            if (installFolder.GetDirectories($"{packageName}").Any())
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_InstalledPackage"), ConsoleColor.Red);
                return;
            }

            //====================================================================get-info
            //get denpendency tree
            Console.WriteLine(I18N.Core("Install_BuildingDependencyTree"));
            var cache1 = GetPackageInfo(packageName, packageDbConn);

            if (!cache1.res)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_NetworkError"), ConsoleColor.Red);
                return;
            }

            //conflict detect
            Console.WriteLine(I18N.Core("Install_DetectConflict"));
            var cache2 = DetectConflict(cache1.topologyMap, packageDbConn);

            if (!cache2.status)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_SelfConflict"), ConsoleColor.Red);
                return;
            }

            //sort dependency
            Console.WriteLine(I18N.Core("Install_SortingDependencyTree"));
            var cache1_1 = new Dictionary <string, List <string> >();

            foreach (var item in cache1.topologyMap.Keys)
            {
                var cache = new List <string>();
                foreach (var depItem in cache1.topologyMap[item].dependency.ToList())
                {
                    cache.Add(GetTopVersion(depItem, packageDbConn));
                }
                cache1_1.Add(item, cache);
            }
            var cache3 = KahnTopologySort(cache1_1);

            if (!cache3.status)
            {
                ConsoleAssistance.WriteLine(I18N.Core("Install_CloseLoop"), ConsoleColor.Red);
                return;
            }

            //remove installed package
            var realPackage = new List <string>(cache3.res);

            foreach (var item in installFolder.GetDirectories())
            {
                if (realPackage.Contains(item.Name))
                {
                    realPackage.Remove(item.Name);
                }
            }

            packageDbConn.Close();

            //sort removed package
            var sort_recorder = new Record();

            sort_recorder.Init();
            var realRemovedPackage = sort_recorder.SortPackage(cache2.res);

            sort_recorder.Save();
            //=======================================================================output

            ConsoleAssistance.WriteLine(I18N.Core("Install_InstallList"), ConsoleColor.Yellow);
            foreach (var item in realPackage)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("");

            ConsoleAssistance.WriteLine(I18N.Core("Install_RemoveList"), ConsoleColor.Yellow);
            if (realRemovedPackage.Count == 0)
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_None"), ConsoleColor.Yellow);
            }
            foreach (var item in realRemovedPackage)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("");

            ConsoleAssistance.Write(I18N.Core("General_Continue"), ConsoleColor.Yellow);
            if (Console.ReadLine().ToUpper() != "Y")
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_CancelOperation"), ConsoleColor.Red);
                return;
            }

            //============================================================================install
            //remove
            Console.WriteLine(I18N.Core("Install_RemovingSelectedPackage"));
            Remove.RealRemove(realRemovedPackage);

            //install
            Console.WriteLine(I18N.Core("Install_InstallingSelectedPackage"));
            //ready recorder
            var recorder = new Record();

            recorder.Init();

            var zipExtractor = new FastZip();

            foreach (var item in realPackage)
            {
                Console.WriteLine(I18N.Core("Install_InstallItem", item));
                //download
                var downloadRes = Download.DownloadPackage(item);
                Console.WriteLine(Download.JudgeDownloadResult(downloadRes));

                if (downloadRes != Download.DownloadResult.OK && downloadRes != Download.DownloadResult.ExistedLocalFile)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_NetworkError"), ConsoleColor.Red);
                    return;
                }

                //remove decompress folder
                Directory.Delete(Information.WorkPath.Enter("cache").Enter("decompress").Path, true);
                Directory.CreateDirectory(Information.WorkPath.Enter("cache").Enter("decompress").Path);

                //decompress
                Console.WriteLine(I18N.Core("Install_ExtractItem", item));

                zipExtractor.ExtractZip(Information.WorkPath.Enter("cache").Enter("download").Enter(item + ".zip").Path, Information.WorkPath.Enter("cache").Enter("decompress").Path, "");

                Console.WriteLine(I18N.Core("Install_RunScriptItem", item));
                var cacheRes = ScriptInvoker.Core(Information.WorkPath.Enter("cache").Enter("decompress").Path, ScriptInvoker.InvokeMethod.Install, "");
                if (!cacheRes.status)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_ScriptError"), ConsoleColor.Red);
                    ConsoleAssistance.WriteLine(cacheRes.desc, ConsoleColor.Red);
                    //save installed package info
                    recorder.Save();
                    return;
                }

                //record first and copy folders
                Console.WriteLine(I18N.Core("Install_RecordItem", item));
                recorder.Add(item);
                PackageAssistance.DirectoryCopy(Information.WorkPath.Enter("cache").Enter("decompress").Path, Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, true);

                Console.WriteLine(I18N.Core("Install_Success", item));
            }

            //close recorder
            recorder.Save();

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            #region comfirm necessary file
            ConsoleAssistance.WriteLine("Server is checking necessary files...", ConsoleColor.Yellow);

            //package storage
            if (!Directory.Exists(Information.WorkPath.Enter("package").Path))
            {
                Directory.CreateDirectory(Information.WorkPath.Enter("package").Path);
            }
            if (!Directory.Exists(Information.WorkPath.Enter("logs").Path))
            {
                Directory.CreateDirectory(Information.WorkPath.Enter("logs").Path);
            }

            var databasePath = Information.WorkPath.Enter("package.db").Path;
            var rsaPublic    = Information.WorkPath.Enter("pub.key").Path;
            var rsaPrivate   = Information.WorkPath.Enter("pri.key").Path;

            //detect database
            if (!File.Exists(databasePath))
            {
                ConsoleAssistance.WriteLine("No existing database file. A empty database file will be created.", ConsoleColor.Yellow);
                General.GeneralDatabase.Open();
                General.GeneralDatabase.Close();
            }

            //detect encrypt file
            if (!File.Exists(rsaPublic) || !File.Exists(rsaPrivate))
            {
                //ensure there are no file.
                ConsoleAssistance.WriteLine("No existing RSA key. A new RSA key will be created.", ConsoleColor.Yellow);
                File.Delete(rsaPublic);
                File.Delete(rsaPrivate);

                SignVerifyHelper.GenerateKey(rsaPublic, rsaPrivate);
            }

            #endregion


            //init config and file pool
            General.ConfigManager = new ShareLib.Config("config.cfg", new Dictionary <string, string>()
            {
                { "IPv4Port", "3850" },
                { "IPv6Port", "3851" },
                { "VerifyBytes", "" },
                { "EnableRecordFile", "True" }
            });
            General.CoreFileReader    = new FileReaderManager();
            General.RecordFileManager = new RecordFile(bool.Parse(General.ConfigManager.Configuration["EnableRecordFile"]));
            General.CoreTcpProcessor  = new TcpProcessor(int.Parse(General.ConfigManager.Configuration["IPv4Port"]), int.Parse(General.ConfigManager.Configuration["IPv6Port"]));

            //check parameter
            if (args.Length != 0 && args[0] == "maintain")
            {
                General.GeneralDatabase.Open();
                General.IsMaintaining = true;
                ConsoleAssistance.WriteLine("Start with maintain mode", ConsoleColor.Yellow);
            }
            else
            {
                //force update verify code
                ConsoleAssistance.WriteLine("Updating verify code....", ConsoleColor.White);
                General.VerifyBytes = SignVerifyHelper.SignData(databasePath, rsaPrivate);
                General.ConfigManager.Configuration["VerifyBytes"] = Convert.ToBase64String(General.VerifyBytes);
                General.ConfigManager.Save();

                General.CoreTcpProcessor.StartListen();
                General.IsMaintaining = false;
                ConsoleAssistance.WriteLine("Start with running mode", ConsoleColor.Yellow);
            }

            //================================================read circle
            string command = "";
            while (true)
            {
                ConsoleAssistance.Write($"BPMServer ({(General.IsMaintaining ? "Maintaining" : "Running")})> ", ConsoleColor.Green);

                command = ImportStack.ReadLine();
                if (CommandProcessor.Process(command))
                {
                    break;
                }
            }

            ConsoleAssistance.WriteLine("Server exit!", ConsoleColor.Yellow);
            //Environment.Exit(0);
        }