Exemplo n.º 1
0
        /// <summary>
        /// Uploads the Document and file in byte[] to the package.
        /// </summary>
        /// <param name="packageId">The package id.</param>
        /// <param name="fileName">The name of the document.</param>
        /// <param name="fileBytes">The file to upload in bytes.</param>
        /// <param name="document">The document object that has field settings.</param>
        internal Document UploadDocument(DocumentPackage package, string fileName, byte[] fileBytes, Document document)
        {
            string path = template.UrlFor(UrlTemplate.DOCUMENT_PATH)
                          .Replace("{packageId}", package.Id.Id)
                          .Build();

            Silanis.ESL.API.Package  internalPackage = new DocumentPackageConverter(package).ToAPIPackage();
            Silanis.ESL.API.Document internalDoc     = new DocumentConverter(document).ToAPIDocument(internalPackage);

            try
            {
                string json         = JsonConvert.SerializeObject(internalDoc, settings);
                byte[] payloadBytes = Converter.ToBytes(json);

                string boundary = GenerateBoundary();
                byte[] content  = CreateMultipartContent(fileName, fileBytes, payloadBytes, boundary);

                string response = restClient.PostMultipartFile(path, content, boundary, json);

                Silanis.ESL.API.Document uploadedDoc = JsonConvert.DeserializeObject <Silanis.ESL.API.Document>(response);
                return(new DocumentConverter(uploadedDoc, internalPackage).ToSDKDocument());
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not upload document to package." + " Exception: " + e.Message, e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the document's data, but not the actually document binary..
        /// </summary>
        /// <param name="package">The DocumentPackage to update.</param>
        /// <param name="document">The Document to update.</param>
        public void UpdateDocumentMetadata(DocumentPackage package, Document document)
        {
            string path = template.UrlFor(UrlTemplate.DOCUMENT_ID_PATH)
                          .Replace("{packageId}", package.Id.Id)
                          .Replace("{documentId}", document.Id)
                          .Build();

            Silanis.ESL.API.Package  apiPackage  = new DocumentPackageConverter(package).ToAPIPackage();
            Silanis.ESL.API.Document apiDocument = new DocumentConverter(document).ToAPIDocument(apiPackage);

            foreach (Silanis.ESL.API.Document apiDoc in apiPackage.Documents)
            {
                if (apiDoc.Id.Equals(document.Id))
                {
                    apiDocument = apiDoc;
                    break;
                }
            }
            if (apiDocument == null)
            {
                throw new EslException("Document is not part of the package.", null);
            }

            try
            {
                string json = JsonConvert.SerializeObject(apiDocument, settings);
                restClient.Post(path, json);
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not update the document's metadata." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not update the document's metadata." + " Exception: " + e.Message, e);
            }

            IContractResolver prevContractResolver = settings.ContractResolver;

            settings.ContractResolver = DocumentMetadataContractResolver.Instance;

            try
            {
                string json = JsonConvert.SerializeObject(apiDocument, settings);
                restClient.Post(path, json);
            }
            catch (EslServerException e)
            {
                throw new EslServerException("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not upload document to package." + " Exception: " + e.Message, e);
            }
            finally
            {
                settings.ContractResolver = prevContractResolver;
            }
        }
        public void ConvertAPIToAPI()
        {
            apiPackage1 = CreateTypicalAPIPackage();
            converter   = new DocumentPackageConverter(apiPackage1);
            apiPackage2 = converter.ToAPIPackage();

            Assert.IsNotNull(apiPackage2);
            Assert.AreEqual(apiPackage2, apiPackage1);
        }
Exemplo n.º 4
0
		public void Update(DocumentPackage template)
		{
			if (template.Id == null)
			{
				throw new ArgumentNullException("template.Id");
			}

			Silanis.ESL.API.Package apiTemplate = new DocumentPackageConverter(template).ToAPIPackage();
			apiTemplate.Type = BasePackageType.TEMPLATE;
            apiClient.Update(apiTemplate);
		}
Exemplo n.º 5
0
        public void Update(DocumentPackage template)
        {
            if (template.Id == null)
            {
                throw new ArgumentNullException("template.Id");
            }

            Silanis.ESL.API.Package apiTemplate = new DocumentPackageConverter(template).ToAPIPackage();
            apiTemplate.Type = "TEMPLATE";
            apiClient.Update(apiTemplate);
        }
Exemplo n.º 6
0
        private Page <DocumentPackage> ConvertToPage(Silanis.ESL.API.Result <Silanis.ESL.API.Package> results, PageRequest request)
        {
            IList <DocumentPackage> converted = new List <DocumentPackage> ();

            foreach (Silanis.ESL.API.Package package in results.Results)
            {
                DocumentPackage dp = new DocumentPackageConverter(package).ToSDKPackage();

                converted.Add(dp);
            }

            return(new Page <DocumentPackage> (converted, results.Count.Value, request));
        }
 public void ConvertNullAPIToAPI()
 {
     apiPackage1 = null;
     converter   = new DocumentPackageConverter(apiPackage1);
     Assert.IsNull(converter.ToAPIPackage());
 }
 public void ConvertNullSDKToAPI()
 {
     sdkPackage1 = null;
     converter   = new DocumentPackageConverter(sdkPackage1);
     Assert.IsNull(converter.ToAPIPackage());
 }
Exemplo n.º 9
0
		private Page<DocumentPackage> ConvertToPage (Silanis.ESL.API.Result<Silanis.ESL.API.Package> results, PageRequest request)
		{
			IList<DocumentPackage> converted = new List<DocumentPackage> ();

			foreach (Silanis.ESL.API.Package package in results.Results)
			{
                DocumentPackage dp = new DocumentPackageConverter(package).ToSDKPackage();

				converted.Add (dp);
			}

			return new Page<DocumentPackage> (converted, results.Count.Value, request);
		}
Exemplo n.º 10
0
		/// <summary>
		/// Uploads the Document and file in byte[] to the package.
		/// </summary>
		/// <param name="packageId">The package id.</param>
		/// <param name="fileName">The name of the document.</param>
		/// <param name="fileBytes">The file to upload in bytes.</param>
		/// <param name="document">The document object that has field settings.</param>
		internal Document UploadDocument (DocumentPackage package, string fileName, byte[] fileBytes, Document document)
		{
			string path = template.UrlFor (UrlTemplate.DOCUMENT_PATH)
				.Replace ("{packageId}", package.Id.Id)
					.Build ();

			Silanis.ESL.API.Package internalPackage = new DocumentPackageConverter(package).ToAPIPackage();
			Silanis.ESL.API.Document internalDoc = new DocumentConverter(document).ToAPIDocument(internalPackage);

			try 
			{
				string json = JsonConvert.SerializeObject (internalDoc, settings);
				byte[] payloadBytes = Converter.ToBytes (json);

				string boundary = GenerateBoundary ();
				byte[] content = CreateMultipartContent (fileName, fileBytes, payloadBytes, boundary);

				string response = restClient.PostMultipartFile(path, content, boundary, json);

				Silanis.ESL.API.Document uploadedDoc = JsonConvert.DeserializeObject<Silanis.ESL.API.Document>(response);
				return new DocumentConverter(uploadedDoc, internalPackage).ToSDKDocument();
			} 
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) 
			{
				throw new EslException ("Could not upload document to package." + " Exception: " + e.Message, e);
			}
		}
Exemplo n.º 11
0
        /// <summary>
        /// Updates the document's data, but not the actually document binary..
        /// </summary>
        /// <param name="package">The DocumentPackage to update.</param>
        /// <param name="document">The Document to update.</param>
		public void UpdateDocumentMetadata(DocumentPackage package, Document document)
        {
            string path = template.UrlFor(UrlTemplate.DOCUMENT_ID_PATH)
				.Replace("{packageId}", package.Id.Id)
				.Replace("{documentId}", document.Id)
				.Build();

            Silanis.ESL.API.Package apiPackage = new DocumentPackageConverter(package).ToAPIPackage();
            Silanis.ESL.API.Document apiDocument = new DocumentConverter(document).ToAPIDocument(apiPackage);

            foreach (Silanis.ESL.API.Document apiDoc in apiPackage.Documents)
            {
                if (apiDoc.Id.Equals(document.Id))
                {
                    apiDocument = apiDoc;
                    break;
                }
            }
            if (apiDocument == null)
            {
                throw new EslException("Document is not part of the package.", null);
            }
            
			try 
			{
				string json = JsonConvert.SerializeObject (apiDocument, settings);
				restClient.Post(path, json);
			} 
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not update the document's metadata." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e) 
			{
                throw new EslException ("Could not update the document's metadata." + " Exception: " + e.Message, e);
			}

            IContractResolver prevContractResolver = settings.ContractResolver;
            settings.ContractResolver = DocumentMetadataContractResolver.Instance;            
            
            try
            {
                string json = JsonConvert.SerializeObject(apiDocument, settings);
                restClient.Post(path, json);
            }
            catch (EslServerException e) 
            {
                throw new EslServerException ("Could not upload document to package." + " Exception: " + e.Message, e.ServerError, e);
            }
            catch (Exception e)
            {
                throw new EslException("Could not upload document to package." + " Exception: " + e.Message, e);
            }
            finally
            {
                settings.ContractResolver = prevContractResolver;
            }
		}