Esempio n. 1
0
        public static void Show(PackageDatabase packageDbConn, string name)
        {
            var reader = from it in packageDbConn.CoreDbContext.version
                         where it.name == name
                         select it;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            ConsoleAssistance.WriteLine(name, ConsoleColor.Yellow);
            var item = reader.First();

            Console.WriteLine($"parent: {item.parent}");
            Console.WriteLine($"additional desc: {item.additional_desc}");
            Console.WriteLine($"timestamp: {item.timestamp} ({item.timestamp.ToDateTime().ToString()})");
            Console.WriteLine($"suit os: Windows [{(OSType.Windows == ((OSType)item.suit_os & OSType.Windows) ? "X" : " ")}], UNIX [{(OSType.Unix == ((OSType)item.suit_os & OSType.Unix) ? "X" : " ")}], macOS [{(OSType.macOS == ((OSType)item.suit_os & OSType.macOS) ? "X" : " ")}]");
            Console.WriteLine($"dependency: {item.dependency}");
            Console.WriteLine($"reverse conflict: {item.reverse_conflict}");
            Console.WriteLine($"conflict: {item.conflict}");
            Console.WriteLine($"require decompress: {item.require_decompress}");
            Console.WriteLine($"internal script: {item.internal_script}");
            Console.WriteLine($"hash: {item.hash}");
        }
Esempio n. 2
0
        public static void AddVersion(PackageDatabase packageDbConn, Command.AddverOption data)
        {
            //check exist
            var reader = from item in packageDbConn.CoreDbContext.version
                         where item.name == data.Name
                         select item;

            if (reader.Any())
            {
                ConsoleAssistance.WriteLine("Existed package.", ConsoleColor.Red);
                return;
            }

            //set database
            var newObj = data.ToDatabaseFormat();

            if (newObj.status)
            {
                //update database
                packageDbConn.CoreDbContext.version.Add(newObj.res);
                //copy package
                File.Copy(data.PackagePath, Information.WorkPath.Enter("package").Enter($"{data.Name}.zip").Path);

                ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
            }
        }
Esempio n. 3
0
 public void StopListen()
 {
     socket4.Close();
     ConsoleAssistance.WriteLine("[Network] Stop listening ipv4 connection.");
     socket6.Close();
     ConsoleAssistance.WriteLine("[Network] Stop listening ipv6 connection.");
 }
Esempio n. 4
0
        public static void Core(string packageName, string parameter)
        {
            if (!packageName.Contains("@"))
            {
                ConsoleAssistance.WriteLine(I18N.Core("General_SpecificVersion"), ConsoleColor.Red);
                return;
            }

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

            var directoryList = installFolder.GetDirectories($"{packageName}");

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

            var finalFolder = directoryList[0];
            var res         = ScriptInvoker.Core(finalFolder.FullName, ScriptInvoker.InvokeMethod.Deploy, parameter);

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

            ConsoleAssistance.WriteLine(I18N.Core("General_AllOperationDown"), ConsoleColor.Yellow);
        }
Esempio n. 5
0
        public void ConnectServer(string ip, int port, bool isIpv6, string username, string password)
        {
            Task.Run(() => {
                try {
                    Socket con;
                    if (isIpv6)
                    {
                        con = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                    }
                    else
                    {
                        con = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    }

                    ConsoleAssistance.WriteLine($"[Network] Connecting {ip}:{port.ToString()}", ConsoleColor.Yellow);
                    con.Connect(ip, port);

                    var cache              = new Server(con, System.Guid.NewGuid().ToString(), username, password);
                    cache.TextMessage     += this.TextMessageHandle;
                    cache.ResponseMessage += this.ResponseMessageHandle;
                    cache.RequestMessage  += this.RequestMessageHandle;
                    cache.FileHeadMessage += this.FileHeadMessageHandle;
                    cache.FileBodyMessage += this.FileBodyMessagehandle;
                    cache.E2EMessage      += this.E2EMessagehandle;
                    cache.RequestRemove   += this.RequestRemoveHandle;
                    ConsoleAssistance.WriteLine($"[Network] Connect {ip}:{port.ToString()} successfully and its Guid is {cache.Guid}.");
                    serverList.Add(cache);
                } catch (Exception) {
                    //abandon
                    ConsoleAssistance.WriteLine($"[Network] Fail to connect {ip}:{port.ToString()}.", ConsoleColor.Red);
                }
            });
        }
