Esempio n. 1
0
        private void RecursiveRestoreDataGridContextsState(DataGridContext dataGridContext)
        {
            WeakDataGridContextKey weakDataGridContextKey = new WeakDataGridContextKey(dataGridContext);

            SaveRestoreDataGridContextStateVisitor saveRestoreDataGridContextStateVisitor;

            if (m_dataGridContextsStateDictionary.TryGetValue(weakDataGridContextKey, out saveRestoreDataGridContextStateVisitor))
            {
                try
                {
                    saveRestoreDataGridContextStateVisitor.RestoreState(dataGridContext as IDataGridContextVisitable);
                }
                finally
                {
                    m_dataGridContextsStateDictionary.Remove(weakDataGridContextKey);
                }
            }

            IEnumerable <DataGridContext> subDataGridContexts = dataGridContext.GetChildContexts();

            foreach (DataGridContext subDataGridContext in subDataGridContexts)
            {
                this.RecursiveRestoreDataGridContextsState(subDataGridContext);
            }
        }
        public override bool Equals(object obj)
        {
            WeakDataGridContextKey weakDataGridContextKey = obj as WeakDataGridContextKey;

            if (weakDataGridContextKey == null)
            {
                return(false);
            }

            if (m_cachedHash != weakDataGridContextKey.m_cachedHash)
            {
                return(false);
            }

            if (m_sourceDetailConfigurationRelationName != weakDataGridContextKey.m_sourceDetailConfigurationRelationName)
            {
                return(false);
            }

            int dataGridContextStatusKeyLength = (weakDataGridContextKey.m_weakItemsTree == null) ? 0 : weakDataGridContextKey.m_weakItemsTree.Length;
            int myLength = (m_weakItemsTree == null) ? 0 : m_weakItemsTree.Length;

            if (myLength != dataGridContextStatusKeyLength)
            {
                return(false);
            }

            for (int i = 0; i < dataGridContextStatusKeyLength; i++)
            {
                object sourceItem = m_weakItemsTree[i].Target;
                object targetItem = weakDataGridContextKey.m_weakItemsTree[i].Target;

                if (!object.Equals(sourceItem, targetItem))
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        private void RecursiveRestoreDataGridContextsState(DataGridContext dataGridContext)
        {
            var weakDataGridContextKey = new WeakDataGridContextKey(dataGridContext);
            var saveRestoreDataGridContextStateVisitor = default(SaveRestoreDataGridContextStateVisitor);

            if (m_dataGridContextsStateDictionary.TryGetValue(weakDataGridContextKey, out saveRestoreDataGridContextStateVisitor))
            {
                try
                {
                    saveRestoreDataGridContextStateVisitor.RestoreState(dataGridContext as IDataGridContextVisitable);
                }
                finally
                {
                    m_dataGridContextsStateDictionary.Remove(weakDataGridContextKey);
                }
            }

            foreach (var subDataGridContext in dataGridContext.GetChildContextsCore())
            {
                this.RecursiveRestoreDataGridContextsState(subDataGridContext);
            }
        }
        internal WeakDataGridContextKey(DataGridContext dataGridContext)
        {
            var parentDataGridContext = dataGridContext.ParentDataGridContext;
            var level = 0;

            while (parentDataGridContext != null)
            {
                level++;
                parentDataGridContext = parentDataGridContext.ParentDataGridContext;
            }

            Debug.Assert(((level == 0) || (dataGridContext.SourceDetailConfiguration != null)), "A child dataGridContext must have a SourceDetailConfiguration.");

            m_sourceDetailConfigurationRelationName = (dataGridContext.SourceDetailConfiguration != null) ? dataGridContext.SourceDetailConfiguration.RelationName : string.Empty;

            if (level > 0)
            {
                // We are NOT dealing with the root DataGridContext.

                // Build the tree of master items.
                m_weakItemsTree = new WeakReference[level];

                var tempDataGridContext = dataGridContext;
                for (int i = level - 1; i >= 0; i--)
                {
                    // Ensure to get a reference to the System.Data.DataRow when doing a
                    // save/restore of a System.Data.DataRowView since the view is recreated
                    // for every detail views
                    var parentItem = ItemsSourceHelper.TryGetDataRowFromDataItem(tempDataGridContext.ParentItem);

                    m_weakItemsTree[i] = new WeakReference(parentItem);

                    tempDataGridContext = tempDataGridContext.ParentDataGridContext;
                }
            }

            m_hashCode = WeakDataGridContextKey.CalculateHashCode(m_sourceDetailConfigurationRelationName, m_weakItemsTree);
        }
Esempio n. 5
0
    internal void RestoreDataGridContextState( DataGridContext dataGridContext )
    {
      if( ( m_dataGridContextsStateDictionary == null ) || ( m_dataGridContextsStateDictionary.Count == 0 ) )
        return;

      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      // A call to RestoreDataGridContextState can be made while processing a save or a restore
      // of a DataGridContext because the Generator forces the call in EnsureNodeTreeCreated
      // when public methods are accessed. If we are saving, already restoring or pending restoring
      // we ignore this call
      if( dataGridContext.IsSavingState
          || dataGridContext.IsDeferRestoringState
          || dataGridContext.IsRestoringState )
        return;

      WeakDataGridContextKey weakDataGridContextKey = new WeakDataGridContextKey( dataGridContext );
      SaveRestoreDataGridContextStateVisitor saveRestoreDataGridContextStateVisitor;

      if( m_dataGridContextsStateDictionary.TryGetValue( weakDataGridContextKey, out saveRestoreDataGridContextStateVisitor ) )
      {
        try
        {
          dataGridContext.IsRestoringState = true;

          // Restoring this dataGridContext state's will expand sub items that should be expanded.
          // Their expansion will make the customItemGenerator generate sub detailNodes, which in turn will try 
          // to be restored to their previous state.
          saveRestoreDataGridContextStateVisitor.RestoreState( ( IDataGridContextVisitable )dataGridContext );
          Debug.WriteLineIf( this.DebugSaveRestore, "RESTORING DataGridContext state for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() + " RESTORED!" );
        }
        catch
        {
          Debug.WriteLineIf( this.DebugSaveRestore, "RESTORING DataGridContext state for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() + " FAILED!" );
        }
        finally
        {
          m_dataGridContextsStateDictionary.Remove( weakDataGridContextKey );
          dataGridContext.IsRestoringState = false;
        }
      }
      else
      {
        Debug.WriteLineIf( this.DebugSaveRestore, "Cannot Restore. No state saved for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() );
      }
    }
Esempio n. 6
0
    internal void SaveDataGridContextState( DataGridContext dataGridContext, bool handleExpandedItems, int maxGroupLevel )
    {
      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      Debug.Assert( !dataGridContext.IsRestoringState );

      if( dataGridContext.IsSavingState )
        return;

      dataGridContext.IsSavingState = true;

      try
      {
        WeakDataGridContextKey weakDataGridContextKey = new WeakDataGridContextKey( dataGridContext );

        if( m_dataGridContextsStateDictionary == null )
        {
          m_dataGridContextsStateDictionary = new Dictionary<WeakDataGridContextKey, SaveRestoreDataGridContextStateVisitor>();
        }
        else if( m_dataGridContextsStateDictionary.ContainsKey( weakDataGridContextKey ) )
        {
          // Already a state saved for this context.  Don't overwrite it.
          Debug.WriteLineIf( this.DebugSaveRestore, "Already a state saved for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() );
          return;
        }

        SaveRestoreDataGridContextStateVisitor saveRestoreDataGridContextStateVisitor = new SaveRestoreDataGridContextStateVisitor( handleExpandedItems, maxGroupLevel, false );

        try
        {
          saveRestoreDataGridContextStateVisitor.SaveState( ( IDataGridContextVisitable )dataGridContext );

          m_dataGridContextsStateDictionary.Add( weakDataGridContextKey, saveRestoreDataGridContextStateVisitor );

          Debug.WriteLineIf( this.DebugSaveRestore, "SAVING DataGridContext state for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() + " SAVED!" );
        }
        catch
        {
          Debug.WriteLineIf( this.DebugSaveRestore, "SAVING DataGridContext state for WeakDataGridContextKey: " + weakDataGridContextKey.GetHashCode().ToString() + " FAILED!" );
        }
      }
      finally
      {
        dataGridContext.IsSavingState = false;
      }
    }
    private void RecursiveRestoreDataGridContextsState( DataGridContext dataGridContext )
    {
      WeakDataGridContextKey weakDataGridContextKey = new WeakDataGridContextKey( dataGridContext );

      SaveRestoreDataGridContextStateVisitor saveRestoreDataGridContextStateVisitor;

      if( m_dataGridContextsStateDictionary.TryGetValue( weakDataGridContextKey, out saveRestoreDataGridContextStateVisitor ) )
      {
        try
        {
          saveRestoreDataGridContextStateVisitor.RestoreState( dataGridContext as IDataGridContextVisitable );
        }
        finally
        {
          m_dataGridContextsStateDictionary.Remove( weakDataGridContextKey );
        }
      }

      IEnumerable<DataGridContext> subDataGridContexts = dataGridContext.GetChildContexts();
      foreach( DataGridContext subDataGridContext in subDataGridContexts )
      {
        this.RecursiveRestoreDataGridContextsState( subDataGridContext );
      }
    }