Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Rules / Design / LogicalExpressionEditor.cs / 1305376 / LogicalExpressionEditor.cs
using System;
using System.CodeDom;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Globalization;
using Microsoft.Win32;
using System.Workflow.Activities.Common;
namespace System.Workflow.Activities.Rules.Design
{
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class LogicalExpressionEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public LogicalExpressionEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
// Do not allow editing expression if the name is not set.
RuleConditionReference conditionDeclaration = typeDescriptorContext.Instance as RuleConditionReference;
if (conditionDeclaration == null || conditionDeclaration.ConditionName == null || conditionDeclaration.ConditionName.Length <= 0)
throw new ArgumentException(Messages.ConditionNameNotSet);
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
RuleConditionCollection conditionDefinitions = null;
RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));
if (rules != null)
conditionDefinitions = rules.Conditions;
if (conditionDefinitions != null && !conditionDefinitions.Contains(conditionDeclaration.ConditionName))
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, conditionDeclaration.ConditionName);
throw new ArgumentException(message);
}
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
CodeExpression experssion = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression;
try
{
using (RuleConditionDialog dlg = new RuleConditionDialog(baseActivity, experssion))
{
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.Expression;
}
}
catch (NotSupportedException)
{
DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider);
}
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class ConditionNameEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public ConditionNameEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
string conditionName = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as string;
ConditionBrowserDialog dlg = new ConditionBrowserDialog(baseActivity, conditionName);
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.SelectedName;
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#region class RuleSetNameEditor
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class RuleSetNameEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public RuleSetNameEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
string ruleSetName = null;
RuleSetReference ruleSetReference = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as RuleSetReference;
if (ruleSetReference != null)
ruleSetName = ruleSetReference.RuleSetName;
RuleSetBrowserDialog dlg = new RuleSetBrowserDialog(baseActivity, ruleSetName);
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentUICulture, dlg.SelectedName);
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#endregion
#region class RuleSetDefinitionEditor
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class RuleSetDefinitionEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public RuleSetDefinitionEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
// Do not allow editing if in debug mode.
WorkflowDesignerLoader workflowDesignerLoader = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
if (workflowDesignerLoader != null && workflowDesignerLoader.InDebugMode)
throw new InvalidOperationException(Messages.DebugModeEditsDisallowed);
// Do not allow editing expression if the name is not set.
RuleSetReference ruleSetReference = typeDescriptorContext.Instance as RuleSetReference;
if (ruleSetReference == null || ruleSetReference.RuleSetName == null || ruleSetReference.RuleSetName.Length <= 0)
throw new ArgumentException(Messages.RuleSetNameNotSet);
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
RuleSetCollection ruleSetCollection = null;
RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));
if (rules != null)
ruleSetCollection = rules.RuleSets;
if (ruleSetCollection != null && !ruleSetCollection.Contains(ruleSetReference.RuleSetName))
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, ruleSetReference.RuleSetName);
throw new ArgumentException(message);
}
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
RuleSet ruleSet = ruleSetCollection[ruleSetReference.RuleSetName];
using (RuleSetDialog dlg = new RuleSetDialog(baseActivity, ruleSet))
{
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.RuleSet;
}
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#endregion
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.CodeDom;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Globalization;
using Microsoft.Win32;
using System.Workflow.Activities.Common;
namespace System.Workflow.Activities.Rules.Design
{
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class LogicalExpressionEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public LogicalExpressionEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
// Do not allow editing expression if the name is not set.
RuleConditionReference conditionDeclaration = typeDescriptorContext.Instance as RuleConditionReference;
if (conditionDeclaration == null || conditionDeclaration.ConditionName == null || conditionDeclaration.ConditionName.Length <= 0)
throw new ArgumentException(Messages.ConditionNameNotSet);
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
RuleConditionCollection conditionDefinitions = null;
RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));
if (rules != null)
conditionDefinitions = rules.Conditions;
if (conditionDefinitions != null && !conditionDefinitions.Contains(conditionDeclaration.ConditionName))
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, conditionDeclaration.ConditionName);
throw new ArgumentException(message);
}
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
CodeExpression experssion = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression;
try
{
using (RuleConditionDialog dlg = new RuleConditionDialog(baseActivity, experssion))
{
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.Expression;
}
}
catch (NotSupportedException)
{
DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider);
}
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class ConditionNameEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public ConditionNameEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
string conditionName = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as string;
ConditionBrowserDialog dlg = new ConditionBrowserDialog(baseActivity, conditionName);
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.SelectedName;
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#region class RuleSetNameEditor
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class RuleSetNameEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public RuleSetNameEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
string ruleSetName = null;
RuleSetReference ruleSetReference = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as RuleSetReference;
if (ruleSetReference != null)
ruleSetName = ruleSetReference.RuleSetName;
RuleSetBrowserDialog dlg = new RuleSetBrowserDialog(baseActivity, ruleSetName);
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentUICulture, dlg.SelectedName);
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#endregion
#region class RuleSetDefinitionEditor
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
internal sealed class RuleSetDefinitionEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService;
public RuleSetDefinitionEditor()
{
}
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
{
if (typeDescriptorContext == null)
throw new ArgumentNullException("typeDescriptorContext");
if (serviceProvider == null)
throw new ArgumentNullException("serviceProvider");
object returnVal = o;
// Do not allow editing if in debug mode.
WorkflowDesignerLoader workflowDesignerLoader = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
if (workflowDesignerLoader != null && workflowDesignerLoader.InDebugMode)
throw new InvalidOperationException(Messages.DebugModeEditsDisallowed);
// Do not allow editing expression if the name is not set.
RuleSetReference ruleSetReference = typeDescriptorContext.Instance as RuleSetReference;
if (ruleSetReference == null || ruleSetReference.RuleSetName == null || ruleSetReference.RuleSetName.Length <= 0)
throw new ArgumentException(Messages.RuleSetNameNotSet);
Activity baseActivity = null;
IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
if (rs != null)
baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
RuleSetCollection ruleSetCollection = null;
RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));
if (rules != null)
ruleSetCollection = rules.RuleSets;
if (ruleSetCollection != null && !ruleSetCollection.Contains(ruleSetReference.RuleSetName))
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, ruleSetReference.RuleSetName);
throw new ArgumentException(message);
}
this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
RuleSet ruleSet = ruleSetCollection[ruleSetReference.RuleSetName];
using (RuleSetDialog dlg = new RuleSetDialog(baseActivity, ruleSet))
{
if (DialogResult.OK == editorService.ShowDialog(dlg))
returnVal = dlg.RuleSet;
}
}
return returnVal;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext typeDescriptorContext)
{
return UITypeEditorEditStyle.Modal;
}
}
#endregion
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TrackingDataItem.cs
- _FtpDataStream.cs
- Image.cs
- IndependentlyAnimatedPropertyMetadata.cs
- SafeRightsManagementHandle.cs
- CompatibleIComparer.cs
- ProvidePropertyAttribute.cs
- ObjectDataSourceDisposingEventArgs.cs
- PropertyGrid.cs
- EventTrigger.cs
- DeploymentSection.cs
- MergeEnumerator.cs
- JournalNavigationScope.cs
- HTTP_SERVICE_CONFIG_URLACL_KEY.cs
- AudioException.cs
- EntityDataSourceDesigner.cs
- SyndicationDeserializer.cs
- QueryStringHandler.cs
- CatalogPart.cs
- GridItemProviderWrapper.cs
- ForeignKeyFactory.cs
- XmlHierarchicalEnumerable.cs
- VectorAnimationUsingKeyFrames.cs
- TextTreeNode.cs
- ILGenerator.cs
- OleDbConnection.cs
- TreeIterators.cs
- OpCellTreeNode.cs
- DeviceSpecific.cs
- Attributes.cs
- AttributeEmitter.cs
- AuthenticationManager.cs
- CreateUserWizardStep.cs
- DbProviderSpecificTypePropertyAttribute.cs
- BindingListCollectionView.cs
- webclient.cs
- ReadContentAsBinaryHelper.cs
- ImageSource.cs
- FrameworkObject.cs
- SessionParameter.cs
- ClonableStack.cs
- _ChunkParse.cs
- IDQuery.cs
- TextPointerBase.cs
- ProfileGroupSettingsCollection.cs
- DataGridViewBindingCompleteEventArgs.cs
- XmlSerializerNamespaces.cs
- WindowsNonControl.cs
- WindowsStartMenu.cs
- EventHandlerList.cs
- SimpleApplicationHost.cs
- Emitter.cs
- XmlSerializerNamespaces.cs
- CapacityStreamGeometryContext.cs
- MatrixTransform3D.cs
- ButtonFlatAdapter.cs
- IconHelper.cs
- BaseResourcesBuildProvider.cs
- CodePageUtils.cs
- IDictionary.cs
- EntityDataSourceConfigureObjectContextPanel.cs
- TreeViewEvent.cs
- VectorConverter.cs
- XmlNodeComparer.cs
- FlowDocumentFormatter.cs
- uribuilder.cs
- ValueQuery.cs
- TextCompositionEventArgs.cs
- BufferBuilder.cs
- TextCharacters.cs
- BitmapDownload.cs
- XmlArrayItemAttribute.cs
- Int16KeyFrameCollection.cs
- CatalogZoneAutoFormat.cs
- TailCallAnalyzer.cs
- AlignmentXValidation.cs
- ProgressBarRenderer.cs
- TrustSection.cs
- RequestQueue.cs
- EncoderNLS.cs
- PropertyGrid.cs
- PagePropertiesChangingEventArgs.cs
- SmtpTransport.cs
- XmlValidatingReaderImpl.cs
- XPathNodeIterator.cs
- ColorContextHelper.cs
- MobileComponentEditorPage.cs
- UpWmlPageAdapter.cs
- GetPageNumberCompletedEventArgs.cs
- PartialCachingAttribute.cs
- EventSinkActivityDesigner.cs
- OdbcInfoMessageEvent.cs
- Soap.cs
- WebConfigurationHost.cs
- MouseButtonEventArgs.cs
- XPathDocumentBuilder.cs
- VisualStates.cs
- DBDataPermission.cs
- NullableConverter.cs
- QueryPageSettingsEventArgs.cs