Esempio n. 1
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Messages = GetObject <TLVector <TLMessageBase> >(bytes, ref position);
            Chats    = GetObject <TLVector <TLChatBase> >(bytes, ref position);
            Users    = GetObject <TLVector <TLUserBase> >(bytes, ref position);
            Pts      = GetObject <TLInt>(bytes, ref position);
            PtsCount = GetObject <TLInt>(bytes, ref position);

            return(this);
        }
Esempio n. 2
0
        protected TLVector <TLFileHash> ReuploadFile(TLFileCdnRedirect redirect, TLInt dcId, TLString requestToken, out TLRPCError er, out bool isCanceled, out bool isTokenInvalid)
        {
            var manualResetEvent           = new ManualResetEvent(false);
            TLVector <TLFileHash> result   = null;
            TLRPCError            outError = null;
            var outIsCanceled     = false;
            var outIsTokenInvalid = false;

            _mtProtoService.ReuploadCdnFileAsync(dcId, redirect.FileToken, requestToken,
                                                 callback =>
            {
                result = callback;

                manualResetEvent.Set();
            },
                                                 error =>
            {
                outError = error;

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

                    manualResetEvent.Set();
                    return;
                }
                if (error.CodeEquals(ErrorCode.BAD_REQUEST) && (error.TypeEquals(ErrorType.FILE_TOKEN_INVALID) || error.TypeEquals(ErrorType.REQUEST_TOKEN_INVALID)))
                {
                    outIsTokenInvalid = true;

                    manualResetEvent.Set();
                    return;
                }

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

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

            manualResetEvent.WaitOne();
            er             = outError;
            isCanceled     = outIsCanceled;
            isTokenInvalid = outIsTokenInvalid;

            return(result);
        }
Esempio n. 3
0
        public void DownloadFileAsync(TLString originalFileName, TLInt dcId, TLInputDocumentFileLocation fileLocation, TLObject owner, TLInt fileSize, Action <double> callback)
        {
            Execute.BeginOnThreadPool(() =>
            {
                var downloadableItem = GetDownloadableItem(originalFileName, dcId, fileLocation, owner, fileSize);

                var downloadedCount = downloadableItem.Parts.Count(x => x.Status == PartStatus.Processed);
                var count           = downloadableItem.Parts.Count;
                var isComplete      = downloadedCount == count;

                if (isComplete)
                {
                    var id            = downloadableItem.InputDocumentLocation.Id;
                    var accessHash    = downloadableItem.InputDocumentLocation.AccessHash;
                    var fileExtension = Path.GetExtension(downloadableItem.FileName.ToString());
                    var fileName      = string.Format("document{0}_{1}{2}", id, accessHash, fileExtension);
                    Func <DownloadablePart, string> getPartName = x => string.Format("document{0}_{1}_{2}.dat", id, accessHash, x.Number);

                    FileUtils.MergePartsToFile(getPartName, downloadableItem.Parts, fileName);

                    downloadableItem.IsoFileName = fileName;
                    _eventAggregator.Publish(downloadableItem);
                }
                else
                {
                    var progress = downloadedCount / (double)count;
                    callback.SafeInvoke(progress);

                    lock (_itemsSyncRoot)
                    {
                        bool addFile = true;
                        foreach (var item in _items)
                        {
                            if (item.InputDocumentLocation.AccessHash.Value == fileLocation.AccessHash.Value &&
                                item.InputDocumentLocation.Id.Value == fileLocation.Id.Value &&
                                item.Owner == owner)
                            {
                                addFile = false;
                                break;
                            }
                        }

                        if (addFile)
                        {
                            _items.Add(downloadableItem);
                        }
                    }

                    StartAwaitingWorkers();
                }
            });
        }
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Nonce       = GetObject <TLInt128>(bytes, ref position);
            ServerNonce = GetObject <TLInt128>(bytes, ref position);
            G           = GetObject <TLInt>(bytes, ref position);
            DHPrime     = GetObject <TLString>(bytes, ref position);
            GA          = GetObject <TLString>(bytes, ref position);
            ServerTime  = GetObject <TLInt>(bytes, ref position);

            return(this);
        }
