public void Get(IPersistenceObjectCollection persistenceObjectCollection, IObjectKey parentObjectKey, HybridDictionary parameterCollection) { if (_proxyTypeSelect == null) { throw new ApplicationException(string.Format("Proxy Get Method is not defined for object {0}.", persistenceObjectCollection.GetType().Name)); } using (var proxy = (IDisposable)Activator.CreateInstance(_proxyTypeSelect)) { try { var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName); var methodInfo = _proxyTypeSelect.GetMethod(_mapperInfo.MethodNameSelect); // copy objectKey collection and parameterCollection into a combined collection var objectKeyFieldCollection = parentObjectKey.ToDictionary(); var combinedParameterCollection = new HybridDictionary(objectKeyFieldCollection.Count + parameterCollection.Count); foreach (DictionaryEntry item in objectKeyFieldCollection) { combinedParameterCollection.Add(item.Key, item.Value); } foreach (DictionaryEntry item in parameterCollection) { combinedParameterCollection.Add(item.Key, item.Value); } var parameterValueCollection = WsRecordMapper.PopulateMethodParameters(methodInfo, fieldMapperCollection, combinedParameterCollection); WsRecordMapper.ProcessProxyCallBack(proxy, _callbackTypeSelect, _mapperInfo.ProxyCallbackPropertyNameSelect); var result = methodInfo.Invoke(proxy, parameterValueCollection); Populate(persistenceObjectCollection, result); WsRecordMapper.Populate(persistenceObjectCollection, methodInfo, parameterValueCollection, result); } catch (TargetInvocationException ex) { if (ex.InnerException != null) { throw ex.InnerException; } throw; } } }
public bool HasObjectToObjectMapper(string businessObjectClassName) { var mapper = MapperFactory.GetInstance().GetObjectMapper(businessObjectClassName, ObjectMapperType.Obj); return(mapper != null); }
//internal static void Populate(IPersistenceObject persistenceObject, object result) //{ // if (result == null) // return; // var gu = GeneralUtility.GetInstance(); // var persistenceObjectType = persistenceObject.GetType(); // var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectType.FullName); // var fieldPropertyNameCollection = (from propertyInfo in persistenceObjectType.GetProperties(BindingFlags.Instance | BindingFlags.Public) // where propertyInfo.GetCustomAttributes(typeof(NotMappedAttribute), true).Length == 0 // select propertyInfo.Name) // .Union // (from fieldInfo in persistenceObjectType.GetFields(BindingFlags.Instance | BindingFlags.Public) // where fieldInfo.GetCustomAttributes(typeof(NotMappedAttribute), true).Length == 0 // select fieldInfo.Name); // var resultType = result.GetType(); // foreach (var fieldPropertyName in fieldPropertyNameCollection) // if (fieldMapperCollection.Contains(fieldPropertyName)) // { // if (resultType.GetMember(fieldMapperCollection[fieldPropertyName].ToString(), BindingFlags.Public | BindingFlags.Instance).Length > 0) // gu.SetMemberValue(persistenceObject, fieldPropertyName, gu.GetMemberValue(result, fieldMapperCollection[fieldPropertyName].ToString())); // else // throw new ApplicationException(string.Format("WebMethodResult Property: {0} does not exist for business object field: {1}.", fieldMapperCollection[fieldPropertyName], fieldPropertyName)); // } // else // { // implied name from fieldPropertyName // if (resultType.GetMember(fieldPropertyName, BindingFlags.Public | BindingFlags.Instance).Length > 0) // gu.SetMemberValue(persistenceObject, fieldPropertyName, gu.GetMemberValue(result, fieldPropertyName)); // else // throw new ApplicationException(string.Format("Implied WebMethodResult Property: {0} does not exist for business object field: {1}.", fieldPropertyName, fieldPropertyName)); // } //} internal static void Populate(IPersistenceObject persistenceObject, MethodInfo methodInfo, object[] returnParameterValueCollection, object returnResult) { if (returnParameterValueCollection == null) { return; } var gu = GeneralUtility.GetInstance(); var persistenceObjectType = persistenceObject.GetType(); var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectType.FullName); var parameterNameCollection = from paramInfo in methodInfo.GetParameters() orderby paramInfo.Position select paramInfo.Name; foreach (DictionaryEntry item in fieldMapperCollection) { var itemValue = item.Value.ToString(); var itemKey = item.Key.ToString(); if (itemValue.IndexOf("{returnParameter}") == 0) { if (itemValue.IndexOf("{returnParameter}.") == 0) { SetMemberValue(persistenceObjectType, persistenceObject, itemKey, gu.GetMemberValue(returnResult, itemValue.Substring("{returnParameter}.".Length))); } else { SetMemberValue(persistenceObjectType, persistenceObject, itemKey, returnResult); } } else { var index = 0; foreach (var parameterName in parameterNameCollection) { if (itemValue.IndexOf(parameterName) == 0) { if (itemValue.IndexOf(parameterName + ".") == 0) { SetMemberValue(persistenceObjectType, persistenceObject, itemKey, gu.GetMemberValue(returnParameterValueCollection[index], itemValue.Substring(parameterName.Length + 1))); } else if (itemValue.IndexOf("[") > -1) { SetMemberValue(persistenceObjectType, persistenceObject, itemKey, gu.GetMemberValue(returnParameterValueCollection[index], itemValue)); } else { SetMemberValue(persistenceObjectType, persistenceObject, itemKey, returnParameterValueCollection[index]); } break; } // implied names if (persistenceObjectType.GetMember(parameterName, BindingFlags.Public | BindingFlags.Instance).Length > 0) { SetMemberValue(persistenceObjectType, persistenceObject, parameterName, returnParameterValueCollection[index]); } index++; } } } }
public bool HasObjectToObjectMapper(IPersistenceObject persistenceObject) { var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObject.GetType().FullName, ObjectMapperType.Obj); return(mapper != null); }