private Assembly CreateActiveXWrapper(string ocxFileName)
        {
            bool hasOutputDirectory = !string.IsNullOrEmpty(OutputDirectory);

            if (hasOutputDirectory && !Directory.Exists(OutputDirectory))
            {
                Directory.CreateDirectory(OutputDirectory);
            }

            if (_options == null)
            {
                _options = new AxImporter.Options();
                _options.outputDirectory = OutputDirectory;
                _options.keyPair = KeyPair;
                _options.references = new AxImporterResolver(ImportedFileNames);
            }
            else
            {
                _options.outputName = null;
            }

            AxImporter importer = new AxImporter(_options);
            importer.GenerateFromFile(new FileInfo(ocxFileName));

            foreach (string fileName in importer.GeneratedAssemblies)
            {
                _existingWrappers.Add(Path.GetFileNameWithoutExtension(fileName), fileName);
                Assembly libraryAssembly = Assembly.LoadFrom(fileName);
                ImportedFileNames[libraryAssembly.FullName] = Path.GetFileName(fileName);
            }

            return Assembly.LoadFrom(hasOutputDirectory
                                         ? Path.Combine(OutputDirectory, _options.outputName)
                                         : _options.outputName);
        }
Esempio n. 2
0
 public AxImporter(AxImporter.Options options)
 {
     this.options = options;
 }
Esempio n. 3
0
 public AxImporter(AxImporter.Options options)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
		// This translates the type library into an assembly
		internal void TranslateTypeLib()
		{
			TraceUtil.WriteLineInfo(this, "TranslateTypeLib");
			// Already associated with an assembly
			if (_assy != null)
				return;
			ReadTypeLibFile();
			if (_iTypeLib == null)
				throw new Exception("Failed to open file: " + _fileName);
			// If this is present, we can't translate the assembly,
			// we just have to try and load it using this name.  This 
			// is the case for things like mscorlib.tlb 
			if (_translatedAssyFullName != null) {
				Assembly assy = null;
				try {
					String fileName;
					// We will have the file name if we are coming through
					// here after the type library has been opened previously
					// (when it is being restored from the registry).
					if (_assyInfo._fileName != null)
						fileName = _assyInfo._fileName;
					else
						fileName = _translatedAssyFullName;
					TraceUtil.WriteLineInfo
						(null,
						"TypeLib - translated assy looking for: " 
						+ fileName);
					assy = Assembly.Load(fileName);
				} catch (FileNotFoundException) {
					// Don't ask the user if we have already asked
					// the user
					if (!_dontFindAssy)
						assy = FindAssemblyFile();
				}
			
				TraceUtil.WriteLineInfo(null,
										"TypeLib - source assy is: "
										+ assy
										+ " for translated lib "
										+ _translatedAssyFullName);
				RecordTranslatedAssy(assy);
				return;
			}
			CheckForPrimaryInteropAssy();
			if (_primaryInteropAssyName != null)
				return;
			// Only create the versioned names if the primary interop assy
			// is not used, since that's not versioned.
			CreateAssyNames();
			TraceUtil.WriteLineIf(null, TraceLevel.Info,
								 "TypeLib - converting - url: " 
								 + _assyInfo._url
								 + " file: " + _assyInfo._fileName);
			String dir = ComponentInspectorProperties.ConvertedAssemblyDirectory;
			Directory.CreateDirectory(dir);
			Directory.SetCurrentDirectory(dir);
			if (IsAssyCurrent(_assyInfo._fileName, _fileName)) {
				// See if there is a translated version already present.
				// We don't know if there should be an Ax version or not,
				// try the normal one and if it succeeds, try the Ax version.
				// If the normal version succeeds however, we can consider
				// that we are done.
				RecordTranslatedAssy(Assembly.LoadFrom(_assyInfo._url));
				TraceUtil.WriteLineInfo(null,
										"TypeLib - found previous xlated "
										+ _assyInfo._name);
				try {
					RecordTranslatedAssy(Assembly.LoadFrom(_axAssyInfo._url));
				} catch {
					// Ignore
				}
				return;
			}
			// Convert the type library to an assembly
				
			// The assembly load event happens in here, it is going to
			// be unable to add the assembly to the registry since there
			// is no CodeBase associated with a dynamically created 
			// assembly, but that's not a problem since we add it below
			// when adding the GUID for the typelib
			ProgressDialog progress = new ProgressDialog();
			progress.Setup("Converting " + GetName() 
						   + " to .NET Assembly",
						  "Please wait while I convert " 
						  + GetName()
						   + " to a .NET Assembly",
						  ProgressDialog.NO_PROGRESS_BAR,
						   !ProgressDialog.HAS_PROGRESS_TEXT,
						  ProgressDialog.FINAL);
			progress.ShowIfNotDone();
			try {
				TypeLibConverter converter = new TypeLibConverter();
				AssemblyBuilder asm = converter.ConvertTypeLibToAssembly
					(_iTypeLib, 
					_assyInfo._fileName,
					// Can't do this because we can't strong name these
					 //TypeLibImporterFlags.PrimaryInteropAssembly, 
					0,
					this,
					null, null, null, null);
				// For the problem associated with Q316653
				//FixEventSinkHelpers(asm);
				asm.Save(_assyInfo._fileName);
				RecordTranslatedAssy(Assembly.LoadFrom(_assyInfo._url));
				// Generate the ActiveX wrapper for the typelib, 
				// if that's necessary
				AxImporter.Options impOptions = new AxImporter.Options();
				impOptions.outputDirectory = dir;
				impOptions.outputName = _axAssyInfo._fileName;
				impOptions.references = this;
				impOptions.genSources = true;
				AxImporter axImport = new AxImporter(impOptions);
				try {
					// This converts the type library and generates the
					// wrapper for any ActiveX controls.  It produces 
					// a list of the assemblies that it created.  If there
					// are no ActiveX controls this will throw.
					String wrapper = axImport.
						GenerateFromTypeLibrary(_iTypeLib);
				} catch (Exception ex) {
					if (ex.Message.StartsWith("Did not find a")) {
						TraceUtil.WriteLineInfo(this, 
												"TypeLib - no controls found");
						return;
					}
					TraceUtil.WriteLineWarning(this, 
											  "TypeLib - AxImporter error "
											  + _assyInfo._url + " " 
											  + ex);
					throw new Exception("Error in AxImporter for: "
										+ _assyInfo._url, ex);
				}
				foreach (String aname in axImport.GeneratedAssemblies) {
					TraceUtil.WriteLineInfo(this, "TypeLib - AX gen assy: " 
											+ aname);
				}
				foreach (String sname in axImport.GeneratedSources) {
					TraceUtil.WriteLineInfo(this, "TypeLib - AX gen source: " 
											+ sname);
				}
				RecordTranslatedAssy(Assembly.LoadFrom(_axAssyInfo._url));
				TraceUtil.WriteLineIf(null, TraceLevel.Info,
									 "TypeLib - conversion done: "
									 + _assyInfo._url);
			} finally {
				progress.Finished();
			}
		}
 public ImporterCallback(AxImporter importer)
 {
     this.importer = importer;
     this.options = importer.options;
 }
 public ImporterCallback(AxImporter importer)
 {
     this.importer = importer;
     this.options  = importer.options;
 }