Esempio n. 1
0
 /// <summary>
 ///   Subscribes an instance to all events declared through implementations of <see cref = "IHandle{T}" />
 /// </summary>
 /// <param name = "instance">The instance to subscribe for event publication.</param>
 /// <returns>True if EventAggregator is available and operation was successful</returns>
 public static bool Subscribe(object instance)
 {
     if (!EventAggregatorLocator.IsAvailable)
     {
         return(false);
     }
     EventAggregatorLocator.GetPart().Subscribe(instance);
     return(true);
 }
Esempio n. 2
0
        /// <summary>
        ///     Save the current <see cref="SessionState" />.  Any <see cref="Frame" /> instances
        ///     registered with <see cref="RegisterFrame" /> will also preserve their current
        ///     navigation stack, which in turn gives their active <see cref="Page" /> an opportunity
        ///     to save its state.
        /// </summary>
        /// <returns>An asynchronous task that reflects when session state has been saved.</returns>
        public static async Task SaveAsync()
        {
            try
            {
                // Notify Root Navigator and AuthenticationService that we are suspending
                if (RootNavigatorLocator.IsAvailable)
                {
                    EventFns.Forward(RootNavigatorLocator.GetPart(), new Suspending(SessionState));
                }
                if (AuthenticationServiceLocator.IsAvailable)
                {
                    EventFns.Forward(AuthenticationServiceLocator.GetPart(), new Suspending(SessionState));
                }

                // Save the navigation state for all registered frames
                foreach (var weakFrameReference in RegisteredFrames)
                {
                    Frame frame;
                    if (weakFrameReference.TryGetTarget(out frame))
                    {
                        SaveFrameNavigationState(frame);
                    }
                }

                // Serialize the session state synchronously to avoid asynchronous access to shared
                // state
                var sessionData = new MemoryStream();
                var serializer  = new DataContractSerializer(typeof(Dictionary <string, object>), KnownTypes);
                serializer.WriteObject(sessionData, _sessionState);

                // Get an output stream for the SessionState file and write the state asynchronously
                var file =
                    await
                    ApplicationData.Current.LocalFolder.CreateFileAsync(SessionStateFilename,
                                                                        CreationCollisionOption.ReplaceExisting);

                using (var fileStream = await file.OpenStreamForWriteAsync())
                {
                    sessionData.Seek(0, SeekOrigin.Begin);
                    await sessionData.CopyToAsync(fileStream);

                    await fileStream.FlushAsync();
                }
            }
            catch (Exception e)
            {
                throw new SuspensionManagerException(e);
            }
        }
Esempio n. 3
0
        private MessageBoxBase CreateMessageBox(string message)
        {
            var messageBoxLocator = new PartLocator <MessageBoxBase>(true)
                                    .WithDefaultGenerator(() => new MessageBoxBase());

            return(messageBoxLocator.GetPart().Start(message));
        }
Esempio n. 4
0
        private static void OnEntityManagerCreated(object sender, EntityManagerCreatedEventArgs args)
        {
            if (!args.EntityManager.IsClient)
            {
                return;
            }

            var locator = new PartLocator <IAuthenticationService>(false, () => args.EntityManager.CompositionContext);

            if (locator.IsAvailable)
            {
                args.EntityManager.AuthenticationContext = locator.GetPart().AuthenticationContext;
            }
        }
Esempio n. 5
0
        internal Task <T> Show()
        {
            _dialogHost = _dialogHostLocator.GetPart().Start(_title, _content, _commands);
            var tcs = new TaskCompletionSource <T>();

            _dialogHost.Completed += (sender, args) =>
            {
                if (Cancelled)
                {
                    tcs.SetCanceled();
                }
                else
                {
                    tcs.SetResult(DialogResult);
                }
            };
            _windowManager.ShowDialog(_dialogHost);
            return(tcs.Task);
        }