private ValidationErrorCollection ValidateBindProperty(ValidationManager manager, Activity activity, PropertyBind bind, BindValidationContext validationContext) { ValidationErrorCollection errors = new ValidationErrorCollection(); string name = bind.Name; Activity enclosingActivity = Helpers.GetEnclosingActivity(activity); Activity refActivity = enclosingActivity; if ((name.IndexOf('.') != -1) && (refActivity != null)) { refActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name); } if (refActivity == null) { ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; errors.Add(error); return(errors); } ValidationError item = null; PropertyInfo property = null; Type activityType = null; if (property == null) { activityType = BindValidatorHelper.GetActivityType(manager, refActivity); if (activityType != null) { property = activityType.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); } } if (activityType == null) { item = new ValidationError(SR.GetString("Error_TypeNotResolvedInPropertyName", new object[] { "Name" }), 0x163) { PropertyName = base.GetFullPropertyName(manager) }; } else if (property == null) { item = new ValidationError(SR.GetString("Error_PropertyNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x164) { PropertyName = base.GetFullPropertyName(manager) }; } else if (!property.CanRead) { item = new ValidationError(SR.GetString("Error_PropertyReferenceNoGetter", new object[] { base.GetFullPropertyName(manager), name }), 360) { PropertyName = base.GetFullPropertyName(manager) }; } else if (property.GetGetMethod() == null) { item = new ValidationError(SR.GetString("Error_PropertyReferenceGetterNoAccess", new object[] { base.GetFullPropertyName(manager), name }), 0x60a) { PropertyName = base.GetFullPropertyName(manager) }; } else if (((refActivity != enclosingActivity) && !property.GetGetMethod().IsAssembly) && !property.GetGetMethod().IsPublic) { item = new ValidationError(SR.GetString("Error_PropertyNotAccessible", new object[] { base.GetFullPropertyName(manager), name }), 0x165) { PropertyName = base.GetFullPropertyName(manager) }; } else if (property.PropertyType == null) { item = new ValidationError(SR.GetString("Error_PropertyTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 0x166) { PropertyName = base.GetFullPropertyName(manager) }; } else { MemberInfo memberInfo = property; if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, property.PropertyType, validationContext.Access))) { item = new ValidationError(SR.GetString("Error_PropertyTypeMismatch", new object[] { base.GetFullPropertyName(manager), property.PropertyType.FullName, validationContext.TargetType.FullName }), 0x167) { PropertyName = base.GetFullPropertyName(manager) }; } else if (!string.IsNullOrEmpty(bind.Path)) { memberInfo = MemberBind.GetMemberInfo(property.PropertyType, bind.Path); if (memberInfo == null) { item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null) { if (WorkflowCompilationContext.Current.CheckTypes) { item = MemberBind.ValidateTypesInPath(property.PropertyType, bind.Path); if (item != null) { item.PropertyName = base.GetFullPropertyName(manager) + ".Path"; } } } if (item == null) { Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType; if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access)) { item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } if (item == null) { if (memberInfo is PropertyInfo) { PropertyInfo info3 = memberInfo as PropertyInfo; if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0)) { item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0)) { item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } else if (memberInfo is FieldInfo) { FieldInfo info4 = memberInfo as FieldInfo; if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0)) { item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } if (item != null) { errors.Add(item); } return(errors); }
public WorkflowCompilerResults Compile(WorkflowCompilerParameters parameters, string[] allFiles) { WorkflowCompilerResults results = new WorkflowCompilerResults(parameters.TempFiles); StringCollection strings = new StringCollection(); StringCollection strings2 = new StringCollection(); foreach (string str in allFiles) { if (str.EndsWith(".xoml", StringComparison.OrdinalIgnoreCase)) { strings.Add(str); } else { strings2.Add(str); } } string[] array = new string[strings.Count]; strings.CopyTo(array, 0); string[] strArray2 = new string[strings2.Count]; strings2.CopyTo(strArray2, 0); string location = typeof(object).Assembly.Location; ServiceContainer serviceProvider = new ServiceContainer(); if (parameters.MultiTargetingInformation == null) { XomlCompilerHelper.FixReferencedAssemblies(parameters, results, parameters.LibraryPaths); } string fileName = Path.GetFileName(location); ReferencedAssemblyResolver resolver = new ReferencedAssemblyResolver(parameters.ReferencedAssemblies, parameters.LocalAssembly); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(resolver.ResolveEventHandler); TypeProvider serviceInstance = new TypeProvider(new ServiceContainer()); int index = -1; if ((parameters.ReferencedAssemblies != null) && (parameters.ReferencedAssemblies.Count > 0)) { for (int i = 0; i < parameters.ReferencedAssemblies.Count; i++) { string path = parameters.ReferencedAssemblies[i]; if ((index == -1) && (string.Compare(fileName, Path.GetFileName(path), StringComparison.OrdinalIgnoreCase) == 0)) { index = i; location = path; } serviceInstance.AddAssemblyReference(path); } } if (index != -1) { parameters.ReferencedAssemblies.RemoveAt(index); } else { serviceInstance.AddAssemblyReference(location); } serviceProvider.AddService(typeof(ITypeProvider), serviceInstance); TempFileCollection files = null; string localAssemblyPath = string.Empty; try { using (WorkflowCompilationContext.CreateScope(serviceProvider, parameters)) { parameters.LocalAssembly = this.GenerateLocalAssembly(array, strArray2, parameters, results, out files, out localAssemblyPath); if (parameters.LocalAssembly != null) { resolver.SetLocalAssembly(parameters.LocalAssembly); serviceInstance.SetLocalAssembly(parameters.LocalAssembly); serviceInstance.AddAssembly(parameters.LocalAssembly); results.Errors.Clear(); XomlCompilerHelper.InternalCompileFromDomBatch(array, strArray2, parameters, results, localAssemblyPath); } } return(results); } catch (Exception exception) { int num4 = 0x15c; results.Errors.Add(new WorkflowCompilerError(string.Empty, -1, -1, num4.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CompilationFailed", new object[] { exception.Message }))); } finally { if ((files != null) && !parameters.TempFiles.KeepFiles) { string directoryName = string.Empty; if (File.Exists(localAssemblyPath)) { directoryName = Path.GetDirectoryName(localAssemblyPath); } foreach (string str7 in files) { try { File.Delete(str7); } catch { } } try { if (!string.IsNullOrEmpty(directoryName)) { Directory.Delete(directoryName); } } catch { } } } return(results); }
public WorkflowCompilerResults Compile(WorkflowCompilerParameters parameters, string[] allFiles) { WorkflowCompilerResults results = new WorkflowCompilerResults(parameters.TempFiles); // Split the xoml files from cs/vb files. StringCollection xomlFiles = new StringCollection(); StringCollection userCodeFiles = new StringCollection(); foreach (string file in allFiles) { if (file.EndsWith(".xoml", StringComparison.OrdinalIgnoreCase)) { xomlFiles.Add(file); } else { userCodeFiles.Add(file); } } string[] files = new string[xomlFiles.Count]; xomlFiles.CopyTo(files, 0); string[] codeFiles = new string[userCodeFiles.Count]; userCodeFiles.CopyTo(codeFiles, 0); string mscorlibPath = typeof(object).Assembly.Location; ServiceContainer serviceContainer = new ServiceContainer(); MultiTargetingInfo mtInfo = parameters.MultiTargetingInformation; if (mtInfo == null) { XomlCompilerHelper.FixReferencedAssemblies(parameters, results, parameters.LibraryPaths); } string mscorlibName = Path.GetFileName(mscorlibPath); // Add assembly resolver. ReferencedAssemblyResolver resolver = new ReferencedAssemblyResolver(parameters.ReferencedAssemblies, parameters.LocalAssembly); AppDomain.CurrentDomain.AssemblyResolve += resolver.ResolveEventHandler; // prepare service container TypeProvider typeProvider = new TypeProvider(new ServiceContainer()); int mscorlibIndex = -1; if ((parameters.ReferencedAssemblies != null) && (parameters.ReferencedAssemblies.Count > 0)) { for (int i = 0; i < parameters.ReferencedAssemblies.Count; i++) { string assemblyPath = parameters.ReferencedAssemblies[i]; if ((mscorlibIndex == -1) && (string.Compare(mscorlibName, Path.GetFileName(assemblyPath), StringComparison.OrdinalIgnoreCase) == 0)) { mscorlibIndex = i; mscorlibPath = assemblyPath; } typeProvider.AddAssemblyReference(assemblyPath); } } // a note about references to mscorlib: // If we found mscorlib in the list of reference assemblies, we should remove it prior to sending it to the CodeDOM compiler. // The CodeDOM compiler would add the right mscorlib [based on the version of the provider we use] and the duplication would // cause a compilation error. // If we didn't found a reference to mscorlib we need to add it to the type-provider, though, so we will support exposing // those known types. if (mscorlibIndex != -1) { parameters.ReferencedAssemblies.RemoveAt(mscorlibIndex); if (string.IsNullOrEmpty(parameters.CoreAssemblyFileName)) { parameters.CoreAssemblyFileName = mscorlibPath; } } else { typeProvider.AddAssemblyReference(mscorlibPath); } serviceContainer.AddService(typeof(ITypeProvider), typeProvider); TempFileCollection intermediateTempFiles = null; string localAssemblyPath = string.Empty; string createdDirectoryName = null; try { using (WorkflowCompilationContext.CreateScope(serviceContainer, parameters)) { parameters.LocalAssembly = GenerateLocalAssembly(files, codeFiles, parameters, results, out intermediateTempFiles, out localAssemblyPath, out createdDirectoryName); if (parameters.LocalAssembly != null) { // WinOE resolver.SetLocalAssembly(parameters.LocalAssembly); // Work around HERE!!! // prepare type provider typeProvider.SetLocalAssembly(parameters.LocalAssembly); typeProvider.AddAssembly(parameters.LocalAssembly); results.Errors.Clear(); XomlCompilerHelper.InternalCompileFromDomBatch(files, codeFiles, parameters, results, localAssemblyPath); } } } catch (Exception e) { results.Errors.Add(new WorkflowCompilerError(String.Empty, -1, -1, ErrorNumbers.Error_UnknownCompilerException.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CompilationFailed, e.Message))); } finally { // Delate the temp files. if (intermediateTempFiles != null && parameters.TempFiles.KeepFiles == false) { foreach (string file in intermediateTempFiles) { try { System.IO.File.Delete(file); } catch { } } try { // GenerateLocalAssembly may have created a directory, so let's try to delete it // We can't just delete Path.GetDirectoryName(localAssemblyPath) because it might be the Temp directory. if (createdDirectoryName != null) { Directory.Delete(createdDirectoryName, true); } } catch { } } } return(results); }
private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext) { ValidationErrorCollection errors = new ValidationErrorCollection(); string name = bind.Name; Activity enclosingActivity = Helpers.GetEnclosingActivity(activity); if ((name.IndexOf('.') != -1) && (enclosingActivity != null)) { enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name); } if (enclosingActivity == null) { ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130) { PropertyName = base.GetFullPropertyName(manager) + ".Name" }; errors.Add(error); return(errors); } ValidationError item = null; Type dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager); if (dataSourceClass == null) { item = new ValidationError(SR.GetString("Error_TypeNotResolvedInFieldName", new object[] { "Name" }), 0x11f) { PropertyName = base.GetFullPropertyName(manager) }; } else { FieldInfo field = dataSourceClass.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (field == null) { item = new ValidationError(SR.GetString("Error_FieldNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x120) { PropertyName = base.GetFullPropertyName(manager) }; } else if (field.FieldType == null) { item = new ValidationError(SR.GetString("Error_FieldTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 290) { PropertyName = base.GetFullPropertyName(manager) }; } else { MemberInfo memberInfo = field; if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, field.FieldType, validationContext.Access))) { item = new ValidationError(SR.GetString("Error_FieldTypeMismatch", new object[] { base.GetFullPropertyName(manager), field.FieldType.FullName, validationContext.TargetType.FullName }), 0x13f) { PropertyName = base.GetFullPropertyName(manager) }; } else if (!string.IsNullOrEmpty(bind.Path)) { memberInfo = MemberBind.GetMemberInfo(field.FieldType, bind.Path); if (memberInfo == null) { item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else { using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null) { if (WorkflowCompilationContext.Current.CheckTypes) { item = MemberBind.ValidateTypesInPath(field.FieldType, bind.Path); if (item != null) { item.PropertyName = base.GetFullPropertyName(manager) + ".Path"; } } } if (item == null) { Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType; if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access)) { item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } if (item == null) { if (memberInfo is PropertyInfo) { PropertyInfo info3 = memberInfo as PropertyInfo; if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0)) { item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0)) { item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } else if (memberInfo is FieldInfo) { FieldInfo info4 = memberInfo as FieldInfo; if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0)) { item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145) { PropertyName = base.GetFullPropertyName(manager) + ".Path" }; } } } } } if (item != null) { errors.Add(item); } return(errors); }