Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / ObjectListCommandCollection.cs / 1305376 / ObjectListCommandCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Security.Permissions; namespace System.Web.UI.MobileControls { /* * Object List Command Collection class. * * Copyright (c) 2000 Microsoft Corporation */ ///[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] public class ObjectListCommandCollection : ArrayListCollectionBase, IStateManager { // ObjectListCommandCollection has a special form of viewstate management. // In normal operation, if you add, remove or modify commands in the // collection, the results are saved as part of view state. // // However, when showing the commands for an item, the ObjectList control // raises an event that allows the application to alter the commands // specifically for the item. These changes are considered local to the // item, and are not saved. // // To do this, the class uses a private state, declared in the MarkState // enumeration below. The following sequence of events are used: // // 1) Class is created. MarkState is set to MarkState.NotMarked. // 2) Class is initialized from persistent values. // 3) Framework calls TrackViewState. MarkState is set to MarkState.MArked. // 4) Properties can be changed. Changes are reflected in viewstate. // 5) Just before raising the ShowItemCommands event, the ObjectList control // calls GlobalStateSet. PreSaveViewState is called to create a // snapshot of viewstate, and MarkState is set to MarkState.PostMarked. // 6) If any changes are made after this, they will be ignored for view state // purposes. // 7) The framework calls SaveViewState. Instead of the current view state // (which would include the changes made in Step 6), the snapshot view state // from step 5 is returned. private enum MarkState { NotMarked, Marked, PostMarked, } private MarkState _markState = MarkState.NotMarked; private bool _dirty; private String[] _savedState; internal ObjectListCommandCollection() { } /// public ObjectListCommand this[int index] { get { return (ObjectListCommand)Items[index]; } } /// public void Clear() { foreach (ObjectListCommand command in Items) { command.Owner = null; } Items.Clear(); SetDirty(); } /// public void Add(ObjectListCommand command) { AddAt(-1, command); } /// public void AddAt(int index, ObjectListCommand command) { if (index == -1) { Items.Add(command); } else { Items.Insert(index, command); } command.Owner = this; SetDirty(); } /// public void Remove(String s) { RemoveAt(IndexOf(s)); } /// public void RemoveAt(int index) { (this[index]).Owner = null; Items.RemoveAt(index); SetDirty(); } /// public int IndexOf(String s) { int index = 0; foreach (ObjectListCommand command in Items) { if (String.Compare(command.Name, s, StringComparison.OrdinalIgnoreCase) == 0) { return index; } index++; } return -1; } internal void GlobalStateSet() { // Base commands have been set. From here, commands will only be // modified on a per-item, non-persistent basis. PreSaveViewState(); _markState = MarkState.PostMarked; } internal void SetDirty() { if (_markState == MarkState.Marked) { _dirty = true; } } ///////////////////////////////////////////////////////////////////////// // STATE MANAGEMENT ///////////////////////////////////////////////////////////////////////// private void PreSaveViewState() { if (_dirty) { ArrayList commands = Items; _savedState = new String[commands.Count * 2]; int i = 0; foreach (ObjectListCommand command in commands) { _savedState[i] = command.Name; _savedState[i + 1] = command.Text; i += 2; } } else { _savedState = null; } } /// protected bool IsTrackingViewState { get { return _markState != MarkState.NotMarked; } } /// protected void TrackViewState() { _markState = MarkState.Marked; } /// protected void LoadViewState(Object state) { if (state != null) { String[] commandStates = (String[])state; int count = commandStates.Length; Clear(); for (int i = 0; i < count; i += 2) { Add(new ObjectListCommand(commandStates[i], commandStates[i + 1])); } } } /// protected Object SaveViewState() { if (_markState == MarkState.Marked) { PreSaveViewState(); } return _savedState; } #region Implementation of IStateManager /// bool IStateManager.IsTrackingViewState { get { return IsTrackingViewState; } } /// void IStateManager.LoadViewState(object state) { LoadViewState(state); } /// void IStateManager.TrackViewState() { TrackViewState(); } /// object IStateManager.SaveViewState() { return SaveViewState(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Security.Permissions; namespace System.Web.UI.MobileControls { /* * Object List Command Collection class. * * Copyright (c) 2000 Microsoft Corporation */ ///[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] public class ObjectListCommandCollection : ArrayListCollectionBase, IStateManager { // ObjectListCommandCollection has a special form of viewstate management. // In normal operation, if you add, remove or modify commands in the // collection, the results are saved as part of view state. // // However, when showing the commands for an item, the ObjectList control // raises an event that allows the application to alter the commands // specifically for the item. These changes are considered local to the // item, and are not saved. // // To do this, the class uses a private state, declared in the MarkState // enumeration below. The following sequence of events are used: // // 1) Class is created. MarkState is set to MarkState.NotMarked. // 2) Class is initialized from persistent values. // 3) Framework calls TrackViewState. MarkState is set to MarkState.MArked. // 4) Properties can be changed. Changes are reflected in viewstate. // 5) Just before raising the ShowItemCommands event, the ObjectList control // calls GlobalStateSet. PreSaveViewState is called to create a // snapshot of viewstate, and MarkState is set to MarkState.PostMarked. // 6) If any changes are made after this, they will be ignored for view state // purposes. // 7) The framework calls SaveViewState. Instead of the current view state // (which would include the changes made in Step 6), the snapshot view state // from step 5 is returned. private enum MarkState { NotMarked, Marked, PostMarked, } private MarkState _markState = MarkState.NotMarked; private bool _dirty; private String[] _savedState; internal ObjectListCommandCollection() { } /// public ObjectListCommand this[int index] { get { return (ObjectListCommand)Items[index]; } } /// public void Clear() { foreach (ObjectListCommand command in Items) { command.Owner = null; } Items.Clear(); SetDirty(); } /// public void Add(ObjectListCommand command) { AddAt(-1, command); } /// public void AddAt(int index, ObjectListCommand command) { if (index == -1) { Items.Add(command); } else { Items.Insert(index, command); } command.Owner = this; SetDirty(); } /// public void Remove(String s) { RemoveAt(IndexOf(s)); } /// public void RemoveAt(int index) { (this[index]).Owner = null; Items.RemoveAt(index); SetDirty(); } /// public int IndexOf(String s) { int index = 0; foreach (ObjectListCommand command in Items) { if (String.Compare(command.Name, s, StringComparison.OrdinalIgnoreCase) == 0) { return index; } index++; } return -1; } internal void GlobalStateSet() { // Base commands have been set. From here, commands will only be // modified on a per-item, non-persistent basis. PreSaveViewState(); _markState = MarkState.PostMarked; } internal void SetDirty() { if (_markState == MarkState.Marked) { _dirty = true; } } ///////////////////////////////////////////////////////////////////////// // STATE MANAGEMENT ///////////////////////////////////////////////////////////////////////// private void PreSaveViewState() { if (_dirty) { ArrayList commands = Items; _savedState = new String[commands.Count * 2]; int i = 0; foreach (ObjectListCommand command in commands) { _savedState[i] = command.Name; _savedState[i + 1] = command.Text; i += 2; } } else { _savedState = null; } } /// protected bool IsTrackingViewState { get { return _markState != MarkState.NotMarked; } } /// protected void TrackViewState() { _markState = MarkState.Marked; } /// protected void LoadViewState(Object state) { if (state != null) { String[] commandStates = (String[])state; int count = commandStates.Length; Clear(); for (int i = 0; i < count; i += 2) { Add(new ObjectListCommand(commandStates[i], commandStates[i + 1])); } } } /// protected Object SaveViewState() { if (_markState == MarkState.Marked) { PreSaveViewState(); } return _savedState; } #region Implementation of IStateManager /// bool IStateManager.IsTrackingViewState { get { return IsTrackingViewState; } } /// void IStateManager.LoadViewState(object state) { LoadViewState(state); } /// void IStateManager.TrackViewState() { TrackViewState(); } /// object IStateManager.SaveViewState() { return SaveViewState(); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StyleModeStack.cs
- GroupItem.cs
- UserControlBuildProvider.cs
- EdmFunctions.cs
- Line.cs
- GreenMethods.cs
- EntityDataSourceWrapper.cs
- ModelPerspective.cs
- Funcletizer.cs
- Matrix3D.cs
- DbMetaDataColumnNames.cs
- XmlSerializerAssemblyAttribute.cs
- HttpListenerRequestUriBuilder.cs
- ToolStripSplitButton.cs
- ArraySegment.cs
- XmlFileEditor.cs
- ChildTable.cs
- MessageQueueEnumerator.cs
- ViewStateException.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- UInt16.cs
- SqlConnectionPoolProviderInfo.cs
- TextLine.cs
- XpsFilter.cs
- ResourceDictionary.cs
- ObjectDataSourceFilteringEventArgs.cs
- MetadataItemSerializer.cs
- NamespaceExpr.cs
- TemplateBindingExtensionConverter.cs
- XmlReader.cs
- Vector3D.cs
- TimeSpanParse.cs
- NotifyParentPropertyAttribute.cs
- ContentElement.cs
- SplitterPanel.cs
- CacheSection.cs
- BitmapScalingModeValidation.cs
- XmlSchemaType.cs
- NativeMethods.cs
- WebControlAdapter.cs
- RegexInterpreter.cs
- StringUtil.cs
- Rectangle.cs
- ErrorView.xaml.cs
- UnrecognizedPolicyAssertionElement.cs
- ReadOnlyHierarchicalDataSourceView.cs
- HotCommands.cs
- XmlObjectSerializerWriteContextComplex.cs
- MonitorWrapper.cs
- FileLogRecordEnumerator.cs
- RuntimeComponentFilter.cs
- BindingValueChangedEventArgs.cs
- QuaternionAnimation.cs
- XomlCompilerResults.cs
- DocumentGridPage.cs
- InputEventArgs.cs
- SchemaHelper.cs
- Byte.cs
- StandardCommands.cs
- Token.cs
- CodeParameterDeclarationExpression.cs
- AddressAccessDeniedException.cs
- ColorComboBox.cs
- EmbeddedMailObjectsCollection.cs
- WebPartMinimizeVerb.cs
- DecimalAnimationUsingKeyFrames.cs
- FlowDocumentReaderAutomationPeer.cs
- AsymmetricSignatureDeformatter.cs
- FormViewRow.cs
- DataView.cs
- CaretElement.cs
- Geometry3D.cs
- SqlDataSourceQueryEditor.cs
- StateMachineAction.cs
- QilGenerator.cs
- XmlWriter.cs
- XmlDictionaryReaderQuotas.cs
- BinaryObjectReader.cs
- MarkupObject.cs
- WindowPattern.cs
- DataGridViewCellLinkedList.cs
- ConfigurationSettings.cs
- RtfNavigator.cs
- ItemsControl.cs
- StylusButtonEventArgs.cs
- ErrorTableItemStyle.cs
- NonVisualControlAttribute.cs
- QueryMatcher.cs
- SqlCacheDependency.cs
- HelpKeywordAttribute.cs
- SecureStringHasher.cs
- OdbcHandle.cs
- ResourceExpressionEditor.cs
- TrustManager.cs
- ParallelActivityDesigner.cs
- EntityDataSourceStatementEditor.cs
- RenamedEventArgs.cs
- ProfilePropertySettings.cs
- AssertHelper.cs
- BinaryCommonClasses.cs