Esempio n. 5
0
        public void RequestEncryptionAsync(TLInputUserBase userId, TLInt randomId, TLString ga, Action <TLEncryptedChatBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLRequestEncryption {
                UserId = userId, RandomId = randomId, G_A = ga
            };

            SendInformativeMessage <TLEncryptedChatBase>("messages.requestEncryption", obj,
                                                         encryptedChat =>
            {
                _cacheService.SyncEncryptedChat(encryptedChat, callback.SafeInvoke);
            },
                                                         faultCallback);
        }
Esempio n. 6
0
        public void PingDelayDisconnectAsync(TLLong pingId, TLInt disconnectDelay, Action <TLPong> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLPingDelayDisconnect {
                PingId = pingId, DisconnectDelay = disconnectDelay
            };

            SendNonInformativeMessage <TLPong>("ping_delay_disconnect", obj,
                                               result =>
            {
                callback.SafeInvoke(result);
            },
                                               faultCallback.SafeInvoke);
        }
Esempio n. 7
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 static async Task <TLPhotoSizeBase> GetFileThumbAsync(StorageFile file)
        {
            try
            {
                var thumb = await file.GetThumbnailAsync(ThumbnailMode.PicturesView, 190, ThumbnailOptions.ResizeThumbnail);

                var volumeId = TLLong.Random();
                var localId  = TLInt.Random();
                var secret   = TLLong.Random();

                var thumbLocation = new TLFileLocation
                {
                    DCId     = new TLInt(0),
                    VolumeId = volumeId,
                    LocalId  = localId,
                    Secret   = secret,
                };

                var fileName = String.Format("{0}_{1}_{2}.jpg",
                                             thumbLocation.VolumeId,
                                             thumbLocation.LocalId,
                                             thumbLocation.Secret);

                var thumbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                var thumbBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumb.Size));
                var iBuf        = await thumb.ReadAsync(thumbBuffer, thumbBuffer.Capacity, InputStreamOptions.None);

                using (var thumbStream = await thumbFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await thumbStream.WriteAsync(iBuf);
                }

                var thumbSize = new TLPhotoSize
                {
                    W        = new TLInt((int)thumb.OriginalWidth),
                    H        = new TLInt((int)thumb.OriginalHeight),
                    Size     = new TLInt((int)thumb.Size),
                    Type     = new TLString(""),
                    Location = thumbLocation,
                };

                return(thumbSize);
            }
            catch (Exception ex)
            {
                Telegram.Api.Helpers.Execute.ShowDebugMessage("GetFileThumbAsync exception " + ex);
            }

            return(null);
        }
