Beispiel #1
0
        private void ImportPositionData(JSONClass positionData)
        {
            foreach (KeyValuePair <string, JSONNode> item in positionData)
            {
                if (item.Key == "_CLRType")
                {
                    continue;
                }
                var filterId = item.Key;
                foreach (KeyValuePair <string, JSONNode> positionItem in item.Value.AsObject)
                {
                    var filterItem = new FilterItem();
                    filterItem.FilterId = filterId;
                    filterItem.NodeId   = positionItem.Key;

                    var x = positionItem.Value["x"].AsInt;
                    var y = positionItem.Value["y"].AsInt;
                    InvertApplication.Log("Importing position ");
                    filterItem.Position  = new Vector2(x, y);
                    filterItem.Collapsed = true;

                    Repository.Add(filterItem);
                }
            }
        }
Beispiel #2
0
        public override void Initialize(QFrameworkContainer container)
        {
            var path          = DbRootPath;
            var dbDirectories = Directory.GetDirectories(path, "*.db", SearchOption.AllDirectories);

            foreach (var item in dbDirectories)
            {
                var db     = new TypeDatabase(new JsonRepositoryFactory(item));
                var config = GetConfig(db, Path.GetFileNameWithoutExtension(item));
                config.FullPath = item;
                container.RegisterInstance <IGraphConfiguration>(config, config.Identifier);
            }

            CurrentConfiguration = Configurations.ContainsKey(CurrentDatabaseIdentifier)
                ? Configurations[CurrentDatabaseIdentifier]
                : Configurations.Values.FirstOrDefault();

            if (CurrentConfiguration != null)
            {
                container.RegisterInstance <IGraphConfiguration>(CurrentConfiguration);

                container.RegisterInstance <IRepository>(CurrentConfiguration.Database);

                //var typeDatabase = container.Resolve<IRepository>();
                CurrentConfiguration.Database.AddListener <IDataRecordInserted>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordRemoved>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordPropertyChanged>(this);
                CurrentConfiguration.Database.AddListener <IDataRecordPropertyBeforeChange>(this);
            }
            else
            {
                InvertApplication.Log("A uFrameDatabase doesn't exist.");
            }
        }
Beispiel #3
0
        public void Execute(BackgroundTaskCommand command)
        {
            BackgroundWorker worker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };

            InvertApplication.Log("Creating background task");
            worker.DoWork += (sender, args) =>
            {
                InvertApplication.Log("Executing background task");
                var bgCommand = args.Argument as BackgroundTaskCommand;

                if (bgCommand != null)
                {
                    bgCommand.Command.Worker = sender as BackgroundWorker;
                    bgCommand.Action(bgCommand.Command);
                }
            };
            worker.ProgressChanged += (sender, args) =>
            {
                InvertApplication.Log("PROGRESS");
                InvertApplication.SignalEvent <ICommandProgressEvent>(_ => _.Progress(null, args.UserState.ToString(), args.ProgressPercentage));
            };
            command.Task = new BackgroundTask(worker);
            worker.RunWorkerAsync(command);
        }
Beispiel #4
0
        private void GraphItemsOnCollectionChangedWith(MVVM.NotifyCollectionChangedEventArgs changeArgs)
        {
            if (changeArgs.NewItems != null)
            {
                foreach (var item in changeArgs.NewItems.OfType <ViewModel>())
                {
                    if (item == null)
                    {
                        InvertApplication.Log("Graph Item is null");
                    }

                    var drawer = InvertGraphEditor.Container.CreateDrawer <IDrawer>(item);

                    if (drawer == null)
                    {
                        InvertApplication.Log("Drawer is null");
                    }

                    Children.Add(drawer);

                    mCachedChildren = Children.OrderBy(p => p.ZOrder).ToArray();
                    drawer.Refresh((IPlatformDrawer)InvertGraphEditor.PlatformDrawer);
                }
            }
            if (changeArgs.OldItems != null && changeArgs.OldItems.Count > 0)
            {
                var c = Children.Count;
                Children.RemoveAll(p => changeArgs.OldItems.Contains(p.ViewModelObject));
                var d = Children.Count;
                if (c != d)
                {
                    mCachedChildren = Children.OrderBy(p => p.ZOrder).ToArray();
                }
            }
        }
