Example #1
0
        protected override void SynchronizeImpl()
        {
            ISerializableObject source = StateOwner.SourceObject;
            ISerializableObject sink   = StateOwner.SinkObject;


            CopyUtils.ForeignKeyCopy(StateOwner.SinkSerializer, KeyCarrier, sink, base._fieldLock);

            //Kopiere die angepassten Daten...
            CopyUtils.PlainCopy(StateOwner.SinkSerializer, _resolved, sink, base._fieldLock, false);
            CopyUtils.PlainCopy(StateOwner.SourceSerializer, _resolved, source, base._fieldLock, false);

            StateOwner.SinkSerializer.Connector.UpdatePlain(sink);
            StateOwner.SourceSerializer.Connector.UpdatePlain(source);


            _sourceSyncItem.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SourceSerializer.Target, source);
            StateOwner.SyncSerializer.Connector.Save(_sourceSyncItem);
            SyncItem tmp = _sourceSyncItem.CounterPart;

            tmp.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SinkSerializer.Target, sink);
            StateOwner.SyncSerializer.Connector.Save(tmp);

            StateOwner.UpdateFieldStates(StateOwner.SourceSerializer.Target, _sourceSyncItem, source);
            StateOwner.UpdateFieldStates(StateOwner.SinkSerializer.Target, tmp, sink);
        }
Example #2
0
        public void CopyPropertiesTest1()
        {
            var pi1 = new PhoneItem()
            {
                FaxNumber = "456598784532", PhoneNumber = "124565789854"
            };
            var pi2 = new PhoneItem()
            {
                FaxNumber = "789874654312", PhoneNumber = "684763251325"
            };
            var phoneItems = new List <PhoneItem>()
            {
                pi1, pi2
            };
            var address = new Address()
            {
                Id = 1, City = "Rennes", Street = "rue de la paix"
            };

            var objOrigin = new Employee {
                Id = 0, Name = "Bernard", Password = "******", Address = address, PhoneItems = phoneItems
            };
            var objDestination = new Customer();

            CopyUtils.CopyProperties(objDestination, objOrigin);

            Assert.IsTrue(objDestination.Id.Equals(objOrigin.Id));
            Assert.IsNull(objDestination.GetName());
            Assert.IsNull(objDestination.Address);
            Assert.IsNull(objDestination.Emails);
        }
        public void TestCollectionUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so1);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            clone.CollectionOne.Add(so2);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreNotEqual(co.CollectionOne.Count, clone.CollectionOne.Count);

            CopyUtils.UpdateFromClone(co, clone);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreEqual(co.CollectionOne.Count, clone.CollectionOne.Count);
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
            Assert.AreSame(co.CollectionOne.ElementAt(1), clone.CollectionOne.ElementAt(1));
        }
        public void TestReferenceUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var ro = new ReferenceObject {
                ReferenceOne = so1
            };

            var clone = (ReferenceObject)CopyUtils.CloneObjectTest(ro);

            clone.ReferenceOne = so2;

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreNotSame(ro.ReferenceOne, clone.ReferenceOne);

            CopyUtils.UpdateFromClone(ro, clone);

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());
            Assert.AreSame(ro.ReferenceOne, clone.ReferenceOne);
        }
Example #5
0
        public void DeepClone_NullValue_ReturnNull()
        {
            string?value  = null;
            var    result = CopyUtils.DeepClone(value);

            Assert.Equal(value, result);
        }
