Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }