Пример #1
0
        /// <summary>
        ///     Provides storage for session state associated with the specified <see cref="Frame" />.
        ///     Frames that have been previously registered with <see cref="RegisterFrame" /> have
        ///     their session state saved and restored automatically as a part of the global
        ///     <see cref="SessionState" />.  Frames that are not registered have transient state
        ///     that can still be useful when restoring pages that have been discarded from the
        ///     navigation cache.
        /// </summary>
        /// <remarks>
        ///     Apps may choose to rely on <see cref="NavigationHelper" /> to manage
        ///     page-specific state instead of working with frame session state directly.
        /// </remarks>
        /// <param name="frame">The instance for which session state is desired.</param>
        /// <returns>
        ///     A collection of state subject to the same serialization mechanism as
        ///     <see cref="SessionState" />.
        /// </returns>
        public static Dictionary <string, object> SessionStateForFrame(Frame frame)
        {
            var frameState = (Dictionary <string, object>)frame.GetValue(FrameSessionStateProperty);

            if (frameState == null)
            {
                var frameSessionKey = (string)frame.GetValue(FrameSessionStateKeyProperty);
                if (frameSessionKey != null)
                {
                    // Registered frames reflect the corresponding session state
                    if (!SessionState.ContainsKey(frameSessionKey))
                    {
                        SessionState[frameSessionKey] = new Dictionary <string, object>();
                    }
                    frameState = (Dictionary <string, object>)SessionState[frameSessionKey];
                }
                else
                {
                    // Frames that aren't registered have transient state
                    frameState = new Dictionary <string, object>();
                }
                frame.SetValue(FrameSessionStateProperty, frameState);
            }
            return(frameState);
        }
Пример #2
0
        public override void OnNavigatedTo(Dictionary <string, object> parameters, NavigationMode mode)
        {
            if (_qrScanner != null && !_qrScanner.IsStarted)
            {
                _qrScanner.StartAsync();
            }

            Employee = (Employee)parameters["Employee"];

            if (mode == NavigationMode.Back)
            {
                if (SessionState.ContainsKey("DevicesToTake"))
                {
                    _devicesToTake = (ObservableCollection <Device>)SessionState["DevicesToTake"];
                }
                if (SessionState.ContainsKey("DevicesToReturn"))
                {
                    _devicesToReturn = (ObservableCollection <Device>)SessionState["DevicesToReturn"];
                }

                UpdateDeviceGroups();
            }

            LoadData();

            LogOutService.Restart();
        }
        public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            var shareArgs = args as ShareTargetActivatedEventArgs;

            if (shareArgs != null)
            {
                var key = nameof(ShareOperation);
                if (SessionState.ContainsKey(key))
                {
                    SessionState.Remove(key);
                }
                SessionState.Add(key, shareArgs.ShareOperation);

                var frame = new Frame();
                var nav   = NavigationServiceFactory(BackButton.Ignore, ExistingContent.Exclude, frame);
                Window.Current.Content = frame;
                nav.Navigate(typeof(Views.SharePage), key);
            }
            else
            {
                var nav = NavigationService ?? NavigationServiceFactory(BackButton.Attach, ExistingContent.Include);
                Window.Current.Content = nav.Frame;
                nav.Navigate(typeof(Views.MainPage));
            }
            return(Task.CompletedTask);
        }
 public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
 {
     if (SessionState.ContainsKey("User"))
     {
         SessionState.Remove("User");
     }
     await Task.CompletedTask;
 }
Пример #5
0
        /// <summary>
        /// Stores the value with the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="data">The data.</param>
        public void Store(string key, object data)
        {
            if (!SessionState.ContainsKey(key))
            {
                _keys.Add(key);
            }

            SessionState[key] = data;
        }
