Пример #1
0
        public void Print(bool clearScreen = true)
        {
            var item = ConzapTools.ChooseFromList <T>(Objects, TitleFactory, Style);

            Conzap.ConzapToolHelpers.ClearScreen(clearScreen);
            ConzapTools.PrintObject <T>(item);
        }
Пример #2
0
 // 3. Pass type and add custom fields, ignore unattributed properties
 private static void Three()
 {
     ConzapTools.PrintObjects(fruit)
     .CustomField("Custom field 1", f => "The default descriptiuon is " + f.Description)
     .Configure(ObjectPrinterOptions.IgnoreUnattributedProperties)
     .Print();
 }
Пример #3
0
 public void ListFruit()
 {
     ConzapTools.ClearScreen();
     ConzapTools.PrintObjects(Fruits)
     .Configure(ObjectPrinterOptions.UseOnlyCustomFields)
     .ItemHeadingFactory(f => f.Type)
     .Print();
 }
Пример #4
0
        private static void InstantiateConzapMenu()
        {
            GlobalViewStyle.Style.HeadingStyle.DecorationType = HeadingDecoration.Wrapped;

            ConzapTools.NewMenu("Menuu MUUUU")
            .Add("Create person", () => handlePersons.CreatePerson())
            .AddAndRun("List persons", () => handlePersons.ListPersons());
        }
Пример #5
0
        static void Main(string[] args)
        {
            var text           = GetFileContent();
            var props          = new StringToObjectifyEntity(text).properties.ToDictionary(p => p[0], p => p[1]);
            var membersOfClass = new ParseToObject <MyClass>(props).ToString();

            //   Console.WriteLine($"Hello World! {NL} {props.ToString()}");
            ConzapTools.KeyInput(membersOfClass);
        }
Пример #6
0
 // 4. Pass type but ignore certain properties
 private static void Four()
 {
     ConzapTools.PrintObjects(fruit)
     .IgnoreProperty(f => f.Type)
     .IgnoreProperty(f => f.Description)
     .IgnoreProperty(f => f.Id)
     .IgnoreProperty(f => f.ContainsKernels)
     .Print();
 }
Пример #7
0
        public void ListPersons()
        {
            Console.Clear();

            ConzapTools.PrintCustomObjects(Persons)
            .CustomField("", p => p.Name.ToUpper())
            .CustomField("Age", p => p.Age.ToString())
            .CustomField("Year", p => p.Year.ToString())
            .Print();
        }
Пример #8
0
        public void CreateFruit()
        {
            ConzapTools.ClearScreen();
            ConzapTools.PrintLine("CREATE NEW FRUIT");
            var fruit = new Fruit();

            fruit.Type        = ConzapTools.ChooseString("Type: ");
            fruit.Description = ConzapTools.ChooseString("Description: ");
            fruit.Quantity    = ConzapTools.ChooseInt("Amount: ", 0, 100);

            Fruits.Add(fruit);
        }
Пример #9
0
        //private static void Blä()
        //{
        //    var nutrientsPrinter = Conzap.ObjectPrinter<Nutrients>();

        //    var fruitPrinter = Conzap.ObjectPrinter<Fruit>(MyObject);
        //        .Field(x => x)
        //        .Field(x => x)
        //        .Field(x => x.list )
        //        .Configure();

        //}

        private static void TestMenuItemAttribute()
        {
            var fruitHandler  = new HandleFruits();
            var personHandler = new HandlePersons();

            while (true)
            {
                ConzapTools.RunMenu("CHOOSE AN OPTION: ",
                                    new ConzapMenuItem("Handle persons ", () => ConzapTools.RunMenu <HandlePersons>(personHandler)),
                                    new ConzapMenuItem("Handle fruits ", () => ConzapTools.RunMenu <HandleFruits>(fruitHandler))
                                    );
            }
        }
Пример #10
0
        public void CreatePerson()
        {
            Console.Clear();
            var now    = DateTime.Now;
            var person = new Person();

            Console.WriteLine("CREATE NEW PERSON");
            person.Name = ConzapTools.ChooseString("Name: ");
            person.Age  = ConzapTools.ChooseInt("Age: ", 0, 110);
            var year = ConzapTools.ChooseInt("Year: ", 1900, DateTime.Now.Year);

            person.Year = new DateTime(year, now.Month, now.Day);

            Persons.Insert(0, person);
        }