Beispiel #5
0
        public void Execute(TestyCommand command)
        {
            var sb = new StringBuilder();

            foreach (var item in InvertApplication.Plugins.OrderBy(p => p.Title))
            {
                sb.AppendLine(item.Title);
            }
            InvertApplication.Log(sb.ToString());
        }
        private IEnumerable <IDrawer> CreateDrawers()
        {
            InvertApplication.Log("Creating drawers");
            foreach (var item in ViewModel.ContentItems)
            {
                var drawer = InvertGraphEditor.Container.CreateDrawer(item);
                if (drawer == null)
                {
                    InvertApplication.Log(string.Format("Couldn't create drawer for {0} make sure it is registered.",
                                                        item.GetType().Name));
                    continue;
                }

                yield return(drawer);
            }
        }
Beispiel #7
0
        private IEnumerable <OutputGenerator> CreateTemplateGenerators(IGraphConfiguration config, IDataRecord graphItem, Type templateType)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (graphItem == null)
            {
                throw new ArgumentNullException("graphItem");
            }
            if (templateType == null)
            {
                throw new ArgumentNullException("templateType");
            }

            var templateClassType = templateType.GetGenericArguments()[1];
            var templateAttribute = templateClassType.GetCustomAttributes(typeof(TemplateClass), true)
                                    .OfType <TemplateClass>()
                                    .FirstOrDefault();

            if (templateAttribute == null)
            {
                InvertApplication.Log(string.Format("ClassTemplate attribute not found on {0} ", templateClassType.Name));
                yield break;
            }


            if (templateAttribute.Location == TemplateLocation.DesignerFile || templateAttribute.Location == TemplateLocation.Both)
            {
                var template = Activator.CreateInstance(templateType) as CodeGenerator;
                template.ObjectData     = graphItem;
                template.IsDesignerFile = true;

                //template.AssetDirectory = graphItem.Graph.Project.SystemDirectory;
                template.AssetDirectory = config.CodeOutputPath;
                yield return(template);
            }
            if (templateAttribute.Location == TemplateLocation.EditableFile || templateAttribute.Location == TemplateLocation.Both)
            {
                var template = Activator.CreateInstance(templateType) as CodeGenerator;
                template.ObjectData     = graphItem;
                template.IsDesignerFile = false;
                template.AssetDirectory = config.CodeOutputPath;

                yield return(template);
            }
        }
Beispiel #8
0
        public static IEnumerable <Type> GetDerivedTypes <T>(bool includeAbstract = false, bool includeBase = true)
        {
            var type = typeof(T);

            if (includeBase)
            {
                yield return(type);
            }
            if (includeAbstract)
            {
                foreach (var assembly in CachedAssemblies)
                {
                    //if (!assembly.FullName.StartsWith("Invert")) continue;
                    foreach (var t in assembly
                             .GetTypes()
                             .Where(x => type.IsAssignableFrom(x)))
                    {
                        yield return(t);
                    }
                }
            }
            else
            {
                var items = new List <Type>();
                foreach (var assembly in CachedAssemblies)
                {
                    try
                    {
                        foreach (var t in assembly
                                 .GetTypes()
                                 .Where(x => type.IsAssignableFrom(x) && !x.IsAbstract))
                        {
                            items.Add(t);
                        }
                    }
                    catch (Exception ex)
                    {
                        InvertApplication.Log(ex.Message);
                    }
                }
                foreach (var item in items)
                {
                    yield return(item);
                }
            }
        }
Beispiel #9
0
 public void LoadDiagram(IGraphData diagram)
 {
     InvertGraphEditor.DesignerWindow = this;
     if (diagram == null)
     {
         return;
     }
     try
     {
         DiagramDrawer       = new DiagramDrawer(new DiagramViewModel(diagram));
         DiagramDrawer.Dirty = true;
         //DiagramDrawer.Data.ApplyFilter();
         DiagramDrawer.Refresh(InvertGraphEditor.PlatformDrawer);
     }
     catch (Exception ex)
     {
         InvertApplication.LogException(ex);
         InvertApplication.Log("Either a plugin isn't installed or the file could no longer be found. See Exception error");
     }
 }
