public override long GetCount(string objectType, DataFilter filter) { Proxy proxy = null; Session session = null; try { DataObject objDef = GetObjectDefinition(objectType); if (objDef != null) { Connect(ref proxy, ref session); Configuration config = GetConfiguration(objDef); int objType = (int)config.Template.ObjectType; string classIds = objDef.tableName.Replace("_", ","); string eql = string.Empty; if (objType == (int)ObjectType.Tag) { eql = string.Format("START WITH Tag WHERE Class.Id IN ({0})", classIds); } else if (objType == (int)ObjectType.Document) { eql = string.Format("START WITH Document WHERE Class.Id IN ({0})", classIds); } else { throw new Exception(string.Format("Object type [{0}] not supported.", objectType)); } if (filter != null) { string whereClause = Utilities.ToSqlWhereClause(filter, objDef); if (!string.IsNullOrEmpty(whereClause)) { eql += whereClause.Replace(" WHERE ", " AND "); } } EqlClient eqlClient = new EqlClient(session); DataTable dt = eqlClient.RunQuery(eql); return Convert.ToInt64(dt.Rows.Count); } else { throw new Exception(string.Format("Object type [{0}] not found.", objectType)); } } catch (Exception e) { _logger.Error(string.Format("Error getting object count for [{0}]: {1}", objectType, e.Message)); throw e; } finally { Disconnect(ref proxy, ref session); } }
protected IList<IContentObject> GetContents(String objectType, IList<int> docIds, Proxy proxy, Session session) { IList<IContentObject> contents = new List<IContentObject>(); try { string query = string.Format(CONTENT_EQL, string.Join(",", docIds.ToArray())); EqlClient client = new EqlClient(session); DataTable dt = client.RunQuery(query); foreach (DataRow row in dt.Rows) { int fileId = (int)row["FilesId"]; string code = (string)row["Code"]; string name = ((string)row["FilesName"]); string type = name.Substring(name.LastIndexOf(".") + 1); eB.Data.File f = new eB.Data.File(session); f.Retrieve(fileId, "Header; Repositories"); MemoryStream stream = new MemoryStream(); f.ContentData = new eB.ContentData.File(f, stream); f.ContentData.ReadAllBytes(); stream.Position = 0; GenericContentObject content = new GenericContentObject() { ObjectType = objectType, identifier = code, content = stream, contentType = _contentTypes.Find(x => x.Extension == type.ToLower()).MimeType, //name = name }; contents.Add(content); } } catch (Exception e) { _logger.Error("Error getting contents: " + e.Message); throw e; } return contents; }
protected Response PostContents(IList<IContentObject> contentObjects, Proxy proxy, Session session) { Response response = new Response() { Level = StatusLevel.Success }; foreach (GenericContentObject contentObject in contentObjects) { try { // // get doc Id // IList<IDataObject> dataObjects = Get(contentObject.ObjectType, new List<string> { contentObject.identifier }, true); int docId = GetDocumentId(dataObjects.FirstOrDefault()); if (docId <= 0) { session.ProtoProxy.AddObjectFile(session.ReaderSessionString, docId, (int)ObjectType.Document, contentObject.content, contentObject.identifier, 0); Status status = new Status() { Identifier = contentObject.identifier, Level = StatusLevel.Error, Messages = new Messages() { string.Format("Document [{0}] not found.", contentObject.identifier) } }; response.StatusList.Add(status); response.Level = StatusLevel.Error; continue; } // // get content id // EqlClient client = new EqlClient(session); DataTable dt = client.RunQuery(string.Format(CONTENT_EQL, docId)); int fileId = (int)(dt.Rows[0]["FilesId"]); if (fileId <= 0) // add { session.ProtoProxy.AddObjectFile(session.ReaderSessionString, docId, (int)ObjectType.Document, contentObject.content, contentObject.identifier, 0); Status status = new Status() { Identifier = contentObject.identifier, Level = StatusLevel.Success, Messages = new Messages() { string.Format("Document [{0}] added successfully.", contentObject.identifier) } }; response.StatusList.Add(status); } else // update { // // check out content // eB.Data.File file = new eB.Data.File(session); file.Retrieve(fileId, "Header;Repositories"); FileInfo localFile = new FileInfo(Path.GetTempPath() + file.Name); if (localFile.Exists) localFile.Delete(); file.CheckOut(localFile.FullName); // // update content // Utility.WriteStream(contentObject.content, localFile.FullName); // // check content back in // file = new eB.Data.File(session); file.Retrieve(fileId, "Header;Repositories"); if (file.IsCheckedOut) { try { file.CheckIn(localFile.FullName, eB.ContentData.File.CheckinOptions.DeleteLocalCopy, null); session.Writer.CheckinDoc(file.Document.Id, 0); Status status = new Status() { Identifier = contentObject.identifier, Level = StatusLevel.Success, Messages = new Messages() { string.Format("Document [{0}] updated successfully.", contentObject.identifier) } }; response.StatusList.Add(status); } catch { file.UndoCheckout(); } } } } catch (Exception e) { _logger.Error("Error posting content: " + e.Message); Status status = new Status() { Identifier = contentObject.identifier, Level = StatusLevel.Error, Messages = new Messages() { e.Message } }; response.StatusList.Add(status); response.Level = StatusLevel.Error; } } return response; }
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; }