예제 #1
0
 public DownloadablePart(DownloadableItem item, int offset, int limit, int number = 0)
 {
     ParentItem = item;
     Offset     = offset;
     Limit      = limit;
     Number     = number;
 }
        private List <DownloadablePart> GetItemParts(int size, DownloadableItem item)
        {
            //var chunkSize = Constants.DownloadChunkSize;

            var chunkSize  = size > 1024 * 1024 ? 1024 * 128 : 1024 * 32;
            var parts      = new List <DownloadablePart>();
            var partsCount = size / chunkSize + (size % chunkSize > 0 ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part       = new DownloadablePart(item, i * chunkSize, size == 0 ? 0 : chunkSize, i);
                var partName   = item.InputDocumentLocation.GetPartFileName(part.Number); //string.Format("document{0}_{1}_{2}.dat", item.InputDocumentLocation.Id, item.InputDocumentLocation.AccessHash, part.Number);
                var partLength = FileUtils.GetLocalFileLength(partName);

                if (partLength >= 0)
                {
                    var isCompletePart = (part.Number + 1 == partsCount) || partLength == part.Limit;
                    part.Status = isCompletePart ? PartStatus.Processed : PartStatus.Ready;
                }

                parts.Add(part);
            }

            return(parts);
        }
예제 #3
0
        protected override List <DownloadablePart> GetItemParts(TLInt size, DownloadableItem item)
        {
            var chunkSize  = size.Value > 1024 * 1024 ? Constants.DownloadedBigChunkSize : Constants.DownloadedChunkSize;
            var parts      = new List <DownloadablePart>();
            var partsCount = size.Value / chunkSize + (size.Value % chunkSize > 0 ? 1 : 0);

            var step = partsCount / 25;

            for (var i = 0; i < partsCount; i++)
            {
                var part       = new DownloadablePart(item, new TLInt(i * chunkSize), size.Value == 0 ? new TLInt(1024 * 1024) : new TLInt(chunkSize), i);
                var partName   = item.InputLocation.GetPartFileName(part.Number, "document");
                var partLength = FileUtils.GetLocalFileLength(partName);

                if (partLength >= 0)
                {
                    var isCompletePart = (part.Number + 1 == partsCount) || partLength == part.Limit.Value;
                    part.Status = isCompletePart ? PartStatus.Processed : PartStatus.Ready;
                }

                part.NotifyProgress = part.Status == PartStatus.Ready && (step == 0 || i % step == 0);

                parts.Add(part);
            }

            return(parts);
        }
예제 #4
0
 public DownloadablePart(DownloadableItem item, TLInt offset, TLInt limit, int number)
 {
     ParentItem     = item;
     Offset         = offset;
     Limit          = limit;
     Number         = number;
     NotifyProgress = true;
 }
