예제 #1
0
파일: StartPoint.cs 프로젝트: BJLU/EvCode
        private static void AddUser()                  // method for defined add new User to the database
        {
            ServerKernel ser = new ServerKernel();     // create instance about class ServerKernel

            ser.SendingData("introduce User's Name");  // call method SendingData for send current string
            var    userName = ser.ReceivingData();     // call method Receiving for got data from client part
            string userN    = userName.ToString();     // convert get data to the type string

            ser.SendingData("introduce User's Age");   // call method SendingData for send current string
            var userAge = ser.ReceivingData();         // call method ReceivingData for get all data from client part
            int userA   = Int32.Parse(userAge);        // convert get data in the int type

            using (UserContext db = new UserContext()) // defined variable about class UserContext
            {
                User newUser = new User {
                    Name = userN, Age = userA
                };                                           // defined instance with got data

                db.Users.Add(newUser);                       // choice current object and add to the database
                db.SaveChanges();                            // save new data in the database
                ser.SendingData("command performed");        // call method SendingData for send current string

                var users = db.Users;                        // got all users from the database

                StartPoint showUsers = new StartPoint();     // instance for description event about showing all users
                showUsers.UsersEvent += showUsers.ShowUsers; // defined current method 'ShowUsers' for event - 'UsersEvent'
                if (showUsers.UsersEvent != null)            // if event have method for performing
                {
                    showUsers.UsersEvent(users);             // call current event
                }
            }
        }
예제 #2
0
파일: StartPoint.cs 프로젝트: BJLU/EvCode
        public event ShowAllUsers UsersEvent;                  // event for performing users from database

        static void Main(string[] args)                        // start point
        {
            ServerKernel servKer = new ServerKernel();         // create instance about ServerKernel class

            servKer.AddEvent  += AddUser;                      // binding performed for event AddEvent
            servKer.DelEvent  += DeleteUser;                   // binding performed for event DelEvent
            servKer.ExitEvent += ExitProgram;                  // binding performed for current event ExitEvent

            StartPoint show = new StartPoint();

            show.UsersEvent += show.ShowUsers;

            //calling in sequence all methods
            servKer.DefinedHostComputer(); // ddefined host for new machine
            servKer.DefinedAddress();      // created full address about Server part
            servKer.DefinedEndPoint();     // defined all data about Server part
            servKer.OpenSocket();          // create socket with all data about Server part
            servKer.NamingSocket();        // naming socket for next connecting to the Server part
        }