Beispiel #1
0
        public List <dynamic> GetBySqlCommand(Model model, System.Data.SqlClient.SqlCommand command)
        {
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(SqlHelper.GetSqlCon(this.sqlCon, model).ToString()))
            {
                con.Open();
                command.Connection = con;
                var table = SqlDataLoader.GetSqlData(command);

                var keyCol = SqlHelper.GetKeyCol(model);

                List <dynamic> items = new List <dynamic>();
                con.Close();
                if (table.Columns.Contains(keyCol) == false)
                {
                    throw new Exception("Can't Gerneration Query Because The Id Column Isn't Included!");
                }
                if (table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        IObjectProxy proxy = SqlDataLoader.getProxy(model, row[keyCol], this.sqlCon, this.ConFac);
                        SqlDataLoader.LoadSqlData(proxy, row, this.sqlCon, this.ConFac);
                        proxy.IsSave = SaveType.Exists;
                        items.Add(proxy);
                    }
                }
                return(items);
            }
        }
Beispiel #2
0
        private object ReverseObject(object src)
        {
            object      retVal = src;
            ProxyResult prs    = src as ProxyResult;

            if (prs != null)
            {
                var fx = new Func <string, IObjectProxy>(s =>
                {
                    IObjectProxy retObj = null;
                    if (!CustomProxy.IsProxyAvailable(prs.Type))
                    {
                        ObjectProxy proxy = CreateProxyInternal(s, prs.Type);
                        retObj            = proxy.ActLike <IObjectProxy>(prs.Type);
                    }
                    else
                    {
                        retObj = CustomProxy.GetCustomProxy(prs.Type, this, s);
                    }

                    return(retObj);
                });

                retVal = abandonnableProxies.AddOrUpdate(prs.UniqueName, fx, (s, o) => o ?? fx(s));
            }

            return(retVal);
        }
        private Object GetValueSingle(IObjectProxy ob, Property property, string exp)
        {
            switch (exp[0])
            {
            case '#':
                return(GetValueSingle(ob.Owner, property, exp.Substring(1)));

            case '.':


                if (string.IsNullOrEmpty(exp.Substring(1)))
                {
                    return(null);
                }
                return(ob[exp.Substring(1)]);

            case '$':
                return(GetStaticVlue(property, exp.Substring(1)));

            case '@':

                return(GetContexValue(exp.Substring(1)));

            //  return ob;



            default:
                return("");
            }
        }
Beispiel #4
0
        protected override void ImplementBusinessLogic()
        {
            AutoViewFactory factory = new AutoViewFactory(Info.AppSqlCon, this);
            View            view    = factory.GetView(mViewId);

            var sql = this.GetViewSql(view);

            global::Soway.Model.SqlServer.dbContext context = new global::Soway.Model.SqlServer.dbContext(sql, this);
            IObjectProxy iObjectProxy  = context.GetDetail(view.Model, this.mObjectId);
            var          method        = view.Operations.FirstOrDefault(p => p.Operation.Operation.ID == this.mOperationId);
            var          methodContext = new Soway.Model.ModelMethodContext(sql, this);

            if (method != null)
            {
                try
                {
                    methodContext.ExcuteOperation(iObjectProxy, method.Operation.Operation);
                    Data.IsSuccess = true;
                    Data.ReturnMsg = method.Operation.SuccessMsg;
                }
                catch (Exception e)
                {
                    Data.Error     = new ErrorInfo(ErrorDescription.CODE_RUN_OPERATION_ERROR, ErrorDescription.MESSAGE_RUN_OPERATION_ERROR);
                    Data.IsSuccess = false;
                    Data.ReturnMsg = method.Operation.ErrorMsg + e.ToString();
                }
            }
        }
