Ejemplo n.º 1
0
        public virtual object RunScriptFunction(string functionName, ref object[] parameters)
        {
            object obj;

            switch (functionName)
            {
            case "CustomNewProjectScreens":
                List <INewProjectScreen> screens = (List <INewProjectScreen>)parameters[0];
                TemplateGen.CustomNewProjectScreens(out screens);
                obj           = (object)null;
                parameters[0] = (object)screens;
                break;

            case "LoadProjectOutput":
                string outputFolder = (string)parameters[0];
                IEnumerable <ProviderInfo> provider = (IEnumerable <ProviderInfo>)parameters[1];
                TemplateData extraData = (TemplateData)parameters[2];
                TemplateGen.LoadProjectOutput(outputFolder, provider, extraData);
                obj           = (object)null;
                parameters[0] = (object)outputFolder;
                parameters[1] = (object)provider;
                parameters[2] = (object)extraData;
                break;

            case "PreGenerationModelInitialisation":
                ProviderInfo      providerInfo = (ProviderInfo)parameters[0];
                PreGenerationData data         = (PreGenerationData)parameters[1];
                TemplateGen.PreGenerationModelInitialisation(providerInfo, data);
                obj           = (object)null;
                parameters[0] = (object)providerInfo;
                parameters[1] = (object)data;
                break;

            case "InternalFunctions.MustSkipCurrentFile":
                return((object)(int)(ScriptFunctionWrapper.instance.SkipCurrentFile ? 1 : 0));

            case "InternalFunctions.ResetSkipCurrentFile":
                ScriptFunctionWrapper.instance.SkipCurrentFile = false;
                return((object)null);

            case "InternalFunctions.GetCurrentFileName":
                return((object)ScriptFunctionWrapper.instance.CurrentFileName);

            case "InternalFunctions.ResetCurrentFileName":
                ScriptFunctionWrapper.instance.CurrentFileName = "";
                return((object)null);

            case "InternalFunctions.SetGeneratedFileName":
                ScriptFunctionWrapper.instance.GeneratedFileName = (string)parameters[0];
                return((object)null);

            case "InternalFunctions.ClearTemplateCache":
                ScriptFunctionWrapper.instance.ClearTemplateCache();
                return((object)null);

            default:
                throw new Exception("Function not handled in RunScriptFunction:" + functionName);
            }
            return(obj);
        }
Ejemplo n.º 2
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;
        }
        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);
        }
Ejemplo n.º 4
0
 public override void InitialiseScriptObjects(PreGenerationData data)
 {
     throw new NotImplementedException();
 }
        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;
            }
        }
Ejemplo n.º 6
0
 public static void PreGenerationModelInitialisation(ArchAngel.Interfaces.ProviderInfo provider, PreGenerationData data)
 {
     if (provider == null)
     {
         return;
     }
     if (provider is ArchAngel.Providers.EntityModel.ProviderInfo)
     {
         new EntityModelPreprocessor((IFileController) new FileController()).InitialiseEntityModel((ArchAngel.Providers.EntityModel.ProviderInfo)provider, data);
     }
     else
     {
         if (!(provider is ArchAngel.NHibernateHelper.ProviderInfo))
         {
             return;
         }
         new NHibernateProjectPreprocessor((IFileController) new FileController()).InitialiseNHibernateProject((ArchAngel.NHibernateHelper.ProviderInfo)provider, data);
     }
 }