Ejemplo n.º 1
0
 private GuerillaBlock FindParent(GuerillaBlock block, GuerillaBlock searchBlock)
 {
     if (ParentLookup.ContainsKey(block))
     {
         return(ParentLookup[block]);
     }
     foreach (var fieldInfo in searchBlock.GetType( ).GetFields( ))
     {
         //  If the field is a GuerillaBlock or an array of GuerillaBlocks
         if (fieldInfo.FieldType.IsSubclassOf(typeof(GuerillaBlock)))
         {
             if (( GuerillaBlock )fieldInfo.GetValue(searchBlock) == block)
             {
                 ParentLookup.Add(block, searchBlock);
                 return(searchBlock);
             }
         }
         if (fieldInfo.FieldType.IsArray &&
             fieldInfo.FieldType.GetElementType( ).IsSubclassOf(typeof(GuerillaBlock)))
         {
             var guerillaBlocks = ( GuerillaBlock[] )fieldInfo.GetValue(searchBlock);
             foreach (var guerillaBlock in guerillaBlocks)
             {
                 if (guerillaBlock == block)
                 {
                     ParentLookup.Add(block, searchBlock);
                     return(searchBlock);
                 }
                 FindParent(block, guerillaBlock);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
 public static void CreateLink(GuerillaBlock guerillaBlock, ICache cache)
 {
     if (guerillaBlock == null || cache == null)
     {
         return;
     }
     Index.Link(guerillaBlock, cache);
 }
Ejemplo n.º 3
0
        public void Display(GuerillaBlock block)
        {
            if (block == null)
            {
                block = _block;
            }
            _activeBlock = block;
            var fields = block.GetType( ).GetFields( );

            dataGridView1.DataSource = fields.Select(u => new { u.Name, Value = u.GetValue(block) }).ToList( );
        }
Ejemplo n.º 4
0
        public void LoadGuerillaBlocks(GuerillaBlock guerillaBlock)
        {
            _guerillaBlock = guerillaBlock;
            if (guerillaBlock == null)
            {
                return;
            }

            var fields = guerillaBlock.GetType( ).GetFields( );

            treeView1.Nodes.Clear( );
            treeView1.Nodes.AddRange(ParseChildNodes(fields, guerillaBlock));
            treeView1.ExpandAll( );
        }
Ejemplo n.º 5
0
        private bool GetActiveNode(out GuerillaBlock element, out Tuple <GuerillaBlock, GuerillaBlock[], FieldInfo> tag)
        {
            var selectedNode = treeView1.SelectedNode;

            element = selectedNode.Tag as GuerillaBlock;

            if (element == null)
            {
                tag = null;
                return(true);
            }

            var parentNode = treeView1.SelectedNode.Parent;

            tag = (Tuple <GuerillaBlock, GuerillaBlock[], FieldInfo>)parentNode.Tag;
            return(false);
        }
Ejemplo n.º 6
0
        private static TreeNode[] ParseChildNodes([NotNull] FieldInfo[] fields, GuerillaBlock guerillaBlock)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }
            var arrayFields =
                fields.Where(
                    x => x.FieldType.IsArray && x.FieldType.GetElementType( ).BaseType == typeof(GuerillaBlock))
                .ToArray( );
            var treeNodes = new TreeNode[arrayFields.Count( )];

            for (var index = 0; index < arrayFields.Length; index++)
            {
                var fieldInfo = arrayFields[index];

                var value = ( GuerillaBlock[] )fieldInfo.Get(guerillaBlock);


                var arrayNode = new TreeNode(fieldInfo.Name)
                {
                    ImageIndex         = 0,
                    SelectedImageIndex = 0,
                    Tag = new Tuple <GuerillaBlock, GuerillaBlock[], FieldInfo>(guerillaBlock, value, fieldInfo)
                };

                for (var i = 0; i < value.Length; i++)
                {
                    var element = value[i];

                    var elementNode = new TreeNode(string.Format(fieldInfo.Name + "[{0}]", i))
                    {
                        ImageIndex         = 1,
                        SelectedImageIndex = 1,
                        Tag = element
                    };
                    elementNode.Nodes.AddRange(ParseChildNodes(fieldInfo.FieldType.GetElementType( ).GetFields( ),
                                                               element));
                    arrayNode.Nodes.Add(elementNode);
                }

                treeNodes[index] = arrayNode;
            }
            return(treeNodes);
        }
Ejemplo n.º 7
0
        public static bool TryGetCacheKey(this GuerillaBlock guerillaBlock, out CacheKey key)
        {
            if (Index.Tags.ContainsKey(guerillaBlock))
            {
                key = Index.Tags[guerillaBlock].CacheKey;
                return(true);
            }

            foreach (var cacheStream in Index.Caches)
            {
                if (!cacheStream.Contains(guerillaBlock))
                {
                    continue;
                }

                key = CacheKey.Create(cacheStream);
                Index.Tags.Add(guerillaBlock, new TagGlobalKey(key, TagIdent.NullIdentifier));
                return(true);
            }
            key = CacheKey.Null;
            return(false);
        }
Ejemplo n.º 8
0
 public void Link(GuerillaBlock guerillaBlock, ICache cache)
 {
     Tags[guerillaBlock] = new TagGlobalKey(CacheKey.Create(cache),
                                            TagIdent.NullIdentifier);
 }
Ejemplo n.º 9
0
 public bool Contains(GuerillaBlock guerillaBlock)
 {
     return(Tags.ContainsKey(guerillaBlock));
 }
Ejemplo n.º 10
0
        private void navParent_Click(object sender, EventArgs e)
        {
            GuerillaBlock parent = FindParent(_activeBlock, _block);

            Display(parent);
        }
Ejemplo n.º 11
0
 public void LoadBlock(GuerillaBlock block)
 {
     _block = block;
 }