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
        private void RenameApplied(ApplyRenameCommand applyRenameCommand)
        {
            var gensNow = InvertGraphEditor.GetAllCodeGenerators(
                Container.Resolve <DatabaseService>().CurrentConfiguration, new IDataRecord[] { applyRenameCommand.Item })
                          .Select(p => Path.Combine(Application.dataPath, p.RelativeFullPathName)).ToArray();

            if (gensNow.Length == RenameGens.Length)
            {
                for (var i = 0; i < gensNow.Length; i++)
                {
                    if (File.Exists(RenameGens[i]))
                    {
                        File.Move(RenameGens[i], gensNow[i]);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void CommandExecuting(ICommand command)
        {
            if (command is ApplyRenameCommand)
            {
                RenameApplying(command as ApplyRenameCommand);
            }
            if (!(command is IFileSyncCommand))
            {
                return;
            }
            IsRename = command is ApplyRenameCommand;
            var items = Container.Resolve <IRepository>().AllOf <IDataRecord>().ToArray();

            Gens = new Dictionary <string, GenFileInfo>();
            foreach (var p in InvertGraphEditor.GetAllCodeGenerators(
                         Container.Resolve <DatabaseService>().CurrentConfiguration, items))
            {
                var key = Path.GetFileName(p.Filename);
                if (!Gens.ContainsKey(key))
                {
                    Gens.Add(key, new GenFileInfo(Path.Combine(Application.dataPath, p.RelativeFullPathName), p));
                }
            }
        }
Exemplo n.º 5
0
        public void CommandExecuted(ICommand command)
        {
            if (command is ApplyRenameCommand)
            {
                RenameApplied(command as ApplyRenameCommand);
            }
            if (!(command is IFileSyncCommand))
            {
                return;
            }
            var items   = Container.Resolve <IRepository>().AllOf <IDataRecord>().ToArray();
            var gensNow = new Dictionary <string, GenFileInfo>();

            foreach (var p in InvertGraphEditor.GetAllCodeGenerators(
                         Container.Resolve <DatabaseService>().CurrentConfiguration, items))
            {
                var key = Path.GetFileName(p.Filename);
                if (!gensNow.ContainsKey(key))
                {
                    gensNow.Add(key, new GenFileInfo(Path.Combine(Application.dataPath, p.RelativeFullPathName), p));
                }
            }

            var deleteList = new List <string>();

            foreach (var item in Gens)
            {
                if (!gensNow.ContainsKey(item.Key))
                {
                    // Its been removed or renamed

                    if (File.Exists(item.Value.FullPath))
                    {
                        deleteList.Add(item.Value.FullPath);
                    }
                }
                else
                {
                    var nowItem = gensNow[item.Key];
                    if (nowItem.Generator.ObjectData == item.Value.Generator.ObjectData)
                    {
                        // It has been moved
                        if (File.Exists(item.Value.FullPath))
                        {
                            File.Move(item.Value.FullPath, nowItem.FullPath);
                        }
                    }
                }
            }

            Gens.Clear();
            GC.Collect();
            IsRename = false;
            if (deleteList.Count > 0)
            {
                if (InvertGraphEditor.Platform.MessageBox("Warning",
                                                          string.Format("You've deleted a record that has {0} file(s) associated with it.  Would you like to remove them?", deleteList.Count),
                                                          "YES (Recommended)", "NO they are special!"))
                {
                    foreach (var item in deleteList)
                    {
                        File.Delete(item);
                    }
                }
                this.Execute(new SaveAndCompileCommand()
                {
                    ForceCompileAll = true
                });
            }
        }
Exemplo n.º 6
0
 private void RenameApplying(ApplyRenameCommand applyRenameCommand)
 {
     RenameGens = InvertGraphEditor.GetAllCodeGenerators(
         Container.Resolve <DatabaseService>().CurrentConfiguration, new IDataRecord[] { applyRenameCommand.Item })
                  .Select(p => Path.Combine(Application.dataPath, p.RelativeFullPathName)).ToArray();
 }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
 public override void Loaded(QFrameworkContainer container)
 {
     InvertGraphEditor.DesignerPluginLoaded();
 }