Example #6
0
        protected override void SynchronizeImpl()
        {
            ISerializableObject source = StateOwner.SourceObject;
            ISerializableObject sink   = StateOwner.SinkSerializer.CreateISerializableObject(StateOwner.SynchronizedType);

            CopyUtils.PlainCopy(StateOwner.SinkSerializer, KeyCarrier, sink, new FieldLock(source.GetType()), true);
            CopyUtils.PlainCopy(StateOwner.SinkSerializer, source, sink, new FieldLock(source.GetType()), false);

            StateOwner.SinkSerializer.Connector.InsertPlain(sink);
            StateOwner.SinkObject = sink;

            SyncItem si1 = StateOwner.SyncSerializer.CreateISerializableObject <SyncItem>();
            SyncItem si2 = StateOwner.SyncSerializer.CreateISerializableObject <SyncItem>();

            si1.SyncGuid = AttributeWorker.RowGuid(source);
            si2.SyncGuid = AttributeWorker.RowGuid(sink);
            si1.ClassID  = source.GetType().Name;
            si2.ClassID  = source.GetType().Name;

            si1.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SourceSerializer.Target, source);
            si2.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SinkSerializer.Target, sink);

            si1.CounterPart = si2;

            StateOwner.SyncSerializer.Connector.Save(si1);
            StateOwner.SyncSerializer.ConnectOneToOne(si1, si2);
            StateOwner.SyncSerializer.Connector.Save(si2);
            StateOwner.SyncSerializer.ConnectOneToOne(si2, si1);
            StateOwner.SyncSerializer.Connector.Save(si1);

            StateOwner.UpdateFieldStates(StateOwner.SourceSerializer.Target, si1, source);//Deaktiviert
            StateOwner.UpdateFieldStates(StateOwner.SinkSerializer.Target, si2, sink);
        }
        public IActionResult GetContentIDs(string containerName, [FromQuery] DateTimeOffset?after, [FromQuery] string maxCount, [FromQuery] string afterContentID, [FromQuery] string auth, [FromHeader] string authenticationKey, CancellationToken cancellationToken)
        {
            var intMaxCount = string.IsNullOrEmpty(maxCount) ? default(int?) : int.Parse(maxCount);

            return(new FileCallbackResult(
                       new MediaTypeHeaderValue("text/plain"),
                       async(outputStream, _) =>
            {
                using (var contentIDsEnumerator = _contents.GetContentIDs(containerName, after, intMaxCount, afterContentID, auth ?? authenticationKey).GetEnumerator())
                {
                    await CopyUtils.CopyAsync(
                        (buffer, ct) =>
                    {
                        var byteCount = 0;
                        while ((byteCount < buffer.Length - 1000) && (contentIDsEnumerator.MoveNext()))
                        {
                            var enumBuff = Encoding.UTF8.GetBytes(contentIDsEnumerator.Current + Environment.NewLine);
                            enumBuff.CopyTo(buffer, byteCount);
                            byteCount += enumBuff.Length;
                        }

                        return Task.FromResult(byteCount);
                    },
                        async(buffer, count, cancellationToken2) =>
                    {
                        await outputStream.WriteAsync(buffer, 0, count, cancellationToken2);
                    },
                        1_000_000,
                        cancellationToken
                        );
                }
            }));
        }
Example #8
0
 /// <summary>
 /// Copy property values from the origin bean to the destination bean for all cases where the property names are the same.
 /// </summary>
 /// <param name="dest">object</param>
 /// <param name="orig">object</param>
 public static void CopyProperties(object dest, object orig)
 {
     try {
         CopyUtils.CopyProperties(dest, orig);
     } catch (ArgumentNullException e) {
         Logger.Error(e, "An error occured while executing method: CopyProperties ");
     }
 }
        public void TestSimpleClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var clone = (SimpleObject)CopyUtils.CloneObjectTest(so);

            Assert.AreNotSame(so, clone);
            Assert.AreSame(so.GetType(), clone.GetType());
            Assert.AreEqual(so.ValueOne, clone.ValueOne);
            Assert.AreEqual(so.ValueTwo, clone.ValueTwo);
        }
