예제 #1
0
        public IEnumerator AddGraphItems(IEnumerable <IDiagramNode> items)
        {
            var dictionary = new Dictionary <string, IFilterItem>();

            foreach (var item in GraphData.CurrentFilter.FilterItems)
            {
                if (dictionary.ContainsKey(item.NodeId))
                {
                    item.Repository.Remove(item);
                    continue;
                }
                dictionary.Add(item.NodeId, item);
            }

            FilterItems = dictionary;



            IsLoading = true;
            // var time = DateTime.Now;
            foreach (var item in items)
            {
                // Get the ViewModel for the data
                //InvertApplication.Log("B-A" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
                var mapping = InvertApplication.Container.RelationshipMappings[item.GetType(), typeof(INotifyPropertyChanged)];
                if (mapping == null)
                {
                    continue;
                }
                var vm = Activator.CreateInstance(mapping, item, this) as GraphItemViewModel;
                //var vm =
                //    InvertApplication.Container.ResolveRelation<ViewModel>(item.GetType(), item, this) as
                //        GraphItemViewModel;
                //InvertApplication.Log("B-B" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
                if (vm == null)
                {
                    continue;
                }
                vm.DiagramViewModel = this;
                GraphItems.Add(vm);
                //// Clear the connections on the view-model
                //vm.Connectors.Clear();
                //vm.GetConnectors(vm.Connectors);
                //connectors.AddRange(vm.Connectors);
                yield return(new TaskProgress(string.Format("Loading..."), 95f));
            }
            IsLoading = false;
            RefreshConnectors();
            //AddConnectors(connectors);
            InvertApplication.SignalEvent <IGraphLoaded>(_ => _.GraphLoaded());
            yield break;
        }
        protected CodeMemberMethod RenderMethod(object instance, KeyValuePair <MethodInfo, GenerateMethod> templateMethod, IDiagramNodeItem data)
        {
            MethodInfo info;
            var        dom = TemplateType.MethodFromTypeMethod(templateMethod.Key.Name, out info, false);

            CurrentMember    = dom;
            CurrentAttribute = templateMethod.Value;
            PushStatements(dom.Statements);

            var args       = new List <object>();
            var parameters = info.GetParameters();

            foreach (var arg in parameters)
            {
                args.Add(GetDefault(arg.ParameterType));
            }

            CurrentDeclaration.Members.Add(dom);

            var result = info.Invoke(instance, args.ToArray());
            var a      = result as IEnumerable;

            if (a != null)
            {
                var dummyIteraters = a.Cast <object>().ToArray();
                foreach (var item in dummyIteraters)
                {
                }
            }

            PopStatements();

            //var isOverried = false;
            //if (!IsDesignerFile && dom.Attributes != MemberAttributes.Final && templateMethod.Value.Location == TemplateLocation.Both)
            //{
            //    dom.Attributes |= MemberAttributes.Override;
            //    isOverried = true;
            //}
            //if ((info.IsVirtual && !IsDesignerFile) || (info.IsOverride() && !info.GetBaseDefinition().IsAbstract && IsDesignerFile))
            //{
            //    if (templateMethod.Value.CallBase)
            //    {
            //        //if (!info.IsOverride() || !info.GetBaseDefinition().IsAbstract && IsDesignerFile)
            //        //{
            //        dom.invoke_base(true);
            //        //}

            //    }
            //}
            InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.MethodAdded(instance, this, dom));
            return(dom);
        }
        public void Load(bool async = false)
        {
            GraphItems.Clear();
            //GraphItems.Add(InspectorViewModel);

            // var graphItems = new List<GraphItemViewModel>();
            //// var time = DateTime.Now;
            // foreach (var item in CurrentNodes)
            // {

            //     // Get the ViewModel for the data
            //     //InvertApplication.Log("B-A" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
            //     var mapping = InvertApplication.Container.RelationshipMappings[item.GetType(), typeof(ViewModel)];
            //     if (mapping == null) continue;
            //     var vm = Activator.CreateInstance(mapping, item, this) as GraphItemViewModel;
            //     //var vm =
            //     //    InvertApplication.Container.ResolveRelation<ViewModel>(item.GetType(), item, this) as
            //     //        GraphItemViewModel;
            //     //InvertApplication.Log("B-B" + DateTime.Now.Subtract(time).TotalSeconds.ToString());
            //     if (vm == null)
            //     {
            //         if (InvertGraphEditor.Platform.MessageBox("Node Error", string.Format("Couldn't find view-model for {0} would you like to remove this item?", item.GetType()), "Yes", "No"))
            //         {
            //             CurrentRepository.Remove(item);
            //         }
            //         continue;
            //     }
            //     vm.DiagramViewModel = this;
            //     GraphItems.Add(vm);
            //     // Clear the connections on the view-model
            //     vm.Connectors.Clear();
            //     vm.GetConnectors(vm.Connectors);
            //     connectors.AddRange(vm.Connectors);
            // }
            CurrentNodes = GraphData.CurrentFilter.FilterNodes.Distinct().ToArray();
            NavigationViewModel.Refresh();
            //if (async)
            //{
            InvertApplication.SignalEvent <ITaskHandler>(_ => _.BeginBackgroundTask(AddGraphItems(CurrentNodes)));
            //}
            //else
            //{
            //var e = AddGraphItems();
            //while (e.MoveNext())
            //{

            //}
            //}
        }
        public void Select(GraphItemViewModel viewModelObject)
        {
            if (viewModelObject == null)
            {
                return;
            }

            InspectorViewModel.TargetViewModel = viewModelObject;

            if (viewModelObject.IsSelected)
            {
                return;
            }

            viewModelObject.IsSelected = true;
            InvertApplication.SignalEvent <IGraphSelectionEvents>(
                _ => _.SelectionChanged(viewModelObject));
        }
        public override void Select()
        {
            if (IsSelected)
            {
                return;
            }
            var items = NodeViewModel.DiagramViewModel.SelectedNodeItems.ToArray();

            foreach (var item in items)
            {
                item.IsSelected = false;
            }
#if UNITY_EDITOR
            GUIUtility.keyboardControl = 0;
#endif
            NodeViewModel.Select();
            IsSelected = true;
            InvertApplication.SignalEvent <IGraphSelectionEvents>(_ => _.SelectionChanged(this));
            //BeginEditing();
        }
        public void DeselectAll()
        {
            if (InspectorViewModel != null)
            {
                InspectorViewModel.TargetViewModel = null;
            }

            foreach (var item in AllViewModels.ToArray())
            {
                var ivm = item as ItemViewModel;
                if (ivm != null)
                {
                    if (ivm.IsEditing)
                    {
                        ivm.EndEditing();
                        break;
                    }
                }
                var nvm = item as DiagramNodeViewModel;
                if (nvm != null)
                {
                    if (nvm.IsEditing)
                    {
                        nvm.EndEditing();
                        break;
                    }
                }


                if (item.IsSelected)
                {
                    item.IsSelected = false;
                }
            }


            InvertApplication.SignalEvent <INothingSelectedEvent>(_ => _.NothingSelected());
#if UNITY_EDITOR
            UnityEngine.GUI.FocusControl("");
#endif
        }
