Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / WorkflowViewStateService.cs / 1305376 / WorkflowViewStateService.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Xaml; using System.Activities.Presentation.Model; using System.Runtime; //ViewState is stored as a Dictionaryon the CFx object. //ModelItem is passed in StoreViewState to get a handle to the CFx object. [Fx.Tag.XamlVisible(false)] public class WorkflowViewStateService : ViewStateService { EditingContext context; public override event ViewStateChangedEventHandler ViewStateChanged; public override event ViewStateChangedEventHandler UndoableViewStateChanged; [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)] public static readonly AttachableMemberIdentifier ViewStateName = new AttachableMemberIdentifier(typeof(WorkflowViewStateService), "ViewState"); UndoEngine UndoEngine { get { return this.context.Services.GetService (); } } public WorkflowViewStateService(EditingContext context) { this.context = context; } public static Dictionary GetViewState(object instance) { if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } Dictionary viewState; AttachablePropertyServices.TryGetProperty(instance, ViewStateName, out viewState); return viewState; } public static void SetViewState(object instance, Dictionary value) { if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } AttachablePropertyServices.SetProperty(instance, ViewStateName, value); } public override object RetrieveViewState(ModelItem modelItem, string key) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } object viewStateObj = null; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState != null) { viewState.TryGetValue(key, out viewStateObj); } return viewStateObj; } public override void StoreViewState(ModelItem modelItem, string key, object value) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } object oldValue = null; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState == null) { viewState = new Dictionary (); WorkflowViewStateService.SetViewState(modelItem.GetCurrentValue(), viewState); } viewState.TryGetValue(key, out oldValue); if (value != null) { viewState[key] = value; } else { RemoveViewState(modelItem, key); } if (this.ViewStateChanged != null && value != oldValue) { this.ViewStateChanged(this, new ViewStateChangedEventArgs(modelItem, key, value, oldValue)); } } public override bool RemoveViewState(ModelItem modelItem, string key) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } bool itemRemoved = false; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState != null && key != null && viewState.ContainsKey(key)) { itemRemoved = viewState.Remove(key); if (viewState.Keys.Count == 0) { AttachablePropertyServices.RemoveProperty(modelItem.GetCurrentValue(), ViewStateName); } } return itemRemoved; } public override Dictionary RetrieveAllViewState(ModelItem modelItem) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } return WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); } public override void StoreViewStateWithUndo(ModelItem modelItem, string key, object value) { object oldValue = RetrieveViewState(modelItem, key); ViewStateChange vsChange = new ViewStateChange(this) { Item = modelItem, Key = key, OldValue = oldValue, NewValue = value, }; ModelTreeManager modelTreeManager = this.context.Services.GetService (); if (modelTreeManager != null) { modelTreeManager.AddToCurrentEditingScope(vsChange); } } void RaiseUndoableViewStateChangedEvent(ModelItem modelItem, string key, object newValue, object oldValue) { if (this.UndoableViewStateChanged != null) { this.UndoableViewStateChanged(this, new ViewStateChangedEventArgs(modelItem, key, newValue, oldValue)); } } internal class ViewStateChange : Change { protected WorkflowViewStateService viewStateService; public ModelItem Item { get; set; } public string Key { get; set; } public object OldValue { get; set; } public object NewValue { get; set; } public ViewStateChange(WorkflowViewStateService viewStateService) { this.viewStateService = viewStateService; } public override string Description { get { return SR.ViewStateUndoUnitDescription; } } public override bool Apply() { viewStateService.StoreViewState(Item, Key, NewValue); this.viewStateService.RaiseUndoableViewStateChangedEvent(Item, Key, NewValue, OldValue); return true; } public override Change GetInverse() { return new ViewStateChange(this.viewStateService) { Item = this.Item, Key = this.Key, OldValue = this.NewValue, NewValue = this.OldValue }; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Xaml; using System.Activities.Presentation.Model; using System.Runtime; //ViewState is stored as a Dictionary on the CFx object. //ModelItem is passed in StoreViewState to get a handle to the CFx object. [Fx.Tag.XamlVisible(false)] public class WorkflowViewStateService : ViewStateService { EditingContext context; public override event ViewStateChangedEventHandler ViewStateChanged; public override event ViewStateChangedEventHandler UndoableViewStateChanged; [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes)] public static readonly AttachableMemberIdentifier ViewStateName = new AttachableMemberIdentifier(typeof(WorkflowViewStateService), "ViewState"); UndoEngine UndoEngine { get { return this.context.Services.GetService (); } } public WorkflowViewStateService(EditingContext context) { this.context = context; } public static Dictionary GetViewState(object instance) { if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } Dictionary viewState; AttachablePropertyServices.TryGetProperty(instance, ViewStateName, out viewState); return viewState; } public static void SetViewState(object instance, Dictionary value) { if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } AttachablePropertyServices.SetProperty(instance, ViewStateName, value); } public override object RetrieveViewState(ModelItem modelItem, string key) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } object viewStateObj = null; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState != null) { viewState.TryGetValue(key, out viewStateObj); } return viewStateObj; } public override void StoreViewState(ModelItem modelItem, string key, object value) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } object oldValue = null; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState == null) { viewState = new Dictionary (); WorkflowViewStateService.SetViewState(modelItem.GetCurrentValue(), viewState); } viewState.TryGetValue(key, out oldValue); if (value != null) { viewState[key] = value; } else { RemoveViewState(modelItem, key); } if (this.ViewStateChanged != null && value != oldValue) { this.ViewStateChanged(this, new ViewStateChangedEventArgs(modelItem, key, value, oldValue)); } } public override bool RemoveViewState(ModelItem modelItem, string key) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } if (key == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("key")); } bool itemRemoved = false; Dictionary viewState = WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); if (viewState != null && key != null && viewState.ContainsKey(key)) { itemRemoved = viewState.Remove(key); if (viewState.Keys.Count == 0) { AttachablePropertyServices.RemoveProperty(modelItem.GetCurrentValue(), ViewStateName); } } return itemRemoved; } public override Dictionary RetrieveAllViewState(ModelItem modelItem) { if (modelItem == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItem")); } return WorkflowViewStateService.GetViewState(modelItem.GetCurrentValue()); } public override void StoreViewStateWithUndo(ModelItem modelItem, string key, object value) { object oldValue = RetrieveViewState(modelItem, key); ViewStateChange vsChange = new ViewStateChange(this) { Item = modelItem, Key = key, OldValue = oldValue, NewValue = value, }; ModelTreeManager modelTreeManager = this.context.Services.GetService (); if (modelTreeManager != null) { modelTreeManager.AddToCurrentEditingScope(vsChange); } } void RaiseUndoableViewStateChangedEvent(ModelItem modelItem, string key, object newValue, object oldValue) { if (this.UndoableViewStateChanged != null) { this.UndoableViewStateChanged(this, new ViewStateChangedEventArgs(modelItem, key, newValue, oldValue)); } } internal class ViewStateChange : Change { protected WorkflowViewStateService viewStateService; public ModelItem Item { get; set; } public string Key { get; set; } public object OldValue { get; set; } public object NewValue { get; set; } public ViewStateChange(WorkflowViewStateService viewStateService) { this.viewStateService = viewStateService; } public override string Description { get { return SR.ViewStateUndoUnitDescription; } } public override bool Apply() { viewStateService.StoreViewState(Item, Key, NewValue); this.viewStateService.RaiseUndoableViewStateChangedEvent(Item, Key, NewValue, OldValue); return true; } public override Change GetInverse() { return new ViewStateChange(this.viewStateService) { Item = this.Item, Key = this.Key, OldValue = this.NewValue, NewValue = this.OldValue }; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SchemaEntity.cs
- linebase.cs
- DetailsViewModeEventArgs.cs
- NativeCppClassAttribute.cs
- XmlMemberMapping.cs
- webeventbuffer.cs
- Image.cs
- Scalars.cs
- FtpWebRequest.cs
- CodeValidator.cs
- DragStartedEventArgs.cs
- RemotingServices.cs
- ParameterCollection.cs
- ColumnHeaderConverter.cs
- ListViewContainer.cs
- ListViewUpdateEventArgs.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- VisualTreeHelper.cs
- WindowsImpersonationContext.cs
- GeneralTransform2DTo3DTo2D.cs
- PropertyToken.cs
- NotifyCollectionChangedEventArgs.cs
- PropertyStore.cs
- UnionExpr.cs
- IdentityReference.cs
- GC.cs
- RectangleConverter.cs
- SqlConnectionStringBuilder.cs
- CustomBindingElement.cs
- TextProperties.cs
- DynamicRouteExpression.cs
- HelpKeywordAttribute.cs
- SqlProcedureAttribute.cs
- AuthenticationManager.cs
- ObjectQuery.cs
- SecurityState.cs
- ReadOnlyDictionary.cs
- TemplateControlParser.cs
- HebrewNumber.cs
- DataServiceResponse.cs
- XmlCharacterData.cs
- XPathEmptyIterator.cs
- Separator.cs
- AssemblyBuilder.cs
- PathData.cs
- DataGridViewSortCompareEventArgs.cs
- TimeSpan.cs
- KeySpline.cs
- ContextInformation.cs
- VolatileEnlistmentState.cs
- PtsCache.cs
- UriTemplateHelpers.cs
- WebConvert.cs
- Restrictions.cs
- HebrewCalendar.cs
- Number.cs
- Char.cs
- FixedBufferAttribute.cs
- AsymmetricKeyExchangeDeformatter.cs
- StreamMarshaler.cs
- COAUTHINFO.cs
- ConnectionManagementElement.cs
- EntityPropertyMappingAttribute.cs
- DependencyPropertyConverter.cs
- DesignerSerializationVisibilityAttribute.cs
- ViewEventArgs.cs
- ProfileManager.cs
- ListViewInsertEventArgs.cs
- FormsAuthenticationCredentials.cs
- LicenseContext.cs
- DayRenderEvent.cs
- HttpEncoderUtility.cs
- BulletedList.cs
- ButtonBase.cs
- TextureBrush.cs
- StringAnimationBase.cs
- VectorValueSerializer.cs
- BindingWorker.cs
- PrimitiveCodeDomSerializer.cs
- SecurityPolicySection.cs
- FormsAuthenticationEventArgs.cs
- CachedTypeface.cs
- NameObjectCollectionBase.cs
- EventPropertyMap.cs
- sqlinternaltransaction.cs
- XslNumber.cs
- WindowsFormsHostAutomationPeer.cs
- RouteItem.cs
- BaseProcessor.cs
- recordstatefactory.cs
- TemplateControl.cs
- DeclaredTypeElementCollection.cs
- RegisteredExpandoAttribute.cs
- Visitor.cs
- RoutedEventArgs.cs
- CellParaClient.cs
- ObjectMemberMapping.cs
- ISAPIRuntime.cs
- FrameDimension.cs
- AttributeSetAction.cs