Esempio n. 9
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            RandomBytes = GetObject <TLString>(bytes, ref position);
            Layer       = GetObject <TLInt>(bytes, ref position);
            InSeqNo     = GetObject <TLInt>(bytes, ref position);
            OutSeqNo    = GetObject <TLInt>(bytes, ref position);
            Message     = GetObject <TLDecryptedMessageBase>(bytes, ref position);

            System.Diagnostics.Debug.WriteLine("  >>TLDecryptedMessageLayer17.FromBytes layer={0} in_seq_no={1} out_seq_no={2} message=[{3}]", Layer, InSeqNo, OutSeqNo, Message);

            return(this);
        }
        public void ValidateRequestedInfoAsync(bool save, TLInt msgId, TLPaymentRequestedInfo info, Action <TLValidatedRequestedInfo> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLValidateRequestedInfo
            {
                Flags = new TLInt(0),
                Save  = save,
                MsgId = msgId,
                Info  = info
            };

            const string caption = "payments.validateRequestedInfo";

            SendInformativeMessage <TLValidatedRequestedInfo>(caption, obj, callback.SafeInvoke, faultCallback);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        private async void EditPhotoExecute(StorageFile file)
        {
            var fileLocation = new TLFileLocation
            {
                VolumeId = TLLong.Random(),
                LocalId  = TLInt.Random(),
                Secret   = TLLong.Random(),
                DCId     = 0
            };

            var fileName  = string.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret);
            var fileCache = await FileUtils.CreateTempFileAsync(fileName);

            //var fileScale = await ImageHelper.ScaleJpegAsync(file, fileCache, 640, 0.77);

            await file.CopyAndReplaceAsync(fileCache);

            var fileScale = fileCache;

            var basicProps = await fileScale.GetBasicPropertiesAsync();

            var imageProps = await fileScale.Properties.GetImagePropertiesAsync();

            var fileId = TLLong.Random();
            var upload = await _uploadFileManager.UploadFileAsync(fileId, fileCache.Name);

            if (upload != null)
            {
                var response = await ProtoService.UploadProfilePhotoAsync(upload.ToInputFile() as TLInputFile);

                if (response.IsSucceeded)
                {
                    var user = Self as TLUser;
                    if (user == null)
                    {
                        return;
                    }

                    var userFull = CacheService.GetFullUser(user.Id);
                    if (userFull == null)
                    {
                        return;
                    }

                    userFull.HasProfilePhoto = true;
                    userFull.ProfilePhoto    = response.Result.Photo;
                    userFull.RaisePropertyChanged(() => userFull.ProfilePhoto);
                }
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
 public void OpenMediaContact(TLInt userId, TLUserBase user, TLString phoneNumber)
 {
     if (user == null)
     {
         MTProtoService.GetFullUserAsync(new TLInputUserContact {
             UserId = userId
         },
                                         userFull => OpenContactInternal(userFull.User, phoneNumber));
     }
     else
     {
         OpenContactInternal(user, phoneNumber);
     }
 }
        public void ChoosePhoto()
        {
            EditChatActions.EditPhoto(photo =>
            {
                var volumeId = TLLong.Random();
                var localId  = TLInt.Random();
                var secret   = TLLong.Random();

                var fileLocation = new TLFileLocation
                {
                    VolumeId = volumeId,
                    LocalId  = localId,
                    Secret   = secret,
                    DCId     = new TLInt(0),
                    //Buffer = p.Bytes
                };

                var fileName = String.Format("{0}_{1}_{2}.jpg",
                                             fileLocation.VolumeId,
                                             fileLocation.LocalId,
                                             fileLocation.Secret);

                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var fileStream = store.CreateFile(fileName))
                    {
                        fileStream.Write(photo, 0, photo.Length);
                    }
                }

                Photo = new TLChatPhoto
                {
                    PhotoSmall = new TLFileLocation
                    {
                        DCId     = fileLocation.DCId,
                        VolumeId = fileLocation.VolumeId,
                        LocalId  = fileLocation.LocalId,
                        Secret   = fileLocation.Secret
                    },
                    PhotoBig = new TLFileLocation
                    {
                        DCId     = fileLocation.DCId,
                        VolumeId = fileLocation.VolumeId,
                        LocalId  = fileLocation.LocalId,
                        Secret   = fileLocation.Secret
                    }
                };
                NotifyOfPropertyChange(() => Photo);
            });
        }
Esempio n. 17
0
        private DownloadableItem GetDownloadableItem(TLString fileName, TLInt dcId, TLInputDocumentFileLocation location, TLObject owner, TLInt fileSize)
        {
            var item = new DownloadableItem
            {
                DCId     = dcId,
                FileName = fileName,
                Owner    = owner,
                InputDocumentLocation = location
            };

            item.Parts = GetItemParts(fileSize, item);

            return(item);
        }
Esempio n. 18
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            TLUtils.WriteLine("--Parse TLContactBlocked--");
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            UserId = GetObject <TLInt>(bytes, ref position);

            Date = GetObject <TLInt>(bytes, ref position);

            TLUtils.WriteLine("UserId: " + UserId);
            TLUtils.WriteLine("Date: " + TLUtils.MessageIdString(Date));

            return(this);
        }
        public async Task <TLMessage25> GetPhotoMessage(StorageFile file)
        {
            var volumeId = TLLong.Random();
            var localId  = TLInt.Random();
            var secret   = TLLong.Random();

            var fileLocation = new TLFileLocation
            {
                VolumeId = volumeId,
                LocalId  = localId,
                Secret   = secret,
                DCId     = new TLInt(0),    //TODO: remove from here, replace with FileLocationUnavailable
                //Buffer = p.Bytes
            };

            var fileName = String.Format("{0}_{1}_{2}.jpg",
                                         fileLocation.VolumeId,
                                         fileLocation.LocalId,
                                         fileLocation.Secret);

            var stream = await file.OpenReadAsync();

            var resizedPhoto = await ResizeJpeg(stream, Constants.DefaultImageSize, file.DisplayName, fileName);

            var photoSize = new TLPhotoSize
            {
                Type     = TLString.Empty,
                W        = new TLInt(resizedPhoto.Width),
                H        = new TLInt(resizedPhoto.Height),
                Location = fileLocation,
                Size     = new TLInt(resizedPhoto.Bytes.Length)
            };

            var photo = new TLPhoto33
            {
                Id         = new TLLong(0),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                Sizes      = new TLVector <TLPhotoSizeBase> {
                    photoSize
                },
            };

            var media = new TLMessageMediaPhoto28 {
                Photo = photo, Caption = TLString.Empty, File = resizedPhoto.File
            };

            return(GetMessage(TLString.Empty, media));
        }
