Exemple #1
0
        public async override void Start()
        {
            if (await synchronisationService.AuthorizeTokenSynchronisationAsync())
            {
                await Task.Run(RefreshToolRoadsAsync);
            }
            else
            {
                Close(this);
                if (IsBound)
                {
                    _track.StopServices();
                }
                ShowViewModel <LoginViewModel>();
                return;
            }

            base.Start();
            _tokens.Add(_messenger.SubscribeOnMainThread <GeoWatcherStatusMessage>((s) => IsBound       = s.Data, MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnThreadPoolThread <LocationMessage>(x => Location          = x.Data, MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnThreadPoolThread <StatusMessage>(x => StatusString        = x.Data.ToString(), MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnMainThread <TollRoadChangedMessage>((s) => TollRoadString = s.Data?.Name, MvxReference.Strong));

            await synchronisationService.DataSynchronisationAsync();

            StatusString   = _track.TollStatus.ToString();
            TollRoadString = WaypointChecker.TollRoad?.Name;

            if (_geoWatcher.Location != null)
            {
                Location = _geoWatcher.Location;
                WaypointChecker.DetectWeAreInsideSomeTollPoint(Location);
            }
        }
Exemple #2
0
        public virtual async Task <bool> StartServices()
        {
            bool isGranted = await Mvx.Resolve <IPermissionsService>().CheckPermissionsAccesGrantedAsync();

            if (!IsBound && isGranted)
            {
                Log.LogMessage(string.Format("FACADE HAS STARTED AT {0}", DateTime.Now));
                Debug.WriteLine("Inside tracking service");

                _textToSpeech.IsEnabled = true;
                _activity.StartDetection();
                _geoWatcher.StartGeolocationWatcher();
                Insights.Track("Subscribed on LocationMessage.");
                _locationToken = _messenger.SubscribeOnThreadPoolThread <LocationMessage>(async x =>
                {
                    Log.LogMessage("Start processing LocationMessage");
                    await CheckTrackStatus();
                });
                _tokens.Add(_locationToken);

                Log.LogMessage("Start Facade location detection and subscride on LocationMessage");
                return(true);
            }

            return(false);
        }
 public void Start(IMvxMessenger messenger)
 {
     IsObserving       = true;
     subscriptionToken = _shouldSubscribeOnThreadPool
         ? messenger.SubscribeOnThreadPoolThread <TMessage>(HandleMessage)
         : messenger.SubscribeOnMainThread <TMessage>(HandleMessage);
 }
Exemple #4
0
        public ProductsViewModel(IMvxNavigationService navigationService, IErpService service, IMvxMessenger messenger, IAuthenticationService authenticationService)
        {
            this.navigationService          = navigationService;
            this.service                    = service;
            this.CurrentUserName            = authenticationService.UserName;
            this.productUpdatedMessageToken = messenger.SubscribeOnThreadPoolThread <ProductUpdatedMessage>(OnProductUpdated);
            this.productDeletedMessageToken = messenger.SubscribeOnMainThread <ProductDeletedMessage>(OnProductDeleted);

            this.ProductStockCount = 12800;

            ExpectedStockQuantitues = new NameValuePair[]
            {
                new NameValuePair(DateTime.Today.AddMonths(-2).ToString("MMMM"), 1500),
                new NameValuePair(DateTime.Today.AddMonths(-1).ToString("MMMM"), 1400),
                new NameValuePair(DateTime.Today.ToString("MMMM"), 1600),
            };

            ActualStockQuantitues = new NameValuePair[]
            {
                new NameValuePair(DateTime.Today.AddMonths(-2).ToString("MMMM"), 1723),
                new NameValuePair(DateTime.Today.AddMonths(-1).ToString("MMMM"), 1413),
                new NameValuePair(DateTime.Today.ToString("MMMM"), 2313),
            };

            TopStockProducts = new NameValuePair[]
            {
                new NameValuePair("A", 1423),
                new NameValuePair("B", 2621),
                new NameValuePair("C", 1724),
                new NameValuePair("D", 2223),
                new NameValuePair("E", 1383)
            };

            TopSoldProducts = new NameValuePair[]
            {
                new NameValuePair("A", 14100),
                new NameValuePair("B", 12200),
                new NameValuePair("C", 11300)
            };

            StorageLocations = new NameValuePair[]
            {
                new NameValuePair("New York", 0.35),
                new NameValuePair("Ohio", 0.30),
                new NameValuePair("California", 0.35),
            };

            currentLayoutMode         = LayoutMode.Grid;
            ToggleLayoutModeCommand   = new Command <LayoutMode?>(ChangeLayoutMode);
            this.CreateProductCommand = new MvxCommand(OnCreateProduct);
            this.EditProductCommand   = new MvxCommand <Product>(OnEditProduct);
            this.DeleteProductCommand = new MvxAsyncCommand <Product>(OnDeleteProduct);
            this.SearchCommand        = new MvxAsyncCommand(OnSearch);
            this.AboutCommand         = new MvxCommand(ShowAboutPage);
            this.listDescription      = "All Products";
        }
Exemple #5
0
 public AutomoveActivity()
 {
     _intervalUpdates = Observable.Interval(TimeSpan.FromSeconds(60));
     _activity        = Mvx.Resolve <IMotionActivity> ();
     _messenger       = Mvx.Resolve <IMvxMessenger> ();
     _activities      = new List <MotionType> ();
     _intervalToken   = _intervalUpdates.Subscribe(x => GetMostProbableResult());
     _messengerToken  = _messenger.SubscribeOnThreadPoolThread <MotionMessage> (x => {
         _activities.Add(_activity.MotionType);
     });
 }
Exemple #6
0
        public async override void Start()
        {
            if (await synchronisationService.AuthorizeTokenSynchronisationAsync())
            {
                await Task.Run(RefreshToolRoadsAsync);
            }
            else
            {
                Close(this);
                ShowViewModel <LoginViewModel>();
                return;
            }

            base.Start();

            _tokens.Add(_messenger.SubscribeOnThreadPoolThread <LocationMessage>(x => Location   = x.Data, MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnThreadPoolThread <StatusMessage>(x => StatusString = x.Data.ToString(), MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnThreadPoolThread <MotionMessage>(x => MotionType   = x.Data, MvxReference.Strong));

            _tokens.Add(_messenger.SubscribeOnMainThread <LogUpdated>((s) => LogText = Log._messageLog.ToString(), MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnMainThread <GeoWatcherStatusMessage>((s) => IsBound = s.Data, MvxReference.Strong));

            _tokens.Add(_messenger.SubscribeOnMainThread <CurrentTollpointChangedMessage>((s) => CurrentWaypointString = string.Join("\n", s.Data?.Select(x => x.Name)), MvxReference.Strong));
            _tokens.Add(_messenger.SubscribeOnMainThread <TollRoadChangedMessage>((s) => TollRoadString = s.Data?.Name, MvxReference.Strong));

            if (_geoWatcher.Location != null)
            {
                Location = _geoWatcher.Location;
            }

            LogText = Log._messageLog.ToString();

            StatusString   = _track.TollStatus.ToString();
            TollRoadString = waypointChecker.TollRoad?.Name;
            if (waypointChecker.TollPointsInRadius != null)
            {
                CurrentWaypointString = string.Join("\n", waypointChecker.TollPointsInRadius?.Select(x => x.Name));
            }
        }
Exemple #7
0
 public CustomersListViewModel(Services.IErpService service, IMvxNavigationService navigationService, IMvxMessenger messenger)
 {
     this.service                     = service;
     this.navigationService           = navigationService;
     this.messenger                   = messenger;
     this.customerUpdatedMessageToken = messenger.SubscribeOnThreadPoolThread <CustomerUpdatedMessage>(OnCustomerUpdated);
     this.customerDeletedMessageToken = messenger.SubscribeOnMainThread <CustomerDeletedMessage>(OnCustomerDeleted);
     this.customerSearchMessageToken  = messenger.SubscribeOnMainThread <CustomerSearchMessage>(OnCustomerSearch);
     this.CreateCustomerCommand       = new MvxCommand(OnCreateCustomer);
     this.SearchCommand               = new MvxAsyncCommand(OnSearch);
     this.AboutCommand                = new MvxCommand(ShowAboutPage);
     this.listDescription             = "All Customers";
 }
        public AutomoveActivity(IList <MotionType> activities, IMvxMessenger messenger, IMotionActivity activity)
        {
            _activities = activities;
            _messenger  = messenger;
            _activity   = activity;

            _intervalUpdates = Observable.Interval(TimeSpan.FromSeconds(60));
            _intervalToken   = _intervalUpdates.Subscribe(x => GetMostProbableResult());
            _messengerToken  = _messenger.SubscribeOnThreadPoolThread <MotionMessage>(x =>
            {
                _activities.Add(_activity.MotionType);
            });
        }
Exemple #9
0
        public override void Start()
        {
            base.Start();

            Task.Run(RefreshToolRoads);
            try
            {
                _tokens.Add(_messenger.SubscribeOnThreadPoolThread <LocationMessage>(x => Location   = x.Data, MvxReference.Strong));
                _tokens.Add(_messenger.SubscribeOnThreadPoolThread <StatusMessage>(x => StatusString = x.Data.ToString(), MvxReference.Strong));
                _tokens.Add(_messenger.SubscribeOnThreadPoolThread <MotionMessage>(x => MotionType   = x.Data, MvxReference.Strong));

                _tokens.Add(_messenger.SubscribeOnMainThread <DistanceToNearestTollpoint>((s) => Distance = s.Data, MvxReference.Strong));
                _tokens.Add(_messenger.SubscribeOnMainThread <GeoWatcherStatusMessage>((s) => IsBound     = s.Data, MvxReference.Strong));

                _tokens.Add(_messenger.SubscribeOnMainThread <CurrentTollpointChangedMessage>((s) => NearestTollpointsString = string.Join("\n", s.Data?.Select(x => x.Name)), MvxReference.Strong));
                _tokens.Add(_messenger.SubscribeOnMainThread <TollRoadChangedMessage>((s) => TollRoadString = s.Data?.Name, MvxReference.Strong));

                IsBound = _geoWatcher.IsBound;
                if (_geoWatcher.Location != null)
                {
                    Location = _geoWatcher.Location;
                }

                //LogText = Log._messageLog.ToString();

                StatusString   = _track.TollStatus.ToString();
                TollRoadString = Mvx.Resolve <IWaypointChecker>().TollRoad?.Name;
                Distance       = Mvx.Resolve <IWaypointChecker>().DistanceToNearestTollpoint;
                if (Mvx.Resolve <IWaypointChecker>().TollPointsInRadius != null)
                {
                    NearestTollpointsString = string.Join("\n", Mvx.Resolve <IWaypointChecker>().TollPointsInRadius?.Select(x => x.Name));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Message: {0} StackTrace: {1}", ex.Message, ex.StackTrace);
            }
        }
Exemple #10
0
        public VendorsViewModel(IMvxNavigationService navigationService, IErpService service, IMvxMessenger messenger, IAuthenticationService authenticationService)
        {
            this.navigationService         = navigationService;
            this.service                   = service;
            this.CurrentUserName           = authenticationService.UserName;
            this.vendorUpdatedMessageToken = messenger.SubscribeOnThreadPoolThread <VendorUpdatedMessage>(OnVendorUpdated);
            this.vendorDeletedMessageToken = messenger.SubscribeOnMainThread <VendorDeletedMessage>(OnVendorDeleted);

            this.currentLayoutMode       = LayoutMode.Grid;
            this.ToggleLayoutModeCommand = new Command <LayoutMode?>(ChangeLayoutMode);
            this.SearchCommand           = new MvxAsyncCommand(OnSearch);
            this.AboutCommand            = new MvxCommand(ShowAboutPage);
            this.CreateVendorCommand     = new MvxCommand(OnCreateVendor);
            this.EditVendorCommand       = new MvxCommand <Vendor>(OnEditVendor);
            this.DeleteVendorCommand     = new MvxAsyncCommand <Vendor>(OnDeleteVendor);
            this.listDescription         = "All Vendors";
        }
        public TrackFacade(ITextToSpeechService textToSpeech, IMvxMessenger messenger, IGeoLocationWatcher geoWatcher,
                           IMotionActivity activity, IStoredSettingsService storedSettingsService, IWaypointChecker waypointChecker)
        {
            Log.LogMessage("Facade ctor start");
            _textToSpeech          = textToSpeech;
            _messenger             = messenger;
            _geoWatcher            = geoWatcher;
            _activity              = activity;
            _storedSettingsService = storedSettingsService;
            this.waypointChecker   = waypointChecker;

            _tokens      = new List <MvxSubscriptionToken>(); // was changed
            _semaphor    = new SemaphoreSlim(1);
            _motionToken = _messenger.SubscribeOnThreadPoolThread <MotionMessage>(async x =>
            {
                Log.LogMessage($"[FACADE] receive new motion type {x.Data}");
                switch (x.Data)
                {
                case MotionType.Automotive:
                case MotionType.Running:
                case MotionType.Walking:
                    if ((_storedSettingsService.SleepGPSDateTime == DateTime.MinValue || _storedSettingsService.SleepGPSDateTime < DateTime.Now) &&
                        !IsBound)
                    {
                        Log.LogMessage($"[FACADE] Start geolocating because we are not still");
                        await StartServicesAsync();
                    }
                    break;

                case MotionType.Still:
                    if (IsBound)
                    {
                        Log.LogMessage($"[FACADE] Stop geolocating because we are still");
                        StopServices();
                    }
                    break;
                }
            });
            _tokens.Add(_motionToken);
            Log.LogMessage("Facade ctor end");
        }