protected override void Initialize() { base.Initialize(); IDesignerLoaderHost host = LoaderHost; if (host != null) { TypeProvider typeProvider = new TypeProvider(host); typeProvider.AddAssemblyReference(typeof(string).Assembly.Location); } }
protected override void Initialize() { base.Initialize(); IDesignerLoaderHost host = LoaderHost; if (host != null) { host.RemoveService(typeof(IIdentifierCreationService)); host.AddService(typeof(IIdentifierCreationService), new IdentifierCreationService(host)); host.AddService(typeof(IMenuCommandService), new MenuCommandService(host)); TypeProvider typeProvider = new TypeProvider(host); typeProvider.AddAssemblyReference(typeof(string).Assembly.Location); host.AddService(typeof(ITypeProvider), typeProvider, true); host.AddService(typeof(IEventBindingService), new EventBindingService()); } }
public Form1() { InitializeComponent(); // ���[�N�t���[�v���W�F�N�g�̃p�X��擾 projectpath = Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\CustomWorkflowLibrary"); // ���[�N�t���[�f�U�C�i�[�̏����� this.designSurface = new DesignSurface(); loader = new MyWorkflowLoader(Path.Combine(projectpath, "Workflow1.xoml")); designSurface.BeginLoad(loader); this.workflowView = new WorkflowView((IServiceProvider) this.designSurface); splitContainer1.Panel1.Controls.Add(this.workflowView); this.workflowView.Dock = DockStyle.Fill; IDesignerHost designerHost = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); designerHost.Activate(); // �R���e�L�X�g���j���[�̕\�� IMenuCommandService menuService = new WorkflowMenuCommandService((IServiceProvider)workflowView); designerHost.AddService(typeof(IMenuCommandService), menuService); // �Q�Ƃ���A�Z���u�� (�ꕔ) ��ݒ� // (�p�����[�^�� Validation �`�F�b�N�Ȃǂ̍ۂɁA���̃A�Z���u������ɂ�������) TypeProvider typeProvider = new TypeProvider((IServiceProvider)workflowView); typeProvider.AddAssemblyReference(@"..\..\..\CustomWorkflowLibrary\bin\Debug\CustomWorkflowLibrary.dll"); designerHost.AddService(typeof(ITypeProvider), typeProvider); // (.NET 3.5 ReceiveActivity �� ServiceOperationInfo �𐳂����ݒ肵�Ȃ� (Validation Error �ƂȂ�) ���߈ȉ���lj�) SequentialWorkflowActivity rootActivity = (SequentialWorkflowActivity)designerHost.RootComponent; ReceiveActivity receiveActivity = (ReceiveActivity)rootActivity.Activities[0]; TypedOperationInfo typedOperationInfo = new TypedOperationInfo(); typedOperationInfo.ContractType = typeof(CustomWorkflowLibrary.IWorkflow1); typedOperationInfo.Name = "CalcData"; receiveActivity.ServiceOperationInfo = typedOperationInfo; }
internal WorkflowDesignSurface(IServiceProvider serviceProvider) { this.ServiceContainer.AddService(typeof(IMenuCommandService), new MenuCommandService(this.ServiceContainer)); TypeProvider typeProvider = new TypeProvider(serviceProvider); typeProvider.AddAssemblyReference(typeof(string).Assembly.Location); this.ServiceContainer.AddService(typeof(ITypeProvider), typeProvider, true); }
protected static TypeProvider CreateTypeProvider(Activity rootActivity) { TypeProvider typeProvider = new TypeProvider(null); Type companionType = rootActivity.GetType(); typeProvider.SetLocalAssembly(companionType.Assembly); typeProvider.AddAssembly(companionType.Assembly); foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies()) { Assembly referencedAssembly = null; try { referencedAssembly = Assembly.Load(assemblyName); if (referencedAssembly != null) { typeProvider.AddAssembly(referencedAssembly); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } } if (referencedAssembly == null && assemblyName.CodeBase != null) { typeProvider.AddAssemblyReference(assemblyName.CodeBase); } } return typeProvider; }
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 Bug 17591: we must set the local assembly here, // otherwise, the resolver won't be able to resolve custom types correctly. 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; }
internal static TypeProvider CreateTypeProvider(Activity rootActivity) { TypeProvider provider = new TypeProvider(null); Type type = rootActivity.GetType(); provider.SetLocalAssembly(type.Assembly); provider.AddAssembly(type.Assembly); foreach (AssemblyName name in type.Assembly.GetReferencedAssemblies()) { Assembly assembly = null; try { assembly = Assembly.Load(name); if (assembly != null) { provider.AddAssembly(assembly); } } catch { } if ((assembly == null) && (name.CodeBase != null)) { provider.AddAssemblyReference(name.CodeBase); } } return provider; }
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); }
internal static TypeProvider CreateTypeProvider(Activity rootActivity) { TypeProvider typeProvider = new TypeProvider(null); Type companionType = rootActivity.GetType(); typeProvider.SetLocalAssembly(companionType.Assembly); typeProvider.AddAssembly(companionType.Assembly); foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies()) { Assembly referencedAssembly = null; try { referencedAssembly = Assembly.Load(assemblyName); if (referencedAssembly != null) typeProvider.AddAssembly(referencedAssembly); } catch { } if (referencedAssembly == null && assemblyName.CodeBase != null) typeProvider.AddAssemblyReference(assemblyName.CodeBase); } return typeProvider; }
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); 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; }
internal PreviewDesignSurface(IServiceProvider parentProvider) : base(new PreviewDesignerServiceProvider(parentProvider)) { ITypeProvider typeProvider = GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) { TypeProvider provider = new TypeProvider(this); provider.AddAssemblyReference(typeof(string).Assembly.Location); ServiceContainer.AddService(typeof(ITypeProvider), provider, true); } }
internal PreviewDesignSurface(IServiceProvider parentProvider) : base(new PreviewDesignerServiceProvider(parentProvider)) { if (!(base.GetService(typeof(ITypeProvider)) is ITypeProvider)) { TypeProvider serviceInstance = new TypeProvider(this); serviceInstance.AddAssemblyReference(typeof(string).Assembly.Location); base.ServiceContainer.AddService(typeof(ITypeProvider), serviceInstance, true); } }