Exemplo n.º 1
0
        public void start()
        {
            tasks.workDone += EmailService.SendEmail;
            tasks.workDone += PushNotification.SendPushNotification;
            tasks.workDone += TextMessageService.SendText;
            do
            {
                Console.WriteLine("Welcome Hero! What would you like to do?");
                Console.WriteLine("[0] Create a Hero?");
                Console.WriteLine("[1] Get all Heros?");
                Console.WriteLine("[2] Go to work?");
                Console.WriteLine("[3] Go back to the main menu?");
                userInput = Console.ReadLine();
                switch (userInput)
                {
                case "0":
                    //call create a hero, get hero details
                    SuperHero newSuperHero = GetHeroDetails();
                    //call the business logic and the repo
                    try{
                        heroService.AddHero(newSuperHero);
                    } catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        continue;
                    }
                    break;

                case "1":
                    //call get all heros
                    foreach (var hero in heroService.GetAllHeroes())
                    {
                        Console.WriteLine($"Hero: \n\tHero Alias: {hero.Alias} \n\tHero Real Name: {hero.RealName} \n\tHero Hideout: {hero.HideOut}");
                        foreach (var power in hero.SuperPowers)
                        {
                            Console.WriteLine($"\tSuper Powers:\n\t\tName: {power.Name}\n\t\tDescription: {power.Description}");
                        }
                    }
                    break;

                case "2":
                    //call the event delegate for hero work, call get hero by name
                    tasks.DoWork();
                    tasks.ManageLife();
                    Console.WriteLine("Press <enter>");
                    break;

                case "3":
                    Console.WriteLine("Going back to main");
                    break;

                default:
                    //invalid input message;
                    service.InvalidInputMessage();
                    break;
                }
            } while (!userInput.Equals("3"));
        }