Пример #6
0
        public bool CheckCurrentSession()
        {
            if (!SessionState.ContainsKey("Squadron"))
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
        public async void ClickCommand(object sender, object parameter)
        {
            var arg = parameter as Windows.UI.Xaml.Controls.ItemClickEventArgs;

            SelectedPost = arg.ClickedItem as Post;
            if (SessionState.ContainsKey("selectedPost"))
            {
                SessionState.Remove("selectedPost");
            }
            SessionState.Add("selectedPost", SelectedPost);
            NavigationService.Navigate(typeof(Views.DetailPage));
        }
Пример #8
0
        public override async Task ActivateAsync(object parameter, IDictionary <string, object> state, NavigationMode mode)
        {
            CameraIsSupported = await _device.GetHasCameraAsync();

            _loggingService.WriteLine($"Camera is supported: {CameraIsSupported}");

            if (state.Count > 0)
            {
                _loggingService.WriteLine("PageState.Count was greater than zero. Restoring.");
                _loggingService.WriteObject(state);

                Username     = state[nameof(Username)] as string;
                Password     = state[nameof(Password)] as string;
                Url          = state[nameof(Url)] as string;
                ClientId     = state[nameof(ClientId)] as string;
                ClientSecret = state[nameof(ClientSecret)] as string;

                CurrentStep       = (int)state[nameof(CurrentStep)];
                UseCustomSettings = (bool?)state[nameof(UseCustomSettings)];

                _restoredFromPageState = true;
            }

            _loggingService.WriteLine("Checking for navigation parameter.");
            ProtocolSetupNavigationParameter protocolSetupParameter = null;

            if (parameter is ProtocolSetupNavigationParameter)
            {
                protocolSetupParameter = parameter as ProtocolSetupNavigationParameter;
                _loggingService.WriteLine($"Parameter existing. Setting it as {nameof(protocolSetupParameter)}.");
            }

            if (SessionState.ContainsKey(QRScanPageViewModel.m_QRRESULTKEY))
            {
                _loggingService.WriteLine($"{nameof(SessionState)} contained {QRScanPageViewModel.m_QRRESULTKEY}. Set it as {nameof(protocolSetupParameter)}.");
                protocolSetupParameter = SessionState[QRScanPageViewModel.m_QRRESULTKEY] as ProtocolSetupNavigationParameter;
            }

            if (protocolSetupParameter != null)
            {
                _loggingService.WriteLine($"Making use of the {nameof(ProtocolSetupNavigationParameter)}.");

                Username = protocolSetupParameter.Username;
                Url      = protocolSetupParameter.Server;

                SelectedProvider = WallabagProvider.GetOther(_device);

                CurrentStep = 1;
            }
        }
Пример #9
0
        public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            //remove the solid-colored backgrounds behind the caption controls and system back button
            ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;

            titleBar.ButtonBackgroundColor         = Colors.Transparent;
            titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            // TODO: add your long-running task here
            if (!SessionState.ContainsKey("State"))
            {
                SessionState.Add("State", new XWingSessionState(await XWingRepository.CreateXWingRepository()));
            }
            //await NavigationService.NavigateAsync(typeof(Views.Shell));
        }
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (state.Any())
            {
            }

            var key = parameter as string;

            if (SessionState.ContainsKey(key))
            {
                //easy way
            }
            else
            {
                //hard way
            }
            //mode = NavigationMode.Back;
            return(base.OnNavigatedToAsync(parameter, mode, state));
        }
Пример #11
0
        private async Task <User> GetUserFromSessionStateAsync()
        {
            if (SessionState.ContainsKey("User"))
            {
                return(SessionState["User"] as User);
            }
            else
            {
                ContentDialog dlg = new ContentDialog()
                {
                    Title             = "Access denied",
                    PrimaryButtonText = "I'm sorry!",
                    Content           = "You haven't logged in yet. Please select a user profile before proceding."
                };
                await dlg.ShowAsync();

                return(null);
            }
        }
