public void CallPreGenerationInitialisationFunction(ProviderInfo provider, PreGenerationData data)
        {
            MethodInfo method = _TemplateGenInstance.GetType().GetMethod(TemplateHelper.PreGenerationModelProcessingFunctionName);

            if (method == null)
            {
                return;
            }

            var parameters = new object[] { provider, data };

            method.Invoke(_TemplateGenInstance, parameters);
        }
        public override void InitialisePreGeneration(ArchAngel.Interfaces.PreGenerationData data)
        {
            ArchAngel.NHibernateHelper.NHibernateProjectPreprocessor preprocessor = new ArchAngel.NHibernateHelper.NHibernateProjectPreprocessor(new Slyce.Common.FileController());
            preprocessor.InitialiseNHibernateProject(this, data);

            foreach (var providerInfo in data.OtherProviderInfos)
            {
                if (providerInfo is ArchAngel.Providers.EntityModel.ProviderInfo)
                {
                    ArchAngel.NHibernateHelper.EntityModelPreprocessor entityModelPreprocessor = new ArchAngel.NHibernateHelper.EntityModelPreprocessor(new Slyce.Common.FileController());
                    entityModelPreprocessor.InitialiseEntityModel((ArchAngel.Providers.EntityModel.ProviderInfo)providerInfo, data);
                }
            }
        }
        public void InitialiseNHibernateProject(ArchAngel.NHibernateHelper.ProviderInfo providerInfo, PreGenerationData data)
        {
            if (providerInfo.ProjectOrigin != ProviderInfo.ProjectType.FromExistingVisualStudioProject)
            {
                if (providerInfo.NhConfigFile.ProviderInfo == null)
                    providerInfo.NhConfigFile.ProviderInfo = providerInfo;

                string outputFolder = null;
                string tempFolder = null;

                if (ArchAngel.Interfaces.SharedData.CurrentProject == null)
                    throw new Exception("CurrentProject is null.");

                if (ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject != null)
                {
                    outputFolder = ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.OutputFolder;
                    tempFolder = ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.TempFolder;
                }
                ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject = FillScriptModel(providerInfo.EntityProviderInfo.MappingSet, null, providerInfo.NhConfigFile);
                ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.OutputFolder = outputFolder;
                ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.TempFolder = tempFolder;
                return;
            }
            XmlDocument csprojDocument = null;
            string filename;

            if (providerInfo.CsProjFile == null || !providerInfo.CsProjFile.FileExists)
            {
                // Find the csproj file we are going to use
                csprojDocument = GetCSProjDocument(data, out filename);

                if (csprojDocument != null)
                    providerInfo.CsProjFile = new CSProjFile(csprojDocument, filename);
            }
            if (!providerInfo.NhConfigFile.FileExists)
            {
                if (csprojDocument == null)
                    csprojDocument = GetCSProjDocument(data, out filename);
                else
                    filename = providerInfo.CsProjFile.FilePath;

                providerInfo.NhConfigFile = ProjectLoader.GetNhConfigFile(providerInfo.CsProjFile, fileController);
            }
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject = FillScriptModel(providerInfo.EntityProviderInfo.MappingSet, providerInfo.CsProjFile, providerInfo.NhConfigFile);
        }
        public void InitialiseEntityModel(ArchAngel.Providers.EntityModel.ProviderInfo providerInfo, PreGenerationData data)
        {
            providerInfo.MappingSet.CodeParseResults = null;
            // Clear the current mapped class.
            providerInfo.MappingSet.EntitySet.Entities.ForEach(e => e.MappedClass = null);

            // Find the csproj file we are going to use
            string filename;
            var csprojDocument = GetCSProjDocument(data, out filename);

            if (csprojDocument == null)
                return;

            CSProjFile csproj = new CSProjFile(csprojDocument, filename);
            var hbmFiles = ProjectLoader.GetHBMFilesFromCSProj(csproj, fileController);

            // Load HBMs
            foreach (string hbmFilePath in hbmFiles)
            {
                if (!File.Exists(hbmFilePath))
                    throw new FileNotFoundException(string.Format("A file is defined is your csproj file [{0}], but it cannot be found: [{1}]", filename, hbmFilePath), hbmFilePath);
            }
            var mappings = hbmFiles.Select(f => MappingFiles.Version_2_2.Utility.Open(f)).ToList();

            // Parse the CSharp files
            var csharpFiles = ProjectLoader.GetCSharpFilesFromCSProj(csproj, fileController);
            var parseResults = ParseResults.ParseCSharpFiles(csharpFiles);

            providerInfo.MappingSet.CodeParseResults = parseResults;

            // Clear the current mapped class.
            providerInfo.MappingSet.EntitySet.Entities.ForEach(e => e.MappedClass = null);

            // Map the Entity objects to the parsed Class
            var entities = providerInfo.MappingSet.EntitySet.Entities.ToDictionary(e => e.Name);

            foreach (var hm in mappings)
            {
                foreach (var hClass in hm.Classes())
                {
                    var fullClassName = HibernateMappingHelper.ResolveFullClassName(hClass, hm);
                    var shortClassName = HibernateMappingHelper.ResolveShortClassName(hClass, hm);

                    // try find the entity
                    Entity entity;
                    if (entities.TryGetValue(shortClassName, out entity))
                    {
                        // try find class in parse results
                        var parsedClass = parseResults.FindClass(fullClassName, entity.Properties.Select(p => p.Name).ToList());
                        entity.MappedClass = parsedClass;
                    }
                    else
                    {
                        Log.InfoFormat("Could not find entity for class named {0} in the NHibernate project on disk.", shortClassName);
                    }
                }
            }
            // Now, try to map entities that haven't been found yet
            foreach (var entity in entities.Select(v => v.Value).Where(e => e.MappedClass == null))
            {
                string entityName = entity.Name;
                // try find class in parse results
                var parsedClass = parseResults.FindClass(entityName, entity.Properties.Select(p => p.Name).ToList());
                entity.MappedClass = parsedClass;
            }
        }
        private XmlDocument GetCSProjDocument(PreGenerationData data, out string filename)
        {
            var doc = new XmlDocument();

            var projectName = data.UserOptions.GetValueOrDefault("ProjectName") as string;
            if (string.IsNullOrEmpty(projectName) == false)
            {
                // Search for the project as named by the ProjectName User Option.
                filename = Path.Combine(data.OutputFolder, projectName + ".csproj");

                if (fileController.FileExists(filename))
                {
                    doc.LoadXml(fileController.ReadAllText(filename));
                    return doc;
                }
            }

            // If we get to this point, we couldn't find the project in the default location,
            // so we search for the first project that has any *.hbm.xml files in it.
            var csProjFilenames = fileController.FindAllFilesLike(data.OutputFolder, "*.csproj", SearchOption.AllDirectories);

            foreach (var csprojFilename in csProjFilenames)
            {
                doc = new XmlDocument();
                doc.LoadXml(fileController.ReadAllText(csprojFilename));
                var hbmFiles = ProjectLoader.GetHBMFilesFromCSProj(new CSProjFile(doc, csprojFilename), fileController);

                if (hbmFiles.Any())
                {
                    filename = csprojFilename;
                    return doc;
                }
            }

            filename = "";
            return null;
        }
