예제 #1
0
        /// <summary>
        /// Load an XML resource from a location specify by the node.
        /// </summary>
        /// <param name="node">An location node</param>
        /// <param name="properties">the global properties</param>
        /// <returns>Return the Xml document load.</returns>
        public static XmlDocument GetAsXmlDocument(XmlNode node, NameValueCollection properties)
        {
            XmlDocument xmlDocument = null;

            if (node.Attributes["resource"] != null)
            {
                string ressource = NodeUtils.ParsePropertyTokens(node.Attributes["resource"].Value, properties);
                xmlDocument = Resources.GetResourceAsXmlDocument(ressource);
            }
            else if (node.Attributes["url"] != null)
            {
                string url = NodeUtils.ParsePropertyTokens(node.Attributes["url"].Value, properties);
                xmlDocument = Resources.GetUrlAsXmlDocument(url);
            }
            else if (node.Attributes["embedded"] != null)
            {
                string embedded = NodeUtils.ParsePropertyTokens(node.Attributes["embedded"].Value, properties);
                xmlDocument = Resources.GetEmbeddedResourceAsXmlDocument(embedded);
                //�Զ�����Ƕ��sqlmap�ļ�
                if (embedded.IndexOf("sql.xml") > -1)
                {
                    FileAssemblyInfo fileInfo = new FileAssemblyInfo(embedded);
                    Assembly         assembly = Assembly.Load(fileInfo.AssemblyName);
                    string           typeName = fileInfo.FileName.Replace(".sql.xml", "");
                    Type             type     = assembly.GetType(typeName);
                    AutoConfigSqlMap(xmlDocument, type);
                }
            }

            return(xmlDocument);
        }
예제 #2
0
        public static XmlDocument GetEmbeddedResourceAsXmlDocument(string resource)
        {
            XmlDocument      document = new XmlDocument();
            bool             flag     = false;
            FileAssemblyInfo info     = new FileAssemblyInfo(resource);

            if (info.IsAssemblyQualified)
            {
                Assembly assembly = null;
                assembly = Assembly.Load(info.AssemblyName);
                Stream manifestResourceStream = assembly.GetManifestResourceStream(info.ResourceFileName);
                if (manifestResourceStream == null)
                {
                    manifestResourceStream = assembly.GetManifestResourceStream(info.FileName);
                }
                if (manifestResourceStream == null)
                {
                    goto Label_00DC;
                }
                try
                {
                    document.Load(manifestResourceStream);
                    flag = true;
                    goto Label_00DC;
                }
                catch (Exception exception)
                {
                    throw new ConfigurationException(string.Format("Unable to load file \"{0}\" in embedded resource. Cause : {1}", resource, exception.Message), exception);
                }
            }
            foreach (Assembly assembly2 in AppDomain.CurrentDomain.GetAssemblies())
            {
                Stream inStream = assembly2.GetManifestResourceStream(info.FileName);
                if (inStream != null)
                {
                    try
                    {
                        document.Load(inStream);
                        flag = true;
                        break;
                    }
                    catch (Exception exception2)
                    {
                        throw new ConfigurationException(string.Format("Unable to load file \"{0}\" in embedded resource. Cause : ", resource, exception2.Message), exception2);
                    }
                }
            }
Label_00DC:
            if (!flag)
            {
                _logger.Error("Could not load embedded resource from assembly");
                throw new ConfigurationException(string.Format("Unable to load embedded resource from assembly \"{0}\".", info.OriginalFileName));
            }
            return(document);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static XmlDocument GetEmbeddedResourceAsXmlDocument(string resource)
        {
            XmlDocument config = new XmlDocument();
            bool        isLoad = false;

            FileAssemblyInfo fileInfo = new FileAssemblyInfo(resource);

            if (fileInfo.IsAssemblyQualified)
            {
                Assembly assembly = null;
#if dotnet2
                assembly = Assembly.Load(fileInfo.AssemblyName);
#else
                assembly = Assembly.LoadWithPartialName(fileInfo.AssemblyName);
#endif
                Stream stream = assembly.GetManifestResourceStream(fileInfo.ResourceFileName);
                // JIRA - IBATISNET-103
                if (stream == null)
                {
                    stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                }
                if (stream != null)
                {
                    try
                    {
                        config.Load(stream);
                        isLoad = true;
                    }
                    catch (Exception e)
                    {
                        throw new ConfigurationException(
                                  string.Format("Unable to load file \"{0}\" in embedded resource. Cause : {1}",
                                                resource,
                                                e.Message), e);
                    }
                }
            }
            else
            {
                // bare type name... loop thru all loaded assemblies
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in assemblies)
                {
                    Stream stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                    if (stream != null)
                    {
                        try
                        {
                            config.Load(stream);
                            isLoad = true;
                        }
                        catch (Exception e)
                        {
                            throw new ConfigurationException(
                                      string.Format("Unable to load file \"{0}\" in embedded resource. Cause : ",
                                                    resource,
                                                    e.Message), e);
                        }
                        break;
                    }
                }
            }

            if (isLoad == false)
            {
                throw new ConfigurationException(
                          string.Format("Unable to load embedded resource from assembly \"{0}\".",
                                        fileInfo.OriginalFileName));
            }

            return(config);
        }