Пример #12
0
        //todo: refactor the favorite/secondary tile stuff to use the same type if possible
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            _favoritesService.FavoritesChanged += FavoritesChanged;

            Views.Busy.BusyCancelled += Busy_BusyCancelled;

            if (mode != NavigationMode.Back)
            {
                //---Plan trip from favorites
                var placeArgs = parameter as NavigateWithFavoritePlaceArgs;
                if (placeArgs != null)
                {
                    if (placeArgs.PlaceNavigationType == NavigationType.AsDestination)
                    {
                        ToPlace = placeArgs.Place;
                    }
                    else if (placeArgs.PlaceNavigationType == NavigationType.AsOrigin)

                    {
                        FromPlace = placeArgs.Place;
                    }
                    else if (placeArgs.PlaceNavigationType == NavigationType.AsIntermediate)
                    {
                        if (placeArgs.IntermediateIndex != null)
                        {
                            IntermediatePlaces.Insert(placeArgs.IntermediateIndex.Value, new IntermediateSearchViewModel(this, placeArgs.Place));
                        }
                    }
                    if (PlanTripCommand.CanExecute(null))
                    {
                        PlanTripCommand.Execute(null);
                    }
                }

                var routeArgs = parameter as FavoriteRoute;
                if (routeArgs != null)
                {
                    var firstPlace = routeArgs.RoutePlaces.First();
                    FromPlace = new Place {
                        Type = PlaceType.Address, Lat = (float)firstPlace.Lat, Lon = (float)firstPlace.Lon, Name = firstPlace.Name
                    };
                    var lastPlace = routeArgs.RoutePlaces.Last();
                    ToPlace = new Place {
                        Type = PlaceType.Address, Lat = (float)lastPlace.Lat, Lon = (float)lastPlace.Lon, Name = lastPlace.Name
                    };
                    if (PlanTripCommand.CanExecute(null))
                    {
                        PlanTripCommand.Execute(null);
                    }
                }

                //---Plan trip from tile
                if (SessionState.ContainsKey(NavParamKeys.SecondaryTilePayload))
                {
                    var secondaryTileArgs = (SecondaryTilePayload)SessionState[NavParamKeys.SecondaryTilePayload];
                    SecondaryTileInvoked(secondaryTileArgs);
                    SessionState.Remove(NavParamKeys.SecondaryTilePayload);
                }
            }

            await FillPinnedFavorites();

            await Task.CompletedTask;
        }
Пример #13
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var key = parameter as string;

            if (key != null && SessionState.ContainsKey(key))
            {
                ShareOperation = SessionState.Get <ShareOperation>(key);
            }
            else
            {
                Content = "Opened without using share";
                return;
            }

            try
            {
                if (this.ShareOperation.Data.Contains(StandardDataFormats.Html))
                {
                    Content = (await ShareOperation.Data.GetHtmlFormatAsync()).ToString();
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.Text))
                {
                    Content = (await ShareOperation.Data.GetTextAsync()).ToString();
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.WebLink))
                {
                    Content = (await ShareOperation.Data.GetWebLinkAsync()).AbsoluteUri;
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.ApplicationLink))
                {
                    Content = (await ShareOperation.Data.GetApplicationLinkAsync()).AbsoluteUri;
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.Bitmap))
                {
                    Content = nameof(StandardDataFormats.Bitmap);
                    var bitmap = await ShareOperation.Data.GetBitmapAsync();

                    using (var stream = await bitmap.OpenReadAsync())
                    {
                        Bitmap = new BitmapImage();
                        Bitmap.SetSource(stream);
                    }
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.StorageItems))
                {
                    Content = nameof(StandardDataFormats.StorageItems);
                    foreach (var item in await ShareOperation.Data.GetStorageItemsAsync())
                    {
                        Content += item.Path + Environment.NewLine;
                    }
                }
                else
                {
                    Content = "Some unsupported share type.";
                    return;
                }

                QuickLink = ShareOperation.QuickLinkId ?? "None set";

                if (ShareOperation.Data.Properties.Square30x30Logo != null)
                {
                    using (var stream = await ShareOperation.Data.Properties.Square30x30Logo.OpenReadAsync())
                    {
                        Logo = new BitmapImage();
                        Logo.SetSource(stream);
                    }
                }

                if (ShareOperation.Data.Properties.Thumbnail != null)
                {
                    using (var stream = await ShareOperation.Data.Properties.Thumbnail.OpenReadAsync())
                    {
                        Thumbnail = new BitmapImage();
                        Thumbnail.SetSource(stream);
                    }
                }
            }
            catch (Exception e) { Content = e.Message; }
        }