Example #1
0
        public override void OnCreate()
        {
            base.OnCreate();

            AlreadyStarted = false;

            Current = this;

            SafeUnregisterReceiver(ScreenOnReciever);
            SafeUnregisterReceiver(StartLazuriteServiceReceiver);
            SafeUnregisterReceiver(GpsOnReciever);
            RegisterReceiver(ScreenOnReciever             = new ScreenOnReciever(), new IntentFilter(Intent.ActionScreenOn));
            RegisterReceiver(StartLazuriteServiceReceiver = new StartLazuriteServiceReceiver(), new IntentFilter(Intent.ActionBootCompleted));
            RegisterReceiver(GpsOnReciever = new GpsOnReciever(), new IntentFilter("android.location.GPS_ENABLED_CHANGE"));

            SingletonPreparator.Initialize();
            MainApplication.InitializeUnhandledExceptionsHandler();
            Log = Singleton.Resolve <ILogger>();

            _manager = new ClientManager();

            if (_manager.ListenerSettings.UseCPUInBackground)
            {
                InitWakeLock();
            }

            _messenger          = new Messenger(_inHandler);
            _inHandler.HasCome += InHandler_HasCome;

            _manager.ConnectionLost         += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionLost));
            _manager.ConnectionRestored     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionRestored), TimerAction.Start);
            _manager.LoginOrPasswordInvalid += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.CredentialsInvalid), TimerAction.Stop);
            _manager.BruteforceSuspition    += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.BruteforceSuspition), TimerAction.Stop);
            _manager.NeedClientSettings     += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedClientSettings));
            _manager.NeedRefresh            += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.NeedRefresh));
            _manager.ScenariosChanged       += (scenarios) => Handle((messenger) => Utils.RaiseEvent(scenarios, messenger, _messenger, ServiceOperation.ScenariosChanged));
            _manager.SecretCodeInvalid      += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.SecretCodeInvalid));
            _manager.ConnectionError        += () => Handle((messenger) => Utils.RaiseEvent(messenger, _messenger, ServiceOperation.ConnectionError));
            _manager.Initialize(null);
        }