Beispiel #1
0
 public void AddPerson(string name)
 {
     if (!IsDayFull())
     {
         ListPersons.Add(name);
     }
 }
        public override ListPersons Select()
        {
            ListPersons listPersons = new ListPersons();
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            socket.Connect(IPAddress.Parse("127.0.0.1"), 3180);

            NetworkStream networkStream = new NetworkStream(socket);

            string dataSend = extension + "|" + "Select";

            byte[] bytes = Encoding.UTF8.GetBytes(dataSend);
            networkStream.Write(bytes, 0, bytes.Length);
            networkStream.Flush();

            bool isWork = true;
            string fromServer = string.Empty;
            while(isWork)
            {
                if(networkStream.DataAvailable)
                {
                    isWork = false;
                    byte[] buffer = new byte[socket.Available];
                    networkStream.Read(buffer, 0, buffer.Length);
                    fromServer = Encoding.UTF8.GetString(buffer);
                }
            }

            listPersons = ClientServerDataSerializable.Deserialize(fromServer);

            networkStream.Close();
            socket.Close();
            return listPersons;
        }
        public static string Serialize(ListPersons listPersons)
        {
            string returnValue = string.Empty;

            foreach (Person person in listPersons)
                returnValue += person.ToXML();

            return returnValue;
        }
        public static ListPersons Deserialize(string str)
        {
            ListPersons returnList = new ListPersons();
            Regex regex = new Regex("<Person>(.+?)</Person>");
            MatchCollection matchCollection = regex.Matches(str);
            if (matchCollection.Count > 0)
            {
                foreach (Match match in matchCollection)
                {
                    Person person = new Person();
                    person.FromXML(match.Value);
                    returnList.Add(person);
                }
            }

            return returnList;
        }
Beispiel #5
0
        public void TestSelect()
        {
            string fileBaseName = @"D:\DataBasePerson.mock";
            File.Delete(fileBaseName);

            Person person = new Person("Uliana", "Kashirnaya", 23);
            DataBaseNetClient dataBaseNetClient = new DataBaseNetClient("mock");
            dataBaseNetClient.Insert(person);

            ListPersons listPerson = dataBaseNetClient.Select();

            ListPersons listPersonsExtended = new ListPersons();
            person.id = listPerson[0].id;
            listPersonsExtended.Add(person);

            Assert.IsTrue(listPersonsExtended.Equals(listPerson));
        }
Beispiel #6
0
        public override ListPersons Select()
        {
            SqlCommand sqlCommand;
            ListPersons listPersons = new ListPersons();
            SqlConnection connection = new SqlConnection(extension);
            connection.Open();

            sqlCommand = new SqlCommand(Person.SelectQuery, connection);
            SqlDataReader myReader = sqlCommand.ExecuteReader();

            while (myReader.Read())
            {
                object[] objects = new object[myReader.FieldCount];
                myReader.GetValues(objects);
                Person person = new Person();
                person.GetData(objects);
                listPersons.Add(person);
            }
            connection.Close();

            return listPersons;
        }
Beispiel #7
0
        public override ListPersons Select()
        {
            FileControl();
            string str = string.Empty;
            ListPersons listPersons = new ListPersons();
            StreamReader streamReader = new StreamReader(fileName);

            while ((str = streamReader.ReadLine()) != null)
            {
                Person person = new Person();
                person.FromCSV(str);
                listPersons.Add(person);
            }
            streamReader.Close();

            return listPersons;
        }