Example #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;
        }
Example #2
0
        protected List<ClassObject> GetClassObjects(EqlClient eqlClient)
        {
            List<ClassObject> classObjects = new List<ClassObject>();

              if (string.IsNullOrEmpty(_classObjects))
              {
            DataTable dt = eqlClient.RunQuery(CLASS_OBJECTS_EQL);

            foreach (DataRow row in dt.Rows)
            {
              int groupId = (int)row["GroupId"];
              string groupName = Enum.GetName(typeof(GroupType), groupId);
              string path = row["Path"].ToString();

              ClassObject classObject = new ClassObject()
              {
            Name = path,
            ObjectType = (ObjectType)(row["ObjectType"]),
            GroupId = groupId,
            Ids = eqlClient.GetClassIds(groupId, path)
              };

              classObjects.Add(classObject);
            }
              }
              else
              {
            string[] cosParts = _classObjects.Split(',');

            for (int i = 0; i < cosParts.Length; i++)
            {
              string[] coParts = cosParts[i].Trim().Split('.');
              string groupName = coParts[0];
              string className = coParts[1];

              ClassObject classObject = new ClassObject()
              {
            Name = className,
            ObjectType = (ObjectType)Enum.Parse(typeof(ObjectType), groupName),
            GroupId = (int)Enum.Parse(typeof(GroupType), groupName),
            Ids = eqlClient.GetClassIds((int)Enum.Parse(typeof(GroupType), groupName), className)
              };

              classObjects.Add(classObject);
            }
              }

              return classObjects;
        }