Esempio n. 1
0
        // TODO(Premek): check for invalid characters in the namePrefix
        private void CreateMemoryBlocksInner(object memBlockOwner, List <PropertyInfo> listOfBlockInfos, string namePrefix = "")
        {
            if (listOfBlockInfos.Count == 0)
            {
                return;
            }

            var usePrefix = (string.IsNullOrEmpty(namePrefix) && (memBlockOwner is IMemBlockNamePrefix))
                ? ((IMemBlockNamePrefix)memBlockOwner).MemBlockNamePrefix
                : namePrefix;

            var existingMemBlockNames = MyMemoryManager.Instance.GetBlocks(this).Select(mb => mb.Name).ToList();

            foreach (PropertyInfo pInfo in listOfBlockInfos)
            {
                MyAbstractMemoryBlock mb = MyMemoryManager.Instance.CreateMemoryBlock(this, pInfo.PropertyType);

                mb.Name = GetUniqueMemBlockName(usePrefix + pInfo.Name, existingMemBlockNames);

                mb.IsOutput    = MyNodeInfo.IsOutputMemoryBlock(pInfo);
                mb.Persistable = pInfo.GetCustomAttribute <MyPersistableAttribute>(true) != null;
                mb.Unmanaged   = pInfo.GetCustomAttribute <MyUnmanagedAttribute>(true) != null;
                mb.IsDynamic   = pInfo.GetCustomAttribute <DynamicBlockAttribute>(true) != null;

                pInfo.SetValue(memBlockOwner, mb);
            }
        }
Esempio n. 2
0
        protected internal MyNode()
        {
            MyNodeInfo.CollectNodeInfo(GetType());

            InputBranches  = GetInfo().InputBlocks.Count;
            OutputBranches = GetInfo().OutputBlocks.Count;

            CreateMemoryBlocks();
            CreateSignals();
            InitPropertiesDefault();
        }
Esempio n. 3
0
        private static List <PropertyInfo> FindNestedMemoryBlocks(Type memBlockOwnerType)
        {
            List <PropertyInfo> memBlocksInfo = MyNodeInfo.CollectNestedMemBlocks(memBlockOwnerType);

            if (!memBlocksInfo.Any())
            {
                MyLog.WARNING.WriteLine($"Nested memory blocks not found on type '{memBlockOwnerType.Name}'");
            }

            return(memBlocksInfo);
        }
Esempio n. 4
0
        private static void CollectNestedMemBlocks(MyNodeInfo nodeInfo, PropertyInfo memBlockOwnerInfo)
        {
            var nestedMemBlocks = CollectNestedMemBlocks(memBlockOwnerInfo.PropertyType);

            if (!nestedMemBlocks.Any())
            {
                return;
            }

            if (nodeInfo.NestedMemoryBlocks.ContainsKey(memBlockOwnerInfo))
            {
                throw new InvalidOperationException($"Nested mem blocks for {memBlockOwnerInfo.Name} already collected.");
            }

            nodeInfo.NestedMemoryBlocks[memBlockOwnerInfo] = nestedMemBlocks;
        }
