コード例 #1
0
        private void InitializeServiceAsync(System.Action callback)
        {
            Debug.WriteLine("[CallInProgressAgentImpl {0}] _mtProtoService == null {1}", GetHashCode(), _mtProtoService == null);

            if (MTProtoService == null)
            {
                var deviceInfoService = new Telegram.Api.Services.DeviceInfo.DeviceInfoService(GetInitConnection(), true, "BackgroundDifferenceLoader", 1);
                var cacheService      = new MockupCacheService();
                var updatesService    = new MockupUpdatesService();

                _transportService = new TransportService();
                var connectionService   = new ConnectionService(deviceInfoService);
                var publicConfigService = new MockupPublicConfigService();

                var mtProtoService = new MTProtoService(deviceInfoService, updatesService, cacheService, _transportService, connectionService, publicConfigService);
                mtProtoService.Initialized += (o, e) =>
                {
                    //Log(string.Format("[MTProtoUpdater {0}] Initialized", GetHashCode()));
                    Thread.Sleep(1000);
                    callback.SafeInvoke();
                };
                mtProtoService.InitializationFailed += (o, e) =>
                {
                    //Log(string.Format("[MTProtoUpdater {0}] InitializationFailed", GetHashCode()));
                };
                mtProtoService.Initialize();

                MTProtoService = mtProtoService;
            }
            else
            {
                callback.SafeInvoke();
            }
        }
コード例 #2
0
        private void ProcessLiveLocations()
        {
            var deviceInfoService   = new Telegram.Api.Services.DeviceInfo.DeviceInfoService(GetInitConnection(), true, "BackgroundDifferenceLoader", 1);
            var cacheService        = new MockupCacheService();
            var updatesService      = new MockupUpdatesService();
            var transportService    = new TransportService();
            var connectionService   = new ConnectionService(deviceInfoService);
            var publicConfigService = new MockupPublicConfigService();

            var manualResetEvent = new ManualResetEvent(false);
            var eventAggregator  = new TelegramEventAggregator();
            var mtProtoService   = new MTProtoService(deviceInfoService, updatesService, cacheService, transportService, connectionService, publicConfigService);

            mtProtoService.Initialized += (o, e) =>
            {
                var liveLocationsService = new LiveLocationService(mtProtoService, eventAggregator);

                liveLocationsService.Load();

                liveLocationsService.UpdateAll();

                manualResetEvent.Set();
            };
            mtProtoService.InitializationFailed += (o, e) =>
            {
                manualResetEvent.Set();
            };
            mtProtoService.Initialize();

            var timeout =
#if DEBUG
                Timeout.InfiniteTimeSpan;
#else
                TimeSpan.FromSeconds(30.0);
#endif

            var result = manualResetEvent.WaitOne(timeout);
        }
コード例 #3
0
        // This method is called when the incoming call processing is complete
        private void OnIncomingCallDialogDismissed(long callId, long callAccessHash, bool rejected)
        {
            Debug.WriteLine("[IncomingCallAgent] Incoming call processing is now complete.");

            if (rejected)
            {
                var deviceInfoService   = new Telegram.Api.Services.DeviceInfo.DeviceInfoService(GetInitConnection(), true, "BackgroundDifferenceLoader", 1);
                var cacheService        = new MockupCacheService();
                var updatesService      = new MockupUpdatesService();
                var transportService    = new TransportService();
                var connectionService   = new ConnectionService(deviceInfoService);
                var publicConfigService = new MockupPublicConfigService();

                var manualResetEvent = new ManualResetEvent(false);
                var mtProtoService   = new MTProtoService(deviceInfoService, updatesService, cacheService, transportService, connectionService, publicConfigService);
                mtProtoService.Initialized += (o, e) =>
                {
                    var peer = new TLInputPhoneCall
                    {
                        Id         = new TLLong(callId),
                        AccessHash = new TLLong(callAccessHash)
                    };

                    var getStateAction = new TLDiscardCall
                    {
                        Peer         = peer,
                        Duration     = new TLInt(0),
                        Reason       = new TLPhoneCallDiscardReasonBusy(),
                        ConnectionId = new TLLong(0)
                    };
                    var actions = new List <TLObject> {
                        getStateAction
                    };

                    mtProtoService.SendActionsAsync(actions,
                                                    (request, result) =>
                    {
                        manualResetEvent.Set();
                    },
                                                    error =>
                    {
                        manualResetEvent.Set();
                    });
                };
                mtProtoService.InitializationFailed += (o, e) =>
                {
                    manualResetEvent.Set();
                };
                mtProtoService.Initialize();

#if DEBUG
                manualResetEvent.WaitOne();
#else
                manualResetEvent.WaitOne(TimeSpan.FromSeconds(10.0));
#endif

                mtProtoService.Stop();
            }

            this.Complete();
        }