Category.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Core » Model » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Core » Model » Category.cs
using System;
using System.Collections.Generic;
using System.Text;
using SokoSolve.Common.Structures;
using SokoSolve.Core.Model.DataModel;

namespace SokoSolve.Core.Model{
    /// <summary>
    /// Simple Folder structure for categories, which are an organising system
    /// </summary>
    public class Category : ITreeNodeBackReference<Category>
    {
        private GenericDescription details;
        private string categoryID;
        private string categoryParentREF;
        private TreeNode<Category> treeNode;
        private int order;
        private Library library;

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="myLib"></param>
        public Category(Library myLib)
        {
            library = myLib;
            details = new GenericDescription();
        }


        public Library Library
        {
            get { return library; }
        }

        /// <summary>
        /// Description
        /// </summary>
        public GenericDescription Details
        {
            get { return details; }
            set { details = value; }
        }


        /// <summary>
        /// Order for display
        /// </summary>
        public int Order
        {
            get { return order; }
            set { order = value; }
        }

        /// <summary>
        /// Global order allowing for tree structure
        /// </summary>
        public string NestedOrder
        {
            get 
            {
                if (treeNode.IsRoot) return order.ToString("00");
                else return treeNode.Parent.Data.NestedOrder + "." + order.ToString("00");
             }
        }

        /// <summary>
        /// ID string
        /// </summary>
        public string CategoryID
        {
            get { return categoryID; }
            set { categoryID = value; }
        }


        /// <summary>
        /// Parent string (cached from treenode, allows the categories to be assembled from XML)
        /// </summary>
        public string CategoryParentREF
        {
            get { return categoryParentREF; }
            set { categoryParentREF = value; }
        }

        /// <summary>
        /// Get all puzzles assigned to this category
        /// </summary>
        /// <returns></returns>
        public List<Puzzle> GetPuzzles()
        {
            return library.Puzzles.FindAll(delegate(Puzzle item) { return item.Category == this; });
        }

        /// <summary>
        /// Children/Sub categories
        /// </summary>
        public Category[] Children
        {
            get
            {
                return treeNode.ChildrenData;
            }
        }

        #region ITreeNodeBackReference<Category> Members

        /// <summary>
        /// Allow the data payload to have a referrence with its structure
        /// </summary>
        public TreeNode<Category> TreeNode
        {
            get { return treeNode; }
            set { treeNode = value; }
        }

        #endregion

        public override string ToString()
        {
            return string.Format("{0} {1}", categoryID, details);
        }

        /// <summary>
        /// Delete *this* category, all sub-categories and all puzzles
        /// </summary>
        public void Delete()
        {
            if (treeNode.IsRoot) return;

            // Remove puzzles
            if (treeNode.HasChildren)
            {
                treeNode.ForEach(delegate(TreeNode<Category> item)
                {
                    foreach (Puzzle catPuz in item.Data.GetPuzzles())
                    {
                        library.Puzzles.Remove(catPuz);
                    }
                }, int.MaxValue);
            }

            foreach (Puzzle catPuz in GetPuzzles())
            {
                library.Puzzles.Remove(catPuz);
            }
            
            // Remove category
            treeNode.Parent.RemoveChild(this);

        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.