DesperateDevs.CodeGeneration.CodeGenerator.CodeGenerator CodeGeneratorFromPreferences(Preferences preferences)
        {
            ICodeGenerationPlugin[] instances    = LoadFromPlugins(preferences);
            CodeGeneratorConfig     andConfigure = preferences.CreateAndConfigure <CodeGeneratorConfig>();

            IPreProcessor[] enabledInstancesOf1 =
                CodeGeneratorUtil.GetEnabledInstancesOf <IPreProcessor>(instances, andConfigure.preProcessors);
            IDataProvider[] enabledInstancesOf2 =
                CodeGeneratorUtil.GetEnabledInstancesOf <IDataProvider>(instances, andConfigure.dataProviders);
            ICodeGenerator[] enabledInstancesOf3 =
                CodeGeneratorUtil.GetEnabledInstancesOf <ICodeGenerator>(instances, andConfigure.codeGenerators);
            IPostProcessor[] enabledInstancesOf4 =
                CodeGeneratorUtil.GetEnabledInstancesOf <IPostProcessor>(instances, andConfigure.postProcessors);
            configure((ICodeGenerationPlugin[])enabledInstancesOf1, preferences);
            configure((ICodeGenerationPlugin[])enabledInstancesOf2, preferences);
            configure((ICodeGenerationPlugin[])enabledInstancesOf3, preferences);
            configure((ICodeGenerationPlugin[])enabledInstancesOf4, preferences);
            bool trackHooks = true;

            if (preferences.HasKey("Jenny.TrackHooks"))
            {
                trackHooks = preferences["Jenny.TrackHooks"] == "true";
            }
            return(new DesperateDevs.CodeGeneration.CodeGenerator.CodeGenerator(enabledInstancesOf1,
                                                                                enabledInstancesOf2, enabledInstancesOf3, enabledInstancesOf4, trackHooks));
        }
        Type[] LoadTypes(Preferences preferences)
        {
            CodeGeneratorConfig andConfigure = preferences.CreateAndConfigure <CodeGeneratorConfig>();
            var dirs = new string[andConfigure.searchPaths.Length];

            for (int i = 0; i < andConfigure.searchPaths.Length; i++)
            {
                dirs[i] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, andConfigure.searchPaths[i]);
            }

            List <Assembly> assemblies = new List <Assembly>();

            foreach (string plugin in andConfigure.plugins)
            {
                var pluginName = plugin;
                if (!plugin.EndsWith(".dll"))
                {
                    pluginName = plugin + ".dll";
                }

                foreach (var dir in dirs)
                {
                    var fileName = Path.Combine(dir, pluginName);
                    if (File.Exists(fileName))
                    {
                        var assembly = Assembly.LoadFrom(fileName);
                        assemblies.Add(assembly);
                    }
                }
            }

            return(assemblies.GetAllTypes());
        }
        public ICodeGenerationPlugin[] LoadFromPlugins(
            Preferences preferences)
        {
            CodeGeneratorConfig andConfigure     = preferences.CreateAndConfigure <CodeGeneratorConfig>();
            AssemblyResolver    assemblyResolver = new AssemblyResolver(false, andConfigure.searchPaths);

            foreach (string plugin in andConfigure.plugins)
            {
                assemblyResolver.Load(plugin);
            }
            //Type[] types = assemblyResolver.GetTypes();
            var types = LoadTypes(preferences);

            Log($"----------------------------types Count = {types.Length}-------------------");
            return(((IEnumerable <Type>)types.GetNonAbstractTypes <ICodeGenerationPlugin>())
                   .Select <Type, ICodeGenerationPlugin>((Func <Type, ICodeGenerationPlugin>)(type => {
                try {
                    return (ICodeGenerationPlugin)Activator.CreateInstance(type);
                }
                catch (TypeLoadException ex) {
                    Log(ex.Message);
                }

                return (ICodeGenerationPlugin)null;
            })).Where <ICodeGenerationPlugin>((Func <ICodeGenerationPlugin, bool>)(instance => instance != null))
                   .ToArray <ICodeGenerationPlugin>());
        }
        void OnEnable()
        {
            var preferences = new Preferences("Entitas.properties", Environment.UserName + ".userproperties");
            var config      = preferences.CreateAndConfigure <VisualDebuggingConfig>();

            _systemWarningThreshold = config.systemWarningThreshold;
        }
