Exemplo n.º 1
0
        private string ExportItems(List <IDataRecord> items, IRepository graph, uFrameExport export)
        {
            var repo = graph as TypeDatabase;

            if (repo == null)
            {
                throw new Exception("Couldn't export, must be TypeDatabase");
            }
            var actualItems = items;

            var ids = items.Select(p => p.Identifier).ToArray();

            foreach (var record in graph.AllOf <IDataRecord>())
            {
                if (record is Workspace)
                {
                    continue;
                }
                if (!record.ForeignKeys.Any())
                {
                    continue;
                }
                if (record.ForeignKeys.All(x => ids.Any(p => p != null && x != null && (p == x || p.StartsWith(x)))))
                {
                    if (!actualItems.Contains(record))
                    {
                        actualItems.Add(record);
                    }
                }
            }
            actualItems.RemoveAll(p => p.Identifier.Contains(":"));

            export.Repositories = actualItems.GroupBy(p => p.GetType()).Select(p => new ExportedRepository()
            {
                Records = p.Select(x => new ExportedRecord()
                {
                    Data       = InvertJsonExtensions.SerializeObject(x).ToString(true),
                    Identifier = x.Identifier
                }).ToList(),
                Type = p.Key.FullName
            }).ToList();
            var config     = Container.Resolve <IGraphConfiguration>();
            var generators = InvertGraphEditor.GetAllFileGenerators(config,
                                                                    actualItems.ToArray(), true);

            export.CodeFiles = generators.Where(p => File.Exists(p.SystemPath)).Select(p => new ExportedCode()
            {
                Code         = File.ReadAllText(p.SystemPath),
                RelativePath = p.AssetPath.Replace(config.CodeOutputPath, "")
            }).ToList();

            var contents = InvertJsonExtensions.SerializeObject(export).ToString(true);

            return(contents);
        }
Exemplo n.º 2
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var node = obj.FirstOrDefault() as DiagramNodeViewModel;

            if (node != null)
            {
                var config         = InvertGraphEditor.Container.Resolve <IGraphConfiguration>();
                var fileGenerators = InvertGraphEditor.GetAllFileGenerators(config, new[] { node.DataObject as IDataRecord }, true).ToArray();
                foreach (var file in fileGenerators)
                {
                    var file1 = file;
                    if (File.Exists(file1.SystemPath))
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Open " + (file.AssetPath.Replace("/", "\\")),
                            Group   = "Open",
                            Command = new LambdaCommand("Open File", () =>
                            {
                                InvertGraphEditor.Platform.OpenScriptFile(file1.AssetPath);
                            })
                        });
                    }
                }

                foreach (var file in fileGenerators)
                {
                    var file1     = file;
                    var outputGen = file1.Generators.FirstOrDefault();
                    if (outputGen == null)
                    {
                        continue;
                    }
                    var templateClassGen = outputGen as ITemplateClassGenerator;
                    if (templateClassGen != null && typeof(IOnDemandTemplate).IsAssignableFrom(templateClassGen.TemplateType))
                    {
                        ui.AddCommand(new ContextMenuItem()
                        {
                            Title   = "Create Editable " + Path.GetFileName(file.AssetPath),
                            Group   = "Open",
                            Command = new LambdaCommand("Create Editable File", () =>
                            {
                                GenerateFile(new FileInfo(file1.SystemPath), file1);
                                AssetDatabase.Refresh();
                                InvertGraphEditor.Platform.OpenScriptFile(file1.AssetPath);
                            })
                        });
                    }
                }
            }
        }
Exemplo n.º 3
0
        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);
            }

            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
        }