Example #6
0
        public void CallPreGenerationInitialisationFunction(ProviderInfo provider, PreGenerationData data)
        {
            MethodInfo method = _TemplateGenInstance.GetType().GetMethod(TemplateHelper.PreGenerationModelProcessingFunctionName);

            if (method == null) return;

            var parameters = new object[] { provider, data };
            method.Invoke(_TemplateGenInstance, parameters);
        }
 public override void InitialiseScriptObjects(ArchAngel.Interfaces.PreGenerationData data)
 {
 }
 public override void InitialisePreGeneration(ArchAngel.Interfaces.PreGenerationData data)
 {
 }
Example #9
0
        public int WriteFiles(
			ProjectFileTreeNode parentNode,
			ArchAngel.Interfaces.Scripting.NHibernate.Model.IProject project,
			string targetFolder,
			ArchAngel.Interfaces.Template.TemplateProject templateProject,
			out List<FilenameInfo> duplicateFiles)
        {
            if (!Directory.Exists(targetFolder))
                throw new FileNotFoundException("Output folder doesn't exist: " + targetFolder, targetFolder);

            ////////////////////////////////////////
            TargetFolder = targetFolder;

            SharedData.IsBusyGenerating = true;
            SharedData.CurrentProject.StartNewFileGenerationRun();

            // Reset the Template before the File name validation run.
            _Loader.CallTemplateFunction(TemplateHelper.ClearTemplateCacheFunctionName);

            // Run the pre generation template function.

            var data = new PreGenerationData
            {
                OutputFolder = SharedData.CurrentProject.ProjectSettings.OutputPath,
                OverwriteFiles = SharedData.CurrentProject.ProjectSettings.OverwriteFiles
            };

            foreach (var uo in SharedData.CurrentProject.Options.Where(o => o.IsVirtualProperty == false))
            {
                var optionValue = SharedData.CurrentProject.GetUserOption(uo.VariableName);
                data.UserOptions.Add(uo.VariableName, optionValue);
            }
            foreach (var provider in SharedData.CurrentProject.Providers)
            {
                ArchAngel.Interfaces.ProviderInfo[] otherProviders = new ProviderInfo[SharedData.CurrentProject.Providers.Count];
                SharedData.CurrentProject.Providers.CopyTo(otherProviders);
                data.OtherProviderInfos = otherProviders.ToList();
                data.OtherProviderInfos.Remove(provider);
                _Loader.CallPreGenerationInitialisationFunction(provider, data);
            }
            ((ProjectFileTree)parentNode).TreeRestructuring = true;
            ((ProjectFileTree)parentNode).Clear();
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.OutputFolder = project.OutputFolder;
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.TempFolder = project.TempFolder;
            ArchAngel.Interfaces.SharedData.CurrentProject.InitialiseScriptObjects();
            SetProjectInCode(ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject);
            project = ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject;
            //SetProjectInCode(project);

            ////////////////////////////////////////

            // TODO: Check for duplicate files and folders
            ScriptProject = project;
            NumFiles = 0;
            //SkipFileProperty = CurrentAssembly.GetType("Slyce.FunctionRunner.FunctionProcessor").GetProperty("SkipCurrentFile");

            foreach (Folder subFolder in templateProject.OutputFolder.Folders)
                ProcessFolder(subFolder, targetFolder, parentNode);

            foreach (ArchAngel.Interfaces.Template.File file in templateProject.OutputFolder.Files)
                ProcessFile(file, targetFolder, parentNode, null);

            foreach (ArchAngel.Interfaces.Template.StaticFile staticFile in templateProject.OutputFolder.StaticFiles)
                ProcessStaticFile(staticFile, targetFolder, parentNode);

            targetFolder += Path.DirectorySeparatorChar.ToString();
            duplicateFiles = new List<FilenameInfo>();

            foreach (var f in AllTextFilenames)
                f.RelativePath = f.RelativePath.Replace(targetFolder, "");

            foreach (var group in AllTextFilenames.GroupBy(n => n.RelativePath).Where(g => g.Count() > 1))
                duplicateFiles.AddRange(group.Select(g => g));

            return NumFiles;
        }