Esempio n. 5
0
        internal static void CollectNodeInfo(Type type)
        {
            if (!NODE_INFO.ContainsKey(type))
            {
                MyNodeInfo nodeInfo = new MyNodeInfo();
                nodeInfo.Attributes = type.GetCustomAttribute <MyNodeInfoAttribute>(true);

                if (nodeInfo.Attributes == null)
                {
                    nodeInfo.Attributes = new MyNodeInfoAttribute();
                }

                foreach (PropertyInfo pInfo in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    if (typeof(MyTask).IsAssignableFrom(pInfo.PropertyType))
                    {
                        nodeInfo.KnownTasks.Add(pInfo.Name, pInfo);
                        nodeInfo.TaskOrder.Add(pInfo);

                        MyTaskGroupAttribute groupAttr = pInfo.GetCustomAttribute <MyTaskGroupAttribute>(true);

                        if (groupAttr != null)
                        {
                            if (!nodeInfo.TaskGroups.ContainsKey(groupAttr.Name))
                            {
                                nodeInfo.TaskGroups[groupAttr.Name] = new List <PropertyInfo>();
                            }

                            nodeInfo.TaskGroups[groupAttr.Name].Add(pInfo);
                        }
                    }
                    else if (typeof(MyAbstractMemoryBlock).IsAssignableFrom(pInfo.PropertyType))
                    {
                        MyInputBlockAttribute inAttr = pInfo.GetCustomAttribute <MyInputBlockAttribute>(true);
                        if (inAttr != null)
                        {
                            nodeInfo.InputBlocks.Add(pInfo);
                        }
                        else
                        {
                            if (typeof(MyWorkingNode).IsAssignableFrom(type))
                            {
                                nodeInfo.OwnedMemoryBlocks.Add(pInfo);
                            }

                            if (pInfo.GetCustomAttribute <MyOutputBlockAttribute>(true) != null)
                            {
                                nodeInfo.OutputBlocks.Add(pInfo);
                            }
                        }
                    }
                    else if (typeof(MySignal).IsAssignableFrom(pInfo.PropertyType))
                    {
                        nodeInfo.RegisteredSignals.Add(pInfo);
                    }

                    object defaultValue = pInfo.GetAttributeProperty((YAXSerializableFieldAttribute fa) => fa.DefaultValue);

                    if (defaultValue != null)
                    {
                        nodeInfo.InitiableProperties.Add(pInfo);
                    }
                }

                nodeInfo.InputBlocks = new List <PropertyInfo>(
                    nodeInfo.InputBlocks.OrderBy(x => x.GetCustomAttribute <MyInputBlockAttribute>(true).Order));

                nodeInfo.OutputBlocks = new List <PropertyInfo>(
                    nodeInfo.OutputBlocks.OrderBy(x => x.GetCustomAttribute <MyOutputBlockAttribute>(true).Order));

                nodeInfo.TaskOrder = new List <PropertyInfo>(
                    nodeInfo.TaskOrder.OrderBy(x => (x.GetCustomAttribute <MyTaskInfoAttribute>(true) != null ?
                                                     x.GetCustomAttribute <MyTaskInfoAttribute>(true).Order : 0)));

                NODE_INFO[type] = nodeInfo;
            }
        }
Esempio n. 6
0
        internal static void CollectNodeInfo(Type type)
        {
            if (!NODE_INFO.ContainsKey(type))
            {
                MyNodeInfo nodeInfo = new MyNodeInfo();
                nodeInfo.Attributes = type.GetCustomAttribute<MyNodeInfoAttribute>(true);

                if (nodeInfo.Attributes == null)
                {
                    nodeInfo.Attributes = new MyNodeInfoAttribute();
                }

                foreach (PropertyInfo pInfo in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    if (typeof(MyTask).IsAssignableFrom(pInfo.PropertyType))
                    {
                        nodeInfo.KnownTasks.Add(pInfo.Name, pInfo);
                        nodeInfo.TaskOrder.Add(pInfo);

                        MyTaskGroupAttribute groupAttr = pInfo.GetCustomAttribute<MyTaskGroupAttribute>(true);

                        if (groupAttr != null)
                        {
                            if (!nodeInfo.TaskGroups.ContainsKey(groupAttr.Name))
                            {
                                nodeInfo.TaskGroups[groupAttr.Name] = new List<PropertyInfo>();
                            }

                            nodeInfo.TaskGroups[groupAttr.Name].Add(pInfo);
                        }
                    }
                    else if (typeof(MyAbstractMemoryBlock).IsAssignableFrom(pInfo.PropertyType))
                    {
                        MyInputBlockAttribute inAttr = pInfo.GetCustomAttribute<MyInputBlockAttribute>(true);
                        if (inAttr != null)
                        {
                            nodeInfo.InputBlocks.Add(pInfo);
                        }
                        else
                        {
                            if (typeof(MyWorkingNode).IsAssignableFrom(type))
                            {
                                nodeInfo.OwnedMemoryBlocks.Add(pInfo);
                            }

                            if (pInfo.GetCustomAttribute<MyOutputBlockAttribute>(true) != null)
                            {
                                nodeInfo.OutputBlocks.Add(pInfo);
                            }
                        }
                    }
                    else if (typeof(MySignal).IsAssignableFrom(pInfo.PropertyType))
                    {
                        nodeInfo.RegisteredSignals.Add(pInfo);
                    }

                    object defaultValue = pInfo.GetAttributeProperty((YAXSerializableFieldAttribute fa) => fa.DefaultValue);

                    if (defaultValue != null)
                    {
                        nodeInfo.InitiableProperties.Add(pInfo);
                    }
                }

                nodeInfo.InputBlocks = new List<PropertyInfo>(
                    nodeInfo.InputBlocks.OrderBy(x => x.GetCustomAttribute<MyInputBlockAttribute>(true).Order));

                nodeInfo.OutputBlocks = new List<PropertyInfo>(
                    nodeInfo.OutputBlocks.OrderBy(x => x.GetCustomAttribute<MyOutputBlockAttribute>(true).Order));

                nodeInfo.TaskOrder = new List<PropertyInfo>(
                    nodeInfo.TaskOrder.OrderBy(x => (x.GetCustomAttribute<MyTaskInfoAttribute>(true) != null ?
                    x.GetCustomAttribute<MyTaskInfoAttribute>(true).Order : 0)));

                NODE_INFO[type] = nodeInfo;
            }
        }