예제 #7
0
        public void ProcessTemplate()
        {
            // Initialize the template
            TemplateContext.Iterators.Clear();
            TemplateClass.TemplateSetup();

            foreach (
                var item in
                TemplateClass.GetType()
                .GetCustomAttributes(typeof(TemplateAttribute), true)
                .OfType <TemplateAttribute>().OrderBy(p => p.Priority))
            {
                item.Modify(TemplateClass, null, TemplateContext);
            }

            var initializeMethods = TemplateClass.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(p => p.IsDefined(typeof(TemplateSetup), true)).ToArray();

            foreach (var item in initializeMethods)
            {
                item.Invoke(TemplateClass, null);
            }

            InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.TemplateGenerating(TemplateClass, TemplateContext));


            foreach (var templateProperty in TemplateProperties)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateProperty.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateProperty(TemplateClass, templateProperty))
                {
                    Results.Add(new TemplateMemberResult(this, templateProperty.Key, templateProperty.Value, item, Decleration));
                }
            }

            foreach (var templateMethod in TemplateMethods)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateMethod.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateMethod(TemplateClass, templateMethod))
                {
                    Results.Add(new TemplateMemberResult(this, templateMethod.Key, templateMethod.Value, item, Decleration));
                }
            }

            foreach (var templateConstructor in TemplateConstructors)
            {
                if (FilterToMembers != null && !FilterToMembers.Contains(templateConstructor.Key.Name))
                {
                    continue;
                }
                foreach (var item in TemplateContext.RenderTemplateConstructor(TemplateClass, templateConstructor))
                {
                    Results.Add(new TemplateMemberResult(this, templateConstructor.Key, templateConstructor.Value, item, Decleration));
                }
            }
            var postMethods = TemplateClass.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(p => p.IsDefined(typeof(TemplateComplete), true)).ToArray();

            foreach (var item in postMethods)
            {
                item.Invoke(TemplateClass, null);
            }

            var list = new List <CodeNamespaceImport>();

            foreach (var item in TemplateContext.Namespace.Imports)
            {
                list.Add((CodeNamespaceImport)item);
            }
            TemplateContext.Namespace.Imports.Clear();
            foreach (var item in list.OrderBy(p => p.Namespace))
            {
                TemplateContext.Namespace.Imports.Add(item);
            }
        }
        public Color GetColor(IGraphItem dataObject)
        {
            try
            {
                var item = dataObject as IDiagramNodeItem;
                if (item != null)
                {
                    var node = item.Node as GenericNode;
                    if (node != null)
                    {
                        var color = node.Config.GetColor(node);
                        switch (color)
                        {
                        case NodeColor.Black:
                            return(Color.black);

                        case NodeColor.Blue:
                            return(new Color(0.25f, 0.25f, 0.65f));

                        case NodeColor.DarkDarkGray:
                            return(new Color(0.25f, 0.25f, 0.25f));

                        case NodeColor.DarkGray:
                            return(new Color(0.45f, 0.45f, 0.45f));

                        case NodeColor.Gray:
                            return(new Color(0.65f, 0.65f, 0.65f));

                        case NodeColor.Green:
                            return(new Color(0.00f, 1f, 0f));

                        case NodeColor.LightGray:
                            return(new Color(0.75f, 0.75f, 0.75f));

                        case NodeColor.Orange:
                            return(new Color(0.059f, 0.98f, 0.314f));

                        case NodeColor.Pink:
                            return(new Color(0.059f, 0.965f, 0.608f));

                        case NodeColor.Purple:
                            return(new Color(0.02f, 0.318f, 0.659f));

                        case NodeColor.Red:
                            return(new Color(1f, 0f, 0f));

                        case NodeColor.Yellow:
                            return(new Color(1f, 0.8f, 0f));

                        case NodeColor.YellowGreen:
                            return(new Color(0.604f, 0.804f, 0.196f));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InvertApplication.LogError(string.Format("Node is null on get color {0} : {1}", dataObject.Label, dataObject.Identifier));
            }
            return(Color.white);
        }
        public IEnumerable <CodeMemberProperty> RenderTemplateProperty(object instance, KeyValuePair <PropertyInfo, GenerateProperty> templateProperty)
        {
            CurrentAttribute = templateProperty.Value;
            var attributes = templateProperty.Key.GetCustomAttributes(typeof(TemplateAttribute), true).OfType <TemplateAttribute>().OrderBy(p => p.Priority).ToArray();

            bool success = true;

            foreach (var attribute in attributes)
            {
                if (!attribute.CanGenerate(instance, templateProperty.Key, this))
                {
                    success = false;
                }
            }
            if (!success)
            {
                yield break;
            }

            // Default to designer file only
            if (!attributes.OfType <Inside>().Any())
            {
                if (!IsDesignerFile)
                {
                    yield break;
                }
            }

            if (Iterators.ContainsKey(templateProperty.Key.Name))
            {
                var iterator = Iterators[templateProperty.Key.Name];
                var items    = iterator(Data).OfType <IDiagramNodeItem>().ToArray();

                foreach (var item in items)
                {
                    if (ItemFilter != null && !ItemFilter(item))
                    {
                        continue;
                    }
                    Item = item;

                    var domObject = RenderProperty(instance, templateProperty);
                    foreach (var attribute in attributes)
                    {
                        attribute.Modify(instance, templateProperty.Key, this);
                    }
                    CurrentDeclaration.Members.Add(domObject);
                    yield return(domObject);

                    InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                }
                Item = null;
            }
            else
            {
                Item = Data as IDiagramNodeItem;
                if (ItemFilter != null && !ItemFilter(Item))
                {
                    yield break;
                }
                var domObject = RenderProperty(instance, templateProperty);
                foreach (var attribute in attributes)
                {
                    attribute.Modify(instance, templateProperty.Key, this);
                }
                CurrentDeclaration.Members.Add(domObject);
                yield return(domObject);

                InvertApplication.SignalEvent <ICodeTemplateEvents>(_ => _.PropertyAdded(instance, this, domObject));
                Item = null;
            }
        }