예제 #5
0
        private DownloadableItem GetDownloadableItem(TLFileLocation location, TLObject owner, TLInt fileSize)
        {
            var item = new DownloadableItem
            {
                Owner    = owner,
                Location = location
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
예제 #6
0
        private DownloadableItem GetDownloadableItem(TLInt dcId, TLInputFileLocationBase location, TLObject owner, TLInt fileSize)
        {
            var item = new DownloadableItem
            {
                Owner         = owner,
                DCId          = dcId,
                InputLocation = location
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
        private DownloadableItem GetDownloadableItem(string fileName, int dcId, TLInputDocumentFileLocation location, TLObject owner, int fileSize)
        {
            var item = new DownloadableItem
            {
                DCId     = dcId,
                FileName = fileName,
                Owner    = owner,
                InputDocumentLocation = location
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
예제 #8
0
        private List <DownloadablePart> GetItemParts(TLInt size, DownloadableItem item)
        {
            var chunkSize  = Constants.DownloadedChunkSize;
            var parts      = new List <DownloadablePart>();
            var partsCount = size.Value / chunkSize + (size.Value % chunkSize > 0 ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new DownloadablePart(item, new TLInt(i * chunkSize), size.Value == 0 ? new TLInt(0) : new TLInt(chunkSize), i);
                parts.Add(part);
            }

            return(parts);
        }
예제 #9
0
        protected DownloadableItem GetDownloadableItem(TLInt dcId, TLInputWebFileGeoPointLocation location, string fileName, TLObject owner, TLInt fileSize, Action <DownloadableItem> callback)
        {
            var item = new DownloadableItem
            {
                Owner         = owner,
                DCId          = dcId,
                Callback      = callback,
                InputLocation = location
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
예제 #10
0
        protected virtual List <DownloadablePart> GetItemParts(TLInt size, DownloadableItem item)
        {
            var chunkSize  = size.Value > 1024 * 1024? Constants.DownloadedBigChunkSize : Constants.DownloadedChunkSize;
            var parts      = new List <DownloadablePart>();
            var partsCount = size.Value / chunkSize + ((size.Value % chunkSize > 0 || size.Value == 0) ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new DownloadablePart(item, new TLInt(i * chunkSize), size.Value == 0 ? new TLInt(1024 * 1024) : new TLInt(chunkSize), i);
                parts.Add(part);
            }

            return(parts);
        }
예제 #11
0
        protected DownloadableItem GetDownloadableItem(TLFileLocation location, TLObject owner, TLInt fileSize, Action <DownloadableItem> callback)
        {
            var item = new DownloadableItem
            {
                Owner         = owner,
                DCId          = location.DCId,
                Callback      = callback,
                InputLocation = location.ToInputFileLocation()
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
        private List <DownloadablePart> GetItemParts(int size, DownloadableItem item)
        {
            var chunkSize  = Constants.DownloadChunkSize;
            var parts      = new List <DownloadablePart>();
            var partsCount = size / chunkSize + (size % chunkSize > 0 ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part = new DownloadablePart(item, i * chunkSize, chunkSize, i);
                parts.Add(part);
            }

            return(parts);
        }
예제 #13
0
        private DownloadableItem GetDownloadableItem(TLString fileName, TLInt dcId, TLInputFileLocationBase location, TLObject owner, TLInt fileSize, Action <DownloadableItem> callback)
        {
            var item = new DownloadableItem
            {
                DCId          = dcId,
                FileName      = fileName,
                Owner         = owner,
                InputLocation = location,
                Callback      = callback
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
예제 #14
0
        private List <DownloadablePart> GetItemParts(int size, DownloadableItem item)
        {
            //var chunkSize = Constants.DownloadChunkSize;

            var chunkSize  = size > 1024 * 1024 ? 1024 * 128 : 1024 * 32;
            var parts      = new List <DownloadablePart>();
            var partsCount = size / chunkSize + 1;

            for (var i = 0; i < partsCount; i++)
            {
                //var part = new DownloadablePart(item, i * chunkSize, size == 0 ? 0 : chunkSize);
                var part = new DownloadablePart(item, i * chunkSize, chunkSize, i);
                parts.Add(part);
            }

            return(parts);
        }
예제 #15
0
        private List <DownloadablePart> GetItemParts(TLInt size, DownloadableItem item)
        {
            var chunkSize  = Constants.DownloadedChunkSize;
            var parts      = new List <DownloadablePart>();
            var partsCount = size.Value / chunkSize + (size.Value % chunkSize > 0 ? 1 : 0);

            for (var i = 0; i < partsCount; i++)
            {
                var part       = new DownloadablePart(item, new TLInt(i * chunkSize), size.Value == 0 ? new TLInt(0) : new TLInt(chunkSize), i);
                var partName   = string.Format("document{0}_{1}_{2}.dat", item.InputDocumentLocation.Id, item.InputDocumentLocation.AccessHash, part.Number);
                var partLength = FileUtils.GetLocalFileLength(partName);

                if (partLength >= 0)
                {
                    var isCompletePart = (part.Number + 1 == partsCount) || partLength == part.Limit.Value;
                    part.Status = isCompletePart ? PartStatus.Processed : PartStatus.Ready;
                }

                parts.Add(part);
            }

            return(parts);
        }