static private void ImitatingShell() { Authorization AutoUser = new Authorization(null, null); string InputCommand = ""; while (InputCommand != "close") { logger.Trace("Новая интерация цикла, ждём ввода с консоли"); Console.Write("\n@WntifDB>");//new interation application if (AutoUser.Name != null) { Console.Write(AutoUser.Name + ">"); } InputCommand = SecurityPassword.ReadCommandWithPassword();//request on obtain command from console string tempSW = ""; try { tempSW = InputCommand.Remove(InputCommand.IndexOf(" ")); } catch (Exception e) { tempSW = InputCommand; //if string is a one word } switch (tempSW) //first word from command line { case "register": //case for registration { Regex reg = new Regex("[register] (Admin|User) [A-z]{1}[A-z||0-9]{0,10} [A-z||0-9]{1,20}", RegexOptions.IgnoreCase); //regular exspression for registration new people and switch him access logger.Trace("Создание объекта класса регистрации"); //logger if (reg.IsMatch(InputCommand)) //check { string[] words = InputCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //obtain array words from string words[3] = hashMP5.ConvertToHash(words[3]); //obtain hash-code by input password Registration NewUser = new Registration(words[1], words[2], words[3]); //access,name,hash-password } else { Console.WriteLine("Try more, uncorrect command syntax\n" + "Examle: register UserOrAdmin YourName .YourPassword {0,50}", "//where '.' used for hidden password");//error-text } } break; case "login": { Regex reg = new Regex("[login] [A-z]{1}[A-z||0-9]{0,10} [A-z||0-9]{1,15}", RegexOptions.IgnoreCase); logger.Trace("Создание объекта класса авторизации"); //будут вводиться три аргумента с командной строки 1 if (reg.IsMatch(InputCommand)) { string[] words = InputCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); words[2] = hashMP5.ConvertToHash(words[2]); AutoUser = new Authorization(words[1], words[2]); // name, hash-code by password AutoUser.LogIn(); //try log in } else { string txt = "Examle: authorization YourName .YourPassword"; int size = 100 - txt.Length; Console.WriteLine("Try more, uncorrect command syntax\n" + "Examle: login YourName .YourPassword {0," + size + "}", "//where '.' used for hidden password"); } } break; case "CREATE": { if (AutoUser.Access == "Admin") { Regex reg = new Regex("[CREATE] (DBase|Table) '[A-z||0-9]{1,15}'", RegexOptions.IgnoreCase); if (reg.IsMatch(InputCommand) == true) { Console.WriteLine(""); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Denied access!"); Console.ForegroundColor = ConsoleColor.Gray; } } break; case "close": { InputCommand = "close"; } break; } } }
static private void ImitatingShell() { Authorization AutoUser = new Authorization(null, null); string InputCommand = ""; while (InputCommand != "close") { logger.Trace("Новая интерация цикла, ждём ввода с консоли"); Console.Write("\n@WntifDB>");//new interation application if (AutoUser.Name != null) { Console.Write(AutoUser.Name + ">"); } InputCommand = SecurityPassword.ReadCommandWithPassword();//request on obtain command from console string tempSW = ""; try { tempSW = InputCommand.Remove(InputCommand.IndexOf(" ")); } catch (Exception e) { tempSW = InputCommand; //if string is a one word } switch (tempSW) //first word from command line { case "register": //case for registration { Regex reg = new Regex("[register] (Admin|User) [A-z]{1}[A-z||0-9]{0,10} [A-z||0-9]{1,20}", RegexOptions.IgnoreCase); //regular exspression for registration new people and switch him access logger.Trace("Создание объекта класса регистрации"); //logger if (reg.IsMatch(InputCommand)) //check { string[] words = InputCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //obtain array words from string words[3] = hashMP5.ConvertToHash(words[3]); //obtain hash-code by input password Registration NewUser = new Registration(words[1], words[2], words[3]); //access,name,hash-password } else { Console.WriteLine("Try more, uncorrect command syntax\n" + "Examle: register UserOrAdmin YourName .YourPassword {0,50}", "//where '.' used for hidden password");//error-text } } break; case "login": { Regex reg = new Regex("[login] [A-z]{1}[A-z||0-9]{0,10} [A-z||0-9]{1,15}", RegexOptions.IgnoreCase); logger.Trace("Создание объекта класса авторизации"); //будут вводиться три аргумента с командной строки 1 if (reg.IsMatch(InputCommand)) { string[] words = InputCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); words[2] = hashMP5.ConvertToHash(words[2]); AutoUser = new Authorization(words[1], words[2]); // name, hash-code by password AutoUser.LogIn(); //try log in } else { string txt = "Examle: authorization YourName .YourPassword"; int size = 100 - txt.Length; Console.WriteLine("Try more, uncorrect command syntax\n" + "Examle: login YourName .YourPassword {0," + size + "}", "//where '.' used for hidden password"); } } break; case "StartJob": { if (CheckAccessUser(AutoUser)) { string tempStr = ""; interpret ob = new interpret(AutoUser); string first_word = ob.command.Remove(ob.command.IndexOf(" ")); // Console.WriteLine("fw" + first_word);// while (first_word != "back") { switch (first_word) { case "IN": { try { Regex reg = new Regex("IN [A-z]"); if (!reg.IsMatch(ob.command)) { throw new Exception("Incorrect syntax\nExample: IN NameDatabase"); } AutoUser.NameDB = ob.command.Substring(ob.command.IndexOf(" ")); if (!File.Exists(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" + AutoUser.NameDB + ".xml")) { AutoUser.NameDB = null; throw new Exception("Database is not exist"); } } catch (Exception e) { Console.WriteLine(e.Message); } } break; case "EXIT": { AutoUser.NameDB = null; } break; case "CREATE": { try { if (ob.command.IndexOf("CREATE TABLE") != -1) { if (AutoUser.NameDB == null) { throw new Exception("Sign in Database! Use command 'IN NameDatabase'"); } Create.Table table = new Create.Table(ob.command, AutoUser.NameDB); table.Create(); } else if (ob.command.IndexOf("CREATE DATABASE") != -1) { Create.Database db = new Create.Database(ob.command); db.Create(); } } catch (Exception e) { logger.Trace(e.Message); } /// ///тут будет словать или свич /// } break; } ob = new interpret(AutoUser); first_word = ob.command.Remove(ob.command.IndexOf(" ")); } //Regex reg = new Regex("[CREATE] (DBase|Table) '[A-z||0-9]{1,15}'", RegexOptions.IgnoreCase); //if (reg.IsMatch(InputCommand) == true) //{ // Console.WriteLine(""); //} } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Denied access!"); Console.ForegroundColor = ConsoleColor.Gray; } } break; case "close": { InputCommand = "close"; } break; } } }