Beispiel #5
0
        private void  CreateComplexRelationBuild(IObjectProxy proxy,
                                                 System.Data.SqlClient.SqlTransaction trans,
                                                 Relation relation, IObjectProxy itemProxy)
        {
            if (IsExits(itemProxy, trans) == false)
            {
                Create(itemProxy, trans);
            }

            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();

            command.CommandText = String.Format(@"IF NOT EXISTS(SELECT * FROM {0}  WHERE {1}=@{1} AND {2} =@{2}) 
                BEGIN
                    INSERT {0}  ({1},{2}) VALUES (@{1},@{2})
                END",
                                                relation.RelationTable, relation.PropertyColumn, relation.TargetColumn);


            if (relation.RelationType == RelationType.Recurve)
            {
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.PropertyColumn, proxy.ID));
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.TargetColumn, itemProxy.ID));
            }
            else
            {
                //这个应该是对的。。。
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.PropertyColumn, itemProxy.ID));
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.TargetColumn, proxy.ID));
            }
            command.Transaction = trans;
            command.Connection  = trans.Connection;
            command.ExecuteNonQuery();
        }
Beispiel #6
0
        private static ObjValuePair GetAddItem(IObjectProxy objectProxy, Model.ViewItem item)
        {
            var addItem = new ObjValuePair()
            {
                PrpId       = item.Property.Name,
                PrpShowName = item.Name,
                ObjId       = (objectProxy[item.Property.Name] ?? "").ToString(),
                FmtValue    = (objectProxy[item.Property.Name] ?? "").ToString(),
                PrpType     = item.Property.PropertyType,
                ReadOnly    = item.ReadOnly,
                EditType    = item.EditType,
                PrpModelId  = item.Property.Model == null ? 0 : item.Property.Model.ID,
            };

            if (item.Property.PropertyType == Data.PropertyType.Date)
            {
                var date = (DateTime)objectProxy[item.Property.Name];
                if (date != null)
                {
                    addItem.FmtValue = date.ToString("yyyy-MM-dd");
                }
            }

            if (item.Property.PropertyType == Data.PropertyType.Time)
            {
                var date = (DateTime)objectProxy[item.Property.Name];
                if (date != null)
                {
                    addItem.FmtValue = date.ToString("HH:mm:ss");
                }
            }

            if (item.Property.PropertyType == Data.PropertyType.BusinessObject)
            {
                addItem.FmtValue = (objectProxy[item.Property.Name] ?? "").ToString();
                if (objectProxy[item.Property.Name] != null)
                {
                    addItem.ObjId = ((objectProxy[item.Property.Name] as IObjectProxy).ID ?? "").ToString();
                }
                else
                {
                    addItem.ObjId = "";
                }
            }
            else if (item.Property.PropertyType == Data.PropertyType.Enum)
            {
                var valueItem = item.Property.Model.EnumValues.FirstOrDefault(p => p.Value == System.Convert.ToInt32(objectProxy[item.Property.Name]));
                if (valueItem != null)
                {
                    addItem.FmtValue = valueItem.String;
                    addItem.ObjId    = valueItem.Value.ToString();
                }
                else
                {
                    addItem.FmtValue = (objectProxy[item.Property.Name] ?? "").ToString();
                    addItem.ObjId    = (objectProxy[item.Property.Name] ?? "").ToString();
                }
            }
            return(addItem);
        }
Beispiel #7
0
        private void DeleteComplexRelationBuild(IObjectProxy proxy,
                                                System.Data.SqlClient.SqlTransaction trans,
                                                Relation relation, IObjectProxy itemProxy)
        {
            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();

            command.CommandText = String.Format(@"DELETE {0}  WHERE {1}=@{1} AND {2} =@{2}",
                                                relation.RelationTable, relation.PropertyColumn, relation.TargetColumn);


            if (relation.RelationType == RelationType.Recurve)
            {
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.PropertyColumn, proxy.ID));
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.TargetColumn, itemProxy.ID));
            }
            else
            {
                //这个应该是对的。。。
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.PropertyColumn, itemProxy.ID));
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + relation.TargetColumn, proxy.ID));
            }
            command.Transaction = trans;
            command.Connection  = trans.Connection;
            command.ExecuteNonQuery();
        }
Beispiel #8
0
 public ItemQueryContext(Soway.Model.View.View view, IObjectProxy current)
 {
     this.ListView     = view;
     this.QueryContext = null;
     this.Current      = current;
     this.CurrentIndex = 1;
     this.TotalRecord  = 1;
 }
