예제 #1
0
        private void AddCommandParameter(DbCommand command, IPersistenceObject persistenceObject)
        {
            var gu = GeneralUtility.GetInstance();
            var pf = PersistenceFacade.GetInstance();
            var fieldMapperCollection       = MapperFactory.GetInstance().GetFieldMappers(persistenceObject.GetType().FullName);
            var fieldPropertyNameCollection = GetFieldPropertyNameCollection(persistenceObject);

            foreach (var fieldPropertyName in fieldPropertyNameCollection)
            {
                DbParameter parameter;
                if (fieldMapperCollection.Contains(fieldPropertyName.Name))
                {
                    parameter = pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldMapperCollection[fieldPropertyName.Name].ToString(), gu.GetMemberValue(persistenceObject, fieldPropertyName.Name));
                }
                else // implied name from fieldPropertyName
                {
                    parameter = pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldPropertyName.Name, gu.GetMemberValue(persistenceObject, fieldPropertyName.Name));
                }
                if (!fieldPropertyName.IsRowVersion)
                {
                    continue;
                }
                parameter.Direction = ParameterDirection.InputOutput;
                if (parameter.Value == DBNull.Value)
                {
                    parameter.Value = new SqlBytes(new byte[8]);
                }
            }
        }
예제 #2
0
        private DataTable GetDataTable(IPersistenceObjectCollection persistenceObjectCollection, IObjectKey parentObjectKey, HybridDictionary parameterCollection)
        {
            var pf = PersistenceFacade.GetInstance();
            var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName);

            var dt         = new DataTable();
            var connection = pf.GetDbConnection(_rdbObjectMapperInfo.RdbConnectionKey);

            using (connection)
            {
                var command = connection.CreateCommand();
                command.CommandText = _rdbObjectMapperInfo.MethodNameSelect ?? string.Format("{0}_sel", _rdbObjectMapperInfo.RdbEntityName);
                command.CommandType = CommandType.StoredProcedure;

                pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", parentObjectKey);
                foreach (DictionaryEntry param in parameterCollection)
                {
                    if (fieldMapperCollection.Contains(param.Key.ToString()))
                    {
                        pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldMapperCollection[param.Key.ToString()].ToString(), param.Value);
                    }
                    else // implied name from param.Key.ToString()
                    {
                        pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, param.Key.ToString(), param.Value);
                    }
                }

                var adapter = pf.GetDbDataAdapter(_rdbObjectMapperInfo.RdbConnectionKey);
                adapter.SelectCommand = command;
                adapter.Fill(dt);

                return(dt);
            }
        }
예제 #3
0
        public void Get(IPersistenceObject persistenceObject, object sourceObject)
        {
            if (sourceObject == null)
            {
                return;
            }
            var gu = GeneralUtility.GetInstance();
            var persistenceObjectType = persistenceObject.GetType();
            var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectType.FullName, ObjectMapperType.Obj);

            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);

            foreach (var fieldPropertyName in fieldPropertyNameCollection)
            {
                if (fieldMapperCollection.Contains(fieldPropertyName))
                {
                    gu.SetMemberValue(persistenceObject, fieldPropertyName, gu.GetMemberValue(sourceObject, fieldMapperCollection[fieldPropertyName].ToString()));
                }
                else // implied name from fieldPropertyName
                {
                    gu.SetMemberValue(persistenceObject, fieldPropertyName, gu.GetMemberValue(sourceObject, fieldPropertyName));
                }
            }
        }
예제 #4
0
 public void Insert(IPersistenceObject persistenceObject)
 {
     if (_proxyTypeInsert == null)
     {
         throw new ApplicationException(string.Format("Proxy Insert Method is not defined for object {0}.", persistenceObject.GetType().Name));
     }
     using (var proxy = (IDisposable)Activator.CreateInstance(_proxyTypeInsert))
     {
         try
         {
             var fieldMapperCollection    = MapperFactory.GetInstance().GetFieldMappers(persistenceObject.GetType().FullName);
             var methodInfo               = _proxyTypeInsert.GetMethod(_mapperInfo.MethodNameInsert);
             var parameterValueCollection = PopulateMethodParameters(methodInfo, fieldMapperCollection, persistenceObject);
             ProcessProxyCallBack(proxy, _callbackTypeInsert, _mapperInfo.ProxyCallbackPropertyNameInsert);
             var result = methodInfo.Invoke(proxy, parameterValueCollection);
             Populate(persistenceObject, methodInfo, parameterValueCollection, result);
         }
         catch (TargetInvocationException ex)
         {
             if (ex.InnerException != null)
             {
                 throw ex.InnerException;
             }
             throw;
         }
     }
 }