Example #10
0
        private IEnumerable <KeyValuePair <string, string> > MultiPartUpload(IMultiPartIDUploadInfo multiPartIDUploadInfo, Stream stream, long streamSize)
        {
            var result = new List <KeyValuePair <string, string> >();

            if (multiPartIDUploadInfo.PartSize <= 0)
            {
                System.Diagnostics.Debug.Assert(multiPartIDUploadInfo.PartUploadInfos.Count() == 1);
                UploadPart(multiPartIDUploadInfo.HttpMethod, stream, streamSize, multiPartIDUploadInfo.PartUploadInfos.First(), "");
            }
            else
            {
                int writePartIndex = 0;

                CopyUtils.CopyAsync(
                    async(buffer, cancellationToken) =>
                {
                    return(await CopyUtils.FillBufferAsync(buffer,
                                                           async(buf, offset, ct) =>
                    {
                        return await stream.ReadAsync(buf, offset, (int)multiPartIDUploadInfo.PartSize - offset);
                    },
                                                           cancellationToken
                                                           ));
                },
                    (buffer, size, cancellationToken) =>
                {
                    var partUploadInfo = multiPartIDUploadInfo.PartUploadInfos.ElementAt(writePartIndex);

                    var uploadPartResult = UploadPart(multiPartIDUploadInfo.HttpMethod, new MemoryStream(buffer), size, partUploadInfo, multiPartIDUploadInfo.MultiPartUploadResultHeaderName);

                    result.Add(new KeyValuePair <string, string>(partUploadInfo.Identifier, uploadPartResult));

                    writePartIndex++;

                    return(Task.CompletedTask);
                },
                    (int)multiPartIDUploadInfo.PartSize,
                    CancellationToken.None
                    )
                .Wait();

                //foreach (var partUploadInfo in multiPartIDUploadInfo.PartUploadInfos)
                //{
                //    var uploadPartResult = UploadPart(multiPartIDUploadInfo.HttpMethod, stream, multiPartIDUploadInfo.PartSize, partUploadInfo, multiPartIDUploadInfo.MultiPartUploadResultHeaderName);
                //    yield return new KeyValuePair<string, string>(partUploadInfo.Identifier, uploadPartResult);
                //}
            }

            return(result);
        }
Example #11
0
        public async Task <Conference?> FindById(string conferenceId)
        {
            var key    = GetConferenceKey(conferenceId);
            var result = await _memoryCache.GetOrCreateAsync(key, async entry =>
            {
                entry.SetSlidingExpiration(TimeSpan.FromMinutes(1));
                return(await _conferenceRepo.FindById(conferenceId));
            });

            if (result == null)
            {
                return(null);
            }
            return(CopyUtils.DeepClone(result)); // important as we cache the conference and the object is mutable
        }
Example #12
0
        public void DeepClone_Conference_ReturnEqualCopy()
        {
            var data = new Conference("123")
            {
                ConferenceId  = "test",
                Version       = 45,
                Configuration = { Moderators = new List <string> {
                                      "ghrd"
                                  }, ScheduleCron= "asd" },
            };

            var result = CopyUtils.DeepClone(data);

            Assert.Equal(JsonConvert.SerializeObject(data), JsonConvert.SerializeObject(result));
        }
        public void TestReferenceClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var ro = new ReferenceObject {
                ReferenceOne = so
            };

            var clone = (ReferenceObject)CopyUtils.CloneObjectTest(ro);

            Assert.AreNotSame(ro, clone);
            Assert.AreSame(ro.GetType(), clone.GetType());

            Assert.AreSame(ro.ReferenceOne, clone.ReferenceOne);
        }
