public static StatusObject SearchTableForValue(JARVISDataSource datasource, string value) { StatusObject SO = new StatusObject(); try { SqlConnection sql_connection = new SqlConnection(datasource.GetConnectionString()); sql_connection.Open(); sql_connection.Close(); } catch (Exception e) { SO = new StatusObject(e.Message, "JARVISDataSourceAlgorithms", StatusObject.StatusCode.FAILURE, e.ToString()); } return(SO); }
public static StatusObject AddDataSource(string Server, string Database) { StatusObject SO = new StatusObject(); try { SqlConnection connection = new SqlConnection(String.Format("server={0};database={1};trusted_connection=true", Server, Database)); // Test the database connection connection.Open(); connection.Close(); // If the connection succeeds then save it to a textfile somewhere and return a new JARVISDataSource Directory.CreateDirectory(file_directory); StreamWriter datasource_file = new StreamWriter(String.Format(@"{0}\WinAuthDataSources.txt", file_directory), append: true); datasource_file.WriteLine(String.Format("{0},{1},{2}", Server, Database, true)); datasource_file.Close(); JARVISDataSource new_data_source = new JARVISDataSource(Server, Database); SO.UDDynamic = new_data_source; } catch (Exception e) { SO = new StatusObject(e.Message, "JARVISDataSourceManager_AddDataSource", StatusObject.StatusCode.FAILURE, e.ToString()); } return(SO); }
/// <summary> /// Handle all JARVIS logic /// </summary> /// <param name="args"></param> static void Main(string[] args) { Dictionary <string, Type> JARVIS_types = new Dictionary <string, Type>(); Dictionary <string, MethodInfo> JARVIS_methods = new Dictionary <string, MethodInfo>(); List <Thread> available_threads = new List <Thread>(); List <JARVISDataSource> available_datasources = new List <JARVISDataSource>(); bool program_running = true; string user_input = ""; Console.Write("Enter a command: "); user_input = Console.ReadLine(); while (program_running) { JARVISLearning.log_command(user_input); List <string> command_parameters = user_input.Split(' ').ToList(); string primary_command = command_parameters[0].Trim().ToLower(); try { if (primary_command != "exit") { if (primary_command == "start") { if (command_parameters.ElementAtOrDefault(1) != null) { string secondary_command = command_parameters[1]; if (secondary_command == "process") { string path = user_input.Remove(0, "start process".Length).Trim(); if (path.Length > 0) { Console.WriteLine("Starting process {0}", path); } else { Console.WriteLine("Invalid process path/name"); } JARVISDiagnostics.StartProcess(path); } else { Console.WriteLine("Unable to perform operation \"start\". Incorrect secondary command"); } } else { } } else if (primary_command == "help") { string secondary_command = command_parameters.ElementAtOrDefault(1); if (secondary_command != null) { if (secondary_command == "method") { string method_name = command_parameters.ElementAtOrDefault(2); List <string> method_list = new List <string>(); if (method_name != null) { method_list = JARVISDiagnostics.FindMethod(method_name); JARVISConsole.list_to_console(method_list); } } } } else if (primary_command == "new") { if (command_parameters.ElementAtOrDefault(1) != null) { string secondary_command = command_parameters[1]; if (secondary_command == "class") { } else { Console.WriteLine("Unable to perform operation \"start\". Incorrect secondary command"); } } } else if (primary_command == "diagnostics") { JARVISConsole.list_to_console(JARVISDiagnostics.ListJARVISTypes()); JARVISConsole.list_to_console(JARVISDiagnostics.ListJARVISTypeProperties("JARVIS4.JARVISLearning")); Console.WriteLine("Path = {0}", JARVISDiagnostics.GetJARVISExecutablePath()); } else if (primary_command == "read") { JARVISCustomAlgorithms.MerimenRequestStatistics_Analyze(@"C:\JARVIS4\CustomAlgorithmSources\MERIMEN"); } else if (primary_command == "getfuseboxfuseaction") { string claims_path = user_input.Replace("getfuseboxfuseaction", "").Trim(); if (claims_path != null) { StatusObject SO_GetFuseboxFuseaction = JARVISCustomAlgorithms.GetFuseboxFuseactionList(claims_path); if (SO_GetFuseboxFuseaction.Status != StatusObject.StatusCode.FAILURE) { } else { Console.WriteLine(SO_GetFuseboxFuseaction.ErrorStacktrace); } } else { Console.WriteLine("Invalid path"); } } else if (primary_command == "customalgo") { Console.WriteLine("JARVIS Custom Algorithms"); JARVISConsole.list_to_console(JARVISDiagnostics.ListJARVISTypeProperties("JARVIS4.JARVISCustomAlgorithms")); } else if (primary_command == "fileprocessing") { if (command_parameters.ElementAtOrDefault(1) != null) { string file_path = user_input.Replace("fileprocessing", "").Trim(); JARVISFileProcessing.read_large_text_file(file_path); } else { Console.WriteLine("Unable to perform operation \"textprocessing\". File name not provided"); } } else if (primary_command == "run") { if (command_parameters.ElementAtOrDefault(1) != null) { string type_name = command_parameters[1]; string function_name = command_parameters.ElementAtOrDefault(2); string function_parameters = command_parameters.ElementAtOrDefault(3); JARVISDiagnostics.RunJARVISMethod("JARVIS4", type_name, function_name, function_parameters); } else { Console.WriteLine("Unable to peform operation \"run\". Type name not provided"); } } else if (primary_command == "thread") { string secondary_command = command_parameters.ElementAtOrDefault(1); if (secondary_command != null) { if (secondary_command == "add") { } else if (secondary_command == "stop") { } else if (secondary_command == "stopall") { } } else { Console.WriteLine("Unable to perform operation \"add\". Insufficient Information Provided"); } } else if (primary_command == "datasource") { string secondary_command = command_parameters.ElementAtOrDefault(1); string auth_type = command_parameters.ElementAtOrDefault(2); if (secondary_command != null && secondary_command.Length > 0) { if (secondary_command == "add") { if (auth_type == "sqlauth") { string server_name = command_parameters.ElementAtOrDefault(3); string database_name = command_parameters.ElementAtOrDefault(4); string database_user_id = command_parameters.ElementAtOrDefault(5); string database_password = command_parameters.ElementAtOrDefault(6); StatusObject SO_AddDataSource = JARVISDataSourceManager.AddDataSource(server_name, database_name, database_user_id, database_password); if (SO_AddDataSource.Status == StatusObject.StatusCode.FAILURE) { Console.WriteLine(SO_AddDataSource.ErrorStacktrace); } } else if (auth_type == "winauth") { string server_name = command_parameters.ElementAtOrDefault(3); string database_name = command_parameters.ElementAtOrDefault(4); StatusObject SO_AddDataSource = JARVISDataSourceManager.AddDataSource(server_name, database_name); if (SO_AddDataSource.Status == StatusObject.StatusCode.FAILURE) { Console.WriteLine(SO_AddDataSource.ErrorStacktrace); } } } else if (secondary_command == "sqlexecute") { string sql = user_input.Replace("datasource", "").Replace("sqlexecute", "").Trim(); JARVISDataSourceAlgorithms.ExecuteSQL(new JARVISDataSource("sql2008kl", "claims_dev", "sa", "password").CreateConnection(), sql); } else if (secondary_command == "ssptofile") { string server_name = command_parameters.ElementAtOrDefault(3); string database_name = command_parameters.ElementAtOrDefault(4); string database_user_id = command_parameters.ElementAtOrDefault(5); string database_password = command_parameters.ElementAtOrDefault(6); JARVISDataSource target_datasource = new JARVISDataSource(); if (auth_type == "sqlauth") { target_datasource = new JARVISDataSource(server_name, database_name, database_user_id, database_password); } else if (auth_type == "winauth") { target_datasource = new JARVISDataSource(server_name, database_name); } StatusObject SO_ssptofile = JARVISDataSourceAlgorithms.StoredProceduresToFile(target_datasource.CreateConnection()); if (SO_ssptofile.Status != StatusObject.StatusCode.FAILURE) { } else { Console.WriteLine(SO_ssptofile.ErrorStacktrace); } } else if (secondary_command == "tracksspchanges") { string server_name = command_parameters.ElementAtOrDefault(3); string database_name = command_parameters.ElementAtOrDefault(4); string database_user_id = command_parameters.ElementAtOrDefault(5); string database_password = command_parameters.ElementAtOrDefault(6); JARVISDataSource target_datasource = new JARVISDataSource(); if (auth_type == "sqlauth") { target_datasource = new JARVISDataSource(server_name, database_name, database_user_id, database_password); } else if (auth_type == "winauth") { target_datasource = new JARVISDataSource(server_name, database_name); } bool tracking = true; while (tracking) { StatusObject SO_ssptofile = JARVISDataSourceAlgorithms.TrackStoredProcedureChanges(target_datasource.CreateConnection()); if (SO_ssptofile.Status != StatusObject.StatusCode.FAILURE) { } else { Console.WriteLine(SO_ssptofile.ErrorStacktrace); tracking = false; } Thread.Sleep(60000); } } else if (secondary_command == "multidbssptofile") { if (File.Exists(@"C:\JARVIS4\UserDefinedDataSources\BatchExtracts\targets.txt")) { StreamReader file_reader = new StreamReader(@"C:\JARVIS4\UserDefinedDataSources\BatchExtracts\targets.txt"); string databaseconfig; while ((databaseconfig = file_reader.ReadLine()) != null) { Console.WriteLine(databaseconfig); JARVISDataSource target_datasource = new JARVISDataSource(databaseconfig); StatusObject SO_ssptofile = JARVISDataSourceAlgorithms.StoredProceduresToFile(target_datasource.CreateConnection()); if (SO_ssptofile.Status != StatusObject.StatusCode.FAILURE) { } else { Console.WriteLine(SO_ssptofile.ErrorStacktrace); } } file_reader.Close(); } else { Console.WriteLine(@"Unable to find batch scripts. Please place batch scripts in \nC:\JARVIS4\UserDefinedDataSources\BatchExtracts\targets.txt"); Directory.CreateDirectory(@"C:\JARVIS4\UserDefinedDataSources\BatchExtracts"); StreamWriter new_file = new StreamWriter(@"C:\JARVIS4\UserDefinedDataSources\BatchExtracts\targets.txt"); new_file.Close(); } } } } else if (primary_command == "record") { string secondary_command = command_parameters.ElementAtOrDefault(1); if (secondary_command != null) { } else { Console.WriteLine("Incorrect syntax for command {0}", primary_command); } } else if (primary_command == "winform") { } else if (primary_command == "writetoexcel") { StatusObject SO_WriteToExcel = JARVISFileProcessing.WriteExcelFile(); if (SO_WriteToExcel.Status != StatusObject.StatusCode.FAILURE) { } else { Console.WriteLine(SO_WriteToExcel.ErrorStacktrace); } } else { Console.WriteLine("Invalid Command"); } Console.Write("Enter a command: "); user_input = Console.ReadLine(); } else { program_running = false; // Do exit logic here } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Write("Enter a command: "); user_input = Console.ReadLine(); program_running = true; } } }