Beispiel #9
0
        /// <summary>
        /// Creates an instance of target type and fills from a string map.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        public static T FromStringMap <T>(Dictionary <string, string> map)
        {
            IObjectProxy proxy  = Get <T>();
            T            result = (T)proxy.CreateObject();

            proxy.ReadFromStringMap(result, map);
            return(result);
        }
        private void ExcuteListMethod(IObjectProxy ob, ICommand command)
        {
            DynamicObject proxyArray = ob[command.Property] as DynamicObject;
            object        ob2        = new object();

            proxyArray.TryInvokeMember(new ObjectInvokeMemberBinder(command.Exp), new object[] { }
                                       , out ob2);
        }
Beispiel #11
0
        private static ObjectKeyValuePair toValuePair(IObjectProxy iob)
        {
            ObjectKeyValuePair pair = new ObjectKeyValuePair();

            pair.ObjectId = iob.ID.ToString();
            pair.Value    = iob.ToString();
            return(pair);
        }
Beispiel #12
0
        public Message Get(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string           sessionToken    = this.GetSessionToken(information);
                MessagePath      path            = new MessagePath(information);
                ISecurityManager securityManager = IoC.Get <ISecurityManager>();
                object           response;
                if (path.IsByParent)
                {
                    MessagePath parentPath = new MessagePath(information, true);
                    if (!parentPath.HasKeyParameter)
                    {
                        throw new ArgumentException("A link to a parent must have parameter key");
                    }
                    dynamic      bo     = securityManager.DynamicGetBO(parentPath.DtoType, sessionToken);
                    object       parent = bo.GetOne(string.Empty, parentPath.QueryInfo);
                    IObjectProxy proxy  = ObjectProxyFactory.Get(parent);
                    object       value  = proxy.GetValue(parent, path.ParentKeyParameter);
                    QueryInfo    query  = new QueryInfo();
                    query.Equal(path.KeyParameterName, value.ToString());
                    bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    response = bo.GetOne(string.Empty, query);
                }
                else
                {
                    dynamic bo = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    if (path.HasKeyParameter)
                    {
                        response = bo.GetOne(string.Empty, path.QueryInfo);
                    }
                    else
                    {
                        response = bo.GetAll(path.QueryInfo);
                    }
                }
                IServiceConfiguration  configuration = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings      = IoC.Get <JsonSerializerSettings>();
                if (configuration.IsHateoas)
                {
                    response = this.ConvertToHateoas(response, configuration, path);
                }
                return(response.ToJsonMessage(settings, configuration.Indented));
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    return(ex.InnerException.Message.ToJsonMessage());
                }
                else
                {
                    return(ex.Message.ToJsonMessage());
                }
            }
        }
Beispiel #13
0
        private System.Data.SqlClient.SqlCommand BuildCreateCommand(IObjectProxy proxy,
                                                                    System.Data.SqlClient.SqlTransaction trans,
                                                                    string ParentCol = "",
                                                                    object id        = null)
        {
            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();

            string values = "\r\n VALUES(";

            command.CommandText = "INSERT " + proxy.Model.DataTableName + "(";

            foreach (var property in proxy.Model.Properties.Where(p => p.PropertyType == PropertyType.SerialNo))
            {
                if (String.IsNullOrEmpty((property.DBName ?? "").Replace("[", "").Replace("]", "")) == false)
                {
                    var serialNo = createSerialNo(proxy, property);
                    proxy[property] = serialNo;

                    if (proxy.Model.AutoSysId == false && proxy.Model.IdProperty == property)
                    {
                        proxy.ID = serialNo;
                    }
                }
            }
            var items = GetColsAndValues(proxy, trans, OperationType.Insert);

            foreach (var item in items)
            {
                command.CommandText += "[" + item.Key + "]\r\n,";
                values += "@" + item.Key + "\r\n,";
                command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + item.Key, item.Value));
            }
            if (String.IsNullOrEmpty(ParentCol) == false)
            {
                if (command.Parameters.Contains("@" + ParentCol) == false)
                {
                    command.CommandText += "[" + ParentCol + "]\r\n,";

                    command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@" + ParentCol, id));
                    values += "@" + ParentCol + "\r\n,";
                }
                else
                {
                    command.Parameters["@" + ParentCol].Value = id;
                }
            }
            command.CommandText  = command.CommandText.Substring(0, command.CommandText.Length - 1);
            command.CommandText += ")\r\n" + values.Substring(0, values.Length - 1) + ")\r\n ";
            if (proxy.Model.Properties.Count(p => p.PropertyType == PropertyType.IdentifyId) > 0 || proxy.Model.AutoSysId)
            {
                command.CommandText += "select @@IDENTITY \r\n";
            }



            return(command);
        }
