Esempio n. 1
0
 /// <summary>
 /// Create a new instance of the args
 /// </summary>
 /// <param name="oldState">The old state of the item</param>
 /// <param name="newState">The new state of the item</param>
 public LazyDataItemStateChangedEventArgs(LazyDataLoadState oldState, LazyDataLoadState newState)
 {
     OldState = oldState;
     NewState = newState;
 }
 /// <summary>
 /// Create a new instance of the args
 /// </summary>
 /// <param name="oldState">The old state of the item</param>
 /// <param name="newState">The new state of the item</param>
 public LazyDataItemStateChangedEventArgs(LazyDataLoadState oldState, LazyDataLoadState newState)
 {
     OldState = oldState;
       NewState = newState;
 }
        public void GoToState(LazyDataLoadState state)
        {
            LazyDataItemStateManagerHelper.CheckTransition(currentState, state);

              switch (state)
              {
            case LazyDataLoadState.Unloaded:
              UnloadAllData();
              break;

            case LazyDataLoadState.Minimum:
              LoadSmallAndFastData();
              break;

            case LazyDataLoadState.Loading:
              LoadLargeAndFastData();
              if (IsPaused)
            Unpause();
              BeginLoadLargeAndSlowData();
              BeginLoadSmallAndSlowData();
              break;

            case LazyDataLoadState.Loaded:
              // nothing;
              break;

            case LazyDataLoadState.Cached:
              UnloadLargeData();
              break;

            case LazyDataLoadState.Reloading:
              LoadLargeAndFastData();
              if (IsPaused)
            Unpause();
              BeginLoadLargeAndSlowData();
              break;

            default:
              throw new InvalidOperationException("Unknown current state " + currentState.ToString());
              }

              EventHandler<LazyDataItemStateChangedEventArgs> handler = CurrentStateChanged;
              if (handler != null)
            handler(this, new LazyDataItemStateChangedEventArgs(currentState, state));

              currentState = state;
        }
 /// <summary>
 /// Create a new instance of the exception
 /// </summary>
 /// <param name="currentState">Current state</param>
 /// <param name="requestedState">Requested state</param>
 public InvalidStateTransitionException(LazyDataLoadState currentState, LazyDataLoadState requestedState)
 {
     CurrentState = currentState;
       RequestedState = requestedState;
 }
