Пример #1
0
        protected DataObject CreateObjectDefinition(Proxy proxy, ClassObject classObject)
        {
            if (classObject.Ids == null || classObject.Ids.Count == 0)
              {
            return null;
              }

              string metadataQuery = string.Empty;

              if (classObject.ObjectType == ObjectType.Tag)
              {
            metadataQuery = string.Format(TAG_METADATA_SQL, (int)ObjectType.Tag);
              }
              else if (classObject.ObjectType == ObjectType.Document)
              {
            metadataQuery = string.Format(DOCUMENT_METADATA_SQL, (int)ObjectType.Document);
              }
              else
              {
            throw new Exception(string.Format("Object type [{0}] not supported.", classObject.ObjectType));
              }

              int status = 0;
              string result = proxy.query(metadataQuery, ref status);
              XmlDocument resultXml = new XmlDocument();
              resultXml.LoadXml(result);

              string type = Enum.GetName(typeof(ObjectType), classObject.ObjectType);
              DataObject objDef = new DataObject();
              objDef.objectNamespace = type;
              objDef.objectName = classObject.Name + "(" + type + ")";
              objDef.tableName = string.Join("_", classObject.Ids.ToArray());
              objDef.keyDelimeter = _keyDelimiter;

              Configuration config = GetConfiguration(objDef);
              if (config == null)
            return null;

              Map codeMap = config.Mappings.ToList<Map>().Find(x => x.Destination == (int)Destination.Code);
              if (codeMap == null)
              {
            throw new Exception("No mapping configured for key property.");
              }

              objDef.keyProperties = new List<KeyProperty>()
              {
            new KeyProperty() { keyPropertyName = codeMap.Column }
              };

              foreach (XmlNode attrNode in resultXml.DocumentElement.ChildNodes)
              {
            DataProperty dataProp = new DataProperty();
            dataProp.columnName = attrNode.SelectSingleNode("char_name").InnerText;

            string propertyName = Utilities.ToPropertyName(dataProp.columnName);
            if (objDef.dataProperties.Find(x => x.propertyName == propertyName) != null)
              continue;

            dataProp.propertyName = propertyName;
            dataProp.dataType = Utilities.ToCSharpType(attrNode.SelectSingleNode("char_data_type").InnerText);
            dataProp.dataLength = Int32.Parse(attrNode.SelectSingleNode("char_length").InnerText);

            if (attrNode.SelectSingleNode("is_system_char").InnerText == "1")
            {
              dataProp.columnName += Utilities.SYSTEM_ATTRIBUTE_TOKEN;
            }
            else
            {
              dataProp.columnName += Utilities.USER_ATTRIBUTE_TOKEN;
            }

            objDef.dataProperties.Add(dataProp);
              }

              // add related properties
              foreach (Map m in config.Mappings.Where(x => x.Destination == (int)Destination.Relationship).Select(m => m))
              {
            DataProperty dataProp = new DataProperty();
            string propertyName = Utilities.ToPropertyName(m.Column);
            DataProperty checkProp = objDef.dataProperties.Find(x => x.propertyName == propertyName);

            if (checkProp != null)  // property already exists, update its column name
            {
              checkProp.columnName = m.Column + Utilities.RELATED_ATTRIBUTE_TOKEN;
            }
            else
            {
              dataProp.columnName = m.Column + Utilities.RELATED_ATTRIBUTE_TOKEN;
              dataProp.propertyName = propertyName;
              dataProp.dataType = DataType.String;
              objDef.dataProperties.Add(dataProp);
            }
              }

              // add other properties
              foreach (Map m in config.Mappings.Where(x => x.Destination != (int)Destination.Relationship &&
            x.Destination != (int)Destination.Attribute && x.Destination != (int)Destination.None).Select(m => m))
              {
            DataProperty dataProp = new DataProperty();
            string propertyName = Utilities.ToPropertyName(m.Column);
            DataProperty checkProp = objDef.dataProperties.Find(x => x.propertyName == propertyName);

            if (checkProp != null)  // property already exists, update its column name
            {
              checkProp.columnName = m.Column + Utilities.OTHER_ATTRIBUTE_TOKEN;
            }
            else
            {
              dataProp.columnName = m.Column + Utilities.OTHER_ATTRIBUTE_TOKEN;
              dataProp.propertyName = propertyName;
              dataProp.dataType = DataType.String;
              objDef.dataProperties.Add(dataProp);
            }
              }

              return objDef;
        }