Example #14
0
        public async Task <List <SpotRecordListDTO> > ListSpotRecord(string coin, string order, string username, string fw, int count)
        {
            if (SpotRecordDao == null)
            {
                logger.Error("---------------- SpotRecordDao wei null");
            }
            var spotRecords = await SpotRecordDao.ListSpotRecord(coin, order, username, fw, count);

            var result = new List <SpotRecordListDTO>();

            foreach (var item in spotRecords)
            {
                result.Add(CopyUtils.Mapper <SpotRecordListDTO, SpotRecord>(item));
            }
            return(result);
        }
        public void TestCollectionClone()
        {
            var so = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var co = new CollectionObject();

            co.CollectionOne.Add(so);

            var clone = (CollectionObject)CopyUtils.CloneObjectTest(co);

            Assert.AreNotSame(co, clone);
            Assert.AreSame(co.GetType(), clone.GetType());
            Assert.AreNotSame(co.CollectionOne, clone.CollectionOne);
            Assert.AreSame(co.CollectionOne.First(), clone.CollectionOne.First());
        }
        public void TestAllUpdate()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var so3 = new SimpleObject {
                ValueOne = 5, ValueTwo = 6
            };
            var so4 = new SimpleObject {
                ValueOne = 7, ValueTwo = 8
            };
            var ao = new AllObject {
                ValueOne = 9, ValueTwo = 10, ReferenceOne = so1
            };

            ao.CollectionOne.Add(so2);

            var clone = (AllObject)CopyUtils.CloneObjectTest(ao);

            clone.ValueTwo     = 11;
            clone.ReferenceOne = so3;
            clone.CollectionOne.Add(so4);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreNotEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreNotSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreNotEqual(ao.CollectionOne.Count, clone.CollectionOne.Count);

            CopyUtils.UpdateFromClone(ao, clone);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreEqual(ao.CollectionOne.Count, clone.CollectionOne.Count);
            Assert.AreSame(ao.CollectionOne.First(), clone.CollectionOne.First());
            Assert.AreSame(ao.CollectionOne.ElementAt(1), clone.CollectionOne.ElementAt(1));
        }
        private async Task CopyStreamToBlobAsync(Stream sourceStream, BlobContainerClient container, string blobName, int bufferSize, string sourceMD5, CancellationToken cancellationToken)
        {
            var blob = container.GetBlockBlobClient(blobName);

            var blobHasher = CopyUtils.GetMD5Hasher();

            var blockIDs    = new List <string>();
            var blockNumber = 0;

            await CopyUtils.CopyAsync(
                (buffer, ct) => CopyUtils.ReadStreamMaxBufferAsync(buffer, sourceStream, ct),
                async (buffer, count, cancellationToken2) =>
            {
                var blockId = GetBlockId(blockNumber);
                blockIDs.Add(blockId);

                var blockMD5Hash = CopyUtils.GetMD5Hash(buffer, 0, count);
                CopyUtils.AppendMDHasherData(blobHasher, buffer, 0, count);

                using (var ms = new MemoryStream(buffer, 0, count))
                {
                    await blob.StageBlockAsync(blockId, ms, blockMD5Hash, null, null, cancellationToken);
                }

                blockNumber++;
            },
                bufferSize,
                cancellationToken
                );

            var blobHash = CopyUtils.GetMD5Hash(blobHasher);

            if ((!string.IsNullOrEmpty(sourceMD5)) && (sourceMD5 != CopyUtils.GetMD5HashString(blobHash)))
            {
                throw new Exception("Invalid destination MD5");
            }

            var headers = new global::Azure.Storage.Blobs.Models.BlobHttpHeaders()
            {
                ContentHash = blobHash
            };

            await blob.CommitBlockListAsync(blockIDs, headers, null, null, null, cancellationToken);
        }
Example #18
0
        protected override void SynchronizeImpl()
        {
            ISerializableObject source = StateOwner.SourceObject;
            ISerializableObject sink   = StateOwner.SinkObject;

            CopyUtils.PlainCopy(StateOwner.SinkSerializer, KeyCarrier, sink, _fieldLock, true);
            CopyUtils.PlainCopy(StateOwner.SinkSerializer, source, sink, _fieldLock, false);

            StateOwner.SinkSerializer.Connector.UpdatePlain(sink);

            _sourceSyncItem.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SourceSerializer.Target, source);
            StateOwner.SyncSerializer.Connector.Save(_sourceSyncItem);
            SyncItem sinkSyncItem = _sourceSyncItem.CounterPart;

            sinkSyncItem.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SinkSerializer.Target, sink);
            StateOwner.SyncSerializer.Connector.Save(sinkSyncItem);

            StateOwner.UpdateFieldStates(StateOwner.SourceSerializer.Target, _sourceSyncItem, source);
            StateOwner.UpdateFieldStates(StateOwner.SinkSerializer.Target, sinkSyncItem, sink);
        }
