Esempio n. 1
0
        public async Task GoToProfilePage(string id)
        {
            Profile prof = _pages.GetPage(Pages.ProfilePage) as Profile;
            await App.ProfileViewModel.GetData(id);

            await PushModal(prof, true);
        }
Esempio n. 2
0
        public void Navigate(Type pageType)
        {
            if (CurrentPage != null)
            {
                _pageHistory.Push(CurrentPage.GetType());
            }

            CurrentPage = _pageFactory.GetPage(pageType);
            _pageForward.Clear();
        }
Esempio n. 3
0
 public async Task LoggedIn(bool result)
 {
     if (result)
     {
         await _navi.PushAsync(_pages.GetPage(Pages.Categories));
     }
     else
     {
         await _navi.DisplayAlert("Error", "Invalid username or password", "ok");
     }
 }
Esempio n. 4
0
        public OrderViewModel(IOrderValidationService validator,
                              ICurrentUserService userCache,
                              IOrderService orderService,
                              IToastService toast,
                              IPageFactory pageFactory,
                              MainThreadNavigator nav,
                              IMessagingSubscriber topicSubscriber,
                              ILogger <OrderViewModel> logger,
                              string deviceType,
                              AlertUtility alertUtility,
                              Action <BaseNavPageType> baseNavigationAction,
                              ICache <Models.Order> orderCache)
        {
            _orderValidator       = validator;
            _userService          = userCache;
            _toast                = toast;
            _nav                  = nav;
            _orderService         = orderService;
            _pageFactory          = pageFactory;
            _orderCache           = orderCache;
            _alertUtility         = alertUtility;
            _topicSubscriber      = topicSubscriber;
            _baseNavigationAction = baseNavigationAction;
            _deviceType           = deviceType;
            _logger               = logger;

            PurchaseOptionsCommand = new Command(async() =>
            {
                var val = await _orderValidator.ValidateOrderRequest(_userService.GetLoggedInAccount());
                if (SubscriptionUtility.SubscriptionActive(val.Subscription))
                {
                    _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, val));
                }
                else
                {
                    _nav.Push(_pageFactory.GetPage(PageType.PurchaseOptions, val));
                }
            });
            OptionsInfoCommand = new Command(async() => await alertUtility.Display("Roof Option Selection",
                                                                                   $"Selecting a roof option allows Fair Squares to determine what roofs you would like measured at the submitted address.{Environment.NewLine}" +
                                                                                   $"{Environment.NewLine}Primary Only- Fair Squares will measure the primary structure, including attached garage.{Environment.NewLine}" +
                                                                                   $"Detached Garage- Fair Squares will also measure the detached garage on the property.{Environment.NewLine}" +
                                                                                   $"Shed/Barn- Fair Squares will also measure a shed or barn on the property.{Environment.NewLine}" +
                                                                                   $"{Environment.NewLine}NOTE: Fair Squares only supports measuring one primary structure per report (with a detached garage or shed/barn if needed).",
                                                                                   "Ok"));
            ErrorMessageRowHeight = 0;
            SelectedOptionIndex   = -1;
            SelectedStateIndex    = -1;
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            SetVisualStateForValidation();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
Esempio n. 5
0
        IndexItem GetIndexItem(long index)
        {
            IndexItem indexItem;

            var indexPage = _indexPageFactory.GetPage(GetIndexPageIndex(index));

            using (var stream = indexPage.GetReadStream(GetIndexItemOffset(index), IndexItemSize))
            {
                indexItem = IndexItem.ReadFromStream(stream);
            }
            _indexPageFactory.ReleasePage(indexPage.Index);

            return(indexItem);
        }
