public void Add(IDataTransferObject dto) { if (dto is MethodDTO) { MethodDTO methodDTO = (MethodDTO) dto; StringBuilder stringBuilder = new StringBuilder (); foreach (ParameterDTO parameterDTO in methodDTO.ParametersCollection) { stringBuilder = stringBuilder.Append (parameterDTO.TypeName); stringBuilder = stringBuilder.Append (" "); stringBuilder = stringBuilder.Append (parameterDTO.VarName); stringBuilder = stringBuilder.Append (", "); } if (stringBuilder.Length != 0) { stringBuilder = stringBuilder.Remove (stringBuilder.Length -2, 2); } listStore.AppendValues ( methodDTO.MethodName, methodDTO.ReturnType, methodDTO.ViewToResponse, methodDTO.ResponseMethod, stringBuilder.ToString () ); list.Add (methodDTO); } }
public void LoadDataForm(IDataTransferObject dto) { if (dto is ViewDTO) { ViewDTO viewDTO = (ViewDTO) dto; viewNameEntry.Text = viewDTO.ViewName; } }
public void Add(IDataTransferObject dto) { if (dto is MethodDTO) { MethodDTO methodDTO = (MethodDTO)dto; StringBuilder stringBuilder = new StringBuilder(); foreach (ParameterDTO parameterDTO in methodDTO.ParametersCollection) { stringBuilder = stringBuilder.Append(parameterDTO.TypeName); stringBuilder = stringBuilder.Append(" "); stringBuilder = stringBuilder.Append(parameterDTO.VarName); stringBuilder = stringBuilder.Append(", "); } if (stringBuilder.Length != 0) { stringBuilder = stringBuilder.Remove(stringBuilder.Length - 2, 2); } listStore.AppendValues( methodDTO.MethodName, methodDTO.ReturnType, methodDTO.ViewToResponse, methodDTO.ResponseMethod, stringBuilder.ToString() ); list.Add(methodDTO); } }
public void CreateDtoGeneric_CreatesINotifyPropertyChanged() { IDtoFactory factory = new DtoFactory(); IDataTransferObject dto = factory.CreateDto <TestPersonDto> (); Assert.IsInstanceOfType(dto, typeof(INotifyPropertyChanged)); }
public void LoadDataForm(IDataTransferObject dto) { if (dto is PreferencesDTO) { PreferencesDTO preferencesDTO = (PreferencesDTO) dto; defaultOutputPathEntry.Text = preferencesDTO.OutputPath; prefixNamespaceEntry.Text = preferencesDTO.PrefixNamespace; } }
public void Add(IDataTransferObject dto) { if (dto is ViewDTO) { ViewDTO viewDTO = (ViewDTO) dto; listStore.AppendValues (viewDTO.ViewName); list.Add (viewDTO); } }
public void LoadDataForm(IDataTransferObject dto) { if (dto is ViewDTO) { ViewDTO viewDTO = (ViewDTO)dto; viewNameEntry.Text = viewDTO.ViewName; } }
public void Serialize(Stream stream, IDataTransferObject dataTransferObject) { if (dataTransferObject is ProjectDTO) { XmlSerializer xmlSerializer = new XmlSerializer (dataTransferObject.GetType ()); StreamWriter streamWriter = new StreamWriter (stream); xmlSerializer.Serialize (streamWriter, dataTransferObject); streamWriter.Close (); } }
public void LoadDataForm(IDataTransferObject dto) { if (dto is PreferencesDTO) { PreferencesDTO preferencesDTO = (PreferencesDTO)dto; defaultOutputPathEntry.Text = preferencesDTO.OutputPath; prefixNamespaceEntry.Text = preferencesDTO.PrefixNamespace; } }
public void Add(IDataTransferObject dto) { if (dto is ViewDTO) { ViewDTO viewDTO = (ViewDTO)dto; listStore.AppendValues(viewDTO.ViewName); list.Add(viewDTO); } }
public void LoadDataForm(IDataTransferObject dto) { if (dto is ParameterDTO) { ParameterDTO parameterDTO = (ParameterDTO)dto; typeEntry.Text = parameterDTO.TypeName; varNameEntry.Text = parameterDTO.VarName; } }
public void Serialize(Stream stream, IDataTransferObject dataTransferObject) { if (dataTransferObject is ProjectDTO) { XmlSerializer xmlSerializer = new XmlSerializer(dataTransferObject.GetType()); StreamWriter streamWriter = new StreamWriter(stream); xmlSerializer.Serialize(streamWriter, dataTransferObject); streamWriter.Close(); } }
public void Add(IDataTransferObject dto) { if (dto is ParameterDTO) { ParameterDTO parameterDTO = (ParameterDTO) dto; listStore.AppendValues ( parameterDTO.TypeName, parameterDTO.VarName ); list.Add (parameterDTO); } }
/* Interface Implementation */ /* * Cargará el proyecto. * Coge el ProjectDTO que le pasamos y asignamos la referencia al modelo * del projectDTO. Además con ese nuevo DTO crea un nuevo Nodo y * rellenará también sus componentes. */ public void LoadDataForm(IDataTransferObject dto) { if (dto is ProjectDTO) { //Refresca el proyecto. ProjectDTO projectDTO = (ProjectDTO) dto; this.projectDTO = projectDTO; ClearForm (); componentNodeStore.AddNode (new ProjectNode (this.projectDTO)); } componentNodeView.ExpandAll (); }
public void Initialise(IDataTransferObject dto) { if (dto.ContainsKey($"{Name}ID") || dto.ContainsKey("ID")) { var key = dto.ContainsKey($"{Name}ID") ? (int)dto[$"{Name}ID"] : (int)dto["ID"]; var value = dto.ContainsKey($"{Name}Name") ? dto[$"{Name}Name"].ToString() : dto["Name"].ToString(); Add(key, value); } }
/* Interface Implementation */ public void LoadDataForm(IDataTransferObject dto) { if (dto is ProjectDTO) { projectView.LoadDataForm(dto); } else if (dto is ComponentDTO) { componentView.LoadDataForm(dto); } }
public void Add(IDataTransferObject dto) { if (dto is ParameterDTO) { ParameterDTO parameterDTO = (ParameterDTO)dto; listStore.AppendValues( parameterDTO.TypeName, parameterDTO.VarName ); list.Add(parameterDTO); } }
/* Interface Implementation */ /* * Cargará el proyecto. * Coge el ProjectDTO que le pasamos y asignamos la referencia al modelo * del projectDTO. Además con ese nuevo DTO crea un nuevo Nodo y * rellenará también sus componentes. */ public void LoadDataForm(IDataTransferObject dto) { if (dto is ProjectDTO) { //Refresca el proyecto. ProjectDTO projectDTO = (ProjectDTO)dto; this.projectDTO = projectDTO; ClearForm(); componentNodeStore.AddNode(new ProjectNode(this.projectDTO)); } componentNodeView.ExpandAll(); }
/* Interface Implementation */ public void LoadDataForm(IDataTransferObject dto) { if (dto is ComponentDTO) { ComponentDTO componentDTO = (ComponentDTO)dto; this.componentDTO = componentDTO; componentNameEntry.Text = componentDTO.ComponentName; exceptionManagerEntry.Text = componentDTO.ClassExceptionManager; viewTableModel = new ViewTableModel(componentDTO.ViewCollection); viewsTreeView.Model = viewTableModel.ListStore; methodTableModel = new MethodTableModel(componentDTO.MethodCollection); methodsTreeView.Model = methodTableModel.ListStore; } }
/// <summary> /// Trims all properties of the dto if the property is a string and not null /// </summary> public static void TrimAllProperties(IDataTransferObject dto) { // checks each property if its a string and trims the value foreach (var property in dto.GetType().GetProperties()) { var propertyValue = property.GetValue(dto); if (propertyValue != null && propertyValue is string) { var propertyValueString = propertyValue as string; property.SetValue(dto, propertyValueString.Trim()); } } }
private bool TryParseXml(XElement xml, out IDataTransferObject dto) { switch (xml.Name.LocalName.ToLowerInvariant()) { case "firmpopularity": return(TryParseFirmPopularity(xml, out dto)); case "rubricpopularity": return(TryParseRubricPopularity(xml, out dto)); default: dto = null; return(false); } }
/// <summary> /// Convert DataTable to DataTransferObject. It will copy value on DataTable to each field on DTO. /// </summary> /// <typeparam name="T">Type of IDataTransferObject which convert to.</typeparam> /// <param name="dataTable">Source DataTable.</param> /// <returns>List of DTO.</returns> public static List <T> ConvertDataTableToList <T>(DataTable dataTable) where T : IDataTransferObject { List <T> list = new List <T>(); if (dataTable == null) { return(list); } DataColumnCollection columns = dataTable.Columns; for (int iRow = 0; iRow < dataTable.Rows.Count; iRow++) { IDataTransferObject dtoInstance = (IDataTransferObject)Activator.CreateInstance(typeof(T)); for (int i = 0; i < columns.Count; i++) { try { //dto = null => did not declare properts if (dtoInstance[columns[i].ColumnName] == null) { System.Diagnostics.Debug.WriteLine(string.Format("Property name: {0} does not declare in class {1}", columns[i].ColumnName, typeof(T).FullName)); continue; } // Copy value from dataTable to DTO. if (dataTable.Rows[iRow].RowState == DataRowState.Deleted) { dtoInstance[columns[i].ColumnName].Value = dataTable.Rows[iRow][i, DataRowVersion.Original]; } else { dtoInstance[columns[i].ColumnName].Value = dataTable.Rows[iRow][i]; } } catch (Exception err) { System.Diagnostics.Debug.WriteLine(err.Message + ", " + err.Source); } } list.Add((T)dtoInstance); } return(list); }
public IReadOnlyCollection <IOperation> Import(IDataTransferObject dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var typedDto = dto as TDto; if (typedDto == null) { throw new ArgumentException($"Expected dto of type {typeof(TDto).Name} but got {dto.GetType().Name}", nameof(dto)); } return(Import(typedDto)); }
public void LoadDataForm(IDataTransferObject dto) { if (dto is MethodDTO) { } else if (dto is ComponentDTO) { ComponentDTO componentDTO = (ComponentDTO)dto; TreeStore treeStore = new TreeStore(typeof(string)); viewToResponseCombo.Model = treeStore; foreach (ViewDTO viewDTO in componentDTO.ViewCollection) { treeStore.AppendValues(viewDTO.ViewName); } } }
private void SetProperty(IDataTransferObject dto, PropertyInfo p) { var key = p.Name; if (!dto.ContainsKey(key)) { return; } if (dto[key] is null) { return; } var propType = p.PropertyType; var fieldType = dto[key].GetType(); dynamic value = null; if (propType == fieldType) { value = dto[key]; } else if (propType == typeof(decimal) && fieldType.IsNumeric()) { value = decimal.Parse(dto[key].ToString()); } else if (propType == typeof(string)) { value = dto[key].ToString().Replace(" 00:00:00", string.Empty); } try { if (p.CanWrite) { p.SetValue(this, value); } else { TrySetReadOnlyPropertyValue(p, value); } } catch (InvalidCastException ex) { throw new Exception( "Data type mismatch error on model key: " + $"{key} for property: {p.Name}", ex); } }
public bool TryParse(XElement xml, out IDataTransferObject dto) { try { dto = new FirmForecastDto { ProjectId = (long)xml.Attribute("BranchCode"), Firms = ParseFirms(xml.Descendants("Firm")) }; return(true); } catch (Exception) { dto = null; return(false); } }
public virtual void Initialise(IDataTransferObject dto) { if (_isInitialised) { throw new NotSupportedException( "Trying to reinitialise which is not supported!"); } var type = GetType(); var props = type.GetProperties(); foreach (var p in props) { SetProperty(dto, p); } PropertyChanged += OnPropertyChanged; _isInitialised = true; }
private bool TryParseFirmPopularity(XElement xml, out IDataTransferObject dto) { try { dto = new FirmStatisticsDto { ProjectId = (long)xml.Attribute("BranchCode"), Firms = xml.Descendants("Firm").Select(x => { var firmDto = new FirmStatisticsDto.FirmDto { FirmId = (long)x.Attribute("Code"), Categories = x.Descendants("Rubric").Select(y => { var clickCountAttr = y.Attribute("ClickCount"); var impressionCountAttr = y.Attribute("ImpressionCount"); if (clickCountAttr == null || impressionCountAttr == null) { throw new ArgumentException(); } var rubricDto = new FirmStatisticsDto.FirmDto.CategoryDto { CategoryId = (long)y.Attribute("Code"), Hits = (int)clickCountAttr, Shows = (int)impressionCountAttr, }; return(rubricDto); }).ToArray() }; return(firmDto); }).ToArray(), }; return(true); } catch (ArgumentException) { _tracer.Warn("Skip FirmPopularity message due to unsupported format"); dto = null; return(false); } }
/// <summary> /// Loads the content from another data transfer object. /// </summary> /// <param name="source">The content source.</param> /// <param name="token">The token that can be used to cancel the operation.</param> /// <returns>The task representing asynchronous state of content loading.</returns> /// <exception cref="OperationCanceledException">The operation has been canceled.</exception> /// <exception cref="NotSupportedException">The underlying stream does not support seeking.</exception> public async ValueTask LoadFromAsync(IDataTransferObject source, CancellationToken token = default) { if (content.CanSeek && content.CanWrite) { try { await source.WriteToAsync(content, token : token).ConfigureAwait(false); } finally { content.Seek(0, SeekOrigin.Begin); } } else { throw new NotSupportedException(); } }
private bool TryParseRubricPopularity(XElement xml, out IDataTransferObject dto) { var branchElement = xml.Element("Branch"); if (branchElement == null) { dto = null; return(false); } try { dto = new CategoryStatisticsDto { ProjectId = (long)branchElement.Attribute("Code"), Categories = xml.Descendants("Rubric").Select(x => { var advFirmCountAttr = x.Attribute("AdvFirmCount"); if (advFirmCountAttr == null) { throw new ArgumentException(); } var rubricDto = new CategoryStatisticsDto.CategoryDto { CategoryId = (long)x.Attribute("Code"), AdvertisersCount = (long)advFirmCountAttr }; return(rubricDto); }).ToArray() }; return(true); } catch (ArgumentException) { _tracer.Warn("Skip RubricPopularity message due to unsupported format"); dto = null; return(false); } }
private bool TryParseXml(XElement xml, out IDataTransferObject dto) { var corporateBusObjectName = xml.Name.LocalName.ToLowerInvariant(); ICorporateBusMessageParser parser; if (!_parsers.TryGetValue(corporateBusObjectName, out parser)) { dto = null; return(false); } if (!parser.TryParse(xml, out dto)) { _tracer.Warn($"Skip {corporateBusObjectName} message due to unsupported format"); dto = null; return(false); } return(true); }
/// <summary> /// Converts DTO content into string. /// </summary> /// <param name="content">The content to read.</param> /// <param name="encoding">The encoding used to decode stored string.</param> /// <param name="token">The token that can be used to cancel asynchronous operation.</param> /// <returns>The content of the object.</returns> public static async Task <string> ReadAsTextAsync(this IDataTransferObject content, Encoding encoding, CancellationToken token = default) { //TODO: Should be rewritten for .NET Standard 2.1, private static ToString method should be removed using (var ms = new MemoryStream(1024)) { await content.CopyToAsync(ms, token).ConfigureAwait(false); ms.Seek(0, SeekOrigin.Begin); if (ms.Length == 0L) { return(string.Empty); } if (ms.TryGetBuffer(out var buffer)) { Memory <byte> memory = buffer; return(ToString(encoding, memory.Span)); } return(encoding.GetString(ms.ToArray())); } }
/// <summary> /// Convert DataRow object to DTO object. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="row"></param> /// <returns></returns> public static T ConvertDataRowToDTO <T>(DataRow row) where T : IDataTransferObject { DataColumnCollection columns = row.Table.Columns; IDataTransferObject dtoInstance = (IDataTransferObject)Activator.CreateInstance(typeof(T)); for (int i = 0; i < columns.Count; i++) { try { // Copy value from dataTable to DTO. dtoInstance[columns[i].ColumnName].Value = row[i]; } catch (Exception err) { System.Diagnostics.Debug.WriteLine(err.Message + ", Column: " + columns[i].ColumnName); } } return((T)dtoInstance); }
// GetList public override async Task <List <T> > GetListAsync <T>(IDbCommand command) { List <T> modelObjList = new List <T>(); try { if (command.Connection.State != ConnectionState.Open) { OpenConnection(command.Connection); } var cmd = command as SqlCommand; var reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { IDataTransferObject <T> mapper = DataMapperFactory.GetMapper <T>(); modelObjList = mapper.GetList(reader).ToList <T>(); reader.Close(); } // We return either the populated list if there was data, // or if there was no data we return an empty list. return(modelObjList); } catch (DatabaseException dbExp) { throw dbExp; } catch (SqlException sqlExp) { throw new DatabaseException(DatabaseException.ErrorCode.EXECUTE_ERROR, "Error executing query", sqlExp); } catch (Exception e) { throw new DatabaseException(DatabaseException.ErrorCode.UNKNOWN, "Error executing query", e); } finally { CloseConnection(command.Connection); } }
// GetSingle public override async Task <T> GetSingleAsync <T>(IDbCommand command) { T modelObj = default(T); try { if (command.Connection.State != ConnectionState.Open) { OpenConnection(command.Connection); } var cmd = command as SqlCommand; var reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { reader.Read(); IDataTransferObject <T> mapper = DataMapperFactory.GetMapper <T>(); modelObj = mapper.EntityMapping(reader); reader.Close(); } // return the MODEL, it's either populated with data or null. return(modelObj); } catch (DatabaseException dbExp) { throw dbExp; } catch (SqlException sqlExp) { throw new DatabaseException(DatabaseException.ErrorCode.EXECUTE_ERROR, "Error executing query", sqlExp); } catch (Exception e) { throw new DatabaseException(DatabaseException.ErrorCode.UNKNOWN, "Error executing query", e); } finally { CloseConnection(command.Connection); } }
/// <summary> /// Convert DataTransferObject to DataTable. It will copy value in property that declare FieldAttribute to new DataTable. /// </summary> /// <typeparam name="T">Type of IDataTransferObject</typeparam> /// <param name="list">List of DTO which will convert.</param> /// <returns>Return null if cannot convert.</returns> public static DataTable ConvertListToDataTable <T>(List <T> list) where T : IDataTransferObject { // Create object given DTO. Type typeOfDTO = typeof(T); object instance = Activator.CreateInstance(typeOfDTO); IDataTransferObject dto = (IDataTransferObject)instance; // Create schema of DataTable DataTable dataTable = null; bool bResult = dto.CreateDataTableSchema(out dataTable); if (bResult == false || dataTable == null) { return(null); } // Dump rows. if (list != null) { for (int i = 0; i < list.Count; i++) { DataRow row = dataTable.NewRow(); // Copy column. for (int iCol = 0; iCol < dataTable.Columns.Count; iCol++) { if (list[i][dataTable.Columns[iCol].ColumnName] == null) { throw new Exception("Please declare " + dataTable.Columns[iCol].ColumnName + " in DTO " + typeOfDTO.Name); } row[iCol] = list[i][dataTable.Columns[iCol].ColumnName].Value; } dataTable.Rows.Add(row); } } return(dataTable); }
public void LoadDataForm(IDataTransferObject dto) { }
async ValueTask IBufferedMessage.LoadFromAsync(IDataTransferObject source, CancellationToken token) { buffer.Dispose(); buffer = await source.ToMemoryAsync(token : token).ConfigureAwait(false); }
public void LoadDataForm(IDataTransferObject dto) { if (dto is MethodDTO) { } else if (dto is ComponentDTO) { ComponentDTO componentDTO = (ComponentDTO) dto; TreeStore treeStore = new TreeStore (typeof (string)); viewToResponseCombo.Model = treeStore; foreach (ViewDTO viewDTO in componentDTO.ViewCollection) { treeStore.AppendValues (viewDTO.ViewName); } } }
public GenericNode(IDataTransferObject dto) { this.dto = dto; }
/* Interface Implementation */ public void LoadDataForm(IDataTransferObject dto) { if (dto is ComponentDTO) { ComponentDTO componentDTO = (ComponentDTO) dto; this.componentDTO = componentDTO; componentNameEntry.Text = componentDTO.ComponentName; exceptionManagerEntry.Text = componentDTO.ClassExceptionManager; viewTableModel = new ViewTableModel (componentDTO.ViewCollection); viewsTreeView.Model = viewTableModel.ListStore; methodTableModel = new MethodTableModel (componentDTO.MethodCollection); methodsTreeView.Model = methodTableModel.ListStore; } }