コード例 #1
0
        internal string GetTypeName(string assemblyPath, string progId, string classId)
        {
            string          retVal  = "";
            AssemblyManager manager = null;
            AppDomain       domain  = AppDomain.CreateDomain("SoapDomain");

            if (null != domain)
            {
                AssemblyName n            = typeof(AssemblyManager).Assembly.GetName();
                Evidence     baseEvidence = AppDomain.CurrentDomain.Evidence;
                Evidence     evidence     = new Evidence(baseEvidence);
                evidence.AddAssembly(n);
                ObjectHandle h = domain.CreateInstance(n.FullName,
                                                       typeof(AssemblyManager).FullName,
                                                       false,
                                                       0,
                                                       null,
                                                       null,
                                                       null,
                                                       null,
                                                       evidence);
                if (null != h)
                {
                    manager = (AssemblyManager)h.Unwrap();
                    if (classId.Length > 0)
                    {
                        retVal = manager.InternalGetTypeNameFromClassId(assemblyPath, classId);
                    }
                    else
                    {
                        retVal = manager.InternalGetTypeNameFromProgId(assemblyPath, progId);
                    }
                }
                AppDomain.Unload(domain);
            }
            return(retVal);
        }
コード例 #2
0
        public void ProcessServerTlb(string ProgId, string SrcTlbPath, string PhysicalPath, string Operation, out string strAssemblyName, out string TypeName, out string Error)
        {
            string name = string.Empty;

            strAssemblyName = string.Empty;
            TypeName        = string.Empty;
            Error           = string.Empty;
            bool flag = false;

            try
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                if ((Operation != null) && (Operation.ToLower(CultureInfo.InvariantCulture) == "delete"))
                {
                    flag = true;
                }
                if (SrcTlbPath.Length > 0)
                {
                    if (!PhysicalPath.EndsWith("/", StringComparison.Ordinal) && !PhysicalPath.EndsWith(@"\", StringComparison.Ordinal))
                    {
                        PhysicalPath = PhysicalPath + @"\";
                    }
                    string str2 = SrcTlbPath.ToLower(CultureInfo.InvariantCulture);
                    if (str2.EndsWith("mscoree.dll", StringComparison.Ordinal))
                    {
                        Type typeFromProgID = Type.GetTypeFromProgID(ProgId);
                        if (typeFromProgID.FullName == "System.__ComObject")
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_DependencyNotInGAC"));
                        }
                        TypeName = typeFromProgID.FullName;
                        name     = typeFromProgID.Assembly.GetName().Name;
                    }
                    else if (str2.EndsWith("scrobj.dll", StringComparison.Ordinal))
                    {
                        if (!flag)
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_WSCNotSupported"));
                        }
                    }
                    else
                    {
                        GenerateMetadata metadata = new GenerateMetadata();
                        if (flag)
                        {
                            name = metadata.GetAssemblyName(SrcTlbPath, PhysicalPath + @"bin\");
                        }
                        else
                        {
                            name = metadata.GenerateSigned(SrcTlbPath, PhysicalPath + @"bin\", false, out Error);
                        }
                        if (!string.IsNullOrEmpty(name))
                        {
                            try
                            {
                                TypeName = this.GetTypeNameFromProgId(PhysicalPath + @"bin\" + name + ".dll", ProgId);
                            }
                            catch (DirectoryNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    if ((!string.IsNullOrEmpty(ProgId) && !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(TypeName))
                    {
                        ServerWebConfig config       = new ServerWebConfig();
                        DiscoFile       file         = new DiscoFile();
                        string          assemblyFile = PhysicalPath + @"bin\" + name + ".dll";
                        if (flag)
                        {
                            config.DeleteElement(PhysicalPath + "Web.Config", name, TypeName, ProgId, "SingleCall", assemblyFile);
                            file.DeleteElement(PhysicalPath + "Default.disco", ProgId + ".soap?WSDL");
                        }
                        else
                        {
                            config.AddGacElement(PhysicalPath + "Web.Config", name, TypeName, ProgId, "SingleCall", assemblyFile);
                            file.AddElement(PhysicalPath + "Default.disco", ProgId + ".soap?WSDL");
                        }
                    }
                    if (!string.IsNullOrEmpty(name))
                    {
                        string fileName = PhysicalPath + @"bin\" + name + ".dll";
                        strAssemblyName = new AssemblyManager().GetFullName(fileName);
                    }
                }
            }
            catch (Exception exception)
            {
                if ((exception is NullReferenceException) || (exception is SEHException))
                {
                    throw;
                }
                Error = exception.ToString();
                ComSoapPublishError.Report(Error);
                if ((typeof(ServicedComponentException) == exception.GetType()) || (typeof(RegistrationException) == exception.GetType()))
                {
                    throw;
                }
            }
        }
コード例 #3
0
 internal void AddGacElement(string FilePath, string AssemblyName, string TypeName, string ProgId, string WkoMode, string AssemblyFile)
 {
     try
     {
         new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration).Demand();
         AssemblyManager manager  = new AssemblyManager();
         string          str      = TypeName + ", " + manager.GetFullName(AssemblyFile);
         string          str2     = TypeName + ", " + AssemblyName;
         XmlDocument     document = new XmlDocument();
         document.Load(FilePath);
         XmlNode documentElement = document.DocumentElement;
         while (documentElement.Name != "configuration")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "system.runtime.remoting")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "application")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "service")
         {
             documentElement = documentElement.NextSibling;
         }
         XmlNodeList list = documentElement.SelectNodes("descendant::*[attribute::type='" + str2 + "']");
         while ((list != null) && (list.Count > 0))
         {
             XmlNode oldChild = list.Item(0);
             if (oldChild.ParentNode != null)
             {
                 oldChild.ParentNode.RemoveChild(oldChild);
                 list = documentElement.SelectNodes("descendant::*[attribute::type='" + str2 + "']");
             }
         }
         list = documentElement.SelectNodes("descendant::*[attribute::type='" + str + "']");
         while ((list != null) && (list.Count > 0))
         {
             XmlNode node3 = list.Item(0);
             if (node3.ParentNode != null)
             {
                 node3.ParentNode.RemoveChild(node3);
                 list = documentElement.SelectNodes("descendant::*[attribute::type='" + str + "']");
             }
         }
         XmlElement newChild = document.CreateElement("", "wellknown", "");
         newChild.SetAttribute("mode", WkoMode);
         newChild.SetAttribute("type", str);
         newChild.SetAttribute("objectUri", ProgId + ".soap");
         documentElement.AppendChild(newChild);
         XmlElement element2 = document.CreateElement("", "activated", "");
         element2.SetAttribute("type", str2);
         documentElement.AppendChild(element2);
         document.Save(FilePath);
     }
     catch (RegistrationException)
     {
         throw;
     }
     catch (Exception exception)
     {
         ComSoapPublishError.Report(exception.ToString());
     }
 }
コード例 #4
0
 internal void DeleteElement(string FilePath, string AssemblyName, string TypeName, string ProgId, string WkoMode, string AssemblyFile)
 {
     try
     {
         new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration).Demand();
         AssemblyManager manager  = new AssemblyManager();
         string          str      = TypeName + ", " + manager.GetFullName(AssemblyFile);
         string          str2     = TypeName + ", " + AssemblyName;
         XmlDocument     document = new XmlDocument();
         document.Load(FilePath);
         XmlNode documentElement = document.DocumentElement;
         while (documentElement.Name != "configuration")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "system.runtime.remoting")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "application")
         {
             documentElement = documentElement.NextSibling;
         }
         documentElement = documentElement.FirstChild;
         while (documentElement.Name != "service")
         {
             documentElement = documentElement.NextSibling;
         }
         XmlNodeList list = documentElement.SelectNodes("descendant::*[attribute::type='" + str2 + "']");
         while ((list != null) && (list.Count > 0))
         {
             XmlNode oldChild = list.Item(0);
             if (oldChild.ParentNode != null)
             {
                 oldChild.ParentNode.RemoveChild(oldChild);
                 list = documentElement.SelectNodes("descendant::*[attribute::type='" + str2 + "']");
             }
         }
         list = documentElement.SelectNodes("descendant::*[attribute::type='" + str + "']");
         while ((list != null) && (list.Count > 0))
         {
             XmlNode node3 = list.Item(0);
             if (node3.ParentNode != null)
             {
                 node3.ParentNode.RemoveChild(node3);
                 list = documentElement.SelectNodes("descendant::*[attribute::type='" + str + "']");
             }
         }
         document.Save(FilePath);
     }
     catch (DirectoryNotFoundException)
     {
     }
     catch (FileNotFoundException)
     {
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         ComSoapPublishError.Report(exception.ToString());
     }
 }