예제 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static XmlDocument GetEmbeddedResourceAsXmlDocument(string resource)
        {
            XmlDocument config = new XmlDocument();
            bool isLoad = false;

            FileAssemblyInfo fileInfo = new FileAssemblyInfo (resource);
            if (fileInfo.IsAssemblyQualified)
            {
                Assembly assembly = null;
            #if dotnet2
                assembly = Assembly.Load(fileInfo.AssemblyName);
            #else
                assembly = Assembly.LoadWithPartialName (fileInfo.AssemblyName);
            #endif
                Stream stream = assembly.GetManifestResourceStream(fileInfo.ResourceFileName);
                // JIRA - IBATISNET-103
                if (stream == null)
                {
                    stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                }
                if (stream != null)
                {
                    try
                    {
                        config.Load(stream);
                        isLoad = true;
                    }
                    catch(Exception e)
                    {
                        throw new ConfigurationException(
                            string.Format("Unable to load file \"{0}\" in embedded resource. Cause : {1}",
                            resource,
                            e.Message  ) ,e);
                    }
                }
            }
            else
            {
                // bare type name... loop thru all loaded assemblies
                Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
                foreach (Assembly assembly in assemblies)
                {
                    Stream stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                    if (stream != null)
                    {
                        try
                        {
                            config.Load(stream);
                            isLoad = true;
                        }
                        catch(Exception e)
                        {
                            throw new ConfigurationException(
                                string.Format("Unable to load file \"{0}\" in embedded resource. Cause : ",
                                resource,
                                e.Message  ) ,e);
                        }
                        break;
                    }
                }
            }

            if (isLoad == false)
            {
                _logger.Error("Could not load embedded resource from assembly");
                throw new ConfigurationException(
                    string.Format("Unable to load embedded resource from assembly \"{0}\".",
                    fileInfo.OriginalFileName));
            }

            return config;
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static XmlDocument GetEmbeddedResourceAsXmlDocument(string resource)
        {
            XmlDocument config = new XmlDocument();
            bool        isLoad = false;

            FileAssemblyInfo fileInfo = new FileAssemblyInfo(resource);

            if (fileInfo.IsAssemblyQualified)
            {
                Assembly assembly = null;

                assembly = Assembly.Load(fileInfo.AssemblyName);

                Stream stream = assembly.GetManifestResourceStream(fileInfo.ResourceFileName);
                // JIRA - IBATISNET-103
                if (stream == null)
                {
                    stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                }
                if (stream != null)
                {
                    try
                    {
                        config.Load(stream);
                        isLoad = true;
                    }
                    catch (Exception e)
                    {
                        throw new X3Platform.IBatis.Common.Exceptions.ConfigurationException(
                                  string.Format("Unable to load file \"{0}\" in embedded resource. Cause : {1}",
                                                resource,
                                                e.Message), e);
                    }
                }
            }
            else
            {
                // bare type name... loop thru all loaded assemblies
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in assemblies)
                {
                    if (assembly.IsDynamic == true)
                    {
                        continue;
                    }

                    Stream stream = null;

                    try
                    {
                        // assembly.FullName = "Microsoft.GeneratedCode";

                        stream = assembly.GetManifestResourceStream(fileInfo.FileName);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("assembly:" + assembly.FullName, ex);

                        throw ex;
                    }

                    if (stream != null)
                    {
                        try
                        {
                            config.Load(stream);
                            isLoad = true;
                        }
                        catch (Exception e)
                        {
                            throw new X3Platform.IBatis.Common.Exceptions.ConfigurationException(
                                      string.Format("Unable to load file \"{0}\" in embedded resource. Cause : ",
                                                    resource,
                                                    e.Message), e);
                        }
                        break;
                    }
                }
            }

            if (isLoad == false)
            {
                _logger.Error("Could not load embedded resource from assembly");
                throw new X3Platform.IBatis.Common.Exceptions.ConfigurationException(
                          string.Format("Unable to load embedded resource from assembly \"{0}\".",
                                        fileInfo.OriginalFileName));
            }

            return(config);
        }