Exemplo n.º 2
0
        public void start()
        {
            tasks.workDone += EmailService.SendEmail;
            tasks.workDone += PushNotification.SendPushNotification;
            tasks.workDone += TextMessageService.SendText;
            do
            {
                Console.WriteLine("Welcome Hero! What would you like to do?");
                Console.WriteLine("[0] Create a Hero?");
                Console.WriteLine("[1] Get all Heros?");
                Console.WriteLine("[2] Go to work?");
                Console.WriteLine("[3] Go back to the main menu?");
                userInput = Console.ReadLine();
                switch (userInput)
                {
                case "0":
                    //call create a hero, get hero details
                    SuperHero newSuperHero = GetHeroDetails();
                    //call the business logic and the repo
                    heroService.AddHero(newSuperHero);
                    break;

                case "1":
                    //call get all heros
                    heroService.GetAllHeroes();
                    break;

                case "2":
                    //call the event delegate for hero work, call get hero by name
                    tasks.DoWork();
                    tasks.ManageLife();
                    Console.WriteLine("Press <enter>");
                    break;

                case "3":
                    //call the main menu
                    MainMenu main = new MainMenu();
                    main.start();
                    break;

                default:
                    //invalid input message;
                    service.InvalidInputMessage();
                    break;
                }
            } while (!userInput.Equals("3"));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Hero obj=new Hero();
            #region default constructor

            /*Hero obj=new Hero();
             * Console.WriteLine($"{obj.id} {obj.name}" );*/
            #endregion
            #region Parameterized constructor
            //Hero obj1=new Hero(2, "Narco");
            //Program obj1=new Program();
            //Console.WriteLine($"{obj1.id} {obj1.name}" );// cannot access the variable if they arenot public
            #endregion
            #region Access via Properties
            // Console.WriteLine(obj1.Id);// read property value
            // obj1.Id=3;
            // Console.Write($"New Id = {obj1.Id}");// write into a property
            #endregion
            #region Accessing  Arrays

            /*Console.Write("Please enter your heros id: ");
             * obj.Id=Int32.Parse(Console.ReadLine());
             * Console.Write("Please enter your Superhero name:");
             * obj.Name=Console.ReadLine();
             * Console.Write("Enter the first Power: ");
             * obj.superPowers[0]
             * Console.ReadLine();
             * Console.Write($"{obj.Id} {obj.Name}  {obj.superPowers[0]}");*/
            // Jagged Arrays rows initializations

            /*obj.ja[0]=new int[2];// first column
             * obj.ja[1]=new int[3];// second column
             * obj.ja[2]=new int[1];// third column
             * obj.ja[0][0]=10;
             * obj.ja[1][2]=15;
             * int[,,] td=new int[2,4,3];// 3-D arrays
             * Console.WriteLine($"Dimension of the Array - {td.Rank}D");
             * Console.WriteLine($"Number of elements in the Array - {td.Length}");
             * Console.WriteLine(obj.ja.Rank);// rank is dimenssion of the array
             * Console.WriteLine(obj.ja.Length);// elements of the arrays
             * // loop through the jagged array
             * foreach (var rows in obj.ja) //looping through all rows
             * {
             *  //looping through all columns of every row
             *  for(int i=0; i<rows.Length;i++){
             *      Console.Write($"{rows[i]} ");
             *  }
             *  Console.WriteLine();
             * }*/
            #endregion
            #region List<T>, Stack<T>
            //Console.WriteLine("Please enter the super power to be removed ");
            //string sp=Console.ReadLine();
            //Hero.superPowers.Remove(sp);
            // foreach(var superPower in Hero.GetSuperPowers()){
            //     Console.WriteLine(superPower);
            // }
            #endregion
            #region Dictionary<key, value>
            // Console.WriteLine("Super Hero     Hideout");
            // foreach(var superhero in Hero.hideOuts){
            //    // Console.WriteLine($"{superhero.Key}   {Hero.hideOuts[superhero.Key]}"); // old way
            // //Console.WriteLine($"{superhero.Key} {superhero.Value}"); // new way of accessing key values
            // }
            #endregion
            #region Calling hero menu
            // IMenu startMenu = new MainMenu();
            // startMenu.Start();
            #endregion
            HeroTasks heroTasks = new HeroTasks();
            #region Delegate, Anonymous methods, Lambda
            //HeroDel del=new HeroDel(heroTasks.GetPowers);
            //Action del =new Action(heroTasks.GetPowers);
            //Func<string, string> fd=new Func<string, string>(some method);
            //Predicate<string> predicate=new Predicate<string>(some method);
            //del += heroTasks.DoWork; // += subscribe to a method
            //del += heroTasks.ManageLife;
            // del();
            // del -= heroTasks.ManageLife; // unsubscribe
            // del();

            // Anonymous methods
            // Action<string> am=delegate(string name){
            //     Console.WriteLine("Hello anonymous");
            // };
            //am("Pushpinder");
            // Lambda expression - shorthand notations to anonymous methods
            // Action result= ()=>Console.WriteLine("Hello Lambda");
            // result();
            #endregion
            #region Asynchronous vs Synchronous programming
            /// Subcribing to publisher
            heroTasks.workDone += EmailService.SendEmail;
            heroTasks.workDone += TextMessageService.SendText;
            heroTasks.workDone += PushNotification.SendPushNotification;
            heroTasks.DoWork();
            heroTasks.ManageLife();
            Console.Read();// Holds the screen until a key pressed
            #endregion
        }
        static void Main(string[] args)
        {
            //Hero obj = new Hero();
            #region default constructor

            /*Hero obj = new Hero();
             * Console.WriteLine($"Hero ID: {obj.id} \nHero Name: {obj.name}");*/
            #endregion
            #region explicit constructor

            /*obj.Id = 5;
             * Console.WriteLine($"Hero ID: {obj.Id} \nHero Name: {obj.name}");*/
            #endregion
            #region arrays

            /*
             * Console.Write("Please enter your hero's id: ");
             * obj.Id=Int32.Parse(Console.ReadLine()); //typecast string to int
             * Console.Write("Please enter your Superhero name: ");
             * obj.Name=Console.ReadLine();
             * Console.Write("Please enter the first superpower: ");
             * obj.superPowers[0] = Console.ReadLine();
             * Console.Write($"ID: {obj.Id}\nName: {obj.Name}\nSuperpowers: {obj.superPowers[0]}");
             */
            #endregion

            #region accessing arrays

            /*
             * obj.ja[0] = new int[2];
             * obj.ja[1] = new int[3];
             * obj.ja[2] = new int[1];
             * obj.ja[0][0] =10;
             * obj.ja[1][2] =15;
             * int[,,] td = new int[2, 4, 3]; //3-D array
             * //Console.WriteLine(obj.ja.Rank); //dimension of the array (1D, 2D, etc.) (jagged arrays are techincally 1D)
             * //Console.WriteLine(obj.ja.Length);//maximum size of the array (num of elements)
             *
             * Console.WriteLine("Values in Jagged Array:");
             * //loop through all rows
             * foreach (var row in obj.ja)
             * {
             *  //loop through all columns
             *  foreach (var val in row)
             *  {
             *      Console.Write($"{val} ");
             *  }
             *  Console.Write("\n");
             * }
             */
            #endregion

            #region List<T>

            /*
             * Console.Write("Remove super power: ");
             * string sp=Console.ReadLine();
             * //Hero.superPowers.Remove(sp);
             *
             * Console.Write("\n");
             * foreach(var superPower in Hero.GetSuperPowers())
             * {
             *  Console.WriteLine(superPower);
             * }*/
            #endregion

            #region Dictionary<key, value>

            /*
             * Console.WriteLine("Superhero       Hideout");
             * foreach(var superhero in Hero.hideOuts) {
             *  Console.WriteLine($"{superhero.Key}       {Hero.hideOuts[superhero.Key]}");
             * }*/
            #endregion

            #region calling Hero menu

            /*
             * MainMenu startMenu = new MainMenu();
             * startMenu.Start();*/
            #endregion

            HeroTasks heroTasks = new HeroTasks();
            #region delegates, anonymous members, lambda

            /*
             * HeroDel del = new HeroDel(heroTasks.GetPowers);
             * del += heroTasks.DoWork; //+= subscribe to a method
             * //del -= heroTasks.DoWork; //-= unsubscribes to a method
             * del += heroTasks.ManageLife;
             * del();
             * //Func<string, string> fd;
             * //Predicate<string> predicate;
             *
             * //Anonymous methods
             * Action<string> am = delegate(string name) {
             *  System.Console.WriteLine("Hello anonymous");
             * };
             * am("foo");
             * //Lambda expression --> shorthand for anonymous method
             * Action<string> lm = (string name) => Console.WriteLine("Hello lambda");
             * lm("foo");*/
            #endregion

            #region asynchronous vs. synchronous programming
            //Subscribing to publisher
            heroTasks.workDone += EmailService.SendEmail;
            heroTasks.workDone += TextMessageService.SendText;
            heroTasks.workDone += PushNotification.SendPushNotification;
            heroTasks.DoWork();     //this will create a second thread and process it in the background
            heroTasks.ManageLife(); //this will be processed by the main thread
            Console.Read();         //this is to make the console wait while the second thread processes
            #endregion
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            #region default constructor
            // Hero obj = new Hero();
            // Console.WriteLine($"{obj.id} {obj.name}");
            #endregion

            #region parameterized constructor
            // Hero obj1 = new Hero(2, "Narco");
            // Console.WriteLine($"{obj1.id} {obj1.name}");
            #endregion

            #region access via properties
            // Console.WriteLine($"ID = {obj1.Id}"); // read property value
            // obj1.Id = 3; // write into property
            // Console.WriteLine($"Updated ID = {obj1.Id}");
            #endregion

            // Hero obj = new Hero();
            // Console.Write("Please enter your hero's ID: ");
            // obj.Id = Int32.Parse(Console.ReadLine());
            // Console.Write("Please enter your hero's name: ");
            // obj.Name = Console.ReadLine();
            // Console.Write("Please enter the first superpower: ");
            // obj.superPowers[0] = Console.ReadLine();
            // Console.Write($"{obj.Id} {obj.Name} {obj.superPowers[0]}");

            #region List<T>, Stack<T>
            // Console.WriteLine("Please enter the superpower to be removed: ");
            // string sp = Console.ReadLine();
            // Hero.RemoveSuperPower(sp);
            // Hero.RemoveSuperPower();
            // foreach(var superPower in Hero.GetSuperPowers()) {
            //     Console.WriteLine(superPower);
            // }
            #endregion

            #region Dictionary<key, value>
            // Console.WriteLine("Superhero/Hideout:");
            // foreach(var superhero in Hero.hideOuts) {
            //     // Console.WriteLine($"{superhero.Key} / {superhero.Value}");
            //     Console.WriteLine($"{superhero.Key} / {Hero.hideOuts[superhero.Key]}");
            // }
            #endregion

            #region calling hero menu
            IMenu startMenu = new MainMenu();
            startMenu.Start();
            #endregion

            HeroTasks heroTask = new HeroTasks();
            #region delegates, anonymous methods, lambda functions
            // HeroDel del = new HeroDel(heroTask.GetSuperPowers);
            Action del = new Action(heroTask.GetSuperPowers); // strongly-typed pre-defined delegate
            del += heroTask.DoWork;                           // subscribe to a method with +=
            del += heroTask.ManageLife;
            del();
            del -= heroTask.ManageLife;  // unsubscribe with -=
            del();

            // anonymous methods
            Action <string> am = delegate(string name) {
                Console.WriteLine("Hello anonymous");
            };
            am("me");

            // lambda expressions => shorthand notations to anonymous methods
            Action result = () => Console.WriteLine("Hello lambda");
            result();
            #endregion

            #region synchronous vs asynchronous programming
            // subscribing to publisher
            heroTask.workDone += EmailService.SendEmail;
            heroTask.workDone += TextMessageService.SendText;
            heroTask.workDone += PushNotificationService.SendPushNotification;
            heroTask.DoWork();
            heroTask.ManageLife();
            // System.Threading.Thread.Sleep(2000);
            Console.Read(); // holds the screen until key is pressed
            #endregion
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            #region default constructor
            #endregion
            #region Parameterized constructor

            // Hero obj = new Hero(1, "brian");
            // Console.WriteLine($"{obj.Id} {obj.name}");
            #endregion
            #region access via properties
            // obj.Id = 2;
            // Console.WriteLine($"New Id = {obj.Id}");
            #endregion
            #region Accessing 1-D Arrays

            Hero obj = new Hero();
            // Console.Write("Please Enter your heros id: ");
            // obj.Id = Int32.Parse(Console.ReadLine());
            // Console.Write("Please Enter your heros name: ");
            // obj.Name = Console.ReadLine();
            // Console.Write("Enter the first super power: ");
            // obj.superPowers[0] = Console.ReadLine();
            // Console.Write($"{obj.Id} {obj.Name} {obj.superPowers[0]}");
            // obj.ja[0] = new int[2]; // first column
            // obj.ja[1] = new int[3]; // second column
            // obj.ja[2] = new int[2]; // third column
            // obj.ja[0][0] = 10;
            // obj.ja[1][2] = 15;
            // Console.WriteLine(obj.ja.Length);
            // Console.WriteLine();

            // for(int i = 0; i < obj.ja.Length; i++) {
            //     for(int j = 0; j < obj.ja[i].Length; j++) {
            //         Console.WriteLine(obj.ja[i][j]);
            //     }
            // }

            // foreach (var rows in obj.ja) {

            //     foreach (var item in rows) {
            //         Console.Write($"{item} ");
            //     }
            //      Console.WriteLine();
            // }
            #endregion
            #region collections

            // foreach(var superPower in obj.GetSuperPowers()) {
            //     Console.WriteLine(superPower);
            // }

            // Console.WriteLine("Please enter the super power to be removed ");
            // string sp = Console.ReadLine();
            // obj.RemoveSuperPower(sp);

            // foreach(var superPower in obj.GetSuperPowers()) {
            //     Console.WriteLine(superPower);
            // }
            #endregion
            #region traverse dictionary
            // Console.WriteLine("Super Hero      Hideout");
            // foreach(var superHero in Hero.hideouts) {
            //     Console.WriteLine($"{superHero.Key}      {superHero.Value}");
            // }
            #endregion

            #region Calling hero menu
            // IMenu startMenu = new MainMenu();
            // startMenu.Start();
            #endregion

            #region Delegate, Anonymous methods, Lambda
            HeroTasks heroTasks = new HeroTasks();

            //HeroDel del=new HeroDel(heroTasks.GetPowers);
            //Action del =new Action(heroTasks.GetPowers);
            //Func<string, string> fd=new Func<string, string>(some method);
            //Predicate<string> predicate=new Predicate<string>(some method);
            // del += heroTasks.DoWork; // += subscribe to a method
            // del += heroTasks.ManageLife;
            // del();
            // del -= heroTasks.ManageLife; // unsubscribe
            // del();

            //Anonymous methods
            // Action<string> am=delegate(string name){
            //     Console.WriteLine($"Hello {name}");
            // };
            // am("Brian");
            //Lambda expression - shorthand notations to anonymous methods
            // Action result= ()=>Console.WriteLine("Hello Lambda");
            // result();
            #endregion
            #region Async and Sync programming
            /// Subscribing to publisher
            heroTasks.workDone += EmailService.SendEmail;
            heroTasks.workDone += TextMessageService.SendText;
            heroTasks.DoWork();
            heroTasks.ManageLife();
            Console.Read(); //hold the screen until a key is pressed
            #endregion
        }