Ejemplo n.º 1
0
        public IList<IDataObject> Get(string objectType, IList<string> identifiers, bool retainSession)
        {
            IList<IDataObject> dataObjects = new List<IDataObject>();
              Proxy proxy = null;
              Session session = null;

              try
              {
            Connect(ref proxy, ref session);

            DataObject objDef = GetObjectDefinition(objectType);

            if (objDef != null)
            {
              string classObject = objDef.objectNamespace;
              string key = objDef.keyProperties.FirstOrDefault().keyPropertyName;
              string keyValues = "('" + string.Join("','", identifiers) + "')";

              if (classObject.ToLower() == "document" || classObject.ToLower() == "tag")
              {
            string eql = "START WITH {0} SELECT {1} WHERE {2} IN {3}";
            StringBuilder builder = new StringBuilder();

            foreach (DataProperty dataProp in objDef.dataProperties)
            {
              string item = Utilities.ToQueryItem(dataProp);

              if (!string.IsNullOrEmpty(item))
              {
                if (builder.Length > 0)
                  builder.Append(",");

                builder.Append(item);
              }
            }

            eql = string.Format(eql, classObject, builder.ToString(), key, keyValues);

            EqlClient eqlClient = new EqlClient(session);
            DataTable result = eqlClient.Search(session, eql, new object[0], 0, -1);

            dataObjects = ToDataObjects(result, objDef);

            //
            // return content when requesting single item like IW data layer
            //
            if (dataObjects.Count == 1 && identifiers.Count == 1)
            {
              IList<int> docIds = GetDocumentIds(dataObjects);
              IList<IContentObject> contentObjects = GetContents(objectType, docIds, proxy, session);

              //
              // make data object a content object
              //
              if (contentObjects.Count > 0)
              {
                IDataObject dataObject = dataObjects.FirstOrDefault();
                IContentObject contentObject = new GenericContentObject { ObjectType = objectType };

                contentObject.content = contentObjects[0].content;
                contentObject.contentType = contentObjects[0].contentType;
                contentObject.identifier = contentObjects[0].identifier;

                foreach (DataProperty prop in objDef.dataProperties)
                {
                  object value = dataObject.GetPropertyValue(prop.propertyName);
                  contentObject.SetPropertyValue(prop.propertyName, value);
                }

                return new List<IDataObject> { contentObject };
              }
            }
              }
              else
              {
            throw new Exception("Class object [" + classObject + "] not supported.");
              }
            }
            else
            {
              throw new Exception("Object type " + objectType + " not found.");
            }
              }
              finally
              {
            if (!retainSession) Disconnect(ref proxy, ref session);
              }

              return dataObjects;
        }
Ejemplo n.º 2
0
        public override IList<IDataObject> Get(string objectType, DataFilter filter, int pageSize, int startIndex)
        {
            IList<IDataObject> dataObjects = new List<IDataObject>();
              Proxy proxy = null;
              Session session = null;

              try
              {
            Connect(ref proxy, ref session);

            DataObject objDef = GetObjectDefinition(objectType);

            if (objDef != null)
            {
              string classObject = objDef.objectNamespace;
              string classIds = objDef.tableName.Replace("_", ",");

              if (classObject.ToLower() == "document" || classObject.ToLower() == "tag")
              {
            string eql = "START WITH {0} SELECT {1} WHERE Class.Id IN ({2})";
            StringBuilder builder = new StringBuilder();

            foreach (DataProperty dataProp in objDef.dataProperties)
            {
              string item = Utilities.ToQueryItem(dataProp);

              if (!string.IsNullOrEmpty(item))
              {
                if (builder.Length > 0)
                  builder.Append(",");

                builder.Append(item);
              }
            }

            eql = string.Format(eql, classObject, builder.ToString(), classIds);

            if (filter != null)
            {
              string whereClause = Utilities.ToSqlWhereClause(filter, objDef);
              if (!string.IsNullOrEmpty(whereClause))
              {
                eql += whereClause.Replace(" WHERE ", " AND ");
              }
            }

            EqlClient eqlClient = new EqlClient(session);
            DataTable result = eqlClient.Search(session, eql, new object[0], startIndex, pageSize);

            dataObjects = ToDataObjects(result, objDef);
              }
              else
              {
            throw new Exception("Class object [" + classObject + "] not supported.");
              }
            }
            else
            {
              throw new Exception("Object type " + objectType + " not found.");
            }
              }
              finally
              {
            Disconnect(ref proxy, ref session);
              }

              return dataObjects;
        }