/// <summary> /// Executa a vinculação dos dados contidos no registro para o objeto informado. /// </summary> /// <typeparam name="T">Tipo que será usado na operação.</typeparam> /// <param name="record">Registro da consulta.</param> /// <param name="mode">Modo da estratégia.</param> /// <param name="instance">Instancia onde será vinculado os dados.</param> /// <returns>Relação das propriedade na qual o bind foi aplicado.</returns> public IEnumerable <string> Bind <T>(Query.IRecord record, Query.BindStrategyMode mode, ref T instance) { record.Require("record").NotNull(); object instance2 = instance; var recordKeyFactory = _entityLoader.GetRecordKeyFactory(); var result = Bind(record, mode, recordKeyFactory, ref instance2); instance = (T)instance2; return(result); }
/// <summary> /// Recupera a chave simples que representa o registro. /// </summary> /// <param name="record">Instancia do registro.</param> /// <returns></returns> public string GetSimpleKey(Query.IRecord record) { record.Require("record").NotNull(); record.Descriptor.Require("record.Descriptor").NotNull(); var values = new string[_fieldNames.Length]; for (var i = 0; i < values.Length; i++) { var indexOf = 0; for (; indexOf < record.Descriptor.Count; indexOf++) { if (StringComparer.InvariantCultureIgnoreCase.Equals(record.Descriptor[indexOf].Name, _fieldNames[i])) { var value = record.GetValue(indexOf); if (value != null) { values[i] = value.ToString(); } break; } } } return(string.Join("|", values)); }
/// <summary> /// Realiza os bind dos dados do registro informado. /// </summary> /// <param name="record">Registro contendo os dados.</param> /// <param name="mode"></param> /// <param name="recordKeyFactory">Factory responsável pela geração da chave do registro.</param> /// <param name="instance"></param> /// <returns></returns> private IEnumerable <string> Bind(Query.IRecord record, Query.BindStrategyMode mode, Query.IRecordKeyFactory recordKeyFactory, ref object instance) { record.Require("record").NotNull(); var descriptor = instance as IEntityDescriptor; if (descriptor == null) { return(new string[0]); } var idFieldIndex = record.Descriptor.GetFieldPosition(_entityLoader.UidPropertyName); var descriptionFieldIndex = record.Descriptor.GetFieldPosition(_entityLoader.DescriptionPropertyName); string nameFieldValue = string.Empty; if (_entityLoader.FindNameProperties.Count() > 1) { var info = Merge(_entityLoader.FindNameProperties, descriptor, record).ToArray(); if (info.Length == 0 && mode == Query.BindStrategyMode.Differences) { nameFieldValue = descriptor.Name; } else { nameFieldValue = _entityLoader.FindNameConverter.Convert(info); } } else { var nameFieldIndex = record.Descriptor.GetFieldPosition(_entityLoader.FindNameProperties.FirstOrDefault()); if (nameFieldIndex >= 0) { nameFieldValue = record[nameFieldIndex]; } else if (mode == Query.BindStrategyMode.Differences) { nameFieldValue = descriptor.Name; } } descriptor.Id = idFieldIndex >= 0 ? record[idFieldIndex] : mode == Query.BindStrategyMode.Differences ? descriptor.Id : 0; descriptor.Name = nameFieldValue; descriptor.Description = descriptionFieldIndex >= 0 ? record[descriptionFieldIndex] : mode == Query.BindStrategyMode.Differences ? descriptor.Description : string.Empty; if (record.Descriptor.Contains("ActivatedDate") && record.Descriptor.Contains("ExpiredDate")) { DateTimeOffset activatedDate = record["ActivatedDate"]; DateTimeOffset?expiredDate = record["ExpiredDate"]; var isActive = activatedDate < ServerData.GetDateTimeOffSet() && !(expiredDate.HasValue && (ServerData.GetDateTimeOffSet() > expiredDate)); var isExpired = expiredDate.HasValue && (ServerData.GetDateTimeOffSet() > expiredDate); descriptor.ConfigureStatusControl(isActive, isExpired); } if (descriptor is BusinessEntityDescriptor) { var businessDescritor = (BusinessEntityDescriptor)descriptor; businessDescritor.RecordKey = recordKeyFactory.Create(_entityLoader.DataModelTypeName, record); } var changedProperties = new List <string> { "Id", "Name", "Description", "IsActive", "IsExpired" }; if (descriptor is IBindableEntityDescriptor) { changedProperties = changedProperties.Union(((IBindableEntityDescriptor)descriptor).Bind(record, mode)).ToList(); } return(changedProperties.ToArray()); }