コード例 #1
0
        private void UpdateClient(Socket recSoc, Employee employee, Texi texi, BinaryFormatter bf)
        {
            // Convert employee and texi to serializable objects.
            SerializableEmployee serEmp  = employee.ToSerializable();
            SerializableTexi     serTexi = texi.ToSerializable();

            // Serialize and send the employee object.
            using (MemoryStream ms = new MemoryStream())
            {
                bf.Serialize(ms, serEmp);
                recSoc.Send(ms.ToArray());
            }

            // Serialize and send the texi object.
            using (MemoryStream ms = new MemoryStream())
            {
                bf.Serialize(ms, serTexi);
                recSoc.Send(ms.ToArray());
            }

            // If the employee has reached his detination remove thred from globalTimer.
            if (employee.Location == employee.Destination)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    bf.Serialize(ms, Encoding.ASCII.GetBytes("Destination reached."));
                    recSoc.Send(ms.ToArray());
                }

                this.globalTimer.Tick -= (o, arg) => this.UpdateClient(recSoc, employee, texi, bf);
            }
        }
コード例 #2
0
        public static SerializableEmployee SerializableEmployee(LayoutSize size)
        {
            string[] firstNames = new string[] { "Christi", "Foster", "Glennis", "Davina", "Matilda",
                                                 "Irene", "Millie", "Elissa", "Raeann", "Marilynn",
                                                 "Lowell", "Nada", "Tamekia", "Corrin", "Twana",
                                                 "Jama", "Ariel", "Kristi", "Alvaro", "Ellena" };
            string[] lastNames = new string[] { "Balmer", "Lema", "Kuhlmann", "Wheless", "Marte",
                                                "Commander", "Reiher", "Gracey", "Obanion", "Getchell",
                                                "Figg", "Kemble", "Weir", "Dahlke", "Wiest",
                                                "Mcnaught", "Pusey", "Tuma", "Shimek", "Lott" };
            Location loc = Location(size);

            SerializableEmployee newEmployee = new SerializableEmployee(firstNames[rnd.Next(20)], lastNames[rnd.Next(20)], rnd.Next(999))
            {
                Location = loc
            };

            return(newEmployee);
        }