Esempio n. 6
0
        public async Task ShowLogin()
        {
            var isLoggedIn = _login.IsLoggedIn();

            if (isLoggedIn)
            {
                await _navi.GoToProfileTab();
            }
            else
            {
                await _navi.PopToRootAsync(false);

                await _navi.PushAsync(_pages.GetPage(Pages.Login), false);
            }
        }
 public ManageSubscriptionViewModel(ValidationModel model,
                                    string runtimePlatform,
                                    Action <Uri> openUri,
                                    MainThreadNavigator nav,
                                    ILogger <ManageSubscriptionViewModel> logger,
                                    IPageFactory pageFactory)
 {
     _model           = model;
     _runtimePlatform = runtimePlatform;
     _openUri         = openUri;
     _nav             = nav;
     _logger          = logger;
     _pageFactory     = pageFactory;
     try
     {
         SubscriptionTypeLabel = "   " + _model.Subscription.SubscriptionType.ToString();
         RemainingOrdersLabel  = "   " + _model.RemainingOrders.ToString();
         PurchasedOrdersLabel  = "   " + _model.PurchasedReports?.Count.ToString();
         EndDateLabel          = "   " + _model.Subscription.EndDateTime.ToString("dddd, dd MMMM yyyy");
         GetMoreReportsLabel   = $"Purchase additional reports at a reduced price of ${SubscriptionUtility.GetSingleReportInfo(_model).Price} per report.";
         GetMoreReportsCommand = new Command(() => _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, _model)));
         var compName   = _runtimePlatform == Device.Android ? "Google" : "Apple";
         var supportUri = _runtimePlatform == Device.Android ? "https://support.google.com/googleplay/answer/7018481" :
                          "https://support.apple.com/en-us/HT202039#subscriptions";
         DisclaimerLabel  = $"NOTE: {compName} does not allow subscriptions to be cancelled through the app. This button will open a web browser with instructions on how to cancel from your device.";
         CancelSubCommand = new Command(() => _openUri(new Uri(supportUri)));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to load manage subscription page.", ex);
     }
 }
Esempio n. 8
0
        private void InitializeMetaData()
        {
            var metaPage = _metaPageFactory.GetPage(0);

            using (var readStream = metaPage.GetReadStream(0, _metaDataItemSize))
            {
                _metaData = MetaData.ReadFromStream(readStream);
            }

            // Update local data pointers from previously persisted index item
            var prevTailIndex     = GetPreviousIndex(_metaData.TailIndex);
            var prevTailIndexItem = GetIndexItem(prevTailIndex);

            _tailDataPageIndex  = prevTailIndexItem.DataPageIndex;
            _tailDataItemOffset = prevTailIndexItem.ItemOffset + prevTailIndexItem.ItemLength;
        }
Esempio n. 9
0
 public MainViewModel(PageService pageService, IPageFactory pageFactory)
 {
     _pageFactory              = pageFactory;
     _pageService              = pageService;
     _pageService.PageChanged += (page) => PageSource = page;
     _pageService.OnPageChanged(_pageFactory.GetPage(PageType.General).Result);
 }
 public BaseTabViewModel(ICache <SettingsModel> settings,
                         IPageFactory pageFactory,
                         ILogger <BaseTabViewModel> logger,
                         MainThreadNavigator nav)
 {
     _settings           = settings;
     _pageFactory        = pageFactory;
     _logger             = logger;
     _nav                = nav;
     OnAppearingBehavior = new Command(() =>
     {
         try
         {
             if (!_dialogShown && (!_settings.GetAll().Any() || _settings.Get("").DisplayWelcomeMessage))
             {
                 _dialogShown = true;
                 _nav.Push(_pageFactory.GetPage(PageType.Instruction, true));
             }
         }
         catch (Exception ex)
         {
             _logger.LogError($"Failed to check settings on load.", ex);
         }
     });
 }