Beispiel #14
0
        /// <summary>
        /// Fills the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public static void Fill(object source, object target)
        {
            IObjectProxy sourceProxy = Get(source);
            IObjectProxy targetProxy = Get(target);

            foreach (string propertyName in sourceProxy.PropertyNames)
            {
                targetProxy.SetValue(target, propertyName, sourceProxy.GetValue(source, propertyName));
            }
        }
Beispiel #15
0
 /// <summary>
 /// 将object值赋给proxy
 /// </summary>
 /// <param name="proxy"></param>
 /// <param name="ob"></param>
 public void SetProxy(ref IObjectProxy proxy, object ob)
 {
     if (proxy.Model.ModelType != ModelType.Enum)
     {
         setProxy(ref proxy, ob, ProxyDic);
     }
     else
     {
         proxy.ID = ob;
     }
 }
Beispiel #16
0
        public IObjectProxy GetDetail(Model model, object id, bool LoadDetail = true)
        {
            if (String.IsNullOrEmpty((id ?? "").ToString()))
            {
                return(null);
            }
            IObjectProxy proxy = SqlDataLoader.getProxy(model, id, this.sqlCon, this.ConFac);

            LoadDataDetail(model, id, LoadDetail, proxy);
            return(proxy);
        }
Beispiel #17
0
        /// <summary>
        /// Fills target object from source object, taking into account th fields to be avoided.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        public void FillUpdate(object source, object target)
        {
            IObjectProxy proxy = ObjectProxyFactory.GetByType(this.EntityType);

            foreach (IMetamodelField field in this.Fields)
            {
                if (!field.AvoidUpdate)
                {
                    proxy.SetValue(target, field.Name, proxy.GetValue(source, field.Name));
                }
            }
        }
Beispiel #18
0
        private String createSerialNo(IObjectProxy proxy, Property property)
        {
            var    str        = property.Format;
            var    nostrs     = str.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
            string Fomate     = "";
            int    len        = 0;
            var    dataFormat = "";
            int    prelen     = 0;

            foreach (var item in nostrs)
            {
                if (item == "S")
                {
                }
                else if (item[0] == 'S')
                {
                    //时间
                    var strs = item.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    len = System.Convert.ToInt32(strs[0].Substring(1));
                    if (strs.Length > 1)
                    {
                        prelen = System.Convert.ToInt32(strs[1]);
                    }
                }
                else if (item[0] == 'D')
                {
                    var date = new Soway.DB.DBContext(GetSqlCon(proxy.Model).ToString()).GetServerDateTime().ToString(item.Substring(1));
                    Fomate += date;
                }
                else if (item[0] == 's')
                {
                    Fomate += item.Substring(1);
                }
                else
                {
                    Fomate += item.Trim();
                }
            }
            string getPreStr = Fomate;

            if (prelen == 0)
            {
                prelen = Fomate.Length;
            }
            if (string.IsNullOrEmpty(Fomate) == false)
            {
                getPreStr = Fomate.Substring(0, prelen);
            }
            //   //// // System.Diagnostics.Trace.WriteLine("preLen:" + getPreStr);
            var s = new Soway.DB.DBContext(GetSqlCon(proxy.Model).ToString()).GetSerialNo(getPreStr, len, "");

            return(s.Insert(prelen, Fomate.Substring(prelen, Fomate.Length - prelen)));
        }