Пример #11
0
        public void Run(string heading = null)
        {
            heading = heading ?? Heading;
            while (true)
            {
                var listItems = MenuItems.Select(ami => ami.Title).ToList();

                ConzapToolHelpers.ClearAndPrintHeading(heading);

                var input = ConzapTools.ChooseFromList(listItems.ToArray()) - 1;

                ConzapTools.ClearScreen();
                var chosenMenuItem = MenuItems[input];
                var value          = chosenMenuItem.Value;
                if (value == "quit")
                {
                    break;
                }
                MenuItems[input].Callback();
            }
        }
Пример #12
0
        //public ObjectPrinter<T>PrintMenu(Func<T, string> objectTitleFabric, string heading = null, bool clearScreen = true)
        //{
        //    ConzapToolHelpers.ClearScreen(clearScreen);
        //    ConzapToolHelpers.PrintHeading(heading);
        //    var stringList = Objects.Select(o => objectTitleFabric(o)).ToList();
        //    stringList.Insert(0, "Quit");

        //    while (true)
        //    {
        //        var chosenIndex = Choose.ChooseFromList(stringList.ToArray());
        //        if (chosenIndex == 0)
        //        {
        //            return this;
        //        }

        //        var item = Objects.ToArray()[chosenIndex];
        //        new ObjectPrinter<T>(new List<T>() { item }).Print();

        //        Misc.PauseForKey();
        //    }
        //}

        /// <summary>
        /// Prints all objects
        /// </summary>
        private void ActuallyPrint(List <T> ObjectsToPrint)
        {
            var parsedObjects = new List <Dictionary <string, string> >();
            var type          = typeof(T);


            // ADD FIELDS FOR EACH ITEM
            foreach (var item in ObjectsToPrint.Select(o => (T)o))
            {
                var currentItem = new Dictionary <string, string>();
                var properties  = type.GetProperties();

                // ADD HEADER IF HEADER USED
                if (_itemHeadingFactory != null)
                {
                    currentItem.Add(_itemHeadingFactory(item), "");
                }

                // CHECK FOR TYPE DEFINITION
                var itemType = Helper.GetListType(item.GetType());
                var exists   =

                    // IF HAS TYPE DEFINITION RECURSIVE PRINT AND EXIT TO NEST ITEM


                    // ADD FROM CUSTOM FIELDS
                    if (CustomFields != null)
                {
                    foreach (var customField in CustomFields)
                    {
                        var label = customField.Label;
                        var value = customField.PrintThis(item);
                        currentItem.Add(label, value);
                    }
                }


                // EXIT IF ONLY CUSTOM FIELDS
                if (UseOnlyCustomFields)
                {
                    continue;
                }

                // AUTO GENERATE FIELD IF NOT EXITED - LAST RESORT
                foreach (var property in properties)
                {
                    if (IgnoreThese.Any(i => i.Name == property.Name))
                    {
                        continue;
                    }

                    var kvpField = ParseProperty(property, item);

                    if (!string.IsNullOrEmpty(kvpField.Key))
                    {
                        currentItem.Add(kvpField.Key, kvpField.Value);
                    }
                }

                parsedObjects.Add(currentItem);
            }


            // PRINT EACH OBJECT
            foreach (var dic in parsedObjects)
            {
                var items = dic.Select(kvp =>
                {
                    var key = string.IsNullOrEmpty(kvp.Key) ? "" : kvp.Key + " : ";
                    return(key + kvp.Value);
                });
                ConzapTools.PrintHeading(items.ElementAt(0), false);
                ConzapTools.PrintList(items.Skip(1).ToArray());
                ConzapTools.SkipLines(1);
            }

            ConzapTools.PauseForKey();
        }
Пример #13
0
 // 2. Pass type and configure to ignore non attributed properties as well as ignore attributes
 private static void Two()
 {
     ConzapTools.PrintObjects(fruit)
     .Configure(ObjectPrinterOptions.IgnoreUnattributedProperties | ObjectPrinterOptions.IgnoreAttributes)
     .Print();
 }
Пример #14
0
 // 1. Pass type but no field information
 private static void ObjectPrinting1()
 {
     ConzapTools.ClearScreen();
     ConzapTools.PrintObjects(fruit).Print();
 }