public void MoveTable(ModbusTable table = null, int index = -1, MOVE_DIRECTION direct = MOVE_DIRECTION.UP) { if (Current != null) { int _currentindex = Current.Current; Current.Move(table, index, direct); switch (direct) { case MOVE_DIRECTION.UP: if (--_currentindex >= 0) { DG_Table.SelectedIndex = _currentindex; } break; case MOVE_DIRECTION.DOWN: if (++_currentindex < Tables.Count()) { DG_Table.SelectedIndex = _currentindex; } break; } Current = Current; IsModify = true; } }
public async void CreateFilesAsync() { try { CreatedTablesCount = 0; if (string.IsNullOrEmpty(DestinationPath)) { return; } string base_code = $@"using Dapper.Contrib.Extensions; using System; using System.Collections.Generic; namespace {NameSpace} {{ [code] }} "; var settings = new DTESettings().Settings; AllTablesCount = Tables.Count(); CreatedTablesCount = 0; foreach (var table in Tables) { await CreateModelThanSave(base_code, _dTECore, _dTECore.Settings, table.DataBaseName, table); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public virtual void ReadTables() { OpenConnection(); Tables = Connection.GetSchema("Tables").GetAzdaraTables().ToList(); if (Tables.Count() > 0) { Catalogs = Tables.OrderBy(o => o.CSharpNameSpace).Select(s => s.CSharpNameSpace).Distinct().ToList(); } }
private void RenderMenu() { WinConsole.WriteLine("Tables:"); var i = 0; for (; i < Tables.Count(); i++) { WinConsole.WriteLine("{0} \t {1}", i, Tables.ToArray()[i].Info.TableName); } WinConsole.WriteLine("Views:"); var j = i; for (; j < Views.Count() + i; j++) { WinConsole.WriteLine("{0} \t {1}", j, Views.ToArray()[j - i].Info.TableName); } WinConsole.WriteLine("Procedures:"); var k = j; for (; k < StoredProcs.Count() + j; k++) { WinConsole.WriteLine("{0} \t {1}", k, StoredProcs.ToArray()[k - j].Parameter.TableName); } WinConsole.WriteLine("Actions: "); WinConsole.WriteLine(@"[Name | Number]"); WinConsole.WriteLine(" Edit table"); WinConsole.WriteLine(@"\compile"); WinConsole.WriteLine(" Starts the Compiling of all Tables"); WinConsole.WriteLine(@"\ns"); WinConsole.WriteLine(" Defines a default Namespace"); WinConsole.WriteLine(@"\fkGen"); WinConsole.WriteLine(" Generates ForgeinKeyDeclarations"); WinConsole.WriteLine(@"\addConfigMethod"); WinConsole.WriteLine(" Moves all attributes from Propertys and Methods into a single ConfigMethod"); WinConsole.WriteLine(@"\withAutoCtor"); WinConsole.WriteLine(" Generates Loader Constructors"); WinConsole.WriteLine(@"\withNotification"); WinConsole.WriteLine($" Adds the '{nameof(INotifyPropertyChanged)}' interface to all Pocos"); WinConsole.WriteLine(@"\autoGenNames"); WinConsole.WriteLine(" Defines all names after a common naming convention"); WinConsole.WriteLine(@"\addCompilerHeader "); WinConsole.WriteLine(" Adds a Timestamp and a created user on each POCO"); WinConsole.WriteLine(@"\withValidators "); WinConsole.WriteLine(" Adds Validator attributes from the System.ComponentModel.DataAnnotations"); WinConsole.WriteLine(@"\exit"); WinConsole.WriteLine(" Stops the execution of the program"); RenderMenuAction(); }
private void UpdateMethod2(int tableScreenId) { Feedback = ""; var tableData = AppServices.DataAccessService.GetCurrentTables(tableScreenId, CurrentPageNo).OrderBy(x => x.Order); if (Tables != null && (Tables.Count() == 0 || Tables.Count != tableData.Count() || Tables.First().Caption != tableData.First().Name)) { Tables = null; } if (Tables == null) { Tables = new ObservableCollection <IDiagram>(); Tables.AddRange(tableData.Select(x => new TableScreenItemViewModel(x, SelectedTableScreen, TableSelectionCommand))); } else { for (var i = 0; i < tableData.Count(); i++) { if (Tables[i] is TableScreenItemViewModel) { ((TableScreenItemViewModel)Tables[i]).Model = tableData.ElementAt(i); } } } if (SelectedTicket != null && !string.IsNullOrEmpty(SelectedTicket.LocationName)) { FeedbackColor = "Red"; FeedbackForeground = "White"; Feedback = string.Format(Resources.SelectTableThatYouWantToMoveTicket_f, SelectedTicket.LocationName); } else if (SelectedTicket != null) { FeedbackColor = "Red"; FeedbackForeground = "White"; Feedback = Resources.SelectTableForTicket; } else { FeedbackColor = "LightYellow"; FeedbackForeground = "Black"; Feedback = Resources.SelectTableForOperation; } RaisePropertyChanged("Tables"); RaisePropertyChanged("TableScreens"); RaisePropertyChanged("SelectedTableScreen"); RaisePropertyChanged("SelectedDisplayMode"); RaisePropertyChanged("IsPageNavigatorVisible"); }
public bool LoadDefinition(string path) { try { XmlSerializer deser = new XmlSerializer(typeof(Definition)); using (var fs = new FileStream(path, FileMode.Open)) { Definition def = (Definition)deser.Deserialize(fs); var newtables = def.Tables.Where(x => Tables.Count(y => x.Build == y.Build && x.Name == y.Name) == 0).ToList(); newtables.ForEach(x => x.Load()); Tables.UnionWith(newtables.Where(x => x.Key != null)); return(true); } } catch { return(false); } }
private string BuildFrom() { if (Tables == null) { throw new Exception("Tables can not be null."); } if (!Tables.Any()) { throw new Exception("Tables can not be empty."); } if (Tables.Any() && Tables.Count() == 1) { return($"FROM [{Tables.First().Schema}].[{Tables.First().Name}]"); } else { throw new NotImplementedException(); } }
static void Main(string[] args) { if (args.Length == 0) { System.Console.WriteLine("Please enter a type of generated report."); System.Console.WriteLine("Usage: sstc -t | -h [-w]"); System.Console.ReadKey(); return; } int sl = 52, st = 7, sk; string opt = ""; string cmd = args[0]; if (args.Length > 1) { opt = args[1]; } if (cmd != "-t" && cmd != "-h") { System.Console.WriteLine("Invalid report type key, supported types keys are text [-t] and html [-h]."); System.Console.ReadKey(); return; } string LookupDirectory; if (opt != "-w") { LookupDirectory = Directory.GetCurrentDirectory() + "\\tables\\ntos\\"; sk = 6; } else { LookupDirectory = Directory.GetCurrentDirectory() + "\\tables\\win32k\\"; sl = 75; sk = 0; } string[] Tables; try { Tables = Directory.GetFiles(LookupDirectory, "*.txt"); } catch (Exception e) { System.Console.WriteLine(e.Message); return; } IComparer Comparer = new ItemsComparer(); Array.Sort(Tables, Comparer); int fcount = Tables.Count(); int count = 0; List <sstTable> DataItems = new List <sstTable>(); int n = 0, id; string header = "ServiceName"; for (int i = 0; i < st; i++) { header += "\t"; } int max = 0; foreach (var sName in Tables) { string[] fData; header += Path.GetFileNameWithoutExtension(sName); try { fData = File.ReadAllLines(sName); for (int i = 0; i < fData.Count(); i++) { int u = 0; int syscall_id; string syscall_name; u = fData[i].IndexOf('\t') + 1; syscall_id = Convert.ToInt32(fData[i].Substring(u)); syscall_name = fData[i].Substring(0, u - 1); if (syscall_name.Length > max) { max = syscall_name.Length; } id = IndexOfItem(syscall_name, DataItems); if (id != -1) { var sstEntry = DataItems[id]; sstEntry.Indexes[n] = syscall_id; } else { var sstEntry = new sstTable(); sstEntry.ServiceName = syscall_name; sstEntry.Indexes = new int[fcount]; for (int k = 0; k < fcount; k++) { sstEntry.Indexes[k] = -1; } sstEntry.Indexes[n] = syscall_id; DataItems.Add(sstEntry); } } } catch (Exception e) { System.Console.WriteLine(e.Message); } n++; header += "\t"; } sl = max + sk; StreamWriter file; try { if (cmd == "-t") { if (opt != "-w") { file = new StreamWriter("syscalls.txt", false, Encoding.UTF8); } else { file = new StreamWriter("w32ksyscalls.txt", false, Encoding.UTF8); } file.WriteLine(header); foreach (var Entry in DataItems) { count += 1; var s = count.ToString("0000") + ") " + Entry.ServiceName; PutSpaces(ref s, sl); for (int i = 0; i < fcount; i++) { s += "\t"; if (Entry.Indexes[i] != -1) { s += Entry.Indexes[i].ToString(); } else { s += " "; } } file.WriteLine(s); } file.Close(); } if (cmd == "-h") { string ReportHead = "<!DOCTYPE html><html><head>" + "<style>" + "table, th, td {" + "border: 1px solid black;" + "border-collapse: collapse;" + "} th, td {" + "padding: 5px;" + "} table tr:nth-child(even) { background-color: #eee;}" + "table tr:nth-child(odd) { background-color:#fff;}" + "table th { background-color: white; color: black; }" + "</style></head><body>"; string ColStart = "<td>"; string ColEnd = "</td>"; string RowEnd = "</tr>"; string ReportEnd = "</table></body></html>"; string TableHead = "<table><caption>Syscall Table Indexes</caption>" + "<tr><th style=\"width:20px\">#</th>" + "<th style=\"width:130px\">ServiceName</th>"; for (int i = 0; i < fcount; i++) { TableHead += "<th style=\"width:40px\">" + Path.GetFileNameWithoutExtension(Tables[i]) + "</th>"; } TableHead += RowEnd; string item = ""; if (opt != "-w") { file = new StreamWriter("syscalls.html", false, Encoding.UTF8); } else { file = new StreamWriter("w32ksyscalls.html", false, Encoding.UTF8); } file.WriteLine(ReportHead); file.WriteLine(TableHead); for (int i = 0; i < DataItems.Count; i++) { var Entry = DataItems[i]; item += "<tr><td>" + (i + 1).ToString() + ColEnd; item += ColStart + Entry.ServiceName + ColEnd; for (int j = 0; j < fcount; j++) { item += ColStart; if (Entry.Indexes[j] != -1) { item += Entry.Indexes[j].ToString(); } else { item += " "; } item += ColEnd; } item += RowEnd; } file.WriteLine(item); file.WriteLine(ReportEnd); file.Close(); } // cmd == -h } //try catch (Exception e) { System.Console.WriteLine(e.Message); System.Console.ReadKey(); } }
private void RenderMenuAction() { var readLine = Program.AutoConsole.GetNextOption(); if (string.IsNullOrEmpty(readLine)) { RenderMenu(); return; } var input = readLine.ToLower(); int result; var hasSelectTable = int.TryParse(input, out result); if (hasSelectTable) { if (result > Tables.Count() || result < 0) { WinConsole.WriteLine("Unvalid number"); RenderMenu(); return; } RenderTableMenu(Tables.ElementAt(result)); } var tableName = Tables.FirstOrDefault(s => s.GetClassName() == readLine); if (tableName != null) { RenderTableMenu(tableName); } else { var split = input.Split(' '); switch (split[0]) { case @"\autogennames": AutoAlignNames(); break; case @"\ns": SetNamespace(); break; case @"\fkgen": SetForgeinKeyDeclarationCreation(); break; case @"\compile": Compile(); break; case @"\withautoctor": SetRenderAutoCtor(); break; case @"\withnotification": SetAddNotifiy(); break; case @"\withfactory": SetRenderFactory(); break; case @"\addconfigmethod": SetConfigMethod(); break; case @"\addcompilerheader": SetCompilerHeader(); break; case @"\exit": return; default: RenderMenuAction(); break; } } }
public void CreateEntrys(string connection, string outputPath, string database) { TargetDir = outputPath; Manager = new DbAccessLayer(DbAccessType.MsSql, connection); bool checkDatabase; try { checkDatabase = Manager.CheckDatabase(); } catch (Exception) { checkDatabase = false; } if (!checkDatabase) { throw new Exception("Database not accessible. Maybe wrong Connection or no Selected Database?"); } var databaseName = string.IsNullOrEmpty(Manager.Database.DatabaseName) ? database : Manager.Database.DatabaseName; if (string.IsNullOrEmpty(databaseName)) { throw new Exception("Database not exists. Maybe wrong Connection or no Selected Database?"); } WinConsole.WriteLine("Connection OK ... Reading Server Version ..."); SqlVersion = Manager.RunSelect <string>(Manager.Database.CreateCommand("SELECT SERVERPROPERTY('productversion')")).FirstOrDefault(); WinConsole.WriteLine("Server version is {0}", SqlVersion); WinConsole.WriteLine("Reading Tables from {0} ...", databaseName); Tables = Manager.Select <TableInformations>() .ToArray() .AsParallel() .Select(s => new TableInfoModel(s, databaseName, new DbAccessLayer(DbAccessType.MsSql, connection))) .ToList(); Views = Manager.Select <ViewInformation>() .ToArray() .AsParallel() .Select(s => new TableInfoModel(s, databaseName, new DbAccessLayer(DbAccessType.MsSql, connection))) .ToList(); StoredProcs = Manager.Select <StoredProcedureInformation>() .Select(s => new StoredPrcInfoModel(s)) .ToList(); WinConsole.WriteLine( "Found {0} Tables, {1} Views, {2} Procedures ... select a Table to see Options or start an Action", Tables.Count(), Views.Count(), StoredProcs.Count()); Enums = new List <Dictionary <int, string> >(); RenderMenu(); }
public void CreateEntrys(string connection, string outputPath, string database) { TargetDir = outputPath; bool checkDatabase = false; if (connection.StartsWith("file:\\\\")) { MsSqlStructure = new DacpacMsSqlStructure(connection.Replace("file:\\\\", "")); checkDatabase = true; } else { var dbAccessLayer = new DbAccessLayer(DbAccessType.MsSql, connection); MsSqlStructure = new DatabaseMsSqlStructure(dbAccessLayer); try { checkDatabase = dbAccessLayer.CheckDatabase(); } catch (Exception) { checkDatabase = false; } var databaseName = string.IsNullOrEmpty(dbAccessLayer.Database.DatabaseName) ? database : dbAccessLayer.Database.DatabaseName; if (string.IsNullOrEmpty(databaseName)) { throw new Exception("Database not exists. Maybe wrong Connection or no Selected Database?"); } } if (!checkDatabase) { throw new Exception("Database not accessible. Maybe wrong Connection or no Selected Database?"); } WinConsole.WriteLine("Connection OK ... Reading Server Version ..."); SqlVersion = MsSqlStructure.GetVersion().ToString(); WinConsole.WriteLine("Server version is {0}", SqlVersion); WinConsole.WriteLine("Reading Tables from {0} ...", MsSqlStructure.GetDatabaseName()); Tables = MsSqlStructure.GetTables() //.AsParallel() .Select(s => new TableInfoModel(s, MsSqlStructure.GetDatabaseName(), MsSqlStructure)) .ToList(); Views = MsSqlStructure.GetViews() //.AsParallel() .Select(s => new TableInfoModel(s, MsSqlStructure.GetDatabaseName(), MsSqlStructure)) .ToList(); StoredProcs = MsSqlStructure.GetStoredProcedures() .Select(s => new StoredPrcInfoModel(s)) .ToList(); WinConsole.WriteLine( "Found {0} Tables, {1} Views, {2} Procedures ... select a Table to see Options or start an Action", Tables.Count(), Views.Count(), StoredProcs.Count()); Enums = new List <Dictionary <int, string> >(); RenderMenu(); }
static void Main(string[] args) { System.Console.WriteLine("SSTC - System Service Table Composer"); var assembly = Assembly.GetEntryAssembly(); var hashId = assembly.ManifestModule.ModuleVersionId; Console.WriteLine("Build MVID: " + hashId); if (args.Length == 0) { System.Console.WriteLine("\r\nNo parameters specified\r\n"); System.Console.WriteLine("Usage: sstc -m | -h [-w]\r\nPress any key to continue"); System.Console.ReadKey(); return; } string opt = ""; string cmd = args[0]; if (args.Length > 1) { opt = args[1]; } if (cmd != "-m" && cmd != "-h") { System.Console.WriteLine("Invalid report type key, supported types keys are markdown [-m] and html [-h]\r\nPress any key to continue"); System.Console.ReadKey(); return; } string LookupDirectory = Directory.GetCurrentDirectory() + "\\tables\\"; if (opt != "-w") { LookupDirectory += "ntos\\"; } else { LookupDirectory += "win32k\\"; } string[] Tables; try { Tables = Directory.GetFiles(LookupDirectory, "*.txt"); } catch (Exception e) { System.Console.WriteLine(e.Message); return; } IComparer Comparer = new ItemsComparer(); Array.Sort(Tables, Comparer); int fcount = Tables.Count(); int count = 0; List <sstTable> DataItems = new List <sstTable>(); int n = 0, id; // // Makrdown header. // string MarkdownHeader = "| # | ServiceName |"; string MarkdownSubHeader = "| --- | --- | "; // // Parse files into internal array. // foreach (var sName in Tables) { string[] fData; MarkdownHeader += (Path.GetFileNameWithoutExtension(sName) + " | "); try { fData = File.ReadAllLines(sName); for (int i = 0; i < fData.Count(); i++) { int u = 0; int syscall_id; string syscall_name; u = fData[i].IndexOf('\t') + 1; syscall_id = Convert.ToInt32(fData[i].Substring(u)); syscall_name = fData[i].Substring(0, u - 1); id = IndexOfItem(syscall_name, DataItems); if (id != -1) { var sstEntry = DataItems[id]; sstEntry.Indexes[n] = syscall_id; } else { var sstEntry = new sstTable(); sstEntry.ServiceName = syscall_name; sstEntry.Indexes = new int[fcount]; for (int k = 0; k < fcount; k++) { sstEntry.Indexes[k] = -1; } sstEntry.Indexes[n] = syscall_id; DataItems.Add(sstEntry); } } } catch (Exception e) { System.Console.WriteLine(e.Message); } n++; MarkdownSubHeader += (" --- | "); } FileStream outputFile; ASCIIEncoding asciiEncoding = new ASCIIEncoding(); MemoryStream ms = new MemoryStream(); var sw = new StreamWriter(ms, asciiEncoding); try { if (cmd == "-m") { Console.WriteLine("Composing markdown table"); // // Generate markdown table as output. // string fileName = (opt != "-w") ? "syscalls.md" : "w32ksyscalls.md"; outputFile = new FileStream(fileName, FileMode.Create, FileAccess.Write); sw.WriteLine(MarkdownHeader); sw.WriteLine(MarkdownSubHeader); foreach (var Entry in DataItems) { count += 1; var s = "| " + count.ToString("0000") + " | "; s += Entry.ServiceName + " | "; for (int i = 0; i < fcount; i++) { if (Entry.Indexes[i] != -1) { s += Entry.Indexes[i].ToString() + " | "; } else { s += " | "; } } sw.WriteLine(s); } sw.Flush(); ms.WriteTo(outputFile); outputFile.Close(); ms.Dispose(); sw.Close(); } else { // // Generate HTML table as output. // Console.WriteLine("Composing HTML table"); string ReportHead = "<!DOCTYPE html><html><head>" + "<style>" + "table, th, td {" + "border: 1px solid black;" + "border-collapse: collapse;" + "} th, td {" + "padding: 5px;" + "} table tr:nth-child(even) { background-color: #eee;}" + "table tr:nth-child(odd) { background-color:#fff;}" + "table th { background-color: white; color: black; }" + "</style></head><body>"; string ColStart = "<td>"; string ColEnd = "</td>"; string RowEnd = "</tr>"; string ReportEnd = "</table></body></html>"; string TableHead = "<table><caption>Syscall Table Indexes</caption>" + "<tr><th style=\"width:20px\">#</th>" + "<th style=\"width:130px\">ServiceName</th>"; for (int i = 0; i < fcount; i++) { TableHead += "<th style=\"width:40px\">" + Path.GetFileNameWithoutExtension(Tables[i]) + "</th>"; } TableHead += RowEnd; string fileName = (opt != "-w") ? "syscalls.html" : "w32ksyscalls.html"; outputFile = new FileStream(fileName, FileMode.Create, FileAccess.Write); sw.WriteLine(ReportHead); sw.WriteLine(TableHead); for (int i = 0; i < DataItems.Count; i++) { var Entry = DataItems[i]; var item = "<tr><td>" + (i + 1).ToString() + ColEnd; item += ColStart + Entry.ServiceName + ColEnd; for (int j = 0; j < fcount; j++) { item += ColStart; if (Entry.Indexes[j] != -1) { item += Entry.Indexes[j].ToString(); } else { item += " "; } item += ColEnd; } item += RowEnd; sw.WriteLine(item); } sw.WriteLine(ReportEnd); sw.Flush(); ms.WriteTo(outputFile); outputFile.Close(); ms.Dispose(); sw.Close(); } // cmd == -h } //try catch (Exception e) { System.Console.WriteLine(e.Message); System.Console.ReadKey(); } }