Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / VisualBasicSettingsHandler.cs / 1305376 / VisualBasicSettingsHandler.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation
{
using System.ComponentModel;
using Microsoft.VisualBasic.Activities;
using System.Activities.Debugger;
using System.Activities.Presentation.Model;
using System.Runtime;
using System.Linq;
//the class does several things:
//1. make sure a special property "Imports" (implemented using VisualBasicSettings attached properties) is added to the root object before it's loaded into ModelTree
//2. make sure the "root workflow" of the root object always have the same VisualBasicSettings
static class VisualBasicSettingsHandler
{
static public void PreviewLoadRoot(object sender, WorkflowDesigner.PreviewLoadEventArgs args)
{
VisualBasicSettings settings = VisualBasic.GetSettings(args.Instance);
if (settings == null)
{
settings = new VisualBasicSettings();
VisualBasic.SetSettings(args.Instance, settings);
}
IDebuggableWorkflowTree root = args.Instance as IDebuggableWorkflowTree;
if (root != null)
{
Activity rootActivity = root.GetWorkflowRoot();
if (rootActivity != null)
{
VisualBasic.SetSettings(rootActivity, settings);
}
args.Context.Services.Subscribe(manager => manager.Root.PropertyChanged += new PropertyChangedEventHandler(OnRootPropertyChanged));
}
TypeDescriptor.AddProvider(new RootModelTypeDescriptionProvider(args.Instance), args.Instance);
}
static void OnRootPropertyChanged(object sender, PropertyChangedEventArgs e)
{
ModelItem rootModel = sender as ModelItem;
Fx.Assert(rootModel != null, "sender item could not be null");
ModelProperty changedProperty = rootModel.Properties[e.PropertyName];
if (changedProperty == null)
{
return;
}
object changedPropertyValue = changedProperty.ComputedValue;
if (changedPropertyValue == null)
{
return;
}
IDebuggableWorkflowTree root = rootModel.GetCurrentValue() as IDebuggableWorkflowTree;
Fx.Assert(root != null, "root must be a IDebuggableWorkflowTree");
if (root.GetWorkflowRoot() == changedPropertyValue)
{
VisualBasicSettings settings = VisualBasic.GetSettings(root);
VisualBasic.SetSettings(changedPropertyValue, settings);
}
}
}
class RootModelTypeDescriptionProvider : TypeDescriptionProvider
{
public RootModelTypeDescriptionProvider(object instance)
: base(TypeDescriptor.GetProvider(instance))
{
}
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{
ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);
return new RootModelTypeDescriptor(defaultDescriptor, instance);
}
}
class RootModelTypeDescriptor : CustomTypeDescriptor
{
object root;
NamespaceListPropertyDescriptor importDescriptor;
public RootModelTypeDescriptor(ICustomTypeDescriptor parent, object root)
: base(parent)
{
this.root = root;
}
PropertyDescriptor ImportDescriptor
{
get
{
if (this.importDescriptor == null)
{
this.importDescriptor = new NamespaceListPropertyDescriptor(this.root);
}
return this.importDescriptor;
}
}
public override PropertyDescriptorCollection GetProperties()
{
return GetProperties(null);
}
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return new PropertyDescriptorCollection(base.GetProperties(attributes).Cast()
.Union(new PropertyDescriptor[] { this.ImportDescriptor }).ToArray());
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation
{
using System.ComponentModel;
using Microsoft.VisualBasic.Activities;
using System.Activities.Debugger;
using System.Activities.Presentation.Model;
using System.Runtime;
using System.Linq;
//the class does several things:
//1. make sure a special property "Imports" (implemented using VisualBasicSettings attached properties) is added to the root object before it's loaded into ModelTree
//2. make sure the "root workflow" of the root object always have the same VisualBasicSettings
static class VisualBasicSettingsHandler
{
static public void PreviewLoadRoot(object sender, WorkflowDesigner.PreviewLoadEventArgs args)
{
VisualBasicSettings settings = VisualBasic.GetSettings(args.Instance);
if (settings == null)
{
settings = new VisualBasicSettings();
VisualBasic.SetSettings(args.Instance, settings);
}
IDebuggableWorkflowTree root = args.Instance as IDebuggableWorkflowTree;
if (root != null)
{
Activity rootActivity = root.GetWorkflowRoot();
if (rootActivity != null)
{
VisualBasic.SetSettings(rootActivity, settings);
}
args.Context.Services.Subscribe(manager => manager.Root.PropertyChanged += new PropertyChangedEventHandler(OnRootPropertyChanged));
}
TypeDescriptor.AddProvider(new RootModelTypeDescriptionProvider(args.Instance), args.Instance);
}
static void OnRootPropertyChanged(object sender, PropertyChangedEventArgs e)
{
ModelItem rootModel = sender as ModelItem;
Fx.Assert(rootModel != null, "sender item could not be null");
ModelProperty changedProperty = rootModel.Properties[e.PropertyName];
if (changedProperty == null)
{
return;
}
object changedPropertyValue = changedProperty.ComputedValue;
if (changedPropertyValue == null)
{
return;
}
IDebuggableWorkflowTree root = rootModel.GetCurrentValue() as IDebuggableWorkflowTree;
Fx.Assert(root != null, "root must be a IDebuggableWorkflowTree");
if (root.GetWorkflowRoot() == changedPropertyValue)
{
VisualBasicSettings settings = VisualBasic.GetSettings(root);
VisualBasic.SetSettings(changedPropertyValue, settings);
}
}
}
class RootModelTypeDescriptionProvider : TypeDescriptionProvider
{
public RootModelTypeDescriptionProvider(object instance)
: base(TypeDescriptor.GetProvider(instance))
{
}
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{
ICustomTypeDescriptor defaultDescriptor = base.GetTypeDescriptor(objectType, instance);
return new RootModelTypeDescriptor(defaultDescriptor, instance);
}
}
class RootModelTypeDescriptor : CustomTypeDescriptor
{
object root;
NamespaceListPropertyDescriptor importDescriptor;
public RootModelTypeDescriptor(ICustomTypeDescriptor parent, object root)
: base(parent)
{
this.root = root;
}
PropertyDescriptor ImportDescriptor
{
get
{
if (this.importDescriptor == null)
{
this.importDescriptor = new NamespaceListPropertyDescriptor(this.root);
}
return this.importDescriptor;
}
}
public override PropertyDescriptorCollection GetProperties()
{
return GetProperties(null);
}
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return new PropertyDescriptorCollection(base.GetProperties(attributes).Cast()
.Union(new PropertyDescriptor[] { this.ImportDescriptor }).ToArray());
}
}
}
// 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
- TableLayoutStyleCollection.cs
- ScriptingAuthenticationServiceSection.cs
- PerformanceCounterPermission.cs
- XsltFunctions.cs
- ProfileSettings.cs
- SQLSingle.cs
- FixedSOMGroup.cs
- StorageBasedPackageProperties.cs
- TableParagraph.cs
- TrueReadOnlyCollection.cs
- Evidence.cs
- XsltArgumentList.cs
- ManagedCodeMarkers.cs
- GridItemPatternIdentifiers.cs
- Deflater.cs
- DynamicDataRouteHandler.cs
- XmlEntityReference.cs
- WindowsFormsSynchronizationContext.cs
- ToolTipService.cs
- Monitor.cs
- TextBoxAutomationPeer.cs
- TypeUtils.cs
- PaperSize.cs
- RelationshipConstraintValidator.cs
- AppSettingsExpressionBuilder.cs
- TextEditor.cs
- SqlComparer.cs
- GifBitmapEncoder.cs
- TypeExtensionConverter.cs
- ParserHooks.cs
- OleDbMetaDataFactory.cs
- DetailsViewPageEventArgs.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Interlocked.cs
- DataGridParentRows.cs
- UpdatableWrapper.cs
- ResourceContainer.cs
- UIElementHelper.cs
- GcSettings.cs
- CollectionViewGroup.cs
- TraceProvider.cs
- TargetInvocationException.cs
- Int64Animation.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- IdentitySection.cs
- TreeNodeBindingDepthConverter.cs
- HashHelpers.cs
- ObfuscateAssemblyAttribute.cs
- TextSchema.cs
- XMLSchema.cs
- AnnotationComponentManager.cs
- ListComponentEditorPage.cs
- MemoryResponseElement.cs
- DoubleCollectionConverter.cs
- View.cs
- PropertyMetadata.cs
- SharedDp.cs
- MaskedTextProvider.cs
- DbProviderFactories.cs
- PageAsyncTaskManager.cs
- FrameworkElementFactory.cs
- DoubleAnimationClockResource.cs
- DefaultParameterValueAttribute.cs
- Win32MouseDevice.cs
- SpellerHighlightLayer.cs
- CodeVariableReferenceExpression.cs
- ConstructorArgumentAttribute.cs
- SqlAggregateChecker.cs
- CookieParameter.cs
- ThemeDictionaryExtension.cs
- DesignerView.xaml.cs
- FlagsAttribute.cs
- Utils.cs
- ReadWriteObjectLock.cs
- ComPlusInstanceProvider.cs
- XmlSortKey.cs
- ToggleButton.cs
- QueryExtender.cs
- BridgeDataRecord.cs
- ProcessingInstructionAction.cs
- HyperLinkDataBindingHandler.cs
- ParallelDesigner.cs
- XmlSerializableWriter.cs
- ExtensionDataReader.cs
- DataServiceHost.cs
- BitmapCodecInfo.cs
- GACIdentityPermission.cs
- BookmarkEventArgs.cs
- AccessControlEntry.cs
- CodeAssignStatement.cs
- DataTransferEventArgs.cs
- PreviewPageInfo.cs
- SqlParameter.cs
- Zone.cs
- SemaphoreSecurity.cs
- Label.cs
- DataGridViewColumnConverter.cs
- Size3DValueSerializer.cs
- ImageFormatConverter.cs
- PrimitiveDataContract.cs