Esempio n. 20
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);
        }
Esempio n. 21
0
        public void GetFeedAsync(bool offsetToMaxReed, TLInt feedId, TLFeedPosition offsetPosition, TLInt addOffset, TLInt limit, TLFeedPosition maxPosition, TLFeedPosition minPosition, TLInt hash, Action <TLMessagesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLGetFeed {
                Flags = new TLInt(0), OffsetToMaxRead = offsetToMaxReed, FeedId = feedId, OffsetPosition = offsetPosition, AddOffset = addOffset, Limit = limit, MaxPosition = maxPosition, MinPosition = minPosition, Hash = hash
            };

            const string caption = "channels.getFeed";

            SendInformativeMessage <TLMessagesBase>(caption, obj,
                                                    result =>
            {
                callback(result);
            },
                                                    faultCallback);
        }
Esempio n. 22
0
        public static string Convert(TLMessageService serviceMessage, bool useActiveLinks = false)
        {
            TLInt      fromId           = new TLInt(0); //serviceMessage.FromId;
            TLUserBase fromUser         = null;         //IoC.Get<ICacheService>().GetUser(fromId);
            string     fromUserFullName = null;         //fromUser != null ? fromUser.FullName : AppResources.User;

            var action = serviceMessage.Action;

            if (action != null && _actionsCache.ContainsKey(action.GetType()))
            {
                return(_actionsCache[action.GetType()](action, fromId.Value, fromUserFullName, useActiveLinks));
            }

            return(null);
        }
Esempio n. 23
0
        public void ChangeFeedBroadcastAsync(TLInputChannelBase channel, TLInt feedId, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChangeFeedBroadcast {
                Flags = new TLInt(0), Channel = channel, FeedId = feedId
            };

            const string caption = "channels.changeFeedBroadcast";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                callback(result);
            },
                                                   faultCallback);
        }
Esempio n. 24
0
        public void ReadFeedAsync(TLInt feedId, TLFeedPosition maxPosition, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLReadFeed {
                FeedId = feedId, MaxPosition = maxPosition
            };

            const string caption = "channels.readFeed";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                callback(result);
            },
                                                   faultCallback);
        }
        public void ReadHistoryAsync(TLChannel channel, TLInt maxId, Action<TLBool> callback, Action<TLRPCError> faultCallback = null)
        {
            var obj = new TLReadChannelHistory { Channel = channel.ToInputChannel(), MaxId = maxId };

            SendInformativeMessage<TLBool>("channels.readHistory", obj,
                result =>
                {
                    channel.ReadInboxMaxId = maxId;

                    _cacheService.Commit();

                    callback.SafeInvoke(result);
                },
                faultCallback);
        }
Esempio n. 26
0
        public void SetFeedBroadcastsAsync(TLInt feedId, TLVector <TLInputChannelBase> channels, TLBool alsoNewlyJoined, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLSetFeedBroadcasts {
                FeedId = feedId, Channels = channels, AlsoNewlyJoined = alsoNewlyJoined
            };

            const string caption = "channels.setFeedBroadcasts";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                callback(result);
            },
                                                   faultCallback);
        }
Esempio n. 27
0
        private static byte[] ComposeGetDialogsRequest(TLInt offset, TLInt maxId, TLInt limit)
        {
            //#eccf1df6
            var signature = new byte[] { 0xf6, 0x1d, 0xcf, 0xec };

            TLUtils.WriteLine("Offset: " + offset);
            TLUtils.WriteLine("MaxId: " + maxId);
            TLUtils.WriteLine("Limit: " + limit);

            return(signature
                   .Concat(offset.ToBytes())
                   .Concat(maxId.ToBytes())
                   .Concat(limit.ToBytes())
                   .ToArray());
        }
