public void Generate() { var sw = Stopwatch.StartNew(); string xml = _codeGenerator.ExecutePlugins(_plugins, "<!--", "-->", new InitialSnippet()).GeneratedCode; string[] segments = xml.Split(new[] { _segmentSplitter }, System.StringSplitOptions.None); if (segments.Count() != EntityFrameworkMapping.ModelFiles.Count()) { throw new FrameworkException("Unexpected number of metadata segments: " + segments.Count() + ", expected " + EntityFrameworkMapping.ModelFiles.Count() + "."); } for (int s = 0; s < segments.Count(); s++) { string clearedXml = XmlUtility.RemoveComments(segments[s]); if (!string.IsNullOrWhiteSpace(clearedXml)) { clearedXml = string.Format(GetXmlRootElements()[s], clearedXml); string filePath = Path.Combine(Paths.GeneratedFolder, EntityFrameworkMapping.ModelFiles[s]); File.WriteAllText(filePath, clearedXml, Encoding.UTF8); } } _performanceLogger.Write(sw, "EntityFrameworkMappingGenerator.GenerateMapping"); }
public void Generate() { var sw = Stopwatch.StartNew(); var generatedSourceCode = _codeGenerator.ExecutePlugins(_plugins, "/*", "*/", null); generatedSourceCode = Regex.Replace(generatedSourceCode, detectLineTag, "\n"); generatedSourceCode = Regex.Replace(generatedSourceCode, detectTag, ""); File.WriteAllText(Path.Combine(_rhetosBuildEnvironment.GeneratedAssetsFolder, AssemblyName + ".cs"), generatedSourceCode, Encoding.UTF8); _performanceLogger.Write(sw, "MvcModelGenerator.Generate"); }
private SimpleAssemblySource GenerateSource() { var generatedSource = _codeGenerator.ExecutePlugins(_plugins, "/*", "*/", null); return(new SimpleAssemblySource { GeneratedCode = string.Concat( InitialTemplates.Import, StringHelper.RegexReplace(generatedSource.GeneratedCode, _replacements), AdditionCodes.Instance.ToString()), RegisteredReferences = generatedSource.RegisteredReferences }); }
public void Generate() { IAssemblySource assemblySource = _codeGenerator.ExecutePlugins(_plugins, "/*", "*/", new CaptionsInitialCodeGenerator()); _logger.Trace("References: " + string.Join(", ", assemblySource.RegisteredReferences)); _sourceLogger.Trace(assemblySource.GeneratedCode); var generatedCode = assemblySource.GeneratedCode.Trim(); generatedCode = generatedCode.Replace("/*implementation*/", ""); File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Generated", CaptionFileName + ".resx"), generatedCode); }
private bool GenerateNewResourcesResx() { var sw = Stopwatch.StartNew(); // NOTE: There is no need for ICaptionsResourceGeneratorPlugin plugins, they are not used. // CaptionsInitialCodePlugin _initialCodePlugin is this only implementation and all the work // is done there by calling ICaptionsProvider and its ICaptionsValuePlugin plugins. // The ICaptionsResourceGeneratorPlugin interface can be deleted, and the code from CaptionsInitialCodePlugin called directly. // We could leave ICaptionsResourceGeneratorPlugin just in case we need to add // to the resx file something other then simple "data" elements for captions. var resxContext = _codeGenerator.ExecutePlugins(_plugins, "<!--", "-->", _initialCodePlugin); resxContext = CleanupXml(resxContext); _performanceLogger.Write(sw, "GenerateNewResourcesResx: ExecutePlugins and cleanup."); var resxHash = _cacheUtility.ComputeHash(resxContext); var cachedHash = _cacheUtility.LoadHash(ResourcesFilePath); _performanceLogger.Write(sw, "GenerateNewResourcesResx: Hash."); if (resxHash.SequenceEqual(cachedHash)) { _logger.Trace(() => $"'{ResourcesFilePath}' hash not changed, using cache."); if (_cacheUtility.FileIsCached(CompiledResourcesFilePath) && _cacheUtility.FileIsCached(SourceFromCompiledResources)) { _cacheUtility.CopyFromCache(ResourcesFilePath); return(false); } _logger.Trace(() => $"'{CompiledResourcesFilePath}' and '{SourceFromCompiledResources}' expected in cache, but some are missing."); } else { _logger.Trace(() => $"'{ResourcesFilePath}' hash changed, invalidating cache."); } _cacheUtility.RemoveFromCache(CompiledResourcesFilePath); _cacheUtility.RemoveFromCache(SourceFromCompiledResources); File.WriteAllText(ResourcesFilePath, resxContext, Encoding.UTF8); _cacheUtility.SaveHash(ResourcesFilePath, resxHash); _cacheUtility.CopyToCache(ResourcesFilePath); _performanceLogger.Write(sw, "GenerateNewResourcesResx: Save."); return(true); }
public void Generate() { var sw = Stopwatch.StartNew(); string xml = _codeGenerator.ExecutePlugins(_plugins, "<!--", "-->", new InitialSnippet()); string[] segments = xml.Split(new[] { "\r\n" + _segmentSplitter + "\r\n" }, StringSplitOptions.None); if (segments.Length != EntityFrameworkMapping.ModelFiles.Length) { throw new FrameworkException($"Unexpected number of metadata segments: {segments.Length}, expected {EntityFrameworkMapping.ModelFiles.Length}."); } for (int s = 0; s < segments.Length; s++) { string clearedXml = XmlUtility.RemoveComments(segments[s]); string filePath = Path.Combine(_rhetosBuildEnvironment.GeneratedAssetsFolder, EntityFrameworkMapping.ModelFiles[s]); File.WriteAllText(filePath, clearedXml, Encoding.UTF8); } _performanceLogger.Write(sw, "GenerateMapping"); }