Example #19
0
 private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     //tiliu
     if (e.ClickedItem.Name == "copy")
     {
         CopyUtils.copyResult(gridView1, focuseName);
     }
     else if (e.ClickedItem.Name == "tiliu")
     {
         DataRow row = gridView1.GetFocusedDataRow( );
         if (row == null)
         {
             return;
         }
         decimal ztl = string.IsNullOrEmpty(row ["WAH024"].ToString( )) == true ? 0 : Convert.ToDecimal(row ["WAH024"]);
         if (ztl == 0)
         {
             return;
         }
         DataRow [] rows = tableView.Select("WAH023='" + row ["WAH023"] + "' AND WAH015<=0");
         if (rows == null || rows.Length < 1)
         {
             return;
         }
         DataRow [] rowes    = tableView.Select("WAH023='" + row ["WAH023"] + "' AND WAH015>0");
         decimal    otherNum = 0M;
         if (rowes != null && rowes.Length > 0)
         {
             foreach (DataRow ro in rowes)
             {
                 otherNum += Convert.ToDecimal(ro ["WAH015"]);
             }
         }
         int     num      = rows.Length;
         decimal everyNum = (ztl - otherNum) / (num * Convert.ToDecimal(1.0));
         foreach (DataRow r in rows)
         {
             r ["WAH015"] = everyNum;
         }
     }
 }
        public async Task CollectAsync(string collectUrl, IEnumerable <KeyValuePair <string, string> > collectHeaders, IIdentityServiceClientInfo collectIdentityServiceClientInfo, string dataCollectionName, string fileName, TimeSpan timeout, bool finishWait, int tryNo, CancellationToken cancellationToken)
        {
            int bufferSize = 1 * 1024 * 1024;

            using (var response = await HttpUtils.SendAsync(collectUrl, HttpMethod.Get, collectUrl, null, collectHeaders, null, timeout, null, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
            {
                var sourceMD5 = response.ContentMD5();

                var fullFileName = GetFullFileName(dataCollectionName, fileName);

                Directory.CreateDirectory(Path.GetDirectoryName(fullFileName));

                using (var sourceStream = await response.Content.ReadAsStreamAsync())
                {
                    using (var fileStream = new FileStream(fullFileName, FileMode.Create))
                    {
                        await CopyUtils.CopyAsync(
                            (buffer, ct) => CopyUtils.ReadStreamMaxBufferAsync(buffer, sourceStream, ct),
                            async (buffer, count, cancellationToken2) => await fileStream.WriteAsync(buffer, 0, count, cancellationToken2),
                            bufferSize,
                            cancellationToken
                            );
                    }
                }

                using (var fileStream = new FileStream(fullFileName, FileMode.Open, FileAccess.Read))
                {
                    var newMD5 = await CopyUtils.GetMD5HashStringAsync(fileStream, bufferSize, cancellationToken);

                    if ((!string.IsNullOrEmpty(sourceMD5)) &&
                        (!string.Equals(newMD5, sourceMD5, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        throw new Exception("Invalid destination MD5");
                    }

                    File.WriteAllText(GetMD5FileName(fullFileName), newMD5);
                }
            }
        }
Example #21
0
        public void CopyPropertiesTest2()
        {
            var address = new CompleteAddress()
            {
                Id = 0, City = "Rennes", Street = "rue de la paix", State = 33, Country = "France"
            };
            var email1 = "*****@*****.**";
            var email2 = "*****@*****.**";
            var emails = new List <string>()
            {
                email1, email2
            };

            var objOrigin = new Customer {
                Id = 0, Address = address, Emails = emails
            };
            var objDestination = new Employee();

            CopyUtils.CopyProperties(objDestination, objOrigin);

            Assert.IsTrue(objDestination.Id.Equals(objOrigin.Id));
            Assert.IsNull(objDestination.Name);
            Assert.IsTrue(objDestination.Address.Equals(objOrigin.Address));
        }
        public void TestAllClone()
        {
            var so1 = new SimpleObject {
                ValueOne = 1, ValueTwo = 2
            };
            var so2 = new SimpleObject {
                ValueOne = 3, ValueTwo = 4
            };
            var ao = new AllObject {
                ValueOne = 5, ValueTwo = 6, ReferenceOne = so1
            };

            ao.CollectionOne.Add(so2);

            var clone = (AllObject)CopyUtils.CloneObjectTest(ao);

            Assert.AreNotSame(ao, clone);
            Assert.AreSame(ao.GetType(), clone.GetType());
            Assert.AreEqual(ao.ValueOne, clone.ValueOne);
            Assert.AreEqual(ao.ValueTwo, clone.ValueTwo);
            Assert.AreSame(ao.ReferenceOne, clone.ReferenceOne);
            Assert.AreNotSame(ao.CollectionOne, clone.CollectionOne);
            Assert.AreSame(ao.CollectionOne.First(), clone.CollectionOne.First());
        }
Example #23
0
 private void contextMenuStrip1_ItemClicked(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e)
 {
     CopyUtils.copyResult(gridView1, focuseName);
 }
Example #24
0
 private void contextMenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     CopyUtils.copyResult(gridView4, focuseName);
 }
Example #25
0
        private async Task MultiPartUploadAsync(Stream sourceStream, string sourceMD5, string bucketName, string keyName, CancellationToken cancellationToken)
        {
            // Create list to store upload part responses.
            var uploadResponses = new List <UploadPartResponse>();

            // Setup information required to initiate the multipart upload.
            var initiateRequest = new InitiateMultipartUploadRequest
            {
                BucketName = bucketName,
                Key        = keyName
            };

            var validateMD5 = !string.IsNullOrEmpty(sourceMD5);

            if (validateMD5)
            {
                initiateRequest.Metadata.Add("Content-MD5", sourceMD5);
            }

            // Initiate the upload.
            var initResponse = await _amazonS3.InitiateMultipartUploadAsync(initiateRequest, cancellationToken);

            try
            {
                var blobHasher = validateMD5 ? CopyUtils.GetMD5Hasher() : null;

                var partSize = 10 * 1024 * 1024;  // todo: config
                var partNo   = 1;

                await CopyUtils.CopyAsync(
                    (buffer, ct) => CopyUtils.ReadStreamMaxBufferAsync(buffer, sourceStream, ct),
                    async (buffer, count, cancellationToken2) =>
                {
                    var blockMD5Hash = CopyUtils.GetMD5HashString(buffer, 0, count);

                    if (validateMD5)
                    {
                        CopyUtils.AppendMDHasherData(blobHasher, buffer, 0, count);
                    }

                    using (var ms = new MemoryStream(buffer, 0, count))
                    {
                        ms.Position = 0;

                        partNo++;

                        var uploadRequest = new UploadPartRequest
                        {
                            BucketName  = bucketName,
                            Key         = keyName,
                            UploadId    = initResponse.UploadId,
                            PartNumber  = partNo,
                            PartSize    = count,
                            InputStream = ms,
                            MD5Digest   = blockMD5Hash
                        };

                        // Upload a part and add the response to our list.
                        var uploadResponse = await _amazonS3.UploadPartAsync(uploadRequest, cancellationToken);
                        uploadResponses.Add(uploadResponse);
                    }
                },
                    partSize,
                    cancellationToken
                    );

                if (validateMD5)
                {
                    var blobHash = CopyUtils.GetMD5HashString(blobHasher);

                    if ((!string.IsNullOrEmpty(sourceMD5)) && (sourceMD5 != blobHash))
                    {
                        throw new Exception("Invalid destination MD5");
                    }
                }

                // Setup to complete the upload.
                var completeRequest = new CompleteMultipartUploadRequest
                {
                    BucketName = bucketName,
                    Key        = keyName,
                    UploadId   = initResponse.UploadId
                };
                completeRequest.AddPartETags(uploadResponses);

                // Complete the upload.
                var completeUploadResponse = await _amazonS3.CompleteMultipartUploadAsync(completeRequest, cancellationToken);
            }
            catch (Exception exception)
            {
                Console.WriteLine("An AmazonS3Exception was thrown: { 0}", exception.Message);

                // Abort the upload.
                var abortMPURequest = new AbortMultipartUploadRequest
                {
                    BucketName = bucketName,
                    Key        = keyName,
                    UploadId   = initResponse.UploadId
                };
                await _amazonS3.AbortMultipartUploadAsync(abortMPURequest, cancellationToken);
            }
        }
Example #26
0
        //复制一行
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            //if ( e . ClickedItem . Name == "ItemOne" )
            //{
            //    if ( rowes == null )
            //    {
            //        XtraMessageBox . Show ( "请选择需要复制的行" );
            //        return;
            //    }

            //    _body . PRE001 = rowes [ "PRE001" ] . ToString ( );
            //    _body . PRE002 = rowes [ "PRE002" ] . ToString ( );
            //    _body . PRE003 = rowes [ "PRE003" ] . ToString ( );
            //    _body . PRE004 = rowes [ "PRE004" ] . ToString ( );
            //    if ( rowes [ "PRE005" ] == null )
            //        _body . PRE005 = null;
            //    else
            //        _body . PRE005 = Convert . ToDateTime ( rowes [ "PRE005" ] . ToString ( ) );
            //    if ( rowes [ "PRE006" ] == null )
            //        _body . PRE006 = null;
            //    else
            //        _body . PRE006 = Convert . ToDateTime ( rowes [ "PRE006" ] . ToString ( ) );
            //    if ( rowes [ "PRE007" ] == null )
            //        _body . PRE007 = null;
            //    else
            //        _body . PRE007 = Convert . ToInt32 ( rowes [ "PRE007" ] . ToString ( ) );
            //    if ( rowes [ "PRE008" ] == null )
            //        _body . PRE008 = null;
            //    else
            //        _body . PRE008 = Convert . ToInt32 ( rowes [ "PRE008" ] . ToString ( ) );
            //    if ( rowes [ "PRE009" ] == null || rowes [ "PRE009" ].ToString() == string.Empty )
            //        _body . PRE009 = null;
            //    else
            //        _body . PRE009 = Convert . ToInt32 ( rowes [ "PRE009" ] . ToString ( ) );
            //    if ( rowes [ "PRE010" ] == null )
            //        _body . PRE010 = null;
            //    else
            //        _body . PRE010 = Convert . ToInt32 ( rowes [ "PRE010" ] . ToString ( ) );

            //    object obj = tableView . Compute ( "MAX(PRE005)" ,"PRE002='" + _body . PRE002 + "' AND PRE003='" + _body . PRE003 + "' AND PRE004='" + _body . PRE004 + "'" );
            //    if ( obj != null )
            //    {
            //        _body . PRE005 = Convert . ToDateTime ( obj ) . AddDays ( 1 );
            //        DataRow row = tableView . NewRow ( );
            //        row [ "PRE001" ] = _body . PRE001;
            //        row [ "PRE002" ] = _body . PRE002;
            //        row [ "PRE003" ] = _body . PRE003;
            //        row [ "PRE004" ] = _body . PRE004;
            //        row [ "PRE005" ] = _body . PRE005;
            //        row [ "PRE006" ] = _body . PRE006;
            //        row [ "PRE007" ] = _body . PRE007;
            //        row [ "PRE008" ] = _body . PRE008;
            //        if ( _body . PRE009 == null )
            //            row [ "PRE009" ] = DBNull . Value;
            //        else
            //            row [ "PRE009" ] = _body . PRE009;
            //       row [ "PRE010" ] = _body . PRE010;
            //        row [ "PRE" ] = rowes [ "PRE" ];
            //        tableView . Rows . Add ( row );
            //    }
            //}
            //            else
            if (e.ClickedItem.Name == "ItemTwo")
            {
                CopyUtils.copyResult(gridView1, focuseName);
            }
        }