//public static IEnumerable<CodeFileGenerator> GetAllFileGenerators(GeneratorSettings settings) //{ // return GetAllFileGenerators(settings, CurrentProject); //} /// <summary> /// Get all of the merged generators for a project, this will merge any output generators with the same filename into a combined "CodeFileGenerator". /// </summary> /// <returns></returns> public static IEnumerable <CodeFileGenerator> GetAllFileGenerators(IGraphConfiguration config, IDataRecord[] items, bool includeDisabled = false) { if (config == null) { throw new ArgumentNullException("config"); } if (items == null) { throw new ArgumentNullException("items"); } var codeGenerators = GetAllCodeGenerators(config, items, includeDisabled).ToArray(); var groups = codeGenerators.GroupBy(p => Path.Combine(config.CodeOutputPath, p.Filename)).Distinct(); foreach (var @group in groups) { var generator = new CodeFileGenerator(config.Namespace) { AssetPath = @group.Key.Replace("\\", "/"), #if UNITY_EDITOR //SystemPath = Path.Combine(config.CodeOutputSystemPath, @group.Key.Substring(7)).Replace("\\", "/"), SystemPath = @group.Key, #endif Generators = @group.ToArray() }; yield return(generator); } }
public override void Initialize(CodeFileGenerator codeFileGenerator) { base.Initialize(codeFileGenerator); _unit = codeFileGenerator.Unit; _ns = codeFileGenerator.Namespace; TryAddNamespace("System"); TryAddNamespace("System.Collections"); TryAddNamespace("System.Collections.Generic"); TryAddNamespace("System.Linq"); }
public override void Initialize(CodeFileGenerator codeFileGenerator) { base.Initialize(codeFileGenerator); _unit = codeFileGenerator.Unit; _ns = codeFileGenerator.Namespace; TryAddNamespace("System"); TryAddNamespace("System.Collections"); TryAddNamespace("System.Collections.Generic"); TryAddNamespace("System.Linq"); }
public override void Initialize(CodeFileGenerator codeFileGenerator) { base.Initialize(codeFileGenerator); //if (!string.IsNullOrEmpty(TemplateType.Namespace)) // TryAddNamespace(TemplateType.Namespace); Decleration = TemplateType.ToClassDecleration(); var inheritable = Data as GenericInheritableNode; if (!Attribute.AutoInherit) { inheritable = null; } if (IsDesignerFile && Attribute.Location != TemplateLocation.DesignerFile) { Decleration.Name = ClassNameBase(Data as IDiagramNodeItem); if (inheritable != null && inheritable.BaseNode != null) { Decleration.BaseTypes.Clear(); Decleration.BaseTypes.Add(ClassName(inheritable.BaseNode)); } } else { Decleration.Name = ClassName(Data as IDiagramNodeItem); if (Attribute.Location != TemplateLocation.DesignerFile) { Decleration.BaseTypes.Clear(); Decleration.BaseTypes.Add(ClassNameBase(Data as IDiagramNodeItem)); } } Namespace.Types.Add(Decleration); ProcessTemplate(); return; // Skip the stuff below for now if (IsDesignerFile) { // base.Initialize(fileGenerator); if (IsDesignerFile) { InitializeDesignerFile(); } else { InitializeEditableFile(); } } }
public override void Initialize(CodeFileGenerator codeFileGenerator) { var nodeConfig = InvertApplication.Container.GetNodeConfig<TData>(); if (!nodeConfig.TypeGeneratorConfigs.ContainsKey(this.GetType())) return; GeneratorConfig = nodeConfig.TypeGeneratorConfigs[this.GetType()] as NodeGeneratorConfig<TData>; if (GeneratorConfig == null) return; if (GeneratorConfig.Condition != null && !GeneratorConfig.Condition(Data)) return; base.Initialize(codeFileGenerator); Decleration = new CodeTypeDeclaration(IsDesignerFile ? NameAsDesignerClass : NameAsClass) { IsPartial = true }; Compose(); }
/// <summary> /// This method gets every method, property, or constructor generated for a node, pass in an item filter to filter only to specific items /// that are set up as iterators on templates. /// /// For Example: /// You can get only the members of a class that have been added since last save and compile by comparing with with the change tracking data. /// </summary> /// <param name="node"></param> /// <param name="itemFilter"></param> /// <returns></returns> public static IEnumerable <TemplateMemberResult> GetEditableOutputMembers(this IDiagramNodeItem node, IGraphConfiguration config, Predicate <IDiagramNodeItem> itemFilter = null) { foreach (var item in GetAllEditableFilesForNode(node, config).OfType <ITemplateClassGenerator>()) { var gen = new CodeFileGenerator() { Generators = new[] { item as OutputGenerator }, SystemPath = string.Empty }; gen.Namespace = new CodeNamespace(); gen.Unit = new CodeCompileUnit(); gen.Unit.Namespaces.Add(gen.Namespace); item.ItemFilter = itemFilter; item.Initialize(gen); foreach (var result in item.Results) { yield return(result); } } }
private static void GenerateFile(FileInfo fileInfo, CodeFileGenerator codeFileGenerator) { // Get the path to the directory var directory = System.IO.Path.GetDirectoryName(fileInfo.FullName); // Create it if it doesn't exist if (directory != null && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } try { // Write the file File.WriteAllText(fileInfo.FullName, codeFileGenerator.ToString()); } catch (Exception ex) { InvertApplication.LogException(ex); InvertApplication.Log("Coudln't create file " + fileInfo.FullName); } }
public void FileSkipped(CodeFileGenerator codeFileGenerator) { }
public void FileGenerated(CodeFileGenerator generator) { }
public virtual void Initialize(CodeFileGenerator codeFileGenerator) { }
public IEnumerator Generate(SaveAndCompileCommand command) { var repository = InvertGraphEditor.Container.Resolve <IRepository>(); var remove = repository.AllOf <IClassNode>().Where(p => string.IsNullOrEmpty(p.Name)).ToArray(); foreach (var item in remove) { repository.Remove(item); } //var allIds = allRecords.Select(p => p.Identifier).ToArray(); //foreach (var item in allRecords) //{ // if (item.ForeignKeys.Where(p=>!string.IsNullOrEmpty(p)).Any(p =>!allIds.Contains(p))) // { // InvertApplication.Log(string.Format("{0} : {1} was removed due to invalid foreign key.", item.Identifier, item.GetType().Name)); // repository.Remove(item); // } //} repository.Commit(); var config = InvertGraphEditor.Container.Resolve <IGraphConfiguration>(); var items = GetItems(repository, command.ForceCompileAll).Distinct().ToArray(); yield return (new TaskProgress(0f, "Validating")); var a = ValidationSystem.ValidateNodes(items.OfType <IDiagramNode>().ToArray()); while (a.MoveNext()) { yield return(a.Current); } if (ValidationSystem.ErrorNodes.SelectMany(n => n.Errors).Any(e => e.Siverity == ValidatorType.Error)) { Signal <INotify>(_ => _.Notify("Please, fix all errors before compiling.", NotificationIcon.Error)); yield break; } Signal <IUpgradeDatabase>(_ => _.UpgradeDatabase(config as uFrameDatabaseConfig)); Signal <ICompilingStarted>(_ => _.CompilingStarted(repository)); // Grab all the file generators var fileGenerators = InvertGraphEditor.GetAllFileGenerators(config, items, true).ToArray(); var length = 100f / (fileGenerators.Length + 1); var index = 0; foreach (var codeFileGenerator in fileGenerators) { index++; yield return(new TaskProgress(length * index, "Generating " + System.IO.Path.GetFileName(codeFileGenerator.AssetPath))); // Grab the information for the file var fileInfo = new FileInfo(codeFileGenerator.SystemPath); // Make sure we are allowed to generate the file if (!codeFileGenerator.CanGenerate(fileInfo)) { var fileGenerator = codeFileGenerator; InvertApplication.SignalEvent <ICompileEvents>(_ => _.FileSkipped(fileGenerator)); if (codeFileGenerator.Generators.All(p => p.AlwaysRegenerate)) { if (File.Exists(fileInfo.FullName)) { File.Delete(fileInfo.FullName); } } continue; } GenerateFile(fileInfo, codeFileGenerator); CodeFileGenerator generator = codeFileGenerator; InvertApplication.SignalEvent <ICompileEvents>(_ => _.FileGenerated(generator)); } ChangedRecrods.Clear(); InvertApplication.SignalEvent <ICompileEvents>(_ => _.PostCompile(config, items)); foreach (var item in items.OfType <IGraphData>()) { item.IsDirty = false; } yield return (new TaskProgress(100f, "Complete")); #if UNITY_EDITOR repository.Commit(); if (InvertGraphEditor.Platform != null) // Testability { InvertGraphEditor.Platform.RefreshAssets(); } #endif }
public void Initialize(CodeFileGenerator codeFileGenerator, Predicate <IDiagramNodeItem> itemFilter = null) { }
public virtual void Initialize(CodeFileGenerator codeFileGenerator) { }