Esempio n. 7
0
        internal static void CollectNodeInfo(Type type)
        {
            if (NODE_INFO.ContainsKey(type))
            {
                return;
            }

            var nodeInfo = new MyNodeInfo
            {
                Attributes = type.GetCustomAttribute <MyNodeInfoAttribute>(true) ?? new MyNodeInfoAttribute()
            };

            foreach (PropertyInfo pInfo in type.GetProperties(
                         BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (typeof(MyTask).IsAssignableFrom(pInfo.PropertyType))
                {
                    nodeInfo.KnownTasks.Add(pInfo.Name, pInfo);
                    nodeInfo.OrderedTasks.Add(pInfo);

                    MyTaskGroupAttribute groupAttr = pInfo.GetCustomAttribute <MyTaskGroupAttribute>(true);

                    if (groupAttr != null)
                    {
                        if (!nodeInfo.TaskGroups.ContainsKey(groupAttr.Name))
                        {
                            nodeInfo.TaskGroups[groupAttr.Name] = new List <PropertyInfo>();
                        }

                        nodeInfo.TaskGroups[groupAttr.Name].Add(pInfo);
                    }
                }
                else if (typeof(MyAbstractMemoryBlock).IsAssignableFrom(pInfo.PropertyType))
                {
                    MyInputBlockAttribute inAttr = pInfo.GetCustomAttribute <MyInputBlockAttribute>(true);
                    if (inAttr != null)
                    {
                        nodeInfo.InputBlocks.Add(pInfo);
                    }
                    else
                    {
                        if (typeof(MyWorkingNode).IsAssignableFrom(type))
                        {
                            nodeInfo.OwnedMemoryBlocks.Add(pInfo);
                        }

                        if (IsOutputMemoryBlock(pInfo))
                        {
                            nodeInfo.OutputBlocks.Add(pInfo);
                        }
                    }
                }
                else if (typeof(IMemBlockOwner).IsAssignableFrom(pInfo.PropertyType))
                {
                    CollectNestedMemBlocks(nodeInfo, pInfo);
                }
                else if (typeof(MySignal).IsAssignableFrom(pInfo.PropertyType))
                {
                    nodeInfo.RegisteredSignals.Add(pInfo);
                }

                object defaultValue = pInfo.GetAttributeProperty((YAXSerializableFieldAttribute fa) => fa.DefaultValue);

                if (defaultValue != null)
                {
                    nodeInfo.InitiableProperties.Add(pInfo);
                }
            }

            nodeInfo.InputBlocks = new List <PropertyInfo>(
                nodeInfo.InputBlocks.OrderBy(p => p.GetCustomAttribute <MyBlockOrderAttribute>(true).Order));

            nodeInfo.OutputBlocks = new List <PropertyInfo>(
                nodeInfo.OutputBlocks.OrderBy(p => p.GetCustomAttribute <MyBlockOrderAttribute>(true).Order));

            nodeInfo.OrderedTasks = new List <PropertyInfo>(
                nodeInfo.OrderedTasks.OrderBy(
                    // check pInfo.PropertyType because MyTaskInfo is a class attribute not property attribute
                    p => p.PropertyType.GetCustomAttribute <MyTaskInfoAttribute>(true)?.Order ?? 0));

            NODE_INFO[type] = nodeInfo;
        }
Esempio n. 8
0
 public MyNodeInfo GetInfo()
 {
     return(MyNodeInfo.Get(GetType()));
 }