Пример #1
0
        public string GenerateMetaData(string strSrcTypeLib, string outPath, byte[] PublicKey, StrongNameKeyPair KeyPair)
        {
            string str2;

            try
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
            }
            catch (Exception exception)
            {
                if ((exception is NullReferenceException) || (exception is SEHException))
                {
                    throw;
                }
                ComSoapPublishError.Report(exception.ToString());
                throw;
            }
            string str = "";

            if ((0 >= strSrcTypeLib.Length) || (0 >= outPath.Length))
            {
                return(str);
            }
            if (!outPath.EndsWith("/", StringComparison.Ordinal) && !outPath.EndsWith(@"\", StringComparison.Ordinal))
            {
                outPath = outPath + @"\";
            }
            ITypeLib typeLib = null;

            typeLib = CacheInfo.GetTypeLib(strSrcTypeLib);
            if (typeLib == null)
            {
                return(str);
            }
            str = CacheInfo.GetMetadataName(strSrcTypeLib, typeLib, out str2);
            if (str.Length == 0)
            {
                return(str);
            }
            if (this._nameonly)
            {
                return(str);
            }
            string assemblyPath = outPath + str2;

            if (this._signed)
            {
                try
                {
                    AssemblyManager manager = new AssemblyManager();
                    if (manager.CompareToCache(assemblyPath, strSrcTypeLib))
                    {
                        new Publish().GacInstall(assemblyPath);
                        return(str);
                    }
                    if (manager.GetFromCache(assemblyPath, strSrcTypeLib))
                    {
                        new Publish().GacInstall(assemblyPath);
                        return(str);
                    }
                    goto Label_0133;
                }
                catch (Exception exception2)
                {
                    if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                    {
                        throw;
                    }
                    ComSoapPublishError.Report(exception2.ToString());
                    goto Label_0133;
                }
            }
            if (File.Exists(assemblyPath))
            {
                return(str);
            }
Label_0133:
            try
            {
                ITypeLibConverter converter  = new TypeLibConverter();
                ImporterCallback  notifySink = new ImporterCallback {
                    OutputDir = outPath
                };
                AssemblyBuilder builder = converter.ConvertTypeLibToAssembly(typeLib, assemblyPath, TypeLibImporterFlags.UnsafeInterfaces, notifySink, PublicKey, KeyPair, null, null);
                FileInfo        info    = new FileInfo(assemblyPath);
                builder.Save(info.Name);
                if (this._signed)
                {
                    new AssemblyManager().CopyToCache(assemblyPath, strSrcTypeLib);
                    new Publish().GacInstall(assemblyPath);
                }
            }
            catch (ReflectionTypeLoadException exception3)
            {
                Exception[] loaderExceptions = exception3.LoaderExceptions;
                for (int i = 0; i < loaderExceptions.Length; i++)
                {
                    try
                    {
                        ComSoapPublishError.Report(loaderExceptions[i].ToString());
                    }
                    catch (Exception exception4)
                    {
                        if ((exception4 is NullReferenceException) || (exception4 is SEHException))
                        {
                            throw;
                        }
                        ComSoapPublishError.Report(exception3.ToString());
                    }
                }
                return(string.Empty);
            }
            catch (Exception exception5)
            {
                if ((exception5 is NullReferenceException) || (exception5 is SEHException))
                {
                    throw;
                }
                ComSoapPublishError.Report(exception5.ToString());
                return(string.Empty);
            }
            return(str);
        }