//--------------------------------------------------------------------------------------------------------- /// <summary> /// Установка отображения простого списка записей /// </summary> //--------------------------------------------------------------------------------------------------------- public void SetListRecords() { if (ListRecords != null && ListRecords.Count > 0) { IList list = ListRecords; // Заполняем таблицу данных for (Int32 r = 0; r < list.Count; r++) { IList record = list[r] as IList; if (record != null && record.Count > 0) { DataRow row = TableRecords.NewRow(); for (Int32 c = 0; c < record.Count; c++) { row[c] = record[c]; } TableRecords.Rows.Add(row); } } // Элемент управления dataRecords.Columns.Clear(); dataRecords.ItemsSource = TableRecords.DefaultView; mDataViewerType = TDataViewerType.Table; labelCountRecord.Content = TableRecords.DefaultView.Count.ToString(); } }
public override void Invoke(CommandInvocationContext context) { VariableContextLogic.Instance.CurrentContext = VariableContextLogic.Instance.VariableContextCollection.Contexts .FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase)); base.Out.Object.Table(TableRecords.CreateVariableContextRecordList(VariableContextLogic.Instance.CurrentContext)); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Установка отображения простого списка записей /// </summary> //--------------------------------------------------------------------------------------------------------- public void SetListRecords() { if (ListRecords != null && ListRecords.Count > 0) { IList list = ListRecords; // Заполняем таблицу данных for (Int32 r = 0; r < list.Count; r++) { IList record = list[r] as IList; if (record != null && record.Count > 0) { DataRow row = TableRecords.NewRow(); for (Int32 c = 0; c < record.Count; c++) { row[c] = record[c]; } TableRecords.Rows.Add(row); } } dataRecord.ItemsSource = TableRecords.DefaultView; } }
public override void Invoke(CommandInvocationContext context) { if (PackageLogic.Instance.PackagesCollection.Packages.Count > 0) { List <Packages.Package> packagesToList = new List <Packages.Package>(); foreach (var pkg in PackageLogic.Instance.PackagesCollection.Packages) { bool isLoaded = PackageLogic.Instance.LoadedPackages.Contains(pkg); bool add = true; if (LoadedOnly.IsPresent && !isLoaded) { add = false; } if (add) { packagesToList.Add(pkg); } } if (!string.IsNullOrWhiteSpace(Filter)) { packagesToList = packagesToList.Where(e => e.Name.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) > -1).ToList(); } base.Out.Object.Write(TableRecords.CreatePackageRecordList(packagesToList.ToArray())); } else { base.Out.Object.Write(TableRecords.CreatePackageRecordList()); } }
/// <summary> /// SaveJson Method(To save records in Json Format) /// </summary> /// <returns>string</returns> public string SaveJson() { TableRecords tableRecords = null; List <TableRecords> lstTableRecords = new List <TableRecords>(); int tblNo = -1; foreach (DTTable dt in this._tbls) { tblNo++; tableRecords = new TableRecords(); tableRecords.tbl = dt.TableName; tableRecords.col = new Dictionary <string, string>(); foreach (DTColumn col in dt.Cols) { tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType)); } tableRecords.row = new ArrayList(); Dictionary <string, object> rowDetails = null; int colNo = 0; int rowStateFlag = 0; foreach (DTRow dr in dt.Rows) { rowDetails = new Dictionary <string, object>(); rowStateFlag = 1; foreach (DTColumn col in dt.Cols) { colNo = colNo + 1; object colValue; colValue = dr[col.ColName]; // add values to rowdetails based on colvalue. string strTemp = CustomMarshaler.StringFromPrimitivetype(colValue, false); rowDetails.Add(col.ColName, strTemp); // adding rowState in rowDeatils. if (rowStateFlag == 1 && colNo == dt.Cols.Count) { rowDetails.Add("rowstate", (int)dr.RowState); rowStateFlag = 0; colNo = 0; } } tableRecords.row.Add(rowDetails); } lstTableRecords.Add(tableRecords); } //converting the list into json format and return that string value string json = JsonConvert.SerializeObject(lstTableRecords); return(json); }
public override void Invoke(CommandInvocationContext context) { var pkg = PackageLogic.Instance.PackagesCollection.Packages .FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase)); base.Out.Standard.WriteLine(); base.Out.Standard.WriteLine(string.Format(" Package: {0}", pkg.Name)); base.Out.Standard.WriteLine(string.Format(" Is Loaded: {0}", PackageLogic.Instance.LoadedPackages.Contains(pkg))); base.Out.Object.Table(TableRecords.CreatePackageModuleTableRecordList(pkg.Modules.ToArray())); }
public override void Invoke(CommandInvocationContext context) { var asm = Util.LoadAssembly(Assembly); if (asm == null) { base.Out.Error.WriteLine(string.Format("Could not load assembly from assembly string '{0}'", Assembly)); return; } Package pkg = PackageLogic.Instance.PackagesCollection.Packages.FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase)); List <string> modulesToInstall = null; if (!string.IsNullOrWhiteSpace(Modules)) { modulesToInstall = new List <string>(Modules.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } int count = 0; foreach (var type in asm.GetTypes()) { if (type.GetInterface(typeof(IModule).FullName) != null) { var module = (IModule)Activator.CreateInstance(type); bool add = true; if (modulesToInstall != null && !modulesToInstall.Contains(module.Name, StringComparer.OrdinalIgnoreCase)) { add = false; } if (add) { base.Out.Verbose.WriteLine(string.Format("Adding module '{0}' from type '{1}'", module.Name, type)); if (AddModule(pkg, module)) { count++; } } } } PackageLogic.Instance.Save(); if (count > 0) { base.Out.Object.Table(TableRecords.CreatePackageRecordList(pkg)); } else { base.Out.Standard.WriteLine("No modules could be found to load"); } }
public override void Invoke(CommandInvocationContext context) { var ctx = new VariableContext() { Name = Name, Description = Description }; VariableContextLogic.Instance.VariableContextCollection.Contexts.Add(ctx); VariableContextLogic.Instance.Save(); base.Out.Object.Table(TableRecords.CreateVariableContextRecordList(ctx)); }
public TableRecords GetTableRecords(string tableName) { _sqlConnection.Open(); // Table records var cmd = _sqlConnection.CreateCommand(); cmd.CommandText = $"SELECT * FROM {tableName} FOR JSON AUTO"; var reader = cmd.ExecuteReader(); var stringBuilder = new StringBuilder(); while (reader.Read()) { stringBuilder.Append(reader[0]); } var recordsJson = JToken.Parse(stringBuilder.ToString()); // Table scheme var table = _sqlConnection.GetSchema("Tables", new[] { _sqlConnection.Database, null, tableName }); var columns = _sqlConnection.GetSchema("Columns", new[] { _sqlConnection.Database, null, tableName }); var tableScheme = new TableScheme() { Name = tableName, Type = table.Rows[0].ItemArray[3].ToString(), Columns = new List <ColumnScheme>(), }; foreach (DataRow column in columns.Rows) { tableScheme.Columns.Add(new ColumnScheme() { Name = column.ItemArray[3].ToString(), OrdinalPosition = column.ItemArray[4].ToString(), DefaultValue = column.ItemArray[5].ToString(), IsNullable = column.ItemArray[6].ToString() == "YES" ? true : false, DataType = column.ItemArray[7].ToString(), CharLength = column.ItemArray[8].ToString() }); } var tableRecords = new TableRecords() { TableName = tableName, Records = recordsJson, TableScheme = tableScheme }; _sqlConnection.Close(); return(tableRecords); }
public override void Invoke(CommandInvocationContext context) { if (string.IsNullOrEmpty(Context) && VariableContextLogic.Instance.CurrentContext == null) { base.Out.Error.WriteLine("There is no context set or specified - please specify or set a context first"); } else { var ctx = VariableContextLogic.Instance.CurrentContext; if (!string.IsNullOrWhiteSpace(Context)) { ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase)); } base.Out.Object.Table(TableRecords.CreateVariableRecordList(ctx.Variables.ToArray())); } }
public override void Invoke(CommandInvocationContext context) { var contextsToApply = new List <VariableContext>(); if (!AllContexts.IsPresent) // apply to specified or default context { VariableContext ctx = null; if (string.IsNullOrEmpty(Context)) // try to use the current context { if (VariableContextLogic.Instance.CurrentContext == null) { base.Out.Error.WriteLine("There is no context currently loaded and no context specified. Please load a context or specify a context using the 'Context' parameter first."); return; } ctx = VariableContextLogic.Instance.CurrentContext; base.Out.Verbose.WriteLine(string.Format("No context was specified - using the current context '{0}'", ctx.Name)); } else // try to or use the specified context { ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase)); } contextsToApply.Add(ctx); } else // load all to apply to { base.Out.Verbose.WriteLine("Applying variable to all contexts"); contextsToApply.AddRange(VariableContextLogic.Instance.VariableContextCollection.Contexts); } // apply to contexts var records = new List <VariableContextVariable>(); foreach (var ctxToApply in contextsToApply) { var rec = ctxToApply.Variables.FirstOrDefault(v => v.Name.Equals(Name)); if (rec != null) { records.Add(rec); } } base.Out.Object.Table(TableRecords.CreateVariableRecordList(records.ToArray())); }
public override void Invoke(CommandInvocationContext context) { if (VariableContextLogic.Instance.VariableContextCollection.Contexts.Count > 0) { var contextsToList = new List <VariableContext>(VariableContextLogic.Instance.VariableContextCollection.Contexts); if (!string.IsNullOrWhiteSpace(Filter)) { contextsToList = contextsToList.Where(e => e.Name.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) > -1).ToList(); } base.Out.Object.Write(TableRecords.CreateVariableContextRecordList(contextsToList.ToArray())); } else { base.Out.Object.Write(TableRecords.CreateVariableContextRecordList()); } }
public override void Invoke(CommandInvocationContext context) { if (base.Confirm("The module will be removed.")) { var pkg = PackageLogic.Instance.PackagesCollection.Packages .FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase)); pkg.Modules.Remove(pkg.Modules.FirstOrDefault(m => m.Name.Equals(Module, StringComparison.OrdinalIgnoreCase))); PackageLogic.Instance.Save(); base.Out.Object.Table(TableRecords.CreatePackageRecordList(pkg)); if (PackageLogic.Instance.LoadedPackages.Contains(pkg)) { base.Out.Warning.WriteLine("This package is currently loaded and must be reloaded before the changes will take effect"); } } }
public override void Invoke(CommandInvocationContext context) { if (PackageLogic.Instance.PackagesCollection.Packages .Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase))) { base.Out.Warning.WriteLine(string.Format("The package name '{0}' is already being used by another package", Name)); } else { var newPkg = new Packages.Package() { Name = Name }; PackageLogic.Instance.PackagesCollection.Packages.Add(newPkg); PackageLogic.Instance.Save(); base.Out.Object.Write(TableRecords.CreatePackageRecordList(newPkg)); } }
public override void Invoke(CommandInvocationContext context) { var contextsToApply = new List <VariableContext>(); if (!AllContexts.IsPresent) // apply to specified or default context { VariableContext ctx = null; if (string.IsNullOrEmpty(Context)) // try to use the current context { if (VariableContextLogic.Instance.CurrentContext == null) { base.Out.Error.WriteLine("There is no context currently loaded and no context specified. Please load a context or specify a context using the 'Context' parameter first."); return; } ctx = VariableContextLogic.Instance.CurrentContext; base.Out.Verbose.WriteLine(string.Format("No context was specified - using the current context '{0}'", ctx.Name)); } else // try to create and / or use the specified context { ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase)); if (ctx == null && base.Confirm(string.Format("The context '{0}' does not exist and will be created", Context), Component.ConfirmationResult.Yes)) { ctx = new VariableContext() { Name = Context }; VariableContextLogic.Instance.VariableContextCollection.Contexts.Add(ctx); VariableContextLogic.Instance.Save(); } if (ctx == null) { base.Out.Error.WriteLine("The variable could not be set because the context was not created"); return; } } contextsToApply.Add(ctx); } else // load all to apply to { base.Out.Verbose.WriteLine("Applying variable to all contexts"); contextsToApply.AddRange(VariableContextLogic.Instance.VariableContextCollection.Contexts); } // apply to contexts foreach (var ctxToApply in contextsToApply) { if (ctxToApply.Variables.Any(v => v.Name.Equals(Name))) { if (AllContexts.IsPresent) { base.Out.Verbose.WriteLine(string.Format("Updating variable '{0}' for context '{1}' with value '{2}'" , Name, ctxToApply.Name, Value)); } else { base.Out.Verbose.WriteLine(string.Format("Updating variable '{0}' with value '{1}'" , Name, Value)); } ctxToApply.Variables.FirstOrDefault(v => v.Name.Equals(Name)).Value = Value; } else { if (AllContexts.IsPresent) { base.Out.Verbose.WriteLine(string.Format("Creating variable '{0}' for context '{1}' with value '{2}'" , Name, ctxToApply.Name, Value)); } else { base.Out.Verbose.WriteLine(string.Format("Creating variable '{0}' with value '{1}" , Name, Value)); } ctxToApply.Variables.Add(new VariableContextVariable() { Name = Name, Value = Value }); } } VariableContextLogic.Instance.Save(); base.Out.Object.Table(TableRecords.CreateVariableRecordList(new VariableContextVariable() { Name = Name, Value = Value })); }
public override void Invoke(CommandInvocationContext context) { base.Out.Object.Table(TableRecords.CreateModuleTableRecordList(false, AssemblyUtil.GetAssemblyModules(Assembly).ToArray())); }
/// <summary> /// SaveJson Method(To save records in Json Format) /// </summary> /// <returns>string</returns> public string SaveJson() { TableRecords tableRecords = null; List<TableRecords> lstTableRecords = new List<TableRecords>(); int tblNo = -1; foreach (DTTable dt in this._tbls) { tblNo++; tableRecords = new TableRecords(); tableRecords.tbl = dt.TableName; tableRecords.col = new Dictionary<string, string>(); foreach (DTColumn col in dt.Cols) { tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType)); } tableRecords.row = new ArrayList(); Dictionary<string, object> rowDetails = null; int colNo = 0; int rowStateFlag = 0; foreach (DTRow dr in dt.Rows) { rowDetails = new Dictionary<string, object>(); rowStateFlag = 1; foreach (DTColumn col in dt.Cols) { colNo = colNo + 1; object colValue; colValue = dr[col.ColName]; // add values to rowdetails based on colvalue. string strTemp = CustomMarshaler.StringFromPrimitivetype(colValue, false); rowDetails.Add(col.ColName, strTemp); // adding rowState in rowDeatils. if (rowStateFlag == 1 && colNo == dt.Cols.Count) { rowDetails.Add("rowstate", (int)dr.RowState); rowStateFlag = 0; colNo = 0; } } tableRecords.row.Add(rowDetails); } lstTableRecords.Add(tableRecords); } //converting the list into json format and return that string value string json = JsonConvert.SerializeObject(lstTableRecords); return json; }
/// <summary> /// SaveJson Method(To save records in Json Format) /// </summary> /// <returns>string</returns> public string SaveJson() { TableRecords tableRecords = null; List <TableRecords> lstTableRecords = new List <TableRecords>(); int tblNo = -1; foreach (DTTable dt in this._tbls) { tblNo++; tableRecords = new TableRecords(); tableRecords.tbl = dt.TableName; tableRecords.col = new Dictionary <string, string>(); foreach (DTColumn col in dt.Cols) { tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType)); } tableRecords.row = new ArrayList(); Dictionary <string, object> rowDetails = null; int colNo = 0; int rowStateFlag = 0; foreach (DTRow dr in dt.Rows) { rowDetails = new Dictionary <string, object>(); rowStateFlag = 1; foreach (DTColumn col in dt.Cols) { colNo = colNo + 1; object colValue; colValue = dr[col.ColName]; if (colValue == null) { //add null to rowDetails rowDetails.Add(col.ColName, null); } else if (DTColumn.CheckType(colValue, DTType.String)) { string strTemp = ((string)colValue); rowDetails.Add(col.ColName, strTemp); } else if (DTColumn.CheckType(colValue, DTType.ByteArray)) { // バイト配列は、Base64エンコードして電文に乗せる string strBase64 = Convert.ToBase64String((byte[])colValue); rowDetails.Add(col.ColName, strBase64); } else if (DTColumn.CheckType(colValue, DTType.DateTime)) { // DateTimeは、yyyy/M/d-H:m:s.fffとする。 DateTime dttm = (DateTime)colValue; string strDttm = ""; strDttm += dttm.Year + "/"; strDttm += dttm.Month + "/"; strDttm += dttm.Day + "-"; strDttm += dttm.Hour + ":"; strDttm += dttm.Minute + ":"; strDttm += dttm.Second + "."; strDttm += dttm.Millisecond; rowDetails.Add(col.ColName, strDttm); } else { rowDetails.Add(col.ColName, colValue.ToString()); } //adding rowState in rowDeatils if (rowStateFlag == 1 && colNo == dt.Cols.Count) { rowDetails.Add("rowstate", (int)dr.RowState); rowStateFlag = 0; colNo = 0; } } tableRecords.row.Add(rowDetails); } lstTableRecords.Add(tableRecords); } //converting the list into json format and return that string value string json = JsonConvert.SerializeObject(lstTableRecords); return(json); }
/// <summary> /// SaveJson Method(To save records in Json Format) /// </summary> /// <returns>string</returns> public string SaveJson() { TableRecords tableRecords = null; List<TableRecords> lstTableRecords = new List<TableRecords>(); int tblNo = -1; foreach (DTTable dt in this._tbls) { tblNo++; tableRecords = new TableRecords(); tableRecords.tbl = dt.TableName; tableRecords.col = new Dictionary<string, string>(); foreach (DTColumn col in dt.Cols) { tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType)); } tableRecords.row = new ArrayList(); Dictionary<string, object> rowDetails = null; int colNo = 0; int rowStateFlag = 0; foreach (DTRow dr in dt.Rows) { rowDetails = new Dictionary<string, object>(); rowStateFlag = 1; foreach (DTColumn col in dt.Cols) { colNo = colNo + 1; object colValue; colValue = dr[col.ColName]; if (colValue == null) { //add null to rowDetails rowDetails.Add(col.ColName, null); } else if (DTColumn.CheckType(colValue, DTType.String)) { string strTemp = ((string)colValue); rowDetails.Add(col.ColName, strTemp); } else if (DTColumn.CheckType(colValue, DTType.ByteArray)) { // バイト配列は、Base64エンコードして電文に乗せる string strBase64 = Convert.ToBase64String((byte[])colValue); rowDetails.Add(col.ColName, strBase64); } else if (DTColumn.CheckType(colValue, DTType.DateTime)) { // DateTimeは、yyyy/M/d-H:m:s.fffとする。 DateTime dttm = (DateTime)colValue; string strDttm = ""; strDttm += dttm.Year + "/"; strDttm += dttm.Month + "/"; strDttm += dttm.Day + "-"; strDttm += dttm.Hour + ":"; strDttm += dttm.Minute + ":"; strDttm += dttm.Second + "."; strDttm += dttm.Millisecond; rowDetails.Add(col.ColName, strDttm); } else { rowDetails.Add(col.ColName, colValue.ToString()); } //adding rowState in rowDeatils if (rowStateFlag == 1 && colNo == dt.Cols.Count) { rowDetails.Add("rowstate", (int)dr.RowState); rowStateFlag = 0; colNo = 0; } } tableRecords.row.Add(rowDetails); } lstTableRecords.Add(tableRecords); } //converting the list into json format and return that string value string json = JsonConvert.SerializeObject(lstTableRecords); return json; }