Esempio n. 1
0
        private string GetFlagPath()
        {
            var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment);

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

            return(Path.Combine(modelsDirectory, "ood.flag"));
        }
        private string?GetErrFile()
        {
            var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment);

            if (!Directory.Exists(modelsDirectory))
            {
                return(null);
            }

            return(Path.Combine(modelsDirectory, "models.err"));
        }
Esempio n. 3
0
    public void GenerateModels()
    {
        var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment);

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

        foreach (var file in Directory.GetFiles(modelsDirectory, "*.generated.cs"))
        {
            File.Delete(file);
        }

        IList <TypeModel> typeModels = _umbracoService.GetAllTypes();

        var builder = new TextBuilder(_config, typeModels);

        foreach (TypeModel typeModel in builder.GetModelsToGenerate())
        {
            var sb = new StringBuilder();
            builder.Generate(sb, typeModel);
            var filename = Path.Combine(modelsDirectory, typeModel.ClrName + ".generated.cs");
            File.WriteAllText(filename, sb.ToString());
        }

        // the idea was to calculate the current hash and to add it as an extra file to the compilation,
        // in order to be able to detect whether a DLL is consistent with an environment - however the
        // environment *might not* contain the local partial files, and thus it could be impossible to
        // calculate the hash. So... maybe that's not a good idea after all?

        /*
         * var currentHash = HashHelper.Hash(ourFiles, typeModels);
         * ourFiles["models.hash.cs"] = $@"using Umbraco.ModelsBuilder;
         * [assembly:ModelsBuilderAssembly(SourceHash = ""{currentHash}"")]
         * ";
         */

        _outOfDateModels.Clear();
    }