Esempio n. 1
0
        public void GetCdnFileHashesAsync(byte[] fileToken, int offset, Action <TLVector <TLCdnFileHash> > callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLUploadGetCdnFileHashes {
                FileToken = fileToken, Offset = offset
            };

            const string caption = "upload.getCdnFileHashes";

            SendInformativeMessage(caption, obj, callback, faultCallback);
        }
Esempio n. 2
0
        private TLVector <TLCdnFileHash> GetCdnFileHashes(TLUploadFileCdnRedirect redirect, TLFileLocation location, int offset, out TLRPCError er, out bool isCanceled)
        {
            var manualResetEvent            = new ManualResetEvent(false);
            TLVector <TLCdnFileHash> result = null;
            TLRPCError outError             = null;
            var        outIsCanceled        = false;

            var req = new TLUploadGetCdnFileHashes();

            req.FileToken = redirect.FileToken;
            req.Offset    = offset;

            _protoService.SendRequestAsync <TLVector <TLCdnFileHash> >("upload.getCdnFileHashes", req, location.DCId, true, callback =>
            {
                result = callback;
                manualResetEvent.Set();
            },
                                                                       error =>
            {
                outError = error;

                if (error.CodeEquals(TLErrorCode.INTERNAL) ||
                    (error.CodeEquals(TLErrorCode.BAD_REQUEST) && (error.TypeEquals(TLErrorType.LOCATION_INVALID) || error.TypeEquals(TLErrorType.VOLUME_LOC_NOT_FOUND))) ||
                    (error.CodeEquals(TLErrorCode.NOT_FOUND) && error.ErrorMessage != null && error.ErrorMessage.ToString().StartsWith("Incorrect dhGen")))
                {
                    outIsCanceled = true;

                    manualResetEvent.Set();
                    return;
                }

                int delay;
                lock (_randomRoot)
                {
                    delay = _random.Next(1000, 3000);
                }

                Execute.BeginOnThreadPool(TimeSpan.FromMilliseconds(delay), () => manualResetEvent.Set());
            });

            manualResetEvent.WaitOne(20 * 1000);
            er         = outError;
            isCanceled = outIsCanceled;

            return(result);
        }