Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ExpressionPrinter.cs
- WinEventHandler.cs
- InfiniteTimeSpanConverter.cs
- WindowsToolbarAsMenu.cs
- PublisherMembershipCondition.cs
- CacheModeValueSerializer.cs
- SettingsAttributeDictionary.cs
- ReflectEventDescriptor.cs
- PathFigure.cs
- FixUpCollection.cs
- ProxyWebPart.cs
- RenderTargetBitmap.cs
- SmtpReplyReader.cs
- DataGridViewRowCollection.cs
- RolePrincipal.cs
- Splitter.cs
- RegionIterator.cs
- EntityParameterCollection.cs
- FixedHighlight.cs
- ObjectAssociationEndMapping.cs
- RuleInfoComparer.cs
- CombinedTcpChannel.cs
- TrackingProfileSerializer.cs
- ListViewDeleteEventArgs.cs
- LinkedList.cs
- BaseServiceProvider.cs
- RangeValuePattern.cs
- TransformDescriptor.cs
- StrokeDescriptor.cs
- UdpTransportSettings.cs
- JsonMessageEncoderFactory.cs
- PackageRelationshipSelector.cs
- AuthenticationException.cs
- _HelperAsyncResults.cs
- DataSourceProvider.cs
- MeasurementDCInfo.cs
- Triangle.cs
- DataServiceResponse.cs
- DataTableExtensions.cs
- Membership.cs
- ReachDocumentPageSerializerAsync.cs
- ParameterModifier.cs
- XsltLibrary.cs
- RegexFCD.cs
- LZCodec.cs
- X509Certificate2Collection.cs
- MarshalByRefObject.cs
- HideDisabledControlAdapter.cs
- CSharpCodeProvider.cs
- NullToBooleanConverter.cs
- HiddenField.cs
- PrintDialog.cs
- Inline.cs
- InternalEnumValidator.cs
- DBCSCodePageEncoding.cs
- InstanceLockException.cs
- WeakReferenceList.cs
- BinaryFormatter.cs
- jithelpers.cs
- PathStreamGeometryContext.cs
- RSAPKCS1SignatureDeformatter.cs
- PropertyDescriptor.cs
- ToolStripContextMenu.cs
- __Error.cs
- SqlProviderServices.cs
- QueueProcessor.cs
- EntityDataSourceWrapper.cs
- GroupDescription.cs
- Visitors.cs
- ApplicationInfo.cs
- Win32KeyboardDevice.cs
- TypeListConverter.cs
- HostedElements.cs
- shaperfactoryquerycacheentry.cs
- XmlBaseWriter.cs
- NativeMethods.cs
- DBProviderConfigurationHandler.cs
- SafeHandle.cs
- Matrix3DValueSerializer.cs
- ToolStripRenderEventArgs.cs
- SecurityTokenValidationException.cs
- ResourceWriter.cs
- CodeStatement.cs
- DataGridViewBindingCompleteEventArgs.cs
- AttachedPropertyBrowsableAttribute.cs
- HyperLink.cs
- WorkflowViewElement.cs
- DateTimeOffset.cs
- TextElementCollectionHelper.cs
- TdsRecordBufferSetter.cs
- DesignBinding.cs
- WmfPlaceableFileHeader.cs
- FactoryId.cs
- TraceContextEventArgs.cs
- ProxyElement.cs
- PageSetupDialog.cs
- DataGridViewHitTestInfo.cs
- COM2Properties.cs
- SolidColorBrush.cs
- MediaTimeline.cs