Esempio n. 11
0
        private async Task HandleSubmitClick()
        {
            try
            {
                var user = _userService.GetLoggedInAccount();

                SubmitButtonEnabled = false;
                ErrorMessage        = "";
                if (string.IsNullOrWhiteSpace(AddressLine1) ||
                    string.IsNullOrWhiteSpace(City) ||
                    SelectedStateIndex < 0 ||
                    SelectedOptionIndex < 0 ||
                    string.IsNullOrWhiteSpace(Zip))
                {
                    ErrorMessageRowHeight = GridLength.Star;
                    ErrorMessage          = "Please fill out all fields before submitting.";
                    SubmitButtonEnabled   = true;
                    return;
                }
                if (user == null)
                {
                    var answer = await _alertUtility.Display("Please Log In", "Please log in first to submit a report.", "Login", "Cancel");

                    if (!answer)
                    {
                        SubmitButtonEnabled = true;
                        return;
                    }
                    _nav.Push(_pageFactory.GetPage(PageType.Landing));
                    SubmitButtonEnabled = true;
                    return;
                }
                await SubmitOrder(user.UserId, user.Email);
            }
            catch (Exception ex)
            {
                ErrorMessageRowHeight = GridLength.Star;
                SubmitButtonEnabled   = true;
                ErrorMessage          = $"Failed to submit order with error {ex.Message}";
                _logger.LogError($"Failed to submit order.", ex);
            }
            finally
            {
                try
                {
                    await SetVisualStateForValidation();
                }
                catch { }
            }
        }
 private void HandleSelectedItemChange(OrderViewCell selected)
 {
     try
     {
         if (selected == null)
         {
             return;
         }
         var id = selected.OrderId;
         _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, _orderCache.Get(id)));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to handle selected item change event.", ex);
     }
     OrderListSelectedItem = null;
 }
        private async Task SubmitFeedback(string feedback)
        {
            if (string.IsNullOrWhiteSpace(feedback))
            {
                return;
            }
            var user = _userCache.GetLoggedInAccount();

            if (user == null)
            {
                var response = await _alertUtility.Display("Not Logged In", "Because you are not logged in, Fair Squares staff will not be able to respond to your feedback. " +
                                                           "Are you sure you want to continue?", "Continue", "Log In");

                if (!response)
                {
                    _nav.Push(_pageFactory.GetPage(PageType.Landing));
                    return;
                }
            }
            try
            {
                _notifier.Notify(new Models.NotificationRequest()
                {
                    From        = "*****@*****.**",
                    To          = "*****@*****.**",
                    Message     = feedback,
                    MessageType = Models.MessageType.Email,
                    Subject     = "Feedback from " + user?.Email
                });
                await _alertUtility.Display("Feedback Submitted", "Thank you for your feedback!", "Ok");
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to submit feedback.", ex, $"Feedback: {feedback}");
            }
            _nav.Pop();
        }
        public MyOrdersViewModel(IOrderService orderSvc,
                                 ICache <Models.Order> orderCache,
                                 ICache <PropertyModel> propertyCache,
                                 ICache <ImageModel> imageCache,
                                 ILogger <MyOrdersViewModel> logger,
                                 ICacheRefresher cacheRefresher,
                                 IOrderValidationService validator,
                                 IPageFactory pageFactory,
                                 ICurrentUserService userService,
                                 LaunchedFromPushModel pushModel,
                                 MainThreadNavigator nav,
                                 IMessagingCenter messagingCenter,
                                 Action <Action> uiInvoke,
                                 Action <BaseNavPageType> baseNavAction)
        {
            _orderService      = orderSvc;
            _orderCache        = orderCache;
            _propertyCache     = propertyCache;
            _imageCache        = imageCache;
            _logger            = logger;
            _uiInvoke          = uiInvoke;
            _cacheRefresher    = cacheRefresher;
            _validationService = validator;
            _pageFactory       = pageFactory;
            _userService       = userService;
            _messagingCenter   = messagingCenter;
            _nav                 = nav;
            _baseNavAction       = baseNavAction;
            ExampleReportCommand = new Command(() =>
            {
                try
                {
                    var order = JsonConvert.DeserializeObject <Models.Order>(Examples.ExampleOrder);
                    _imageCache.Put(order.OrderId, new ImageModel()
                    {
                        OrderId = order.OrderId,
                        Image   = Convert.FromBase64String(Examples.ExampleImage)
                    });
                    _propertyCache.Put(order.OrderId, JsonConvert.DeserializeObject <PropertyModel>(Examples.ExampleProperty));
                    _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"An error occurred while trying to open example order.", ex);
                }
            });
            Action refreshAction = async() =>
            {
                try
                {
                    OrderListRefreshing = true;
                    var fresh = await _orderService.GetMemberOrders(_userService.GetLoggedInAccount()?.UserId);

                    _orderCache.Put(fresh.ToDictionary(x => x.OrderId, x => x));
                    SetListViewSource(fresh.ToList());
                    OrderListRefreshing = false;
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Failed to refresh order list.", ex);
                }
            };

            OrderListRefreshCommand = new Command(refreshAction);
            _messagingCenter.Subscribe <App>(this, "CacheInvalidated", async x =>
            {
                await this.SetViewState();
            });
            OnAppearingBehavior = new Command(async() =>
            {
                if (!_pmEventSubscribed)
                {
                    _pmEventSubscribed         = true;
                    pushModel.PropertyChanged += async(s, e) =>
                    {
                        if (!string.IsNullOrWhiteSpace(pushModel.OrderId))
                        {
                            var order = await _orderService.GetOrder(pushModel.OrderId);
                            _orderCache.Put(order.OrderId, order);
                            _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order));
                        }
                    };
                }
                await SetViewState();
            });
        }
