Esempio n. 1
0
        private List <UploadablePart> GetItemParts(UploadableItem item, long isoFileLength)
        {
            //const int partSize = 32 * 1024; // 32 Kb: êðàòíî 1 Kb è íàöåëî äåëèò 1024 Kb
            //var parts = new List<UploadablePart>();
            //var partsCount = item.FileLength / partSize + (item.FileLength % partSize > 0 ? 1 : 0);



            var partSize = (int)Math.Max(128, (isoFileLength + 1024 * 3000 - 1) / (1024 * 3000));

            if (1024 % partSize != 0)
            {
                int chunkSize = 64;
                while (partSize > chunkSize)
                {
                    chunkSize *= 2;
                }
                partSize = chunkSize;
            }

            partSize *= 1024;

            var parts      = new List <UploadablePart>();
            var partsCount = (int)(isoFileLength + partSize - 1) / partSize;

            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, i, i * partSize, Math.Min(partSize, isoFileLength - i * partSize));
                parts.Add(part);
            }

            item.IsSmallFile = item.FileLength < Constants.SmallFileMaxSize;// size < chunkSize;

            return(parts);
        }
        private List <UploadablePart> GetItemParts(UploadableItem item, long isoFileLength, IList <UploadablePart> uploadedParts)
        {
            const int partSize = 32 * 1024;

            foreach (var uploadedPart in uploadedParts)
            {
                uploadedPart.SetParentItem(item);
            }
            var parts = new List <UploadablePart>(uploadedParts);

            var uploadedLength = uploadedParts.Sum(x => x.Count);

            var uploadingLength = item.IsoFileLength - uploadedLength;

            if (uploadingLength == 0)
            {
                return(parts);
            }
            var partsCount = uploadingLength / partSize + 1;

            for (var i = 0; i < partsCount; i++)
            {
                var partId = i + uploadedParts.Count;
                var part   = new UploadablePart(item, new TLInt(partId), uploadedLength + i * partSize, Math.Min(partSize, isoFileLength - (uploadedLength + i * partSize)));
                parts.Add(part);
            }

            return(parts);
        }
        private UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, string isoFileName, long isoFileLength)
        {
            var item = new UploadableItem(fileId, owner, isoFileName, isoFileLength);

            item.Parts = GetItemParts(item, isoFileLength);
            return(item);
        }
        private UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, byte[] bytes)
        {
            var item = new UploadableItem(fileId, owner, bytes);

            item.Parts = GetItemParts(item);
            return(item);
        }
Esempio n. 5
0
 public UploadablePart(UploadableItem item, int filePart, long position, long count)
 {
     ParentItem = item;
     FilePart   = filePart;
     Position   = position;
     Count      = count;
 }
