Esempio n. 1
0
        private void PublishEvent(EventArgs eventArgs)
        {
            EventFns.Publish(new EntityManagerEventMessage <T>(Manager, eventArgs));

            var entityChangedEventArgs = eventArgs as EntityChangedEventArgs;

            if (entityChangedEventArgs != null)
            {
                EntityChanged(Manager, entityChangedEventArgs);
            }

            var entityQueryingEventArgs = eventArgs as EntityQueryingEventArgs;

            if (entityQueryingEventArgs != null)
            {
                Querying(Manager, entityQueryingEventArgs);
            }

            var entitySavingEventArgs = eventArgs as EntitySavingEventArgs;

            if (entitySavingEventArgs != null)
            {
                Saving(Manager, entitySavingEventArgs);
            }

            var entitySavedEventArgs = eventArgs as EntitySavedEventArgs;

            if (entitySavedEventArgs != null)
            {
                Saved(Manager, entitySavedEventArgs);
            }
        }
Esempio n. 2
0
        private T CreateEntityManagerCore()
        {
            var compositionProvider = Composition.Provider as ISupportsRecomposition;

            if (compositionProvider != null && compositionProvider.IsRecomposing)
            {
                throw new InvalidOperationException(StringResources.CreatingEntityManagerDuringRecompositionNotAllowed);
            }

            Composition.BuildUp(this);
            EventFns.Subscribe(this);
            EnsureDelegates();
            var manager = CreateEntityManager();

            if (ConnectionOptions.IsDesignTime)
            {
                manager.Fetching +=
                    delegate { throw new InvalidOperationException(StringResources.ManagerTriedToFetchData); };
                manager.Saving +=
                    delegate { throw new InvalidOperationException(StringResources.ManagerTriedToSaveData); };

                if (SampleDataProviders != null)
                {
                    SampleDataProviders.ForEach(p => p.AddSampleData(manager));
                }
            }

            return(manager);
        }
Esempio n. 3
0
        /// <summary>
        ///   Raises the <see cref="Completed" /> event.
        /// </summary>
        protected void OnComplete()
        {
            if (Completed == null)
            {
                return;
            }

            EventFns.RaiseOnce(ref Completed, this, EventArgs.Empty);
        }
Esempio n. 4
0
        private void PublishEntities(IEnumerable <object> exportEntities)
        {
            var syncData = new SyncDataMessage(this, exportEntities, _deletedEntityKeys);

            EventFns.Publish(syncData);

            // Signal to our clients that data has changed
            if (syncData.SavedEntities.Any() || syncData.DeletedEntityKeys.Any())
            {
                RaiseDataChangedEvent(syncData.SavedEntities, syncData.DeletedEntityKeys);
            }
        }
Esempio n. 5
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. 6
0
        private void OnComplete(INotifyCompletedArgs args)
        {
            if (Completed == null)
            {
                return;
            }

            var resultArgs = new ResultCompletionEventArgs
            {
                Error        = args.IsErrorHandled ? null : args.Error,
                WasCancelled = args.Cancelled
            };

            EventFns.RaiseOnce(ref Completed, this, resultArgs);
        }
Esempio n. 7
0
        /// <summary>
        ///     Restores previously saved <see cref="SessionState" />.  Any <see cref="Frame" /> instances
        ///     registered with <see cref="RegisterFrame" /> will also restore their prior navigation
        ///     state, which in turn gives their active <see cref="Page" /> an opportunity restore its
        ///     state.
        /// </summary>
        /// <returns>
        ///     An asynchronous task that reflects when session state has been read.  The
        ///     content of <see cref="SessionState" /> should not be relied upon until this task
        ///     completes.
        /// </returns>
        public static async Task RestoreAsync()
        {
            _sessionState = new Dictionary <String, Object>();

            try
            {
                // Get the input stream for the SessionState file
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync(SessionStateFilename);

                using (var inStream = await file.OpenSequentialReadAsync())
                {
                    // Deserialize the Session State
                    var serializer = new DataContractSerializer(typeof(Dictionary <string, object>), KnownTypes);
                    _sessionState = (Dictionary <string, object>)serializer.ReadObject(inStream.AsStreamForRead());
                }

                // Notify Root Navigator and AuthenticationService that we are restoring
                if (RootNavigatorLocator.IsAvailable)
                {
                    EventFns.Forward(RootNavigatorLocator.GetPart(), new Restoring(SessionState));
                }
                if (AuthenticationServiceLocator.IsAvailable)
                {
                    EventFns.Forward(AuthenticationServiceLocator.GetPart(), new Restoring(SessionState));
                }

                // Restore any registered frames to their saved state
                foreach (var weakFrameReference in RegisteredFrames)
                {
                    Frame frame;
                    if (weakFrameReference.TryGetTarget(out frame))
                    {
                        frame.ClearValue(FrameSessionStateProperty);
                        RestoreFrameNavigationState(frame);
                    }
                }
            }
            catch (Exception e)
            {
                throw new SuspensionManagerException(e);
            }
        }
Esempio n. 8
0
 /// <summary>
 ///   Triggers the PrincipalChanged event.
 /// </summary>
 protected virtual void OnPrincipalChanged()
 {
     NotifyPropertyChanged("Principal");
     PrincipalChanged(this, EventArgs.Empty);
     EventFns.Publish(new PrincipalChangedMessage(Principal));
 }