How to use SDK asynchronously
Thursday, November 3, 2016 at 07:27amHi,
I've been trying to send multiple packages asynchonously. After some testing, I discovered that it cannot truly run in parallel because EslClient.CreatePackage(DocumentPackage) acts as a bottleneck for my application. I figured that it must use some kind of lock mechanism to allow only one call at a time. So here are my questions.
      
                                    - Why is there a lock in the CreatePackage function?
- Is there a way to work around it using the .Net SDK?
- If not, is there a way to do it with the REST API?
Reply to: How to use SDK asynchronously
Thursday, November 3, 2016 at 09:42amReply to: How to use SDK asynchronously
Thursday, November 3, 2016 at 08:29ampublic static void main() { Thread.CurrentThread.Name = "Main"; Task[] taskArray = new Task[10]; for (int i = 0; i taskArray.Length; i++) { var temp = i; taskArray[i] = Task.Factory.StartNew(() => CreatePackage(temp)); } Task.WaitAll(taskArray); } public static void CreatePackage(int index) { DocumentPackage package = PackageBuilder.NewPackageNamed("package " + index) .WithSigner(SignerBuilder.NewSignerWithEmail("[email protected]") .WithFirstName("John") .WithLastName("Smith") .WithCustomId("Signer1")) .WithDocument(DocumentBuilder.NewDocumentNamed("something") .FromFile("C:/Users/hhaidary/Desktop/PDFs/doc1.pdf") .WithSignature(SignatureBuilder.SignatureFor("[email protected]") .AtPosition(100, 100) .OnPage(0))) .Build(); PackageId packageId = new EslClient(Properties.Settings.Default.key, Properties.Settings.Default.url).CreatePackage(package); Debug.WriteLine(packageId.ToString()); }Reply to: How to use SDK asynchronously
Thursday, November 3, 2016 at 09:09aminternal Silanis.ESL.SDK.Document UploadDocument(DocumentPackage package, string fileName, byte[] fileBytes, Silanis.ESL.SDK.Document document) { lock (PackageService.syncLock) { string local_0 = this.template.UrlFor(UrlTemplate.DOCUMENT_PATH).Replace("{packageId}", package.Id.Id).Build(); Package local_1 = new DocumentPackageConverter(package).ToAPIPackage(); Silanis.ESL.API.Document local_2 = new DocumentConverter(document).ToAPIDocument(local_1); try { string local_3 = JsonConvert.SerializeObject((object) local_2, this.settings); byte[] local_4 = Converter.ToBytes(local_3); string local_5 = this.GenerateBoundary(); byte[] local_6 = this.CreateMultipartContent(fileName, fileBytes, local_4, local_5); return new DocumentConverter(JsonConvert.DeserializeObject(this.restClient.PostMultipartFile(local_0, local_6, local_5, local_3)), local_1).ToSDKDocument();
        }
        catch (EslServerException exception_0)
        {
          throw new EslServerException("Could not upload document to package. Exception: " + exception_0.Message, exception_0.ServerError, exception_0);
        }
        catch (Exception exception_1)
        {
          throw new EslException("Could not upload document to package. Exception: " + exception_1.Message, exception_1);
        }
      }
    }
 Is there a way around the lock with the SDK or do I need to use the REST API?Reply to: How to use SDK asynchronously
Thursday, November 3, 2016 at 10:24am