Ejemplo n.º 1
0
        private static async Task <TlAbsInputFile> UploadFile(string name, StreamReader reader,
                                                              ITelegramClient client, bool isBigFileUpload)
        {
            var file      = GetFile(reader);
            var fileParts = GetFileParts(file);

            var partNumber = 0;
            var partsCount = fileParts.Count;
            var fileId     = BitConverter.ToInt64(TlHelpers.GenerateRandomBytes(8), 0);

            while (fileParts.Count != 0)
            {
                var part = fileParts.Dequeue();

                if (isBigFileUpload)
                {
                    await client.SendRequestAsync <bool>(new TlRequestSaveBigFilePart
                    {
                        FileId         = fileId,
                        FilePart       = partNumber,
                        Bytes          = part,
                        FileTotalParts = partsCount
                    });
                }
                else
                {
                    await client.SendRequestAsync <bool>(new TlRequestSaveFilePart
                    {
                        FileId   = fileId,
                        FilePart = partNumber,
                        Bytes    = part
                    });
                }
                partNumber++;
            }

            if (isBigFileUpload)
            {
                return new TlInputFileBig
                       {
                           Id    = fileId,
                           Name  = name,
                           Parts = partsCount
                       }
            }
            ;
            return(new TlInputFile
            {
                Id = fileId,
                Name = name,
                Parts = partsCount,
                Md5Checksum = GetFileHash(file)
            });
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate <see cref="TVector{T}"/> with random long numbers
        /// </summary>
        /// <param name="length">Length of list</param>
        /// <returns>Returns a instance of <see cref="TVector{T}"/> with random long numbers</returns>
        /// TODO: Move to  TlHelpers?
        public static TVector <long> GenerateRandomTVectorLong(int length)
        {
            var randomIds = new TVector <long>();

            for (int i = 0; i < length; i++)
            {
                randomIds.Items.Add(TlHelpers.GenerateRandomLong());
            }

            return(randomIds);
        }