Beispiel #10
0
        public 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);
            }
        }
Beispiel #11
0
        public static IDrawer CreateDrawer <TDrawerBase>(this IQFrameworkContainer container, ViewModel viewModel)
            where TDrawerBase : IDrawer
        {
            if (_drawers != null)
            {
            }

            if (viewModel == null)
            {
                InvertApplication.LogError("Data is null.");
                return(null);
            }

            var drawer = container.ResolveRelation <TDrawerBase>(viewModel.GetType(), viewModel);

            if (drawer == null)
            {
                InvertApplication.Log(String.Format("Couldn't Create drawer for {0}.", viewModel.GetType()));
            }

            return(drawer);
        }
Beispiel #12
0
 public void Progress(ICommand command, string message, float progress)
 {
     InvertApplication.Log(message);
 }
Beispiel #13
0
        public void Draw(float width, float height, Vector2 scrollPosition, float scale)
        {
            DiagramDrawer.IsEditingField = false;
            if (Drawer == null)
            {
                InvertApplication.Log("DRAWER IS NULL");
                return;
            }
            var diagramRect = new Rect();

            if (DrawToolbar)
            {
                var toolbarTopRect  = new Rect(0, 0, width, 18);
                var tabsRect        = new Rect(0, toolbarTopRect.height, width, 31);
                var breadCrumbsRect = new Rect(0, tabsRect.y + tabsRect.height, width, 30);

                diagramRect = new Rect(0f, breadCrumbsRect.y + breadCrumbsRect.height, width,
                                       height - (toolbarTopRect.height * 2) - breadCrumbsRect.height - 31);
                var toolbarBottomRect = new Rect(0f, diagramRect.y + diagramRect.height, width,
                                                 toolbarTopRect.height);


                var modalItems = new List <DesignerWindowModalContent>();

                var overlayItems = new List <DesignerWindowOverlayContent>();

                //Disable diagram input if any modal content presents or if mouse is over overlay content
                mShouldProcessInputFromDiagram = !modalItems.Any() && overlayItems.All(i => !i.Drawer.CalculateBounds(diagramRect).Contains(Event.current.mousePosition));

                Drawer.DrawStretchBox(toolbarTopRect, CachedStyles.Toolbar, 0f);

                Drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Left);
                //drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Right);

                Drawer.DrawRect(tabsRect, InvertGraphEditor.Settings.GridLinesColor);

                //Drawer.DoTabs(Drawer,tabsRect, this);
                DiagramRect = diagramRect;

                /*
                 * DRAW DIAGRAM
                 * Using GUI.color hack to avoid transparent diagram on disabled input (Thanks Unity :( )
                 */

                if (!mShouldProcessInputFromDiagram)
                {
                    Drawer.DisableInput();
                }

                if (DiagramDrawer != null)
                {
                    DiagramDrawer.DrawTabs(Drawer, tabsRect);
                    DiagramDrawer.DrawBreadcrumbs(Drawer, breadCrumbsRect.y);
                }

                var fpsCounterRect = tabsRect.WithWidth(80).RightOf(tabsRect).Translate(-100, 0);

                if (ShowFPS)
                {
                    if ((DateTime.Now - mLastFpsUpdate).TotalMilliseconds > 1000)
                    {
                        mFpsShown      = mFramesLastSec;
                        mLastFpsUpdate = DateTime.Now;
                        mFramesLastSec = 0;
                    }
                    else
                    {
                        mFramesLastSec++;
                    }
                    Drawer.DrawLabel(fpsCounterRect, string.Format("FPS: {0}", mFpsShown), CachedStyles.WizardSubBoxTitleStyle);
                }

                Drawer.DrawRect(diagramRect, InvertGraphEditor.Settings.BackgroundColor);

                DiagramRect = diagramRect;

                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);

                Drawer.EnableInput();

                /*
                 * DRAW OVERLAY CONTENT
                 */

                if (modalItems.Any())
                {
                    Drawer.DisableInput();
                }

                foreach (var item in overlayItems)
                {
                    var bounds      = item.Drawer.CalculateBounds(diagramRect);
                    var isMouseOver = bounds.Contains(Event.current.mousePosition);

                    var colorCache = GUI.color;

                    if (!isMouseOver && !item.DisableTransparency)
                    {
                        GUI.color = new Color(colorCache.r, colorCache.g, colorCache.b, colorCache.a / 4);
                    }

                    item.Drawer.Draw(bounds);

                    GUI.color = colorCache;
                }

                Drawer.EnableInput();

                /*
                 * DRAW MODAL CONTENT
                 */

                if (modalItems.Any())
                {
                    var modalBackgroundRect = new Rect().Cover(breadCrumbsRect, tabsRect, diagramRect);
                    var modalContentRect    = new Rect().WithSize(800, 500).CenterInsideOf(modalBackgroundRect);
                    var activeModal         = modalItems.OrderBy(i => i.ZIndex).Last();

                    Drawer.DisableInput();

                    foreach (var source in modalItems.OrderBy(i => i.ZIndex).Except(new[] { activeModal }))
                    {
                        source.Drawer(modalContentRect);
                    }

                    Drawer.EnableInput();

                    Drawer.DrawRect(modalBackgroundRect, new Color(0, 0, 0, 0.8f));

                    activeModal.Drawer(modalContentRect);
                }


                DrawToolip(breadCrumbsRect);

                Drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomLeft);
                //drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomRight);
            }
            else
            {
                diagramRect = new Rect(0f, 0f, width, height);
                DiagramRect = diagramRect;
                DrawDiagram(Drawer, scrollPosition, scale, diagramRect);
            }

            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawDesignerWindow(new Rect(0, 0, width, height)));
            InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.DrawComplete());
        }