Esempio n. 6
0
        private UploadableItem GetUploadableItem(long fileId, TLObject owner, string fileName, long fileLength, IList <UploadablePart> parts)
        {
            var item = new UploadableItem(fileId, owner, fileName, fileLength);

            item.Parts = GetItemParts(item, fileLength, parts);
            return(item);
        }
 public UploadablePart(UploadableItem item, TLInt filePart, byte[] bytes, long position, long count)
 {
     ParentItem = item;
     FilePart   = filePart;
     Bytes      = bytes;
     Position   = position;
     Count      = count;
 }
        private UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, string fileName, long fileLength)
        {
            FileUtils.SwitchIdleDetectionMode(false);

            var item = new UploadableItem(fileId, owner, fileName, fileLength);
            item.Parts = GetItemParts(item, fileLength);
            return item;
        }
        private UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, StorageFile file)
        {
            var item = new UploadableItem(fileId, owner, file);

            var task = file.GetBasicPropertiesAsync().AsTask();

            task.Wait();
            var propertie = task.Result;
            var size      = propertie.Size;

            item.Parts = GetItemParts(item, (int)size);
            return(item);
        }
        private List <UploadablePart> GetItemParts(UploadableItem item, long isoFileLength)
        {
            const int partSize   = 32 * 1024; // 32 Kb: кратно 1 Kb и нацело делит 1024 Kb
            var       parts      = new List <UploadablePart>();
            var       partsCount = item.IsoFileLength / partSize + (item.IsoFileLength % partSize > 0 ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, new TLInt(i), i * partSize, Math.Min(partSize, isoFileLength - i * partSize));
                parts.Add(part);
            }

            return(parts);
        }
        private static List <UploadablePart> GetItemParts(UploadableItem item, int size)
        {
            var chunkSize  = FileUtils.GetChunkSize(size);
            var partsCount = FileUtils.GetPartsCount(size, chunkSize);
            var parts      = new List <UploadablePart>(partsCount);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, new TLInt(i), i * chunkSize, Math.Min(chunkSize, (long)size - i * chunkSize));
                parts.Add(part);
            }

            return(parts);
        }
        private static List <UploadablePart> GetItemParts(UploadableItem item)
        {
            var size       = item.Bytes.Length;
            var chunkSize  = FileUtils.GetChunkSize(size);
            var partsCount = FileUtils.GetPartsCount(size, chunkSize);
            var parts      = new List <UploadablePart>(partsCount);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, new TLInt(i), item.Bytes.SubArray(i * chunkSize, Math.Min(chunkSize, item.Bytes.Length - i * chunkSize)));
                parts.Add(part);
            }

            return(parts);
        }
        private List<UploadablePart> GetItemParts(UploadableItem item, long fileLength)
        {
            var chunkSize = FileUtils.GetChunkSize(fileLength);
            var partsCount = FileUtils.GetPartsCount(fileLength, chunkSize);
            var parts = new List<UploadablePart>();
            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, new TLInt(i), i * chunkSize, Math.Min(chunkSize, fileLength - i * chunkSize));
                parts.Add(part);
            }

            item.IsSmallFile = fileLength < chunkSize;

            return parts;
        }
Esempio n. 14
0
        private static List <UploadablePart> GetItemParts(UploadableItem item)
        {
            var size       = item.Bytes.Length;
            var chunkSize  = FileUtils.GetChunkSize(size);
            var partsCount = FileUtils.GetPartsCount(size, chunkSize);
            var parts      = new List <UploadablePart>(partsCount);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new UploadablePart(item, i, item.Bytes.SubArray(i * chunkSize, Math.Min(chunkSize, item.Bytes.Length - i * chunkSize)));
                parts.Add(part);
            }

            item.IsSmallFile = size < Constants.SmallFileMaxSize;// size < chunkSize;

            return(parts);
        }
        private List<UploadablePart> GetItemParts(UploadableItem item, long fileLength, IList<UploadablePart> uploadedParts)
        {
            var chunkSize = FileUtils.GetChunkSize(fileLength);
            var parts = new List<UploadablePart>(uploadedParts);
            foreach (var uploadedPart in uploadedParts)
            {
                uploadedPart.SetParentItem(item);
            }
            var uploadedLength = uploadedParts.Sum(x => x.Count);

            var partsCount = FileUtils.GetPartsCount(item.IsoFileLength - uploadedLength, chunkSize);
            for (var i = 0; i < partsCount; i++)
            {
                var partId = i + uploadedParts.Count;
                var part = new UploadablePart(item, new TLInt(partId), uploadedLength + i * chunkSize, Math.Min(chunkSize, fileLength - (uploadedLength + i * chunkSize)));
                parts.Add(part);
            }

            item.IsSmallFile = fileLength < chunkSize;

            return parts;
        }
 public UploadProgressChangedEventArgs(UploadableItem item, double progress)
 {
     Item     = item;
     Progress = progress;
 }
Esempio n. 17
0
 public void SetParentItem(UploadableItem item)
 {
     ParentItem = item;
 }
 public UploadingCanceledEventArgs(UploadableItem item)
 {
     Item = item;
 }
Esempio n. 19
0
 public UploadablePart(UploadableItem item, int filePart, byte[] bytes)
 {
     ParentItem = item;
     FilePart   = filePart;
     Bytes      = bytes;
 }