コード例 #1
0
        /// <summary>
        /// Saves the code to disk.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="component">The component.</param>
        /// <param name="project">The project.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="code">The code.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static bool SaveCodeToProject(IGeneratorTemplate plugin, GeneratorComponent component, Project project, string tableName, string code, string fileName)
        {
            _logger.Trace("ProjectController.SaveCodeToDisk()");

            var targetDirectory = Path.Combine(project.SaveDirectory, "Files", tableName);

            if (!Directory.Exists(targetDirectory))
            {
                Directory.CreateDirectory(targetDirectory);
            }

            var entity = project.Entities.FirstOrDefault(e => e.Name.Equals(tableName, StringComparison.InvariantCultureIgnoreCase));

            if (entity == null)
            {
                entity      = new ProjectEntity();
                entity.Name = tableName;
                project.Entities.Add(entity);
            }

            project.Entities = project.Entities.OrderBy(e => e.Name).ToList();

            string guid = ((GuidAttribute)(plugin.GetType().Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0])).Value;

            var file = entity.Files.FirstOrDefault(f => f.Guid.Equals(guid, StringComparison.InvariantCultureIgnoreCase) && f.Plugin.Equals(plugin.GetType().ToString(), StringComparison.InvariantCultureIgnoreCase) && f.Component.Equals(component.Id));

            if (file == null)
            {
                file           = new ProjectEntityFile();
                file.Guid      = guid;
                file.Plugin    = plugin.GetType().ToString();
                file.Component = component.Id;
                file.File      = fileName;
                entity.Files.Add(file);
            }

            entity.Files = entity.Files.OrderBy(e => e.File).ToList();

            var targetLocation = Path.Combine(targetDirectory, fileName);

            File.WriteAllText(targetLocation, code, Encoding.UTF8);

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Updates the plugin settings.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="plugin">The plugin.</param>
        /// <returns></returns>
        public static Project UpdatePluginSettings(Project project, IGeneratorTemplate plugin)
        {
            _logger.Trace("ProjectController.UpdatePluginSettings()");

            if (project.Properties == null)
            {
                project.Properties = new ProjectProperties();
            }

            var    type = plugin.GetType();
            string guid = ((GuidAttribute)(type.Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0])).Value;

            var pluginAssembly = project.Properties.Plugins.FirstOrDefault(p => p.Guid.Equals(guid, StringComparison.InvariantCultureIgnoreCase));

            if (pluginAssembly == null)
            {
                pluginAssembly      = new ProjectPropertiesPlugin();
                pluginAssembly.Guid = guid;
                project.Properties.Plugins.Add(pluginAssembly);
            }

            if (pluginAssembly.Parameters == null)
            {
                pluginAssembly.Parameters = new List <PluginParameter>();
            }

            // Remove all default values from plugin parameters
            pluginAssembly.Parameters.RemoveAll(p => plugin.Settings.Any(s => s.Key.Equals(p.Code, StringComparison.InvariantCultureIgnoreCase) && s.UseDefault));

            // Check all non-default parameters
            foreach (PluginSettingValue settingValue in plugin.Settings.Where(s => !s.UseDefault))
            {
                var parameter = pluginAssembly.Parameters.FirstOrDefault(c => c.Code.Equals(settingValue.Key, StringComparison.InvariantCultureIgnoreCase));
                if (parameter == null)
                {
                    parameter = new PluginParameter();
                    pluginAssembly.Parameters.Add(parameter);
                }

                parameter.Code  = settingValue.Key;
                parameter.Value = settingValue.Value;
                parameter.Type  = settingValue.Type;
            }

            return(project);
        }