Esempio n. 15
0
 private async Task SetInitialState(AccountModel user)
 {
     ToolbarInfoCommand = new Command(() => _navigation.Push(_pageFactory.GetPage(PageType.Instruction, false)));
     LogOutCommand      = new Command(async() =>
     {
         if (_userCache.GetLoggedInAccount() == null)
         {
             _navigation.Push(_pageFactory.GetPage(PageType.Landing));
         }
         else
         {
             _userCache.LogOut();
             SetAccountState(null);
             await SetSubState(null);
         }
     });
     SubscriptionCommand = new Command(async() =>
     {
         if (_userCache.GetLoggedInAccount() == null)
         {
             return;
         }
         var valid = await _orderValidator.ValidateOrderRequest(_userCache.GetLoggedInAccount());
         try
         {
             SubscriptionButtonEnabled = false;
             if (SubscriptionUtility.SubscriptionActive(valid.Subscription))
             {
                 _navigation.Push(_pageFactory.GetPage(PageType.ManageSubscription, valid));
             }
             else
             {
                 _navigation.Push(_pageFactory.GetPage(PageType.PurchaseOptions, valid));
             }
         }
         catch (Exception ex)
         {
             _logger.LogError("Failed to handle subscription click command.", ex);
         }
         finally
         {
             SubscriptionButtonEnabled = true;
         }
     });
     FeedbackCommand = new Command(() =>
     {
         try
         {
             FeedbackButtonEnabled = false;
             _navigation.Push(_pageFactory.GetPage(PageType.Feedback, _navigation));
         }
         catch (Exception ex)
         {
             _logger.LogError("Failed to handle feedback click command.", ex);
         }
         finally
         {
             FeedbackButtonEnabled = true;
         }
     });
     SetAccountState(user);
     await SetSubState(user);
 }
Esempio n. 16
0
        public void Initialize()
        {
            IPageViewModel page = m_pageFactory.GetPage <HomeViewModel>();

            CurrentPage = page;
        }
Esempio n. 17
0
        public void Enqueue(ReadOnlySpan <byte> itemData)
        {
            lock (_lockObject)
            {
                // Throw or silently return if itemData is null?
                if (itemData == null)
                {
                    return;
                }

                if (itemData.Length > _dataPageSize)
                {
                    throw new ArgumentOutOfRangeException(nameof(itemData),
                                                          "Item data length is greater than queue data page size");
                }

                if (_tailDataItemOffset + itemData.Length > _dataPageSize) // Not enough space in current page
                {
                    _tailDataPageIndex++;
                    _tailDataItemOffset = 0;
                }

                // Get data page
                var dataPage = _dataPageFactory.GetPage(_tailDataPageIndex);

                // Get write stream
                using (var writeStream = dataPage.GetWriteStream(_tailDataItemOffset, itemData.Length))
                {
                    // Write data to write stream
                    writeStream.Write(itemData);
                }

                // Release our reference to the data page
                _dataPageFactory.ReleasePage(_tailDataPageIndex);

                // Udate index
                // Get index page
                var indexPage = _indexPageFactory.GetPage(GetIndexPageIndex(_metaData.TailIndex));

                // Get write stream
                using (var writeStream =
                           indexPage.GetWriteStream(GetIndexItemOffset(_metaData.TailIndex), _indexItemSize))
                {
                    var indexItem = new IndexItem
                    {
                        DataPageIndex = _tailDataPageIndex,
                        ItemOffset    = _tailDataItemOffset,
                        ItemLength    = itemData.Length
                    };
                    indexItem.WriteToStream(writeStream);
                }

                _indexPageFactory.ReleasePage(GetIndexPageIndex(_metaData.TailIndex));

                // Advance
                _tailDataItemOffset += itemData.Length;

                // Update meta data
                _metaData.TailIndex++;

                _queueMonitor.Update(_metaData.TailIndex);
                PersistMetaData();
            }
        }
Esempio n. 18
0
        public IPage GetPage(TcmUri pageId)
        {
            var page = _pageFactory.GetPage(pageId.ToString());

            return(page);
        }