Ejemplo n.º 1
0
        protected override IDictionary <string, IRoutingAttribute> ParserRoutings(string defaultTableName,
                                                                                  XmlNodeList routingNodes)
        {
            IDictionary <string, IRoutingAttribute> routings = new Dictionary <string, IRoutingAttribute>();

            if (null == routingNodes || 0 == routingNodes.Count)
            {
                //set the default value when the routingnodes is not exist

                IRoutingAttribute defaultRouting = new RoutingAttribute
                {
                    Name        = DefaultRoutingName,
                    Permission  = PermissionMode.WR,
                    StorageName = StorageParser.DefaultStorageName,
                    TableName   = defaultTableName,
                };
                routings.Add(DefaultRoutingName, defaultRouting);
                return(routings);
            }

            foreach (XmlNode node in routingNodes)
            {
                IRoutingAttribute routing = ParserRouting(defaultTableName, node);
                if (null != routing)
                {
                    routings.Add(routing.Name, routing);
                }
            }
            return(routings);
        }
Ejemplo n.º 2
0
        public IFakeCommandAttribute BuildSaveFakeCommandByRouting <T>(PermissionMode permission, T target,
                                                                       IRoutingAttribute routing,
                                                                       IObjectAttribute objectAttribute,
                                                                       PropertyInfo[] properties)
            where T : IAlbianObject
        {
            if (null == routing)
            {
                throw new ArgumentNullException("routing");
            }
            if (null == properties || 0 == properties.Length)
            {
                throw new ArgumentNullException("properties");
            }
            if (null == objectAttribute)
            {
                throw new ArgumentNullException("objectAttribute");
            }
            if (0 == (permission & routing.Permission))
            {
                if (null != Logger)
                {
                    Logger.WarnFormat("The routing permission {0} is no enough.", permission);
                }
                return(null);
            }

            return(target.IsNew
                       ?
                   BuildCreateFakeCommandByRouting(permission, target, routing, objectAttribute, properties)
                       :
                   BuildModifyFakeCommandByRouting(permission, target, routing, objectAttribute, properties));
        }
Ejemplo n.º 3
0
        public static string GetTableFullName(IRoutingAttribute routing, IAlbianObject target)
        {
            HashAlbianObjectHandler <IAlbianObject> handler = HashAlbianObjectManager.GetHandler(routing.Name, AssemblyManager.GetFullTypeName(target));
            string tableName = null == handler
                                   ? routing.TableName
                                   : String.Format("{0}{1}", routing.TableName, handler(target));

            return("dbo" == routing.Owner || String.IsNullOrEmpty(routing.Owner)
                       ? tableName
                       : String.Format("[{0}].[{1}]", routing.Owner, tableName));
        }
Ejemplo n.º 4
0
        public IFakeCommandAttribute BuildCreateFakeCommandByRouting <T>(PermissionMode permission, T target,
                                                                         IRoutingAttribute routing,
                                                                         IObjectAttribute objectAttribute,
                                                                         PropertyInfo[] properties)
            where T : IAlbianObject
        {
            if (null == routing)
            {
                throw new ArgumentNullException("routing");
            }
            if (null == properties || 0 == properties.Length)
            {
                throw new ArgumentNullException("properties");
            }
            if (null == objectAttribute)
            {
                throw new ArgumentNullException("objectAttribute");
            }
            if (0 == (permission & routing.Permission))
            {
                if (null != Logger)
                {
                    Logger.WarnFormat("The routing permission {0} is no enough.", permission);
                }
                return(null);
            }



            //create the connection string
            IStorageAttribute storageAttr = (IStorageAttribute)StorageCache.Get(routing.StorageName);

            if (null == storageAttr)
            {
                if (null != Logger)
                {
                    Logger.WarnFormat(
                        "No {0} rounting mapping storage attribute in the sotrage cache.Use default storage.",
                        routing.Name);
                }
                storageAttr = (IStorageAttribute)StorageCache.Get(StorageParser.DefaultStorageName);
            }

            if (!storageAttr.IsHealth)
            {
                if (null != Logger)
                {
                    Logger.WarnFormat("Routing:{0},Storage:{1} is not health.", routing.Name, storageAttr.Name);
                }
                return(null);
            }

            var sbInsert = new StringBuilder();
            var sbCols   = new StringBuilder();
            var sbValues = new StringBuilder();

            IList <DbParameter> paras = new List <DbParameter>();

            //create the hash table name
            string tableFullName = Utils.GetTableFullName(routing, target);

            //build the command text
            IDictionary <string, IMemberAttribute> members = objectAttribute.MemberAttributes;

            foreach (PropertyInfo property in properties)
            {
                object value = property.GetValue(target, null);
                if (null == value)
                {
                    continue;
                }
                IMemberAttribute member = members[property.Name];
                if (!member.IsSave)
                {
                    continue;
                }
                sbCols.AppendFormat("{0},", member.FieldName);
                string paraName = DatabaseFactory.GetParameterName(storageAttr.DatabaseStyle, member.FieldName);
                sbValues.AppendFormat("{0},", paraName);
                paras.Add(DatabaseFactory.GetDbParameter(storageAttr.DatabaseStyle, paraName, member.DBType, value,
                                                         member.Length));
            }
            int colsLen = sbCols.Length;

            if (0 < colsLen)
            {
                sbCols.Remove(colsLen - 1, 1);
            }
            int valLen = sbValues.Length;

            if (0 < valLen)
            {
                sbValues.Remove(valLen - 1, 1);
            }
            sbInsert.AppendFormat("INSERT INTO {0} ({1}) VALUES({2}) ", tableFullName, sbCols, sbValues);
            IFakeCommandAttribute fakeCmd = new FakeCommandAttribute
            {
                CommandText = sbInsert.ToString(),
                Paras       = ((List <DbParameter>)paras).ToArray(),
                StorageName = routing.StorageName
            };

            return(fakeCmd);
        }