Exemplo n.º 1
0
        /// <include file='doc\AxToWFC.uex' path='docs/doc[@for="AxImp.Run"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        private static void Run(AxImporter.Options options)
        {
            string[] assemsGenerated;

            AxImporter importer = new AxImporter(options);

            FileInfo file      = new FileInfo(typeLibName);
            string   axctlType = importer.GenerateFromFile(file);

            if (!options.silentMode && options.genSources && importer.GeneratedSources.Length > 0)
            {
                string[] srcGen = importer.GeneratedSources;
                foreach (string s in srcGen)
                {
                    Console.WriteLine(AxImpSR.GetString(AxImpSR.GeneratedSource, s));
                }
            }

            if (!options.silentMode)
            {
                assemsGenerated = importer.GeneratedAssemblies;
                foreach (string a in assemsGenerated)
                {
                    Console.WriteLine(AxImpSR.GetString(AxImpSR.GeneratedAssembly, a));
                }
            }
        }
Exemplo n.º 2
0
        private static bool ParseArguments(String [] aArgs, ref AxImporter.Options Options, ref int ReturnCode)
        {
            CommandLine cmdLine;
            Option      opt;

            // Create the options object that will be returned.
            options = new AxImporter.Options();

            options.outputDirectory = Environment.CurrentDirectory;
            options.overwriteRCW    = true;

            // Parse the command line arguments using the command line argument parser.
            try {
                cmdLine = new CommandLine(aArgs, new String[] { "*out", "*publickey", "*keyfile", "*keycontainer",
                                                                "source", "delaysign", "nologo", "silent", "verbose", "?", "help", "*rcw" });
            }
            catch (ApplicationException e) {
                PrintLogo();
                WriteErrorMsg(null, e);
                ReturnCode = ErrorReturnCode;
                return(false);
            }

            // Make sure there is at least one argument.
            if ((cmdLine.NumArgs + cmdLine.NumOpts) < 1)
            {
                PrintUsage();
                ReturnCode = SuccessReturnCode;
                return(false);
            }

            // Get the name of the COM typelib.
            typeLibName = cmdLine.GetNextArg();

            // Go through the list of options.
            while ((opt = cmdLine.GetNextOption()) != null)
            {
                // Determine which option was specified.
                if (opt.Name.Equals("out"))
                {
                    FileInfo fi  = new FileInfo(opt.Value);
                    string   dir = fi.Directory.FullName;
                    if (dir != null && dir.Length > 0)
                    {
                        options.outputDirectory = dir;
                    }

                    options.outputName = fi.Name;
                }
                else if (opt.Name.Equals("publickey"))
                {
                    if (options.keyPair != null || options.publicKey != null)
                    {
                        PrintLogo();
                        WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_TooManyKeys));
                        ReturnCode = ErrorReturnCode;
                        return(false);
                    }
                    // Read data from binary file into byte array.
                    byte[] aData;
                    try {
                        FileStream fs      = new FileStream(opt.Value, FileMode.Open, FileAccess.Read, FileShare.Read);
                        int        iLength = (int)fs.Length;
                        aData = new byte[iLength];
                        fs.Read(aData, 0, iLength);
                        fs.Close();
                    }
                    catch (Exception e) {
                        PrintLogo();
                        WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_ErrorWhileOpeningFile, opt.Value), e);
                        ReturnCode = ErrorReturnCode;
                        return(false);
                    }
                    options.publicKey = aData;
                }
                else if (opt.Name.Equals("keyfile"))
                {
                    if (options.keyPair != null || options.publicKey != null)
                    {
                        PrintLogo();
                        WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_TooManyKeys));
                        ReturnCode = ErrorReturnCode;
                        return(false);
                    }
                    // Read data from binary file into byte array.
                    byte[] aData;
                    try {
                        FileStream fs      = new FileStream(opt.Value, FileMode.Open, FileAccess.Read);
                        int        iLength = (int)fs.Length;
                        aData = new byte[iLength];
                        fs.Read(aData, 0, iLength);
                        fs.Close();
                    }
                    catch (Exception e) {
                        PrintLogo();
                        WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_ErrorWhileOpeningFile, opt.Value), e);
                        ReturnCode = ErrorReturnCode;
                        return(false);
                    }
                    options.keyFile = opt.Value;
                    options.keyPair = new StrongNameKeyPair(aData);
                }
                else if (opt.Name.Equals("keycontainer"))
                {
                    if (options.keyPair != null)
                    {
                        PrintLogo();
                        WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_TooManyKeys));
                        ReturnCode = ErrorReturnCode;
                        return(false);
                    }
                    options.keyContainer = opt.Value;
                    options.keyPair      = new StrongNameKeyPair(opt.Value);
                }
                else if (opt.Name.Equals("source"))
                {
                    options.genSources = true;
                }
                else if (opt.Name.Equals("delaysign"))
                {
                    options.delaySign = true;
                }
                else if (opt.Name.Equals("nologo"))
                {
                    options.noLogo = true;
                }
                else if (opt.Name.Equals("silent"))
                {
                    options.silentMode = true;
                }
                else if (opt.Name.Equals("rcw"))
                {
                    // Store away for later processing
                    rcwOptions.Add(opt.Value);
                }
                else if (opt.Name.Equals("verbose"))
                {
                    options.verboseMode = true;
                }
                else if (opt.Name.Equals("?") || opt.Name.Equals("help"))
                {
                    PrintUsage();
                    ReturnCode = SuccessReturnCode;
                    return(false);
                }
                else
                {
                    PrintLogo();
                    WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_InvalidOption));
                    ReturnCode = ErrorReturnCode;
                    return(false);
                }
            }

            // Validate that the typelib name has been specified.
            if (typeLibName == null)
            {
                PrintLogo();
                WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_NoInputFile));
                ReturnCode = ErrorReturnCode;
                return(false);
            }

            // Gather information needed for strong naming the assembly (if
            // the user desires this).
            if ((options.keyPair != null) && (options.publicKey == null))
            {
                try {
                    options.publicKey = options.keyPair.PublicKey;
                }
                catch (Exception) {
                    PrintLogo();
                    WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_InvalidStrongName));
                    ReturnCode = ErrorReturnCode;
                    return(false);
                }
            }

            if (options.delaySign && options.keyPair == null && options.keyContainer == null)
            {
                PrintLogo();
                WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_DelaySignError));
                ReturnCode = ErrorReturnCode;
                return(false);
            }

            if (!File.Exists(typeLibName))
            {
                FileInfo file = new FileInfo(typeLibName);
                PrintLogo();
                WriteErrorMsg(AxImpSR.GetString(AxImpSR.Err_FileNotExists, file.FullName));
                ReturnCode = ErrorReturnCode;
                return(false);
            }

            return(true);
        }