Esempio n. 5
0
        public static void CheckTransition(LazyDataLoadState currentState, LazyDataLoadState requestedState)
        {
            // Call not needed...
            if (currentState == requestedState)
            {
                Debug.WriteLine("Uneccessary state transition from " + currentState + " to itself");
                return;
            }

            // Call to unloaded is always OK
            if (requestedState == LazyDataLoadState.Unloaded)
            {
                return;
            }

            switch (currentState)
            {
            case LazyDataLoadState.Unloaded:
                if (requestedState == LazyDataLoadState.Minimum)
                {
                    return;
                }

                break;

            case LazyDataLoadState.Minimum:
                if (requestedState == LazyDataLoadState.Loading)
                {
                    return;
                }

                break;

            case LazyDataLoadState.Loading:
                if (requestedState == LazyDataLoadState.Loaded || requestedState == LazyDataLoadState.Cached)
                {
                    return;
                }

                break;

            case LazyDataLoadState.Loaded:
                if (requestedState == LazyDataLoadState.Cached)
                {
                    return;
                }

                break;

            case LazyDataLoadState.Cached:
                if (requestedState == LazyDataLoadState.Reloading)
                {
                    return;
                }

                break;

            case LazyDataLoadState.Reloading:
                if (requestedState == LazyDataLoadState.Loaded || requestedState == LazyDataLoadState.Cached)
                {
                    return;
                }

                break;

            default:
                throw new InvalidOperationException("Unknown current state " + currentState.ToString());
            }

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }

            throw new InvalidStateTransitionException(currentState, requestedState);
        }
        /// <summary>
        /// Forces the item to be visible or invisible
        /// </summary>
        /// <param name="isVisible">True if the item is visible, false otherwise</param>
        /// <param name="currentSnapshotVersion">Version information used for cache purposes</param>
        internal void SetIsVisible(bool isVisible, int currentSnapshotVersion)
        {
            // We have special behaviour if the item is an ILazyDataItem
            ILazyDataItem lazyItem = DataContext as ILazyDataItem;

            cachedIsVisible        = isVisible;
            visibleSnapshotVersion = currentSnapshotVersion;

            if (isVisible)
            {
                // If it's a special item, tell it to change states based on its current state
                if (lazyItem != null)
                {
                    LazyDataLoadState currentState = lazyItem.CurrentState;

                    // It was cached, so tell it to re-load
                    if (currentState == LazyDataLoadState.Cached)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Reloading);
                    }

                    // It was loading and we asked it to pause; unpause it
                    else if (currentState == LazyDataLoadState.Loading || currentState == LazyDataLoadState.Reloading)
                    {
                        if (lazyItem.IsPaused)
                        {
                            lazyItem.Unpause();
                        }
                    }

                    // Otherwise, tell it to load unless it is already loading
                    else if (currentState != LazyDataLoadState.Loaded)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Loading);
                    }
                }

                // Set the loaded item template, if it exists
                if (Owner.LoadedItemTemplate != null)
                {
                    ContentTemplate = Owner.LoadedItemTemplate;
                }
            }
            else
            {
                bool alreadyResetTemplate = false;

                // If it's a special item, tell it to change state
                if (lazyItem != null)
                {
                    // if the slow items are already loaded, switch to the cached template (vs the default template)
                    if (lazyItem.CurrentState == LazyDataLoadState.Loaded)
                    {
                        lazyItem.GoToState(LazyDataLoadState.Cached);
                        if (Owner.CachedItemTemplate != null)
                        {
                            ContentTemplate      = Owner.CachedItemTemplate;
                            alreadyResetTemplate = true;
                        }
                    }
                }

                // If we didn't set it to the CachedItemTemplate, then reset to the ItemTemplate
                if (alreadyResetTemplate != true && Owner.Template != null)
                {
                    ContentTemplate = Owner.ItemTemplate;
                }
            }
        }
        public static void CheckTransition(LazyDataLoadState currentState, LazyDataLoadState requestedState)
        {
            // Call not needed...
              if (currentState == requestedState)
              {
            Debug.WriteLine("Uneccessary state transition from " + currentState + " to itself");
            return;
              }

              // Call to unloaded is always OK
              if (requestedState == LazyDataLoadState.Unloaded)
              {
            return;
              }

              switch (currentState)
              {
            case LazyDataLoadState.Unloaded:
              if (requestedState == LazyDataLoadState.Minimum)
            return;

              break;

            case LazyDataLoadState.Minimum:
              if (requestedState == LazyDataLoadState.Loading)
            return;

              break;

            case LazyDataLoadState.Loading:
              if (requestedState == LazyDataLoadState.Loaded || requestedState == LazyDataLoadState.Cached)
            return;

              break;

            case LazyDataLoadState.Loaded:
              if (requestedState == LazyDataLoadState.Cached)
            return;

              break;

            case LazyDataLoadState.Cached:
              if (requestedState == LazyDataLoadState.Reloading)
            return;

              break;

            case LazyDataLoadState.Reloading:
              if (requestedState == LazyDataLoadState.Loaded || requestedState == LazyDataLoadState.Cached)
            return;

              break;

            default:
              throw new InvalidOperationException("Unknown current state " + currentState.ToString());
              }

              if (Debugger.IsAttached)
            Debugger.Break();

              throw new InvalidStateTransitionException(currentState, requestedState);
        }
 /// <summary>
 /// Create a new instance of the exception
 /// </summary>
 /// <param name="currentState">Current state</param>
 /// <param name="requestedState">Requested state</param>
 public InvalidStateTransitionException(LazyDataLoadState currentState, LazyDataLoadState requestedState)
 {
     CurrentState   = currentState;
     RequestedState = requestedState;
 }