예제 #1
0
        /// <summary>
        /// Get all defined entity types for a SQL development plugin.
        /// </summary>
        /// <param name="plugin">The SQL development plugin in which the entities are defined.</param>
        /// <returns>A <see cref="IList{T}"/> which contains all defined entities in the plugin.</returns>
        public static IList <System.Type> GetEntityTypes(IProvidesDatabaseConnectivity plugin)
        {
            if (plugin == null)
            {
                return(null);
            }

            var pluginNamespace = plugin.GetType().Namespace;

            var dataEntities = plugin.GetType().Assembly.GetTypes().Where(x =>
                                                                          x.IsClass &&
                                                                          !string.IsNullOrEmpty(x.Namespace) &&
                                                                          (x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Entities"), StringComparison.InvariantCulture) || x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Data.Entities"), StringComparison.InvariantCulture)))
                               .ToList();

            if (!dataEntities.Any())
            {
                foreach (var assembly in plugin.GetType().Assembly.GetReferencedAssemblies())
                {
                    var assemblyType = Assembly.Load(assembly);

                    dataEntities.AddRange(assemblyType.GetTypes().Where(x =>
                                                                        x.IsClass &&
                                                                        !string.IsNullOrEmpty(x.Namespace) &&
                                                                        (x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Entities"), StringComparison.InvariantCulture) || x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Data.Entities"), StringComparison.InvariantCulture)))
                                          .ToList());
                }
            }

            return(dataEntities);
        }
예제 #2
0
        /// <summary>
        /// Get the embedded SQL scripts of a plugin.
        /// </summary>
        /// <param name="plugin">The plugin in which the SQL scripts are contained.</param>
        /// <returns>A <see cref="IList{SqlScript}"/> which contains all SQL scripts that are contained in the overgiven plugin.</returns>
        public static IList <SqlScript> GetSqlScripts(IProvidesDatabaseConnectivity plugin)
        {
            var scriptList = new List <SqlScript>();

            if (plugin == null)
            {
                return(null);
            }

            var embeddedScripts = GetEmbeddedResources(plugin, "Script");

            foreach (var scriptContainer in embeddedScripts)
            {
                var scriptsStream = plugin.GetType().Assembly.GetManifestResourceStream(scriptContainer);

                if (scriptsStream == null)
                {
                    continue;
                }

                var scripts = XmlHelper.Deserialize <SqlScripts>(scriptsStream);

                scriptList.AddRange(scripts.SqlScript);
            }

            return(scriptList);
        }
예제 #3
0
        /// <summary>
        /// Get the fields for the overgiven entity type of a SQL development plugin.
        /// </summary>
        /// <param name="plugin">The SQL development plugin in which the entity is defined.</param>
        /// <param name="entityName">The name of the entity for which the fields should be delivered.</param>
        /// <returns>A <see cref="IList{T}"/> which contains a list of all the field names for the overgiven entity.</returns>
        public static IList <string> GetEntityFields(IProvidesDatabaseConnectivity plugin, string entityName)
        {
            var fieldList = new List <string>();

            if (plugin == null)
            {
                return(null);
            }

            var pluginNamespace = plugin.GetType().Namespace;

            var dataEntities = plugin.GetType().Assembly.GetTypes().Where(x =>
                                                                          x.IsClass &&
                                                                          x.Name == entityName &&
                                                                          !string.IsNullOrEmpty(x.Namespace) &&
                                                                          (x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Entities"), StringComparison.InvariantCulture) ||
                                                                           x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Data.Entities"), StringComparison.InvariantCulture)))
                               .ToList();

            if (!dataEntities.Any())
            {
                foreach (var assembly in plugin.GetType().Assembly.GetReferencedAssemblies())
                {
                    var assemblyType = Assembly.Load(assembly);

                    dataEntities.AddRange(assemblyType.GetTypes().Where(x =>
                                                                        x.IsClass &&
                                                                        x.Name == entityName &&
                                                                        !string.IsNullOrEmpty(x.Namespace) &&
                                                                        (x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Entities"), StringComparison.InvariantCulture) ||
                                                                         x.Namespace.StartsWith(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", pluginNamespace, "Data.Entities"), StringComparison.InvariantCulture)))
                                          .ToList());
                }
            }

            var dataEntity = dataEntities.FirstOrDefault();

            if (dataEntity == null)
            {
                return(fieldList);
            }

            fieldList.AddRange(dataEntity.GetProperties().Select(x => x.Name));

            return(fieldList);
        }