Exemple #1
0
        public Batch GetBatch(string jobId, string batchId)
        {
            String requestUrl = "https://" + _sfService.Pod + ".salesforce.com/services/async/31.0/job/" + jobId + "/batch/" + batchId;

            String resultXML = invokeRestAPI(requestUrl);

            return(Batch.CreateBatch(resultXML));
        }
        public static List <Batch> CreateBatches(String batchesResultXML)
        {
            XDocument    doc           = XDocument.Parse(batchesResultXML);
            XElement     batchInfoList = doc.Root;
            List <Batch> batches       = new List <Batch>();

            foreach (XNode batchInfoNode in batchInfoList.Nodes())
            {
                Batch batch = Batch.CreateBatch(batchInfoNode.ToString());

                batches.Add(batch);
            }

            return(batches);
        }
Exemple #3
0
        public Batch CreateBatch(CreateBatchRequest createBatchRequest)
        {
            String requestUrl = "https://" + _sfService.Pod + ".salesforce.com/services/async/31.0/job/" + createBatchRequest.JobId + "/batch";

            String requestXML = createBatchRequest.BatchContents;

            String contentType = String.Empty;

            if (createBatchRequest.BatchContentType.HasValue)
            {
                contentType = createBatchRequest.BatchContentHeader;
            }

            String resultXML = invokeRestAPI(requestUrl, requestXML, "Post", contentType);

            return(Batch.CreateBatch(resultXML));
        }
Exemple #4
0
        public Batch CreateAttachmentBatch(CreateAttachmentBatchRequest request)
        {
            String requestTxtFileCSVContents = "Name,ParentId,Body" + Environment.NewLine;

            requestTxtFileCSVContents += request.FilePath + "," + request.ParentId + ",#" + request.FilePath;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    byte[] requestTxtFileCSVContentsBytes = UTF8Encoding.UTF8.GetBytes(requestTxtFileCSVContents);
                    var    requestTxtFileInArchive        = archive.CreateEntry("request.txt");
                    using (var entryStream = requestTxtFileInArchive.Open())
                        using (var fileToCompressStream = new MemoryStream(requestTxtFileCSVContentsBytes))
                        {
                            fileToCompressStream.CopyTo(entryStream);
                        }

                    byte[] attachmentFileContentsBytes = File.ReadAllBytes(request.FilePath);
                    var    attachmentFileInArchive     = archive.CreateEntry(request.FilePath);
                    using (var attachmentEntryStream = attachmentFileInArchive.Open())
                        using (var attachmentFileToCompressStream = new MemoryStream(attachmentFileContentsBytes))
                        {
                            attachmentFileToCompressStream.CopyTo(attachmentEntryStream);
                        }

                    byte[] zipFileBytes = memoryStream.ToArray();

                    String requestUrl = "https://" + _sfService.Pod + ".salesforce.com/services/async/31.0/job/" + request.JobId + "/batch";

                    byte[] responseBytes = invokeRestAPI(requestUrl, zipFileBytes, "POST", "zip/csv");

                    String resultXML = UTF8Encoding.UTF8.GetString(responseBytes);

                    return(Batch.CreateBatch(resultXML));
                }
            }
        }