コード例 #5
0
        public void AddServerTlb(string progId, string classId, string interfaceId, string srcTlbPath, string rootWebServer, string inBaseUrl, string inVirtualRoot, string clientActivated, string wellKnown, string discoFile, string operation, out string strAssemblyName, out string typeName)
        {
            string name = string.Empty;

            strAssemblyName = string.Empty;
            typeName        = string.Empty;
            bool flag      = false;
            bool inDefault = false;
            bool flag3     = false;
            bool flag4     = true;

            try
            {
                try
                {
                    new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
                }
                catch (SecurityException)
                {
                    ComSoapPublishError.Report(Resource.FormatString("Soap_SecurityFailure"));
                    throw;
                }
                if ((operation != null) && (operation.ToLower(CultureInfo.InvariantCulture) == "delete"))
                {
                    flag = true;
                }
                if (srcTlbPath.Length > 0)
                {
                    inDefault = SoapServerInfo.BoolFromString(discoFile, inDefault);
                    flag3     = SoapServerInfo.BoolFromString(wellKnown, flag3);
                    flag4     = SoapServerInfo.BoolFromString(clientActivated, flag4);
                    string str3 = SoapServerInfo.ServerPhysicalPath(rootWebServer, inBaseUrl, inVirtualRoot, !flag);
                    string str4 = srcTlbPath.ToLower(CultureInfo.InvariantCulture);
                    if (str4.EndsWith("mscoree.dll", StringComparison.Ordinal))
                    {
                        Type typeFromProgID = Type.GetTypeFromProgID(progId);
                        typeName = typeFromProgID.FullName;
                        name     = typeFromProgID.Assembly.GetName().Name;
                    }
                    else if (str4.EndsWith("scrobj.dll", StringComparison.Ordinal))
                    {
                        if (!flag)
                        {
                            throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_WSCNotSupported"));
                        }
                    }
                    else
                    {
                        string           error    = "";
                        GenerateMetadata metadata = new GenerateMetadata();
                        if (flag)
                        {
                            name = metadata.GetAssemblyName(srcTlbPath, str3 + @"\bin\");
                        }
                        else
                        {
                            name = metadata.GenerateSigned(srcTlbPath, str3 + @"\bin\", false, out error);
                        }
                        if (!string.IsNullOrEmpty(name))
                        {
                            try
                            {
                                typeName = this.GetTypeName(str3 + @"\bin\" + name + ".dll", progId, classId);
                            }
                            catch (DirectoryNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                if (!flag)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    if ((!string.IsNullOrEmpty(progId) && !string.IsNullOrEmpty(name)) && !string.IsNullOrEmpty(typeName))
                    {
                        DiscoFile file         = new DiscoFile();
                        string    assemblyFile = str3 + @"\bin\" + name + ".dll";
                        if (flag)
                        {
                            SoapServerConfig.DeleteComponent(str3 + @"\Web.Config", name, typeName, progId, assemblyFile);
                            file.DeleteElement(str3 + @"\Default.disco", progId + ".soap?WSDL");
                        }
                        else
                        {
                            SoapServerConfig.AddComponent(str3 + @"\Web.Config", name, typeName, progId, assemblyFile, "SingleCall", flag3, flag4);
                            if (inDefault)
                            {
                                file.AddElement(str3 + @"\Default.disco", progId + ".soap?WSDL");
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(name))
                    {
                        string fileName = str3 + @"bin\" + name + ".dll";
                        strAssemblyName = new AssemblyManager().GetFullName(fileName);
                    }
                }
            }
            catch (ServicedComponentException exception)
            {
                this.ThrowHelper("Soap_PublishServerTlbFailure", exception);
            }
            catch (RegistrationException exception2)
            {
                this.ThrowHelper("Soap_PublishServerTlbFailure", exception2);
            }
            catch (Exception exception3)
            {
                if ((exception3 is NullReferenceException) || (exception3 is SEHException))
                {
                    throw;
                }
                this.ThrowHelper("Soap_PublishServerTlbFailure", null);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        internal static void DeleteComponent(
            string filePath,
            string assemblyName,
            string typeName,
            string progId,
            string assemblyFile
            )
        {
            try
            {
                AssemblyManager manager    = new AssemblyManager();
                string          WKOstrType = typeName + ", " + manager.GetFullName(assemblyFile, assemblyName);
                string          CAOstrType = typeName + ", " + assemblyName;
                XmlDocument     configXml  = new XmlDocument();
                configXml.Load(filePath);
                XmlNode node = configXml.DocumentElement;
                node = FindOrCreateElement(configXml, node, "system.runtime.remoting");
                node = FindOrCreateElement(configXml, node, "application");
                node = FindOrCreateElement(configXml, node, "service");
                XmlNodeList nodelist = node.SelectNodes("descendant::*[attribute::type='" + CAOstrType + "']");
                while (nodelist != null && nodelist.Count > 0)
                {
                    //foreach (XmlNode n in nodelist) // this code throws an "index out of range exception"
                    XmlNode n = nodelist.Item(0);
                    {
                        if (n.ParentNode != null)
                        {
                            n.ParentNode.RemoveChild(n);
                            nodelist = node.SelectNodes("descendant::*[attribute::type='" + CAOstrType + "']");
                        }
                    }
                }
                nodelist = node.SelectNodes("descendant::*[attribute::type='" + WKOstrType + "']");
                while (nodelist != null && nodelist.Count > 0)
                {
                    //foreach (XmlNode n in nodelist) // this code throws an "index out of range exception"
                    XmlNode n = nodelist.Item(0);
                    {
                        if (n.ParentNode != null)
                        {
                            n.ParentNode.RemoveChild(n);
                            nodelist = node.SelectNodes("descendant::*[attribute::type='" + WKOstrType + "']");
                        }
                    }
                }

                configXml.Save(filePath);
            }
            // these exceptions are not reported because on a proxy uninstall these files will not be present, but the
            // the proxy bit is not set on deletions
            catch (System.IO.DirectoryNotFoundException) {}
            catch (System.IO.FileNotFoundException) {}
            //COM+ 32052 - on a client proxy delete this code path is hit because it is impossible to
            //to tell from the catalog that we are a client proxy. If the assembly has been removed from
            //the GAC the deletion will fail if we re-throw this exception.
            catch (System.EnterpriseServices.RegistrationException) {}
            catch (Exception e)
            {
                string Error = Resource.FormatString("Soap_ConfigDeletionFailure");
                ComSoapPublishError.Report(Error + " " + e.Message);
                throw;
            }
        }
コード例 #8
0
 internal static void AddComponent(
     string filePath,
     string assemblyName,
     string typeName,
     string progId,
     string assemblyFile,
     string wkoMode, // singleton or singlecall
     bool wellKnown,
     bool clientActivated
     )
 {
     try
     {
         AssemblyManager manager    = new AssemblyManager();
         string          WKOstrType = typeName + ", " + manager.GetFullName(assemblyFile, assemblyName);
         string          CAOstrType = typeName + ", " + assemblyName;
         XmlDocument     configXml  = new XmlDocument();
         configXml.Load(filePath);
         XmlNode node = configXml.DocumentElement;
         node = FindOrCreateElement(configXml, node, "system.runtime.remoting");
         node = FindOrCreateElement(configXml, node, "application");
         node = FindOrCreateElement(configXml, node, "service");
         XmlNodeList nodelist = node.SelectNodes("descendant::*[attribute::type='" + CAOstrType + "']");
         while (nodelist != null && nodelist.Count > 0)
         {
             //foreach (XmlNode n in nodelist) // this code throws an "index out of range exception"
             XmlNode n = nodelist.Item(0);
             if (n.ParentNode != null)
             {
                 n.ParentNode.RemoveChild(n);
                 nodelist = node.SelectNodes("descendant::*[attribute::type='" + CAOstrType + "']");
             }
         }
         nodelist = node.SelectNodes("descendant::*[attribute::type='" + WKOstrType + "']");
         while (nodelist != null && nodelist.Count > 0)
         {
             //foreach (XmlNode n in nodelist) // this code throws an "index out of range exception"
             XmlNode n = nodelist.Item(0);
             if (n.ParentNode != null)
             {
                 n.ParentNode.RemoveChild(n);
                 nodelist = node.SelectNodes("descendant::*[attribute::type='" + WKOstrType + "']");
             }
         }
         if (wellKnown)
         {
             XmlElement WKOElement = configXml.CreateElement("wellknown");
             WKOElement.SetAttribute("mode", wkoMode);
             WKOElement.SetAttribute("type", WKOstrType);
             WKOElement.SetAttribute("objectUri", progId + ".soap");
             node.AppendChild(WKOElement);
         }
         if (clientActivated)
         {
             XmlElement CAElement = configXml.CreateElement("activated");
             CAElement.SetAttribute("type", CAOstrType);
             node.AppendChild(CAElement);
         }
         configXml.Save(filePath);
     }
     catch (Exception e)
     {
         string Error = Resource.FormatString("Soap_ConfigAdditionFailure");
         ComSoapPublishError.Report(Error + " " + e.Message);
         throw;
     }
 }