Beispiel #19
0
 public dynamic GetFromProxy(IObjectProxy proxy)
 {
     if (proxy.Model.ModelType != ModelType.Enum)
     {
         Dictionary <Model, Dictionary <string, object> > ProxyDic = new Dictionary <Model, Dictionary <string, object> >();
         var ob = getFromProxy(proxy, ProxyDic);
         return(ob);
     }
     else
     {
         return(proxy.ID);
     }
 }
Beispiel #20
0
        /// <summary>
        /// Gets the object key.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public ObjectKey GetObjectKey(object entity)
        {
            List <KeyValuePair <string, object> > keyPairs = new List <KeyValuePair <string, object> >();
            IObjectProxy proxy = ObjectProxyFactory.GetByType(this.EntityType);

            foreach (IMetamodelField field in this.Fields)
            {
                if (field.IsPrimaryKey)
                {
                    keyPairs.Add(new KeyValuePair <string, object>(field.Name, proxy.GetValue(entity, field.Name)));
                }
            }
            return(new ObjectKey(this.EntityType.Name, keyPairs));
        }
Beispiel #21
0
        /// <summary>
        /// Given a source type, clones the type but only the common type properties.
        /// </summary>
        /// <param name="sourceType">Type of the source.</param>
        /// <param name="domain">The domain.</param>
        /// <param name="assemblyNameStr">The assembly name string.</param>
        /// <param name="dynamicModuleName">Name of the dynamic module.</param>
        /// <param name="typeName">Name of the type.</param>
        /// <returns></returns>
        public static Type CloneCommonType(Type sourceType, AppDomain domain, string assemblyNameStr, string dynamicModuleName, string typeName)
        {
            TypeBuilder  typeBuilder = TypeBuilderHelper.GetClassTypeBuilder(domain, assemblyNameStr, dynamicModuleName, typeName);
            IObjectProxy entityProxy = ObjectProxyFactory.GetByType(sourceType);

            foreach (PropertyInfo propertyInfo in entityProxy.Properties)
            {
                if (TypesManager.IsCommonType(propertyInfo.PropertyType))
                {
                    TypeBuilderHelper.AddProperty(typeBuilder, propertyInfo.Name, propertyInfo.PropertyType);
                }
            }
            return(typeBuilder.CreateType());
        }
        public void TestObjectProxyFactoryGetProxy()
        {
            IObjectProxy proxy1 = ObjectProxyFactory.Get <TestClass1>();

            Assert.IsNotNull(proxy1);
            Assert.AreEqual(typeof(TestClass1), proxy1.ProxyType);
            IObjectProxy proxy2 = ObjectProxyFactory.GetByType(typeof(TestClass1));

            Assert.AreSame(proxy1, proxy2);
            TestClass1   instance = new TestClass1();
            IObjectProxy proxy3   = ObjectProxyFactory.Get(instance);

            Assert.AreSame(proxy1, proxy3);
        }
Beispiel #23
0
        protected override void ImplementBusinessLogic()
        {
            AutoViewFactory factory = new AutoViewFactory(this.Info.AppSqlCon, this);
            View            view    = factory.GetView(this.Option.SaveObj.ViewID);
            var             sql     = GetViewSql(view);


            global::Soway.Model.SqlServer.dbContext context = new global::Soway.Model.SqlServer.dbContext(sql, this);

            IObjectProxy iObjectProxy = context.GetDetail(view.Model, this.Option.SaveObj.Id);

            DataFormator.ObjUpdateToProxy(this.Option.SaveObj, iObjectProxy);
            context.Save(iObjectProxy);
        }
Beispiel #24
0
 public void Delete(IObjectProxy proxy)
 {
     foreach (var trigger in proxy.Model.Triggers.Where(p => p.ModelTriggerType == ModelTriggerType.Delete))
     {
         new ModelMethodContext(this.sqlCon, this.ConFac).ExcuteOperation(proxy, trigger);
     }
     using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(this.GetSqlCon(proxy.Model).ToString()))
     {
         con.Open();
         System.Data.SqlClient.SqlTransaction trans = con.BeginTransaction();
         delete(proxy, trans);
         trans.Commit();
     }
 }