예제 #5
0
        public void Get(IPersistenceObjectCollection persistenceObjectCollection, HybridDictionary parameterCollection)
        {
            var persistenceObjectType = persistenceObjectCollection.GetType();
            var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObjectType.FullName) as IRecordSetMapper;

            if (mapper == null)
            {
                throw new ApplicationException("Mapper is not defined for " + persistenceObjectType.FullName);
            }
            mapper.Get(persistenceObjectCollection, parameterCollection);
        }
예제 #6
0
        public void GetFromObject(IPersistenceObject persistenceObject, object sourceObject)
        {
            var persistenceObjectType = persistenceObject.GetType();
            var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObjectType.FullName, ObjectMapperType.Obj) as IRecordObjectMapper;

            if (mapper == null)
            {
                throw new ApplicationException(string.Format("Mapper Type Obj is not defined for {0}", persistenceObjectType.FullName));
            }
            mapper.Get(persistenceObject, sourceObject);
        }
예제 #7
0
        public void Get(IPersistenceObject persistenceObject, ObjectMapperType objectMapperType)
        {
            var persistenceObjectType = persistenceObject.GetType();
            var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObjectType.FullName, objectMapperType) as IRecordMapper;

            if (mapper == null)
            {
                throw new ApplicationException(string.Format("Mapper Type {0} is not defined for {1}", objectMapperType, persistenceObjectType.FullName));
            }
            mapper.Get(persistenceObject);
        }
예제 #8
0
        public void Get(IPersistenceObject persistenceObject)
        {
            var persistenceObjectType = persistenceObject.GetType();
            var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObjectType.FullName) as IRecordMapper;

            if (mapper == null)
            {
                throw new ApplicationException("Mapper is not defined for " + persistenceObjectType.FullName);
            }
            mapper.Get(persistenceObject);
        }
예제 #9
0
        public string GetRdbConnectionKey(IPersistenceObject obj)
        {
            var type   = obj.GetType();
            var mapper = MapperFactory.GetInstance().GetObjectMapper(type.FullName);

            if (mapper == null)
            {
                throw new ApplicationException("Mapper is not defined for " + type.FullName);
            }
            if (mapper is IRdbMapper)
            {
                return(((IRdbMapper)mapper).RdbConnectionKey);
            }
            return(string.Empty);
        }
예제 #10
0
        private void RetrieveRowVersion(IPersistenceObject persistenceObject, DbCommand command)
        {
            var rowVersion = persistenceObject as IRowVersion;

            if (rowVersion == null)
            {
                return;
            }
            var providerName           = ConfigurationManager.ConnectionStrings[RdbConnectionKey].ProviderName;
            var fieldMapperCollection  = MapperFactory.GetInstance().GetFieldMappers(persistenceObject.GetType().FullName);
            var rowVersionPropertyName = typeof(IRowVersion).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => p.Name).First();
            var parameterName          = providerName == "System.Data.SqlClient"
                                    ? "@" + fieldMapperCollection[rowVersionPropertyName]
                                    : fieldMapperCollection[rowVersionPropertyName];

            rowVersion.RowVersion = new SqlBytes((SqlBinary)command.Parameters[parameterName.ToString()].Value);
        }
예제 #11
0
        internal static void Populate(IPersistenceObject persistenceObject, DataRow dr)
        {
            var gu = GeneralUtility.GetInstance();
            var fieldMapperCollection       = MapperFactory.GetInstance().GetFieldMappers(persistenceObject.GetType().FullName);
            var fieldPropertyNameCollection = GetFieldPropertyNameCollection(persistenceObject);

            foreach (var fieldPropertyName in fieldPropertyNameCollection)
            {
                if (fieldMapperCollection.Contains(fieldPropertyName.Name))
                {
                    gu.SetMemberValue(persistenceObject, fieldPropertyName.Name, dr[fieldMapperCollection[fieldPropertyName.Name].ToString()]);
                }
                else // implied name from fieldPropertyName
                {
                    gu.SetMemberValue(persistenceObject, fieldPropertyName.Name, dr[fieldPropertyName.Name]);
                }
            }
        }
예제 #12
0
        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;
                }
            }
        }
예제 #13
0
        //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++;
                    }
                }
            }
        }
예제 #14
0
        public bool HasObjectToObjectMapper(string businessObjectClassName)
        {
            var mapper = MapperFactory.GetInstance().GetObjectMapper(businessObjectClassName, ObjectMapperType.Obj);

            return(mapper != null);
        }
예제 #15
0
        public bool HasObjectToObjectMapper(IPersistenceObject persistenceObject)
        {
            var mapper = MapperFactory.GetInstance().GetObjectMapper(persistenceObject.GetType().FullName, ObjectMapperType.Obj);

            return(mapper != null);
        }