Example #5
0
        public override void Initialize(Preferences preferences)
        {
            _visualDebuggingConfig = preferences.CreateAndConfigure <VisualDebuggingConfig>();
            preferences.properties.AddProperties(_visualDebuggingConfig.defaultProperties, false);

            _scriptingDefineSymbols = new ScriptingDefineSymbols();
            _enableVisualDebugging  = !_scriptingDefineSymbols.buildTargetToDefSymbol.Values
                                      .All <string>(defs => defs.Contains(ENTITAS_DISABLE_VISUAL_DEBUGGING));
        }
        public static void GenerateITypeDrawer(string typeName)
        {
            var preferences = new Preferences("Entitas.properties", Environment.UserName + ".userproperties");
            var config      = preferences.CreateAndConfigure <VisualDebuggingConfig>();
            var folder      = config.typeDrawerFolderPath;
            var filePath    = folder + Path.DirectorySeparatorChar + typeName.ShortTypeName() + "TypeDrawer.cs";
            var template    = TYPE_DRAWER_TEMPLATE_FORMAT
                              .Replace("${Type}", typeName)
                              .Replace("${ShortType}", typeName.ShortTypeName());

            generateTemplate(folder, filePath, template);
        }
        public static void GenerateIDefaultInstanceCreator(string typeName)
        {
            var preferences = new Preferences("Entitas.properties", Environment.UserName + ".userproperties");
            var config      = preferences.CreateAndConfigure <VisualDebuggingConfig>();
            var folder      = config.defaultInstanceCreatorFolderPath;
            var filePath    = folder + Path.DirectorySeparatorChar + "Default" + typeName.ShortTypeName() + "InstanceCreator.cs";
            var template    = DEFAULT_INSTANCE_CREATOR_TEMPLATE_FORMAT
                              .Replace("${Type}", typeName)
                              .Replace("${ShortType}", typeName.ShortTypeName());

            generateTemplate(folder, filePath, template);
        }
        public static ICodeGenerationPlugin[] LoadFromPlugins(Preferences preferences)
        {
            CodeGeneratorConfig codeGeneratorConfig = preferences.CreateAndConfigure <CodeGeneratorConfig>();
            AssemblyResolver    assemblyResolver    = new AssemblyResolver(false, codeGeneratorConfig.searchPaths);

            string[] plugins = codeGeneratorConfig.plugins;
            foreach (string path in plugins)
            {
                assemblyResolver.Load(path);
            }
            return(assemblyResolver.GetTypes().GetInstancesOf <ICodeGenerationPlugin>());
        }
Example #9
0
        static EntitasHierarchyIcon()
        {
            try
            {
                var preferences = new Preferences("Entitas.properties", Environment.UserName + ".userproperties");
                var config      = preferences.CreateAndConfigure <VisualDebuggingConfig>();
                _systemWarningThreshold = config.systemWarningThreshold;
            }
            catch (Exception)
            {
                _systemWarningThreshold = int.MaxValue;
            }

            EditorApplication.hierarchyWindowItemOnGUI += onHierarchyWindowItemOnGUI;
        }
        public static CodeGenerator CodeGeneratorFromPreferences(Preferences preferences)
        {
            ICodeGenerationPlugin[] instances           = CodeGeneratorUtil.LoadFromPlugins(preferences);
            CodeGeneratorConfig     codeGeneratorConfig = preferences.CreateAndConfigure <CodeGeneratorConfig>();

            IPreProcessor[]  enabledInstancesOf  = CodeGeneratorUtil.GetEnabledInstancesOf <IPreProcessor>(instances, codeGeneratorConfig.preProcessors);
            IDataProvider[]  enabledInstancesOf2 = CodeGeneratorUtil.GetEnabledInstancesOf <IDataProvider>(instances, codeGeneratorConfig.dataProviders);
            ICodeGenerator[] enabledInstancesOf3 = CodeGeneratorUtil.GetEnabledInstancesOf <ICodeGenerator>(instances, codeGeneratorConfig.codeGenerators);
            IPostProcessor[] enabledInstancesOf4 = CodeGeneratorUtil.GetEnabledInstancesOf <IPostProcessor>(instances, codeGeneratorConfig.postProcessors);
            CodeGeneratorUtil.configure(enabledInstancesOf, preferences);
            CodeGeneratorUtil.configure(enabledInstancesOf2, preferences);
            CodeGeneratorUtil.configure(enabledInstancesOf3, preferences);
            CodeGeneratorUtil.configure(enabledInstancesOf4, preferences);
            bool trackHooks = true;

            if (preferences.HasKey("Jenny.TrackHooks"))
            {
                trackHooks = (preferences["Jenny.TrackHooks"] == "true");
            }
            return(new CodeGenerator(enabledInstancesOf, enabledInstancesOf2, enabledInstancesOf3, enabledInstancesOf4, trackHooks));
        }
        protected override void GenerateCodes()
        {
            Log((object)"Generating...");
            var recordpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, JennyPropertyPath);

            LogError("recordpath " + recordpath);
            var text       = File.ReadAllText(recordpath);
            var preference = new Preferences(recordpath, recordpath);

            ICodeGenerationPlugin[] instances        = CodeGeneratorUtil.LoadFromPlugins(preference);
            CodeGeneratorConfig     andConfigure     = preference.CreateAndConfigure <CodeGeneratorConfig>();
            AssemblyResolver        assemblyResolver = new AssemblyResolver(false, andConfigure.searchPaths);

            foreach (string plugin in andConfigure.plugins)
            {
                Log("load plugin " + plugin);
                assemblyResolver.Load(plugin);
            }

            DesperateDevs.CodeGeneration.CodeGenerator.CodeGenerator codeGenerator =
                CodeGeneratorFromPreferences(preference);
            codeGenerator.OnProgress += (GeneratorProgress)((title, info, progress) => {
                Log("progress " + (progress));
            });

            CodeGenFile[] codeGenFileArray1 = new CodeGenFile[0];
            CodeGenFile[] codeGenFileArray2;
            try {
                codeGenFileArray2 = codeGenerator.Generate();
            }
            catch (Exception ex) {
                codeGenFileArray1 = new CodeGenFile[0];
                codeGenFileArray2 = new CodeGenFile[0];
                LogError("Error" + ex.Message + ex.StackTrace);
            }

            UpdateOutputProjectFile();
            LogGenInfo(codeGenFileArray2, codeGenFileArray1);
        }