コード例 #1
0
        public async Task <LegalIdentity> AddLegalIdentity(RegisterIdentityModel model, params LegalIdentityAttachment[] attachments)
        {
            AssertContractsIsAvailable();
            AssertFileUploadIsAvailable();

            await contractsClient.GenerateNewKeys();

            LegalIdentity identity = await contractsClient.ApplyAsync(model.ToProperties(this.neuronService));

            foreach (var a in attachments)
            {
                HttpFileUploadEventArgs e2 = await fileUploadClient.RequestUploadSlotAsync(Path.GetFileName(a.Filename), a.ContentType, a.ContentLength);

                if (!e2.Ok)
                {
                    throw new Exception(e2.ErrorText);
                }

                await e2.PUT(a.Data, a.ContentType, (int)Constants.Timeouts.UploadFile.TotalMilliseconds);

                byte[] signature = await contractsClient.SignAsync(a.Data, SignWith.CurrentKeys);

                identity = await contractsClient.AddLegalIdAttachmentAsync(identity.Id, e2.GetUrl, signature);
            }

            return(identity);
        }
コード例 #2
0
        public void FileUpload_Test_02_RequestUploadSlot()
        {
            this.FileUpload_Test_01_Discovery();

            string FileName    = Guid.NewGuid().ToString().Replace("-", string.Empty) + ".bin";
            string ContentType = "application/octet-stream";
            Random Rnd         = new Random();

            byte[] Bin = new byte[1024];
            Rnd.NextBytes(Bin);

            ManualResetEvent        Done  = new ManualResetEvent(false);
            ManualResetEvent        Error = new ManualResetEvent(false);
            HttpFileUploadEventArgs e     = null;

            this.httpUpload.RequestUploadSlot(FileName, ContentType, Bin.Length, (sender, e2) =>
            {
                e = e2;
                if (e2.Ok)
                {
                    Done.Set();
                }
                else
                {
                    Error.Set();
                }

                return(Task.CompletedTask);
            }, null);

            Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done, Error }), 5000);

            Console.Out.WriteLine("GET URL:" + e.GetUrl);
            Console.Out.WriteLine("PUT URL:" + e.PutUrl);
            Console.Out.WriteLine("PUT Headers:");

            if (e.PutHeaders != null)
            {
                foreach (KeyValuePair <string, string> Header in e.PutHeaders)
                {
                    Console.Out.WriteLine(Header.Key + ": " + Header.Value);
                }
            }
        }