Beispiel #25
0
 /// <summary>
 /// Adds from object.
 /// </summary>
 /// <param name="instance">The instance.</param>
 public void AddFromObject(object instance)
 {
     if (instance != null)
     {
         IObjectProxy proxy = ObjectProxyFactory.Get(instance);
         foreach (string propertyName in proxy.PropertyNames)
         {
             object value = proxy.GetValue(instance, propertyName);
             if (value != null)
             {
                 this.AddAttribute(propertyName, value);
             }
         }
     }
 }
Beispiel #26
0
        /// <summary>
        /// Maps to source.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public object MapToSource(object target)
        {
            if (target == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxySource.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.tgtToSrc)
            {
                proxySource.SetValue(result, entry.Value, proxyTarget.GetValue(target, entry.Key));
            }
            return(result);
        }
Beispiel #27
0
        /// <summary>
        /// Maps to target.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public object MapToTarget(object source)
        {
            if (source == null)
            {
                return(null);
            }
            IObjectProxy proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            object       result      = proxyTarget.CreateObject();

            foreach (KeyValuePair <string, string> entry in this.srcToTgt)
            {
                proxyTarget.SetValue(result, entry.Value, proxySource.GetValue(source, entry.Key));
            }
            return(result);
        }
Beispiel #28
0
        /// <summary>
        /// Adds default mapping.
        /// </summary>
        /// <returns></returns>
        public IMapper DefaultMap()
        {
            IObjectProxy   proxySource = ObjectProxyFactory.GetByType(this.SourceType);
            IObjectProxy   proxyTarget = ObjectProxyFactory.GetByType(this.TargetType);
            IList <string> sourceNames = proxySource.PropertyNames.ToList();
            IList <string> targetNames = proxyTarget.PropertyNames.ToList();

            foreach (string sourceName in sourceNames)
            {
                if (targetNames.IndexOf(sourceName) > -1)
                {
                    this.AddPropertyMap(sourceName, sourceName);
                }
            }
            return(this);
        }
Beispiel #29
0
 public ResolvableArray(T[] value) : base(null)
 {
     NullType = typeof(T[]);
     foreach (T obj in value)
     {
         IObjectProxy pobj = obj as IObjectProxy;
         if (pobj != null)
         {
             proxies.Add(pobj.ObjectName);
         }
         else
         {
             fixObjects.Add(obj);
         }
     }
 }
Beispiel #30
0
        /// <summary>
        /// Registers a pair entity and dto.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="dtoType">Type of the dto.</param>
        public IMetamodelEntity RegisterEntity(Type entityType, Type dtoType)
        {
            IMetamodelEntity metamodelEntity = this.GetEntity(entityType);

            if (metamodelEntity == null)
            {
                metamodelEntity = new MetamodelEntity(entityType);
                this.RegisterEntity(metamodelEntity);
            }
            metamodelEntity.AddDto(dtoType);
            if (this.dtoMap.ContainsKey(dtoType))
            {
                this.dtoMap[dtoType] = metamodelEntity;
            }
            else
            {
                this.dtoMap.Add(dtoType, metamodelEntity);
            }
            string lowname = dtoType.Name.ToLower();

            if (this.dtoNameMap.ContainsKey(lowname))
            {
                this.dtoNameMap[lowname] = metamodelEntity;
            }
            else
            {
                this.dtoNameMap.Add(lowname, metamodelEntity);
            }
            IObjectProxy   proxy       = ObjectProxyFactory.GetByType(dtoType);
            IList <string> sourceNames = new List <string>();
            IList <string> targetNames = new List <string>();

            foreach (PropertyInfo property in proxy.Properties)
            {
                DtoFieldAttribute attribute = property.GetCustomAttribute <DtoFieldAttribute>();
                if (attribute != null)
                {
                    metamodelEntity.AddFieldMap(dtoType, attribute.Name, property.Name);
                    sourceNames.Add(attribute.Name);
                    targetNames.Add(property.Name);
                }
            }

            ObjectProxyFactory.CreateMap(entityType, dtoType, sourceNames, targetNames);
            return(metamodelEntity);
        }