Beispiel #14
0
        public void ImportData(JSONClass node)
        {
            var typeName = string.Empty;

            if (node["_CLRType"] != null)
            {
                typeName = node["_CLRType"].Value;
            }
            else if (node["Type"] != null)
            {
                typeName = node["Type"].Value;
            }
            var type = InvertApplication.FindType(typeName) ?? Type.GetType(typeName);

            if (type == null && typeName.StartsWith("ConnectionData"))
            {
                type = typeof(ConnectionData);
            }

            if (type != null)
            {
                var result = ImportType(type, node);

                if (result is IGraphData)
                {
                    var item = InvertApplication.Container.Resolve <WorkspaceService>();
                    if (item.CurrentWorkspace != null)
                    {
                        item.CurrentWorkspace.AddGraph(result as IGraphData);
                    }
                    CurrentGraph = result as InvertGraph;
                    CurrentGraph.RootFilterId = node["RootNode"]["Identifier"].Value;
                    Debug.Log("Set Root filter id to " + CurrentGraph.RootFilterId);
                }
                if (result is GraphNode)
                {
                    CurrentNode         = result as GraphNode;
                    CurrentNode.GraphId = CurrentGraph.Identifier;
                }
                if (result is DiagramNodeItem)
                {
                    ((IDiagramNodeItem)result).NodeId = CurrentNode.Identifier;
                }
                if (result is ITypedItem)
                {
                    // TODO Find type and replace it will fullname
                    ((ITypedItem)result).RelatedType = node["ItemType"].Value;
                }

                foreach (KeyValuePair <string, JSONNode> child in node)
                {
                    var array = child.Value as JSONArray;
                    if (array != null)
                    {
                        foreach (var item in array.Childs.OfType <JSONClass>())
                        {
                            ImportData(item);
                        }
                    }
                    var cls = child.Value as JSONClass;
                    if (cls != null)
                    {
                        if (child.Key == "FilterState")
                        {
                            continue;
                        }
                        if (child.Key == "Settings")
                        {
                            continue;
                        }
                        if (child.Key == "Changes")
                        {
                            continue;
                        }
                        if (child.Key == "PositionData")
                        {
                            ImportPositionData(cls);
                        }
                        else
                        {
                            if (child.Key == "RootNode")
                            {
                                InvertApplication.Log("Importing ROOT NODE");
                            }
                            ImportData(cls);
                        }
                    }
                }
            }
        }