public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(string) && context != null && context.PropertyDescriptor != null) { ActivityBind activityBind = context.PropertyDescriptor.GetValue(context.Instance) as ActivityBind; if (activityBind != null) { return(true); } } ITypeDescriptorContext actualContext = null; TypeConverter actualConverter = null; GetActualTypeConverterAndContext(context, out actualConverter, out actualContext); if (actualConverter != null && actualConverter.GetType() != typeof(ActivityBindTypeConverter)) { return(actualConverter.CanConvertTo(actualContext, destinationType)); } else if (destinationType == typeof(string)) { return(true); } return(base.CanConvertTo(context, destinationType)); }
public WorkFlowDataBinding() { IfElseActivity ifelse_activity = new IfElseActivity(); IfElseBranchActivity branch1 = new IfElseBranchActivity(); IfElseBranchActivity branch2 = new IfElseBranchActivity(); CodeCondition ifelse_condition1 = new CodeCondition(); CodeActivity code_branch1 = new CodeActivity(); ourCodeActivity code_branch2 = new ourCodeActivity(); code_branch1.Name = "Code1"; code_branch2.Name = "Code2"; code_branch1.ExecuteCode += new EventHandler(ExecuteCode1); branch1.Activities.Add(code_branch1); branch2.Activities.Add(code_branch2); ifelse_condition1.Condition += new EventHandler <ConditionalEventArgs> (IfElseCondition1); branch1.Condition = ifelse_condition1; ifelse_activity.Activities.Add(branch1); ifelse_activity.Activities.Add(branch2); ActivityBind activitybind1 = new ActivityBind(); activitybind1.Name = "WorkFlowDataBinding"; activitybind1.Path = "Address"; //Console.WriteLine ("DependecyParent {0}", this.GetType ().FullName); code_branch2.SetBinding(ourCodeActivity.DataProperty, activitybind1); Activities.Add(ifelse_activity); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } string convertedValue = null; ActivityBind activityBind = value as ActivityBind; if (activityBind != null) { Activity activity = PropertyDescriptorUtils.GetComponent(context) as Activity; activity = (activity != null) ? Helpers.ParseActivityForBind(activity, activityBind.Name) : null; convertedValue = String.Format(CultureInfo.InvariantCulture, ("Activity={0}, Path={1}"), (activity != null) ? activity.QualifiedName : activityBind.Name, activityBind.Path); } else { ITypeDescriptorContext actualContext = null; TypeConverter actualConverter = null; GetActualTypeConverterAndContext(context, out actualConverter, out actualContext); if (actualConverter != null && actualConverter.GetType() != typeof(ActivityBindTypeConverter) && actualConverter.CanConvertTo(actualContext, destinationType)) { convertedValue = actualConverter.ConvertTo(actualContext, culture, value, destinationType) as string; } else { convertedValue = base.ConvertTo(context, culture, value, destinationType) as string; } } return(convertedValue); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = ValidationHelpers.ValidateObject(manager, obj); if (validationErrors.Count == 0) { Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name)); } CodeCondition codeCondition = obj as CodeCondition; if (codeCondition != null && codeCondition.IsBindingSet(CodeCondition.ConditionEvent)) { ActivityBind activityBind = codeCondition.GetBinding(CodeCondition.ConditionEvent) as ActivityBind; if (activityBind != null) { Activity contextActivity = Helpers.ParseActivityForBind(activity, activityBind.Name); if (contextActivity != null && Helpers.IsChildActivity(activity.Parent, contextActivity)) { string propertyName = GetFullPropertyName(manager); ValidationError error = new ValidationError(SR.GetString(SR.Error_NestedConstrainedGroupConditions, propertyName), ErrorNumbers.Error_NestedConstrainedGroupConditions); error.PropertyName = propertyName; validationErrors.Add(error); } } } } return(validationErrors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = System.Workflow.Activities.Common.ValidationHelpers.ValidateObject(manager, obj); if (errors.Count == 0) { Activity context = manager.Context[typeof(Activity)] as Activity; if (context == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } CodeCondition condition = obj as CodeCondition; if ((condition != null) && condition.IsBindingSet(CodeCondition.ConditionEvent)) { ActivityBind binding = condition.GetBinding(CodeCondition.ConditionEvent); if (binding != null) { Activity activity = System.Workflow.Activities.Common.Helpers.ParseActivityForBind(context, binding.Name); if ((activity != null) && System.Workflow.Activities.Common.Helpers.IsChildActivity(context.Parent, activity)) { string fullPropertyName = base.GetFullPropertyName(manager); ValidationError item = new ValidationError(SR.GetString("Error_NestedConstrainedGroupConditions", new object[] { fullPropertyName }), 0x615) { PropertyName = fullPropertyName }; errors.Add(item); } } } } return(errors); }
internal static void ValidateRoles(Activity activity, string identity) { DependencyProperty dependencyProperty = DependencyProperty.FromName("Roles", activity.GetType().BaseType); if (dependencyProperty == null) { dependencyProperty = DependencyProperty.FromName("Roles", activity.GetType()); } if (dependencyProperty == null) { return; } ActivityBind rolesBind = activity.GetBinding(dependencyProperty) as ActivityBind; if (rolesBind == null) { return; } WorkflowRoleCollection roles = rolesBind.GetRuntimeValue(activity) as WorkflowRoleCollection; if (roles == null) { return; } if (!roles.IncludesIdentity(identity)) { throw new WorkflowAuthorizationException(activity.Name, identity); } }
public void SetRuntimeValueNull() { string st = string.Empty; ActivityBind ab = new ActivityBind("ClassProvider", "Name"); ab.SetRuntimeValue(null, null); }
void Container4() { //ReceiveActivity.ServiceOperationInfo //<snippet4> ReceiveActivity receiveQuoteFromShipper1 = new ReceiveActivity(); CodeActivity shipper1ShippingQuote = new CodeActivity(); ContextToken contextToken1 = new ContextToken(); ActivityBind activityBind1 = new ActivityBind(); WorkflowParameterBinding workflowParameterBinding1 = new WorkflowParameterBinding(); TypedOperationInfo typedOperationInfo1 = new TypedOperationInfo(); receiveQuoteFromShipper1.Activities.Add(shipper1ShippingQuote); contextToken1.Name = "Shipper1Context"; contextToken1.OwnerActivityName = "GetShippingQuotes"; receiveQuoteFromShipper1.ContextToken = contextToken1; receiveQuoteFromShipper1.Name = "receiveQuoteFromShipper1"; activityBind1.Name = "SupplierWorkflow"; activityBind1.Path = "quoteShipper1"; workflowParameterBinding1.ParameterName = "quote"; workflowParameterBinding1.SetBinding(WorkflowParameterBinding.ValueProperty, ((ActivityBind)(activityBind1))); receiveQuoteFromShipper1.ParameterBindings.Add(workflowParameterBinding1); typedOperationInfo1.ContractType = typeof(IShippingQuote); typedOperationInfo1.Name = "ShippingQuote"; receiveQuoteFromShipper1.ServiceOperationInfo = typedOperationInfo1; //</snippet4> }
void Container0() { ChannelToken channelToken1 = new ChannelToken(); SendActivity RequestQuoteFromShipper3 = new SendActivity(); ActivityBind activityBind2 = new ActivityBind(); ActivityBind activityBind3 = new ActivityBind(); ActivityBind activityBind4 = new ActivityBind(); WorkflowParameterBinding workflowParameterBinding2 = new WorkflowParameterBinding(); WorkflowParameterBinding workflowParameterBinding3 = new WorkflowParameterBinding(); WorkflowParameterBinding workflowParameterBinding4 = new WorkflowParameterBinding(); //SendActivity.ParameterBindings //<snippet0> channelToken1.EndpointName = "Shipper3Endpoint"; channelToken1.Name = "Shipper3Endpoint"; channelToken1.OwnerActivityName = "GetShippingQuotes"; RequestQuoteFromShipper3.ChannelToken = channelToken1; RequestQuoteFromShipper3.Name = "RequestQuoteFromShipper3"; activityBind2.Name = "SupplierWorkflow"; activityBind2.Path = "order"; workflowParameterBinding2.ParameterName = "po"; workflowParameterBinding2.SetBinding(System.Workflow.ComponentModel.WorkflowParameterBinding.ValueProperty, ((System.Workflow.ComponentModel.ActivityBind)(activityBind2))); activityBind3.Name = "SupplierWorkflow"; activityBind3.Path = "contextShipper3"; workflowParameterBinding3.ParameterName = "context"; workflowParameterBinding3.SetBinding(System.Workflow.ComponentModel.WorkflowParameterBinding.ValueProperty, ((System.Workflow.ComponentModel.ActivityBind)(activityBind3))); activityBind4.Name = "SupplierWorkflow"; activityBind4.Path = "ackShipper3"; workflowParameterBinding4.ParameterName = "(ReturnValue)"; workflowParameterBinding4.SetBinding(System.Workflow.ComponentModel.WorkflowParameterBinding.ValueProperty, ((System.Workflow.ComponentModel.ActivityBind)(activityBind4))); RequestQuoteFromShipper3.ParameterBindings.Add(workflowParameterBinding2); RequestQuoteFromShipper3.ParameterBindings.Add(workflowParameterBinding3); RequestQuoteFromShipper3.ParameterBindings.Add(workflowParameterBinding4); //</snippet0> }
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { ArrayList properties = new ArrayList(); ActivityBind activityBind = value as ActivityBind; if (activityBind != null && context != null) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(value, new Attribute[] { BrowsableAttribute.Yes }); PropertyDescriptor activityDescriptor = props["Name"]; if (activityDescriptor != null) { properties.Add(new ActivityBindNamePropertyDescriptor(context, activityDescriptor)); } PropertyDescriptor pathDescriptor = props["Path"]; if (pathDescriptor != null) { properties.Add(new ActivityBindPathPropertyDescriptor(context, pathDescriptor)); } } else if (context != null && context.PropertyDescriptor != null) { ITypeDescriptorContext actualContext = null; TypeConverter actualConverter = null; GetActualTypeConverterAndContext(context, out actualConverter, out actualContext); if (actualConverter != null && actualConverter.GetType() != typeof(ActivityBindTypeConverter)) { properties.AddRange(actualConverter.GetProperties(actualContext, value, attributes)); } } return(new PropertyDescriptorCollection((PropertyDescriptor[])properties.ToArray(typeof(PropertyDescriptor)))); }
/// <summary> /// Overridden to remove properties at design-time. /// </summary> /// <param name="properties"></param> protected override void PreFilterProperties(IDictionary properties) { base.PreFilterProperties(properties); if (this.Activity != null && this.Activity is FileSystem) { CommandType command = ((FileSystem)this.Activity).Command; if (command != CommandType.CopyFile && command != CommandType.MoveFile && command != CommandType.MoveDirectory) { properties.Remove("Destination"); } if (command != CommandType.DeleteDirectory && command != CommandType.FindFiles) { properties.Remove("Recursive"); } if (command != CommandType.CopyFile && command != CommandType.MoveFile && command != CommandType.MoveDirectory) { properties.Remove("Overwrite"); } if (command != CommandType.OpenFile && command != CommandType.CloseFile) { properties.Remove("FileStream"); } if (command != CommandType.OpenTextFile && command != CommandType.CloseFile) { properties.Remove("StreamReader"); } if (command == CommandType.CloseFile) { properties.Remove("Source"); //jamescon: //Bind bind = ((FileSystem)this.Activity).GetBinding(FileSystem.StreamReaderProperty); ActivityBind bind = ((FileSystem)this.Activity).GetBinding(FileSystem.StreamReaderProperty); if (bind != null && bind.UserData.Count > 0) { properties.Remove("FileStream"); } else { bind = ((FileSystem)this.Activity).GetBinding(FileSystem.FileStreamProperty); if (bind != null && bind.UserData.Count > 0) { properties.Remove("StreamReader"); } } } if (command != CommandType.OpenFile) { properties.Remove("FileMode"); properties.Remove("FileAccess"); } if (command != CommandType.FindFiles) { properties.Remove("SearchPattern"); properties.Remove("FileList"); } } }
protected override InstanceDescriptor GetInstanceDescriptor(WorkflowMarkupSerializationManager serializationManager, object value) { ActivityBind bind = value as ActivityBind; if (bind == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "value"); } return(new InstanceDescriptor(typeof(ActivityBind).GetConstructor(new Type[] { typeof(string) }), new object[] { bind.Name })); }
public virtual void GenerateCode(CodeGenerationManager manager, object obj) { if (manager == null) { throw new ArgumentNullException("manager"); } if (obj == null) { throw new ArgumentNullException("obj"); } Activity activity = obj as Activity; if (activity == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj"); } manager.Context.Push(activity); // Generate code for all the member Binds. Walker walker = new Walker(); walker.FoundProperty += delegate(Walker w, WalkerEventArgs args) { // ActivityBind bindBase = args.CurrentValue as ActivityBind; if (bindBase != null) { // push if (args.CurrentProperty != null) { manager.Context.Push(args.CurrentProperty); } manager.Context.Push(args.CurrentPropertyOwner); // call generate code foreach (ActivityCodeGenerator codeGenerator in manager.GetCodeGenerators(bindBase.GetType())) { codeGenerator.GenerateCode(manager, args.CurrentValue); } // pops manager.Context.Pop(); if (args.CurrentProperty != null) { manager.Context.Pop(); } } }; walker.WalkProperties(activity, obj); manager.Context.Pop(); }
public void SetGetRuntimeValue() { object obj; string st = string.Empty; ClassProvider cp = new ClassProvider(); ActivityBind ab = new ActivityBind("ClassProvider", "Name"); obj = ab.GetRuntimeValue(cp, st.GetType()); Assert.AreEqual("Hello", obj.ToString(), "C1#1"); ab.SetRuntimeValue(cp, "Bye"); obj = ab.GetRuntimeValue(cp, st.GetType()); Assert.AreEqual("Bye", obj.ToString(), "C1#2"); }
protected override object GetBoundValue(ActivityBind bind, Type targetType) { if (bind == null) { throw new ArgumentNullException("bind"); } if (targetType == null) { throw new ArgumentNullException("targetType"); } object runtimeValue = bind; Activity parentDependencyObject = base.ParentDependencyObject as Activity; if (parentDependencyObject != null) { runtimeValue = bind.GetRuntimeValue(parentDependencyObject, targetType); } return(runtimeValue); }
public virtual void GenerateCode(CodeGenerationManager manager, object obj) { if (manager == null) { throw new ArgumentNullException("manager"); } if (obj == null) { throw new ArgumentNullException("obj"); } Activity context = obj as Activity; if (context == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj"); } manager.Context.Push(context); Walker walker = new Walker(); walker.FoundProperty += delegate(Walker w, WalkerEventArgs args) { ActivityBind currentValue = args.CurrentValue as ActivityBind; if (currentValue != null) { if (args.CurrentProperty != null) { manager.Context.Push(args.CurrentProperty); } manager.Context.Push(args.CurrentPropertyOwner); foreach (ActivityCodeGenerator generator in manager.GetCodeGenerators(currentValue.GetType())) { generator.GenerateCode(manager, args.CurrentValue); } manager.Context.Pop(); if (args.CurrentProperty != null) { manager.Context.Pop(); } } }; walker.WalkProperties(context, obj); manager.Context.Pop(); }
protected override object GetBoundValue(ActivityBind bind, Type targetType) { if (bind == null) { throw new ArgumentNullException("bind"); } if (targetType == null) { throw new ArgumentNullException("targetType"); } object returnVal = bind; Activity activity = this.ParentDependencyObject as Activity; if (activity != null) { returnVal = bind.GetRuntimeValue(activity, targetType); } return(returnVal); }
internal static void ValidateRoles(Activity activity, string identity) { DependencyProperty dependencyProperty = DependencyProperty.FromName("Roles", activity.GetType().BaseType); if (dependencyProperty == null) { dependencyProperty = DependencyProperty.FromName("Roles", activity.GetType()); } if (dependencyProperty != null) { ActivityBind binding = activity.GetBinding(dependencyProperty); if (binding != null) { WorkflowRoleCollection runtimeValue = binding.GetRuntimeValue(activity) as WorkflowRoleCollection; if ((runtimeValue != null) && !runtimeValue.IncludesIdentity(identity)) { throw new WorkflowAuthorizationException(activity.Name, identity); } } } }
public static void ValidateRoles(Activity activity, string identity) { DependencyProperty dp = DependencyProperty.FromName("Roles", activity.GetType().BaseType); if (dp == null) { dp = DependencyProperty.FromName("Roles", activity.GetType()); } if (dp != null) { ActivityBind bind = activity.GetBinding(dp); if (bind != null) { WorkflowRoleCollection collection = bind.GetRuntimeValue(activity) as WorkflowRoleCollection; if ((collection != null) && !collection.IncludesIdentity(identity)) { throw new WorkflowAuthorizationException(activity.Name, identity); } } } }
private ValidationErrorCollection ValidateActivityBind(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); ActivityBind bind = obj as ActivityBind; PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name })); } if (!(manager.Context[typeof(Activity)] is Activity)) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } ValidationError item = null; BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext; if (context2 == null) { Type baseType = BindHelpers.GetBaseType(manager, validationContext); if (baseType != null) { AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext); context2 = new BindValidationContext(baseType, accessType); } } if (context2 != null) { Type targetType = context2.TargetType; if (item == null) { errors.AddRange(this.ValidateActivity(manager, bind, new BindValidationContext(targetType, context2.Access))); } } if (item != null) { errors.Add(item); } return(errors); }
public override void SetValue(object component, object value) { object obj2 = this.GetValue(component); ActivityBind bind = value as ActivityBind; DependencyObject obj3 = component as DependencyObject; DependencyProperty dependencyProperty = DependencyProperty.FromName(this.Name, this.ComponentType); if (((obj3 != null) && (dependencyProperty != null)) && (bind != null)) { using (new ComponentChangeDispatcher(base.ServiceProvider, obj3, this)) { if (dependencyProperty.IsEvent && (base.ServiceProvider != null)) { IEventBindingService service = base.ServiceProvider.GetService(typeof(IEventBindingService)) as IEventBindingService; if ((service != null) && (service.GetEvent(base.RealPropertyDescriptor) != null)) { base.RealPropertyDescriptor.SetValue(component, null); } } obj3.SetBinding(dependencyProperty, bind); base.OnValueChanged(obj3, EventArgs.Empty); goto Label_00F8; } } if (((obj3 != null) && (dependencyProperty != null)) && obj3.IsBindingSet(dependencyProperty)) { using (new ComponentChangeDispatcher(base.ServiceProvider, obj3, this)) { obj3.RemoveProperty(dependencyProperty); base.OnValueChanged(obj3, EventArgs.Empty); } } base.SetValue(component, value); Label_00F8: if ((obj2 != value) && (((obj2 is ActivityBind) && !(value is ActivityBind)) || (!(obj2 is ActivityBind) && (value is ActivityBind)))) { TypeDescriptor.Refresh(component); } }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != typeof(string)) { return(base.ConvertTo(context, culture, value, destinationType)); } ActivityBind bind = value as ActivityBind; if (bind != null) { Activity component = PropertyDescriptorUtils.GetComponent(context) as Activity; component = (component != null) ? Helpers.ParseActivityForBind(component, bind.Name) : null; return(string.Format(CultureInfo.InvariantCulture, "Activity={0}, Path={1}", new object[] { (component != null) ? component.QualifiedName : bind.Name, bind.Path })); } ITypeDescriptorContext realContext = null; TypeConverter realTypeConverter = null; this.GetActualTypeConverterAndContext(context, out realTypeConverter, out realContext); if (((realTypeConverter != null) && (realTypeConverter.GetType() != typeof(ActivityBindTypeConverter))) && realTypeConverter.CanConvertTo(realContext, destinationType)) { return(realTypeConverter.ConvertTo(realContext, culture, value, destinationType) as string); } return(base.ConvertTo(context, culture, value, destinationType) as string); }
public override bool GetPropertiesSupported(ITypeDescriptorContext context) { bool propertiesSupported = false; if (context != null && context.PropertyDescriptor != null) { ActivityBind activityBind = context.PropertyDescriptor.GetValue(context.Instance) as ActivityBind; if (activityBind != null) { propertiesSupported = true; } else { ITypeDescriptorContext actualContext = null; TypeConverter actualConverter = null; GetActualTypeConverterAndContext(context, out actualConverter, out actualContext); if (actualConverter != null && actualConverter.GetType() != typeof(ActivityBindTypeConverter)) { propertiesSupported = actualConverter.GetPropertiesSupported(actualContext); } } } return(propertiesSupported); }
internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError) { if (!string.IsNullOrEmpty(activityBind.Path)) { Type toType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context); Activity component = PropertyDescriptorUtils.GetComponent(context) as Activity; if ((component != null) && (toType != null)) { component = Helpers.ParseActivityForBind(component, activityBind.Name); if (component == Helpers.GetRootActivity(component)) { bool ignoreCase = CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB; Type dataSourceClass = Helpers.GetDataSourceClass(component, context); if (dataSourceClass != null) { string path = activityBind.Path; int length = path.IndexOfAny(new char[] { '.', '/', '[' }); if (length != -1) { path = path.Substring(0, length); } MemberInfo info = FindMatchingMember(path, dataSourceClass, ignoreCase); if (info != null) { Type fromType = null; bool isPrivate = false; if (info is FieldInfo) { isPrivate = ((FieldInfo) info).IsPrivate; fromType = ((FieldInfo) info).FieldType; } else if (info is PropertyInfo) { MethodInfo getMethod = ((PropertyInfo) info).GetGetMethod(); MethodInfo setMethod = ((PropertyInfo) info).GetSetMethod(); isPrivate = ((getMethod != null) && getMethod.IsPrivate) || ((setMethod != null) && setMethod.IsPrivate); } else if (info is MethodInfo) { isPrivate = ((MethodInfo) info).IsPrivate; } if (length != -1) { PathWalker walker = new PathWalker(); PathMemberInfoEventArgs finalEventArgs = null; walker.MemberFound = (EventHandler<PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate (object sender, PathMemberInfoEventArgs eventArgs) { finalEventArgs = eventArgs; }); if (!walker.TryWalkPropertyPath(dataSourceClass, activityBind.Path)) { if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } fromType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo); } if (((info.DeclaringType == dataSourceClass) || !isPrivate) && ((info is FieldInfo) && TypeProvider.IsAssignable(toType, fromType))) { return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } Activity activity2 = null; if (string.Compare(component.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { activity2 = component; } else if ((component is CompositeActivity) && (component is CompositeActivity)) { foreach (Activity activity3 in Helpers.GetAllNestedActivities(component as CompositeActivity)) { if (string.Compare(activity3.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { activity2 = activity3; } } } if (activity2 != null) { if (TypeProvider.IsAssignable(toType, activity2.GetType())) { return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } IMemberCreationService service = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service != null) { IDesignerHost host = context.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null) { service.CreateField(host.RootComponentClassName, activityBind.Path, toType, null, MemberAttributes.Public, null, false); return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName })); } } else if (throwOnError) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } } } } else { if ((component == null) && throwOnError) { throw new InvalidOperationException(SR.GetString("Error_InvalidActivityIdentifier", new object[] { activityBind.Name })); } if ((toType == null) && throwOnError) { throw new InvalidOperationException(SR.GetString("Error_PropertyTypeNotDefined", new object[] { context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name })); } } } return false; }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); ActivityBind bind = obj as ActivityBind; if (bind == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "obj"); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name })); } ValidationError item = null; if (string.IsNullOrEmpty(bind.Name)) { item = new ValidationError(SR.GetString("Error_IDNotSetForActivitySource"), 0x613) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; errors.Add(item); return(errors); } Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name); if (refActivity == null) { if (bind.Name.StartsWith("/")) { item = new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128); } else { item = new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129); } item.PropertyName = base.GetFullPropertyName(manager) + ".Name"; errors.Add(item); } if (string.IsNullOrEmpty(bind.Path)) { item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; errors.Add(item); } if ((refActivity != null) && (errors.Count == 0)) { string path = bind.Path; string str2 = string.Empty; int startIndex = path.IndexOfAny(new char[] { '.', '/', '[' }); if (startIndex != -1) { str2 = path.Substring(startIndex); str2 = str2.StartsWith(".") ? str2.Substring(1) : str2; path = path.Substring(0, startIndex); } Type baseType = BindHelpers.GetBaseType(manager, validationContext); MemberInfo memberInfo = null; Type srcType = null; if (!string.IsNullOrEmpty(path)) { srcType = BindValidatorHelper.GetActivityType(manager, refActivity); if (srcType != null) { memberInfo = MemberBind.GetMemberInfo(srcType, path); if ((memberInfo == null) && str2.StartsWith("[", StringComparison.Ordinal)) { string str3 = bind.Path.Substring(startIndex); int index = str3.IndexOf(']'); if (index != -1) { string str4 = str3.Substring(0, index + 1); str2 = ((index + 1) < str3.Length) ? str3.Substring(index + 1) : string.Empty; str2 = str2.StartsWith(".") ? str2.Substring(1) : str2; str3 = str4; } path = path + str3; memberInfo = MemberBind.GetMemberInfo(srcType, path); } } } Validator validator = null; object obj2 = null; if (memberInfo != null) { string str5 = !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : bind.Name; if (memberInfo is FieldInfo) { obj2 = new FieldBind(str5 + "." + path, str2); validator = new FieldBindValidator(); } else if (memberInfo is MethodInfo) { if (typeof(Delegate).IsAssignableFrom(baseType)) { obj2 = new MethodBind(str5 + "." + path); validator = new MethodBindValidator(); } else { item = new ValidationError(SR.GetString("Error_InvalidMemberType", new object[] { path, base.GetFullPropertyName(manager) }), 0x629) { PropertyName = base.GetFullPropertyName(manager) }; errors.Add(item); } } else if (memberInfo is PropertyInfo) { if (refActivity == activity) { obj2 = new PropertyBind(str5 + "." + path, str2); validator = new PropertyBindValidator(); } else { obj2 = bind; validator = this; } } else if (memberInfo is EventInfo) { obj2 = bind; validator = this; } } else if (((memberInfo == null) && (baseType != null)) && typeof(Delegate).IsAssignableFrom(baseType)) { obj2 = bind; validator = this; } if ((validator != null) && (obj2 != null)) { if ((validator == this) && (obj2 is ActivityBind)) { errors.AddRange(this.ValidateActivityBind(manager, obj2)); return(errors); } errors.AddRange(validator.Validate(manager, obj2)); return(errors); } if (item == null) { item = new ValidationError(SR.GetString("Error_PathCouldNotBeResolvedToMember", new object[] { bind.Path, !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : refActivity.GetType().Name }), 0x60d) { PropertyName = base.GetFullPropertyName(manager) }; errors.Add(item); } } return(errors); }
public void GetRuntimeValueNull() { string st = string.Empty; ActivityBind ab = new ActivityBind("ClassProvider", "Name"); object obj = ab.GetRuntimeValue(null, st.GetType()); }
public void ProvideValue() { ActivityBind ab = new ActivityBind("ClassProvider", "Name"); Assert.AreEqual(ab, ab.ProvideValue(null), "C2#1"); }
private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext) { ValidationError error = null; ValidationErrorCollection validationErrors = new ValidationErrorCollection(); Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).Name)); Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name); if (refActivity == null) { error = (bind.Name.StartsWith("/", StringComparison.Ordinal)) ? new ValidationError(SR.GetString(SR.Error_CannotResolveRelativeActivity, bind.Name), ErrorNumbers.Error_CannotResolveRelativeActivity) : new ValidationError(SR.GetString(SR.Error_CannotResolveActivity, bind.Name), ErrorNumbers.Error_CannotResolveActivity); error.PropertyName = GetFullPropertyName(manager) + ".Name"; } else if (bind.Path == null || bind.Path.Length == 0) { error = new ValidationError(SR.GetString(SR.Error_PathNotSetForActivitySource), ErrorNumbers.Error_PathNotSetForActivitySource); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { // if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(refActivity, activity)) { error = new ValidationError(SR.GetString(SR.Error_BindActivityReference, refActivity.QualifiedName, activity.QualifiedName), ErrorNumbers.Error_BindActivityReference, true); error.PropertyName = GetFullPropertyName(manager) + ".Name"; } IDesignerHost designerHost = manager.GetService(typeof(IDesignerHost)) as IDesignerHost; WorkflowDesignerLoader loader = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader; if (designerHost != null && loader != null) { Type refActivityType = null; if (designerHost.RootComponent == refActivity) { ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); refActivityType = typeProvider.GetType(designerHost.RootComponentClassName); } else { refActivity.GetType(); } if (refActivityType != null) { MemberInfo memberInfo = MemberBind.GetMemberInfo(refActivityType, bind.Path); if (memberInfo == null || (memberInfo is PropertyInfo && !(memberInfo as PropertyInfo).CanRead)) { error = new ValidationError(SR.GetString(SR.Error_InvalidMemberPath, refActivity.QualifiedName, bind.Path), ErrorNumbers.Error_InvalidMemberPath); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { Type memberType = null; if (memberInfo is FieldInfo) memberType = ((FieldInfo)(memberInfo)).FieldType; else if (memberInfo is PropertyInfo) memberType = ((PropertyInfo)(memberInfo)).PropertyType; else if (memberInfo is EventInfo) memberType = ((EventInfo)(memberInfo)).EventHandlerType; if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access)) { if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType)) { error = new ValidationError(SR.GetString(SR.Warning_ParameterBinding, bind.Path, refActivity.QualifiedName, validationContext.TargetType.FullName), ErrorNumbers.Warning_ParameterBinding, true); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } } } } } else { MemberInfo memberInfo = MemberBind.GetMemberInfo(refActivity.GetType(), bind.Path); if (memberInfo == null || (memberInfo is PropertyInfo && !(memberInfo as PropertyInfo).CanRead)) { error = new ValidationError(SR.GetString(SR.Error_InvalidMemberPath, refActivity.QualifiedName, bind.Path), ErrorNumbers.Error_InvalidMemberPath); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { DependencyProperty dependencyProperty = DependencyProperty.FromName(memberInfo.Name, memberInfo.DeclaringType); object value = BindHelpers.ResolveActivityPath(refActivity, bind.Path); if (value == null) { Type memberType = null; if (memberInfo is FieldInfo) memberType = ((FieldInfo)(memberInfo)).FieldType; else if (memberInfo is PropertyInfo) memberType = ((PropertyInfo)(memberInfo)).PropertyType; else if (memberInfo is EventInfo) memberType = ((EventInfo)(memberInfo)).EventHandlerType; if (!TypeProvider.IsAssignable(typeof(ActivityBind), memberType) && !DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access)) { if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType)) { error = new ValidationError(SR.GetString(SR.Warning_ParameterBinding, bind.Path, refActivity.QualifiedName, validationContext.TargetType.FullName), ErrorNumbers.Warning_ParameterBinding, true); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } } } // If this is the top level activity, we should not valid that the bind can be resolved because // the value of bind can be set when this activity is used in another activity. else if (value is ActivityBind && refActivity.Parent != null) { ActivityBind referencedBind = value as ActivityBind; bool bindRecursionContextAdded = false; // Check for recursion BindRecursionContext recursionContext = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext; if (recursionContext == null) { recursionContext = new BindRecursionContext(); manager.Context.Push(recursionContext); bindRecursionContextAdded = true; } if (recursionContext.Contains(activity, bind)) { error = new ValidationError(SR.GetString(SR.Bind_ActivityDataSourceRecursionDetected), ErrorNumbers.Bind_ActivityDataSourceRecursionDetected); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } else { recursionContext.Add(activity, bind); PropertyValidationContext propertyValidationContext = null; if (dependencyProperty != null) propertyValidationContext = new PropertyValidationContext(refActivity, dependencyProperty); else propertyValidationContext = new PropertyValidationContext(refActivity, memberInfo as PropertyInfo, memberInfo.Name); validationErrors.AddRange(ValidationHelpers.ValidateProperty(manager, refActivity, referencedBind, propertyValidationContext, validationContext)); } if (bindRecursionContextAdded) manager.Context.Pop(); } else if (validationContext.TargetType != null && !DoesTargetTypeMatch(validationContext.TargetType, value.GetType(), validationContext.Access)) { error = new ValidationError(SR.GetString(SR.Error_TargetTypeMismatch, memberInfo.Name, value.GetType().FullName, validationContext.TargetType.FullName), ErrorNumbers.Error_TargetTypeMismatch); error.PropertyName = GetFullPropertyName(manager) + ".Path"; } } } } if (error != null) validationErrors.Add(error); return validationErrors; }
/// <summary> /// Set the new binding for an event /// </summary> /// <param name="component"></param> /// <param name="value"></param> public override void SetValue(object component, object value) { DependencyObject dependencyObject = component as DependencyObject; String eventHandlerName = value as String; if (dependencyObject == null || _eventProperty == null) { return; } //is an event handler already defined for this event? String currentHandlerName = String.Empty; if (dependencyObject.IsBindingSet(_eventProperty)) { currentHandlerName = dependencyObject.GetBinding(_eventProperty).Path; } //the handler name is the same so just get out now if (eventHandlerName == currentHandlerName) { return; } IDesignerHost designerHost = _serviceProvider.GetService( typeof(IDesignerHost)) as IDesignerHost; //use the IComponentChangeService to notify the //designer of the change IComponentChangeService changeService = _serviceProvider.GetService( typeof(IComponentChangeService)) as IComponentChangeService; if (changeService != null) { //notify that the component is changing changeService.OnComponentChanging( component, _eventDescriptor); } //set or remove the binding String bindingName = String.Empty; if (eventHandlerName == null || eventHandlerName == "[Clear]") { //remove the old binding dependencyObject.RemoveProperty(_eventProperty); } else { //Add a new ActivityBind object to the component ActivityBind bind = new ActivityBind( ((Activity)designerHost.RootComponent).Name, eventHandlerName); dependencyObject.SetBinding(_eventProperty, bind); } if (changeService != null) { //notify that the component has changed changeService.OnComponentChanged( component, _eventDescriptor, currentHandlerName, bindingName); } }
private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext) { ValidationError item = null; ValidationErrorCollection errors = new ValidationErrorCollection(); Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name })); } Activity request = Helpers.ParseActivityForBind(activity, bind.Name); if (request == null) { item = bind.Name.StartsWith("/", StringComparison.Ordinal) ? new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128) : new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129); item.PropertyName = base.GetFullPropertyName(manager) + ".Name"; } else if ((bind.Path == null) || (bind.Path.Length == 0)) { item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(request, activity)) { item = new ValidationError(SR.GetString("Error_BindActivityReference", new object[] { request.QualifiedName, activity.QualifiedName }), 0x12a, true) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; } IDesignerHost service = manager.GetService(typeof(IDesignerHost)) as IDesignerHost; WorkflowDesignerLoader loader = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader; if ((service != null) && (loader != null)) { Type srcType = null; if (service.RootComponent == request) { ITypeProvider provider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (provider == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName })); } srcType = provider.GetType(service.RootComponentClassName); } else { request.GetType(); } if (srcType != null) { MemberInfo memberInfo = MemberBind.GetMemberInfo(srcType, bind.Path); if ((memberInfo == null) || ((memberInfo is PropertyInfo) && !(memberInfo as PropertyInfo).CanRead)) { item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { Type memberType = null; if (memberInfo is FieldInfo) { memberType = ((FieldInfo)memberInfo).FieldType; } else if (memberInfo is PropertyInfo) { memberType = ((PropertyInfo)memberInfo).PropertyType; } else if (memberInfo is EventInfo) { memberType = ((EventInfo)memberInfo).EventHandlerType; } if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access)) { if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType)) { item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName }), 0x12d) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } } else { MemberInfo info2 = MemberBind.GetMemberInfo(request.GetType(), bind.Path); if ((info2 == null) || ((info2 is PropertyInfo) && !(info2 as PropertyInfo).CanRead)) { item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { DependencyProperty dependencyProperty = DependencyProperty.FromName(info2.Name, info2.DeclaringType); object obj2 = BindHelpers.ResolveActivityPath(request, bind.Path); if (obj2 == null) { Type fromType = null; if (info2 is FieldInfo) { fromType = ((FieldInfo)info2).FieldType; } else if (info2 is PropertyInfo) { fromType = ((PropertyInfo)info2).PropertyType; } else if (info2 is EventInfo) { fromType = ((EventInfo)info2).EventHandlerType; } if (!TypeProvider.IsAssignable(typeof(ActivityBind), fromType) && !DoesTargetTypeMatch(validationContext.TargetType, fromType, validationContext.Access)) { if (typeof(WorkflowParameterBinding).IsAssignableFrom(info2.DeclaringType)) { item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, fromType.FullName, validationContext.TargetType.FullName }), 0x12d) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } else if ((obj2 is ActivityBind) && (request.Parent != null)) { ActivityBind bind2 = obj2 as ActivityBind; bool flag = false; BindRecursionContext context = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext; if (context == null) { context = new BindRecursionContext(); manager.Context.Push(context); flag = true; } if (context.Contains(activity, bind)) { item = new ValidationError(SR.GetString("Bind_ActivityDataSourceRecursionDetected"), 0x12f) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { context.Add(activity, bind); PropertyValidationContext propertyValidationContext = null; if (dependencyProperty != null) { propertyValidationContext = new PropertyValidationContext(request, dependencyProperty); } else { propertyValidationContext = new PropertyValidationContext(request, info2 as PropertyInfo, info2.Name); } errors.AddRange(ValidationHelpers.ValidateProperty(manager, request, bind2, propertyValidationContext, validationContext)); } if (flag) { manager.Context.Pop(); } } else if ((validationContext.TargetType != null) && !DoesTargetTypeMatch(validationContext.TargetType, obj2.GetType(), validationContext.Access)) { item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, obj2.GetType().FullName, validationContext.TargetType.FullName }), 0x12d) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } if (item != null) { errors.Add(item); } return(errors); }
internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError) { //Check if the activity is root activity and has valid design time type if (!String.IsNullOrEmpty(activityBind.Path)) { Type boundType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context); Activity activity = PropertyDescriptorUtils.GetComponent(context) as Activity; if (activity != null && boundType != null) { activity = Helpers.ParseActivityForBind(activity, activityBind.Name); if (activity == Helpers.GetRootActivity(activity)) { bool isVB = (CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB); Type designedType = Helpers.GetDataSourceClass(activity, context); if (designedType != null) { //field path could be nested too. //need to find field only with the name up to the first dot (CimplexTypeField in the example below) //and the right type (that would be tricky if the field doesnt exist yet) //example: CimplexTypeField.myIDictionary_int_string[10].someOtherGood2 string fieldName = activityBind.Path; int indexOfDot = fieldName.IndexOfAny(new char[] { '.', '/', '[' }); if (indexOfDot != -1) fieldName = fieldName.Substring(0, indexOfDot); //path is a nested field access MemberInfo matchingMember = ActivityBindPropertyDescriptor.FindMatchingMember(fieldName, designedType, isVB); if (matchingMember != null) { Type memberType = null; bool isPrivate = false; if (matchingMember is FieldInfo) { isPrivate = ((FieldInfo)matchingMember).IsPrivate; memberType = ((FieldInfo)matchingMember).FieldType; } else if (matchingMember is PropertyInfo) { MethodInfo getMethod = ((PropertyInfo)matchingMember).GetGetMethod(); MethodInfo setMethod = ((PropertyInfo)matchingMember).GetSetMethod(); isPrivate = ((getMethod != null && getMethod.IsPrivate) || (setMethod != null && setMethod.IsPrivate)); } else if (matchingMember is MethodInfo) { isPrivate = ((MethodInfo)matchingMember).IsPrivate; } if (indexOfDot != -1) { //need to find the type of the member the path references (and if the path is valid at all) PathWalker pathWalker = new PathWalker(); PathMemberInfoEventArgs finalEventArgs = null; pathWalker.MemberFound += delegate(object sender, PathMemberInfoEventArgs eventArgs) { finalEventArgs = eventArgs; }; if (pathWalker.TryWalkPropertyPath(designedType, activityBind.Path)) { //successfully walked the entire path memberType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo); } else { //the path is invalid if (throwOnError) throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); return false; } } if ((matchingMember.DeclaringType == designedType || !isPrivate) && matchingMember is FieldInfo && TypeProvider.IsAssignable(boundType, memberType)) { return true; } else { if (throwOnError) throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); return false; } } else { // Find out if the name conflicts with an existing activity that has not be flushed in to the // code beside. An activity bind can bind to this field only if the type of the property // is the assignable from the activity type. Activity matchingActivity = null; if (string.Compare(activity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) matchingActivity = activity; else if (activity is CompositeActivity) { if (activity is CompositeActivity) { foreach (Activity existingActivity in Helpers.GetAllNestedActivities(activity as CompositeActivity)) { if (string.Compare(existingActivity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) matchingActivity = existingActivity; } } } if (matchingActivity != null) { if (TypeProvider.IsAssignable(boundType, matchingActivity.GetType())) return true; else { if (throwOnError) throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); return false; } } } IMemberCreationService memberCreationService = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { if (throwOnError) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } else { IDesignerHost designerHost = context.GetService(typeof(IDesignerHost)) as IDesignerHost; if (designerHost == null) { if (throwOnError) throw new InvalidOperationException(SR.GetString("General_MissingService", typeof(IDesignerHost).FullName)); } else { memberCreationService.CreateField(designerHost.RootComponentClassName, activityBind.Path, boundType, null, MemberAttributes.Public, null, false); return true; } } } } } else { if (activity == null && throwOnError) throw new InvalidOperationException(SR.GetString(SR.Error_InvalidActivityIdentifier, activityBind.Name)); if (boundType == null && throwOnError) throw new InvalidOperationException(SR.GetString(SR.Error_PropertyTypeNotDefined, context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name)); } } return false; }
/// <summary> /// Create a workflow by hand /// </summary> /// <returns></returns> private static Activity CreateWorkflowInCode() { MarkupOnlyBaseWorkflow workflow = null; //create the root workflow object workflow = new MarkupOnlyBaseWorkflow(); workflow.Name = "CodedWorkflow"; //create an IfElseActivity IfElseActivity ifElse = new IfElseActivity("ifElseActivity1"); // //Add the left side branch to the IfElseActivity // IfElseBranchActivity branch = new IfElseBranchActivity("ifElseBranchActivity1"); #if COMPILE_RULES_WORKFLOW //add a rule condition to the branch RuleConditionReference ruleCondition = new RuleConditionReference(); ruleCondition.ConditionName = "IsNumberPositive"; branch.Condition = ruleCondition; #else //add a condition to the branch CodeCondition condition = new CodeCondition(); //bind the ConditionEvent to the IsNumberPositive member ActivityBind bind = new ActivityBind( "CodedWorkflow", "IsNumberPositive"); condition.SetBinding(CodeCondition.ConditionEvent, bind); branch.Condition = condition; #endif //add a custom WriteMessageActivity to the branch WriteMessageActivity writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessagePositive"; writeMessage.Message = "The number is positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); // //add the right side branch to the IfElseActivity // branch = new IfElseBranchActivity("ifElseBranchActivity2"); //add a custom WriteMessageActivity to the branch writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessageNotPositive"; writeMessage.Message = "The number is NOT positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); //add the IfElseActivity to the workflow workflow.Activities.Add(ifElse); #if COMPILE_WORKFLOW //provide a class name for the new workflow workflow.SetValue(WorkflowMarkupSerializer.XClassProperty, "ProWF.MyNewWorkflowClass"); #endif return(workflow); }