Esempio n. 28
0
        protected void ProcessFilePart(DownloadablePart part, TLInt dcId, TLInputFileLocationBase location, out bool canceled)
        {
            do
            {
                TLRPCError error;

                TLFileBase result;
                if (part.ParentItem.CdnRedirect != null)
                {
                    TLCdnFileReuploadNeeded cdnFileReuploadNeeded;
                    bool tokenInvalid;
                    result = GetCdnFile(part.ParentItem.CdnRedirect, part.Offset, part.Limit, out cdnFileReuploadNeeded, out error, out canceled, out tokenInvalid);
                    if (cdnFileReuploadNeeded != null)
                    {
                        ReuploadFile(part.ParentItem.CdnRedirect, dcId, cdnFileReuploadNeeded.RequestToken, out error, out canceled, out tokenInvalid);
                    }

                    if (tokenInvalid)
                    {
                        lock (_itemsSyncRoot)
                        {
                            part.ParentItem.CdnRedirect = null;
                        }
                        continue;
                    }
                }
                else
                {
                    result = GetFile(dcId, location, part.Offset, part.Limit, out error, out canceled);
                    var fileCdnRedirect = result as TLFileCdnRedirect;
                    if (fileCdnRedirect != null)
                    {
                        lock (_itemsSyncRoot)
                        {
                            part.ParentItem.CdnRedirect = fileCdnRedirect;
                        }
                        continue;
                    }
                }

                part.File = result as TLFile;

                if (canceled)
                {
                    return;
                }
            } while (part.File == null);
        }
        private void CheckAndUpdateMainTransportAsync(ITransport transport)
        {
            LogPublicConfig(string.Format("Get config from id={0} dc_id={1} ip={2} port={3} proxy=[{4}]", transport.Id, transport.DCId, transport.Host, transport.Port, transport.ProxyConfig));
            GetConfigByTransportAsync(transport,
                                      config =>
            {
                LogPublicConfig(string.Format("Get config completed id={0}", transport.Id));

                var dcId     = new TLInt(_activeTransport.DCId);
                var dcOption = TLUtils.GetDCOption(config, dcId) as TLDCOption78;
                if (dcOption == null)
                {
                    LogPublicConfig(string.Format("dcOption is null id={0}", transport.Id));
                    return;
                }
                if (string.Equals(_activeTransport.Host, dcOption.IpAddress.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    LogPublicConfig(string.Format("dcOption ip equals ip={0}", dcOption.IpAddress.ToString()));
                    return;
                }
                LogPublicConfig("Close transport id=" + transport.Id);
                _transportService.CloseSpecialTransport(transport);

                // replace main dc ip and port
                transport = GetSpecialTransport(dcOption.IpAddress.ToString(), dcOption.Port.Value, Type, new TransportSettings
                {
                    DcId                  = dcOption.Id.Value,
                    Secret                = TLUtils.ParseSecret(dcOption),
                    AuthKey               = _activeTransport.AuthKey,
                    Salt                  = _activeTransport.Salt,
                    SessionId             = TLLong.Random(),
                    MessageIdDict         = new Dictionary <long, long>(),
                    SequenceNumber        = 0,
                    ClientTicksDelta      = _activeTransport.ClientTicksDelta,
                    PacketReceivedHandler = OnPacketReceivedByTransport
                });

                CheckAndUpdateTransportInfoInternalAsync(dcOption, transport, null);
                // reconnect
            },
                                      error2 =>
            {
                LogPublicConfig(string.Format("Get config error id={0} error={1}", transport.Id, error2));

                LogPublicConfig("Close transport id=" + transport.Id);
                _transportService.CloseSpecialTransport(transport);
            });
        }
        public static void DeleteContactAsync(IStateService stateService, TLInt userId)
        {
#if WP8
            Telegram.Api.Helpers.Execute.BeginOnThreadPool(() =>
                                                           stateService.GetNotifySettingsAsync(
                                                               async settings =>
            {
                if (settings.PeopleHub)
                {
                    var store        = await ContactStore.CreateOrOpenAsync();
                    var phoneContact = await store.FindContactByRemoteIdAsync(userId.ToString());
                    await store.DeleteContactAsync(phoneContact.Id);
                }
            }));
#endif
        }