Esempio n. 6
0
        public static void AddPackage(PackageDatabase packageDbConn, Command.AddpkgOption data)
        {
            var reader = from item in packageDbConn.CoreDbContext.package
                         where item.name == data.Name
                         select item;

            if (reader.Any())
            {
                ConsoleAssistance.WriteLine("Existed package.", ConsoleColor.Red);
                return;
            }

            //set database
            var newObj = data.ToDatabaseFormat();

            if (newObj.status)
            {
                packageDbConn.CoreDbContext.package.Add(newObj.res);
                ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("Welcome to use Hermit!", ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine("Light, free and secure instant-messaging(IM) software.");

            //initialize
            //todo:init

            //circle
            while (true)
            {
                var    result  = Console.ReadKey(true);
                string command = "";
                if (result.Key == ConsoleKey.Tab)
                {
                    ConsoleAssistance.WriteLine("Hermit-client>", ConsoleColor.Yellow);
                    command = Console.ReadLine();
                    //todo:process command
                }
            }

            //todo:exit


            ConsoleAssistance.WriteLine("You will go back to reality which is filled with dangers. Mind yourself! Good luck for you!", ConsoleColor.Yellow);
        }
Esempio n. 8
0
        void GetCaller(Socket s)
        {
            Task.Run(() => {
                try {
                    Socket client = s.Accept();
                    var cache     = new Client(client, System.Guid.NewGuid().ToString());
                    //add event handle
                    cache.TextMessage     += this.TextMessageHandle;
                    cache.CommandMessage  += this.CommandMessageHandle;
                    cache.RequestMessage  += this.RequestMessageHandle;
                    cache.FileHeadMessage += this.FileHeadMessageHandle;
                    cache.FileBodyMessage += this.FileBodyMessagehandle;
                    cache.E2EMessage      += this.E2EMessagehandle;
                    cache.RequestRemove   += this.RequestRemoveHandle;
                    //add item
                    clientList.Add(cache);
                    ConsoleAssistance.WriteLine($"[Network] Accept {cache.EndPoint}'s connection and its Guid is {cache.Guid}.");

                    OnConnectionCountChanged();
                } catch (Exception) {
                    //jump
                    return;
                }

                //accept next
                this.GetCaller(s);
            });
        }
Esempio n. 9
0
        public void StartListen()
        {
            if (isListening)
            {
                return;
            }

            socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

            var endPoint4 = new IPEndPoint(IPAddress.Any, int.Parse(General.serverConfig["ipv4Port"]));
            var endPoint6 = new IPEndPoint(IPAddress.IPv6Any, int.Parse(General.serverConfig["ipv6Port"]));

            socket4.Bind(endPoint4);
            socket6.Bind(endPoint6);

            socket4.Listen(5);
            GetCaller(socket4);
            ConsoleAssistance.WriteLine($"[Network] Listening on port {General.serverConfig["ipv4Port"]} for ipv4 connection.");
            socket6.Listen(5);
            GetCaller(socket6);
            ConsoleAssistance.WriteLine($"[Network] Listening on port {General.serverConfig["ipv6Port"]} for ipv6 connection.");

            isListening = true;
        }
Esempio n. 10
0
        public static void RemovePackage(PackageDatabase packageDbConn, string name)
        {
            //remove from package table
            var reader = from item in packageDbConn.CoreDbContext.package
                         where item.name == name
                         select item;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            //set database
            packageDbConn.CoreDbContext.package.RemoveRange(reader);

            //remove all version
            var reader2 = from item in packageDbConn.CoreDbContext.version
                          where item.parent == name
                          select item;

            foreach (var item in reader2)
            {
                //remove file and database
                File.Delete(Information.WorkPath.Enter("package").Enter($"{item.name}.zip").Path);
                packageDbConn.CoreDbContext.version.Remove(item);
            }

            ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
        }
Esempio n. 11
0
        public static void EditPackage(PackageDatabase packageDbConn, Command.EditpkgOption data)
        {
            var reader = from item in packageDbConn.CoreDbContext.package
                         where item.name == data.Name
                         select item;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            var got    = reader.First();
            var newObj = data.ToDatabaseFormat(got);

            if (newObj.status)
            {
                packageDbConn.CoreDbContext.package.Remove(got);
                packageDbConn.CoreDbContext.package.Add(newObj.res);
                ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
            }
        }
Esempio n. 12
0
        public void Generate(SqliteCommand cmd, string type)
        {
            switch (type)
            {
            case "user":
                cmd.CommandText = "CREATE TABLE user(name TEXT PRIMARY KEY NOT NULL,nickname TEXT NOT NULL,isAdmin INT NOT NULL,avatarGuid TEXT NOT NULL,salt1 TEXT NOT NULL,salt2 TEXT NOT NULL,saltHash TEXT NOT NULL";
                break;

            case "room":
                cmd.CommandText = "CREATE TABLE room(name TEXT PRIMARY KEY NOT NULL,type TEXT NOT NULL,password TEXT NOT NULL,host TEXT NOT NULL,users TEXT NOT NULL";
                break;

            case "ban":
                cmd.CommandText = "CREATE TABLE ban(value TEXT PRIMARY KEY NOT NULL,type TEXT NOT NULL";
                break;

            case "emotion":
                cmd.CommandText = "CREATE TABLE emotion(name TEXT PRIMARY KEY NOT NULL,emotionGuid TEXT NOT NULL";
                break;

            default:
                return;
            }

            cmd.ExecuteNonQuery();
            ConsoleAssistance.WriteLine("[Database] Generate new database file successfully.");
        }
Esempio n. 13
0
        public static void EditVersion(PackageDatabase packageDbConn, Command.EditverOption data)
        {
            var reader = from item in packageDbConn.CoreDbContext.version
                         where item.name == data.Name
                         select item;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            var got    = reader.First();
            var newObj = data.ToDatabaseFormat(got);

            if (newObj.status)
            {
                packageDbConn.CoreDbContext.version.Remove(got);
                packageDbConn.CoreDbContext.version.Add(newObj.res);

                //copy file
                if (data.PackagePath != "~")
                {
                    File.Delete(Information.WorkPath.Enter("package").Enter($"{data.Name}.zip").Path);
                    File.Copy(data.PackagePath, Information.WorkPath.Enter("package").Enter($"{data.Name}.zip").Path);
                }
                ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
            }
        }
Esempio n. 14
0
        public static bool RealRemove(List <string> packageList)
        {
            //start recorder
            var recorder = new Record();

            recorder.Init();

            foreach (var item in packageList)
            {
                Console.WriteLine(I18N.Core("Remove_Removing", item));
                var res = ScriptInvoker.Core(Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, ScriptInvoker.InvokeMethod.Remove, "");
                if (!res.status)
                {
                    ConsoleAssistance.WriteLine(I18N.Core("General_ScriptError"), ConsoleColor.Red);
                    ConsoleAssistance.WriteLine(res.desc, ConsoleColor.Red);
                    return(false);
                }
                Directory.Delete(Information.WorkPath.Enter("cache").Enter("installed").Enter(item).Path, true);
                recorder.Remove(item);

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

            recorder.Save();
            return(true);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
 static bool CheckStatus(bool isCheckMaintain)
 {
     if (isCheckMaintain)
     {
         if (General.IsMaintaining)
         {
             return(true);
         }
         else
         {
             ConsoleAssistance.WriteLine("This command is illegal in current status.", ConsoleColor.Red);
             return(false);
         }
     }
     else
     {
         if (General.IsMaintaining)
         {
             ConsoleAssistance.WriteLine("This command is illegal in current status.", ConsoleColor.Red);
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Esempio n. 17
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);
        }
Esempio n. 18
0
        public void StopListen()
        {
            if (!isListening)
            {
                return;
            }

            socket4.Close();
            ConsoleAssistance.WriteLine("[Socket] Stop listening ipv4 connection.");
            socket6.Close();
            ConsoleAssistance.WriteLine("[Socket] Stop listening ipv6 connection.");
        }
Esempio n. 19
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();
        }
Esempio n. 20
0
        public static bool CommandProcessor(string command, ref ShareLib.RenderStruct.RenderSettings obj)
        {
            if (command == "")
            {
                return(true);
            }

            var sp = CommandSplitter.SplitCommand(command);

            if (sp.Count == 0)
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
                return(true);
            }
            var main = sp[0];

            sp.RemoveAt(0);
            switch (main)
            {
            case "render":
                Render.RenderKernel(obj);
                break;

            case "tt":
                try {
                    var cache = Tutorial();
                    obj = cache;
                } catch (Exception) {
                    ConsoleAssistance.WriteLine("Error occured! All setting is lost", ConsoleColor.Red);
                }
                break;

            case "ls":
                OutputRenderSettings(obj);
                break;

            case "exit":
                //save settings
                ConfigManager.Write <ShareLib.RenderStruct.RenderSettings>(obj, ConfigManager.RenderSettingsFile);
                return(false);

            case "help":
                Help();
                break;

            default:
                ConsoleAssistance.WriteLine("Unknow command", ConsoleColor.Red);
                break;
            }

            return(true);
        }
Esempio n. 21
0
 public void Close()
 {
     try {
         databaseSavingTd.Abort();
     } catch (Exception) {
         //pass
     }
     lock (lockCoreDbContext) {
         CoreDbContext.SaveChanges();
     }
     ConsoleAssistance.WriteLine("[Database] Save database successfully.");
     CoreDbContext.Dispose();
 }
Esempio n. 22
0
 public static bool Process(string[] command)
 {
     return(parser.ParseArguments <HelpOption, UpdateOption, SearchOption, InstallOption, ListOption, RemoveOption, ConfigOption, ShowOption, DeployOption, GuideOption, CleanOption>(command)
            .MapResult(//todo: finish command processor
                (UpdateOption opt) => {
         return false;
     },
                (SearchOption opt) => {
         //
         return false;
     },
                (InstallOption opt) => {
         //
         return false;
     },
                (ListOption opt) => {
         //
         return false;
     },
                (RemoveOption opt) => {
         //
         return false;
     },
                (ConfigOption opt) => {
         //
         return false;
     },
                (ShowOption opt) => {
         //
         return false;
     },
                (DeployOption opt) => {
         //
         return false;
     },
                (GuideOption opt) => {
         //
         return false;
     },
                (CleanOption opt) => {
         //
         return false;
     },
                (HelpOption opt) => {
         //OutputHelp();
         return false;
     },
                errs => { ConsoleAssistance.WriteLine("Unknow command. Use help to find the correct command", ConsoleColor.Red); return false; }));//todo: i18n
 }
Esempio n. 23
0
        public ServerDatabase()
        {
            //connect database
            var existed = false;

            existed         = System.IO.File.Exists(General.serverConfig["userDatabasePath"]);
            userDatabaseCon = new SqliteConnection("Data Source=" + General.serverConfig["userDatabasePath"]);
            userDatabaseCon.Open();
            userDatabaseCmd = userDatabaseCon.CreateCommand();
            if (!existed)
            {
                Generate(userDatabaseCmd, "user");
            }
            ConsoleAssistance.WriteLine("[Database] Read user database successfully.");

            existed         = System.IO.File.Exists(General.serverConfig["roomDatabasePath"]);
            roomDatabaseCon = new SqliteConnection("Data Source=" + General.serverConfig["roomDatabasePath"]);
            roomDatabaseCon.Open();
            roomDatabaseCmd = roomDatabaseCon.CreateCommand();
            if (!existed)
            {
                Generate(roomDatabaseCmd, "room");
            }
            ConsoleAssistance.WriteLine("[Database] Read room database successfully.");

            existed        = System.IO.File.Exists(General.serverConfig["banDatabasePath"]);
            banDatabaseCon = new SqliteConnection("Data Source=" + General.serverConfig["banDatabasePath"]);
            banDatabaseCon.Open();
            banDatabaseCmd = banDatabaseCon.CreateCommand();
            if (!existed)
            {
                Generate(banDatabaseCmd, "ban");
            }
            ConsoleAssistance.WriteLine("[Database] Read ban database successfully.");

            existed            = System.IO.File.Exists(General.serverConfig["emotionDatabasePath"]);
            emotionDatabaseCon = new SqliteConnection("Data Source=" + General.serverConfig["emotionDatabasePath"]);
            emotionDatabaseCon.Open();
            emotionDatabaseCmd = emotionDatabaseCon.CreateCommand();
            if (!existed)
            {
                Generate(emotionDatabaseCmd, "emotion");
            }
            ConsoleAssistance.WriteLine("[Database] Read emotion database successfully.");
        }
Esempio n. 24
0
        public static void Process(string command)
        {
            var cache = CommandSplitter.SplitCommand(command);

            if (cache.Count == 0)
            {
                ConsoleAssistance.WriteLine("Error command", ConsoleColor.Red);
                return;
            }

            switch (cache[0])
            {
            //todo:finish command
            default:
                ConsoleAssistance.WriteLine("No such command.", ConsoleColor.Red);
                break;
            }
        }
Esempio n. 25
0
        public void StartListen()
        {
            socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

            var endPoint4 = new IPEndPoint(IPAddress.Any, Port4);
            var endPoint6 = new IPEndPoint(IPAddress.IPv6Any, Port6);

            socket4.Bind(endPoint4);
            socket6.Bind(endPoint6);

            socket4.Listen(5);
            GetCaller(socket4);
            ConsoleAssistance.WriteLine($"[Network] Listening on port {Port4} for ipv4 connection.");
            socket6.Listen(5);
            GetCaller(socket6);
            ConsoleAssistance.WriteLine($"[Network] Listening on port {Port6} for ipv6 connection.");
        }
Esempio n. 26
0
        void AcceptCallback(IAsyncResult ar)
        {
            Socket s      = (Socket)ar.AsyncState;
            var    client = s.EndAccept(ar);
            var    cache  = new ServerSocketItem(client, System.Guid.NewGuid().ToString());

            cache.StatusChanged += client_StatusChanged;
            ConsoleAssistance.WriteLine($"[Socket] Accept {cache.EndPoint}'s connection and its Guid is {cache.Guid}.");
            ConsoleAssistance.WriteLine($"[Socket] {cache.Guid} starts to handshake...");

            cache.TimeClips = 3;
            handshakeList.Add(cache.Guid, cache);
            cache.BelongTo = ServerSocketBelongTo.Handshake;
            OnUserCountChanged();

            //accept next
            s.BeginAccept(new AsyncCallback(AcceptCallback), s);
        }
Esempio n. 27
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);
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            ConsoleAssistance.WriteLine("Welcome to use Hermit!", ConsoleColor.Yellow);
            ConsoleAssistance.WriteLine("Light, free and secure instant-messaging(IM) software.");

            //initialize
            //todo:init
            ConsoleAssistance.WriteLine("[Main] Initialize server config...");
            General.serverConfig = new ServerConfig(Information.WorkPath.Enter("config.json").Path());
            ConsoleAssistance.WriteLine("[Main] Initialize server database...");
            General.serverDatabase = new ServerDatabase();
            ConsoleAssistance.WriteLine("[Main] Initialize server socket...");
            General.serverSocket = new ServerSocket();
            ConsoleAssistance.WriteLine("[Main] Start listening...");
            General.serverSocket.StartListen();

            //circle
            while (true)
            {
                var    result  = Console.ReadKey(true);
                string command = "";
                if (result.Key == ConsoleKey.Tab)
                {
                    ConsoleAssistance.WriteLine("Hermit-server>", ConsoleColor.Yellow);
                    command = Console.ReadLine();
                    //todo:process command
                }
            }

            //close server
            ConsoleAssistance.WriteLine("[Main] Start closing server...");
            //todo:finish closing
            ConsoleAssistance.WriteLine("[Main] Close all clients...");
            General.serverSocket.Close();
            ConsoleAssistance.WriteLine("[Main] Stop listening...");
            General.serverSocket.StopListen();
            ConsoleAssistance.WriteLine("[Main] Store server database...");
            General.serverDatabase.Close();
            ConsoleAssistance.WriteLine("[Main] Save server config...");
            General.serverConfig.Save();


            ConsoleAssistance.WriteLine("Thanks for using Hermit.", ConsoleColor.Yellow);
        }
Esempio n. 29
0
        public void Open()
        {
            ConsoleAssistance.WriteLine("[Database] Reading database...");
            CoreDbContext = new ServerDataContext();
            ConsoleAssistance.WriteLine("[Database] Making sure all database is fine...");
            CoreDbContext.Database.EnsureCreated();

            ConsoleAssistance.WriteLine("[Database] Read database successfully.");

            //start a thread for saving database
            databaseSavingTd = new Thread(() => {
                Thread.Sleep(1000 * 60 * 10);
                lock (lockCoreDbContext) {
                    CoreDbContext.SaveChanges();
                }
                ConsoleAssistance.WriteLine("[Database] Save database successfully.");
            });
            databaseSavingTd.IsBackground = true;
            databaseSavingTd.Start();
        }
Esempio n. 30
0
        public static void RemoveVersion(PackageDatabase packageDbConn, string name)
        {
            var reader = from item in packageDbConn.CoreDbContext.version
                         where item.name == name
                         select item;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            //set database
            packageDbConn.CoreDbContext.version.RemoveRange(reader);

            //del file
            File.Delete(Information.WorkPath.Enter("package").Enter($"{name}.zip").Path);

            ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
        }