Example #10
0
        public override void InitialiseScriptObjects(PreGenerationData data)
        {
            string outputFolder = null;
            string tempFolder = null;

            if (ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject != null)
            {
                outputFolder = ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.OutputFolder;
                tempFolder = ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.TempFolder;
            }
            //this.NhConfigFile.ProviderInfo = this;
            InitialisePreGeneration(data);
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject = ArchAngel.NHibernateHelper.NHibernateProjectPreprocessor.FillScriptModel(this.EntityProviderInfo.MappingSet, null, this.NhConfigFile);
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.OutputFolder = outputFolder;
            ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject.TempFolder = tempFolder;
        }
Example #11
0
        public void InitialiseScriptObjects()
        {
            var data = new PreGenerationData
            {
                OutputFolder = this.ProjectSettings.OutputPath,
                OverwriteFiles = this.ProjectSettings.OverwriteFiles
            };

            foreach (var uo in this.Options.Where(o => o.IsVirtualProperty == false))
            {
                var optionValue = this.GetUserOption(uo.VariableName);
                data.UserOptions.Add(uo.VariableName, optionValue);
            }
            foreach (var provider in this.Providers)
            {
                ArchAngel.Interfaces.ProviderInfo[] otherProviders = new ProviderInfo[this.Providers.Count];
                this.Providers.CopyTo(otherProviders);
                data.OtherProviderInfos = otherProviders.ToList();
                data.OtherProviderInfos.Remove(provider);
                //provider.InitialiseScriptObjects(data);
            }
            foreach (var provider in this.Providers)
                provider.InitialiseScriptObjects(data);
        }