Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            IPAddress  address  = IPAddress.Parse("127.0.0.1");
            IPEndPoint endPoint = new IPEndPoint(address, 22000);
            TcpClient  client   = new TcpClient();

            //Console.WriteLine("Нажмите кнопку чтобы подключиться");
            //Console.ReadKey();
            client.Connect(endPoint);
            BinaryFormatter formatter = new BinaryFormatter();

            while (true)
            {
                string            text    = Console.ReadLine();
                DataLayer.Message message = new DataLayer.Message
                {
                    Text = text,
                    Date = DateTime.Now
                };
                NetworkStream networkStream = client.GetStream();
                formatter.Serialize(networkStream, message);
                if (text == "exit")
                {
                    break;
                }
            }
            client.Close();
        }
        public void testNormalCase()
        {
            var bob = new User
            {
                Address = "11791",
                FirstName = "Bob",
                LastName = "ForApples",
                Age = 28,
                Gender = false,
                Photo = "APPLE.jpg",
                Deleted = false,
                InterestedIn = true,
                RegistrationDate = DateTime.Now,
                LastLoginDate = DateTime.Now,

            };
            var mark = new User
            {
                Address = "11791",
                FirstName = "Mark",
                LastName = "man",
                Age = 28,
                Gender = false,
                Photo = "MARK.jpg",
                Deleted = false,
                InterestedIn = true,
                RegistrationDate = DateTime.Now,
                LastLoginDate = DateTime.Now,

            };
            var msg = new Message
            {
                Text = "spaghetti",
                From = bob,
                To = mark,
                Date = DateTime.Now,
                Read = false
            };
            db.User.Add(mark);
            db.User.Add(bob);
            db.Messages.Add(msg);
            db.SaveChanges();

            msging.read(mark.Id, msg.Id);
            db = new YATContext();
            Message mess = db.Messages.Where(m => m.Id.Equals(msg.Id)).FirstOrDefault();
            Assert.IsTrue(mess.Read);

        }
        public void sendMessage(string toID, string fromID, string textToSend)
        {
            if (!isBlocked(toID, fromID))
            {
                var message = new Message
                {
                    Date = DateTime.Now,
                    Text = textToSend,
                    FromId = fromID,
                    ToId = toID,
                    Read = false
                };

                db.Messages.Add(message);
                db.SaveChanges();
            }
        }
        public ActionResult Create(Herundo.Models.MessageModel model)
        {
            try
            {
                if (model.Content.Length > 140)
                {
                    throw new Exception("Message can't be longer than 140 symbols");
                }
                Message newMsg = new Message(User.Identity.Name, model.Content, DateTime.Now, model.Location);
                db.AddTweet(newMsg);
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Messages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMessages(Message message)
 {
     base.AddObject("Messages", message);
 }
 /// <summary>
 /// Create a new Message object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 public static Message CreateMessage(global::System.Int32 id, global::System.String name, global::System.String text)
 {
     Message message = new Message();
     message.Id = id;
     message.Name = name;
     message.Text = text;
     return message;
 }
 public void AddTweet(Message tweet)
 {
     Tweets.Insert(tweet);
 }
        public void putData()
        {
            using (var dbContext = new YATContext())
            {
                User paul = dbContext.User.Where(p => p.FirstName.Contains("Paul")).FirstOrDefault();
                if (paul != null)
                {
                    return;
                }

                paul = new User
                {
                    Id = "1",
                    Address = "11791",
                    FirstName = "Paul",
                    LastName = "Sultan",
                    Age = 28,
                    Gender = true,
                    Deleted = false,
                    InterestedIn = false,
                    Photo = "male.jpg",
                    RegistrationDate = Convert.ToDateTime("01/11/2015"),
                    LastLoginDate = DateTime.Now,
                };
                var mike = new User
                {
                    Address = "11791",
                    FirstName = "Mike",
                    LastName = "Sultan",
                    Age = 28,
                    Gender = true,
                    Deleted = false,
                    InterestedIn = false,
                    Photo = "male.jpg",
                    RegistrationDate = Convert.ToDateTime("01/10/2015"),
                    LastLoginDate = DateTime.Now,
                };
                var sue = new User
                {
                    Address = "10010",
                    FirstName = "Sue",
                    LastName = "Flower",
                    Age = 28,
                    Gender = false,
                    Deleted = false,
                    InterestedIn = true,
                    Photo = "female.jpg",
                    RegistrationDate = Convert.ToDateTime("04/10/2015"),
                    LastLoginDate = DateTime.Now,
                };
                var Ariel = new User
                {
                    Id = "d",
                    Address = "94101",
                    FirstName = "Brad",
                    LastName = "Gabe",
                    Age = 30,
                    Gender = true,
                    Deleted = false,
                    InterestedIn = false,
                    Photo = "male.jpg",
                    RegistrationDate = Convert.ToDateTime("04/10/2015"),
                    LastLoginDate = DateTime.Now,
                };
                dbContext.User.Add(paul);
                dbContext.User.Add(mike);
                dbContext.User.Add(sue);
                dbContext.User.Add(Ariel);
            
                var gump = new Likes { Movie = "Forest Gump" };
                var nemo = new Likes { Movie = "Finding Nemo" };
                var avengers = new Likes { Movie = "Avengers" };
                mike.Likes.Add(nemo);
                mike.Likes.Add(gump);
                paul.Likes.Add(nemo);
                sue.Likes.Add(avengers);
                sue.Likes.Add(gump);

                Likes movie = dbContext.Likes.FirstOrDefault(L => L.Movie == "Avengers");
                Ariel.Likes.Add(movie);

                var sueConnection = new Connections { From = sue, To = mike, IsBlocked = true, IsRemoved=false };
                var sueConnection2 = new Connections { From = sue, To = paul, IsBlocked=false, IsRemoved = true };
                dbContext.Connections.Add(sueConnection);
                dbContext.Connections.Add(sueConnection2);
                
                var message = new Message
                {
                    Text = "Hi there",
                    From = mike,
                    To = sue,
                    Date = DateTime.Now,
                    Read = false
                };
                var reply = new Message
                {
                    Text = "Hello",
                    From = sue,
                    To = mike,
                    Date = DateTime.Now.AddMinutes(5),
                    Read = false
                };
                var repAgain = new Message
                {
                    Text = "wanna go program some tests??!?!!",
                    From = mike,
                    To = sue,
                    Date = DateTime.Now.AddMinutes(8),
                    Read = false
                };
                var anotherMessage = new Message
                {
                    Text = "something awesome",
                    From = Ariel,
                    To = sue,
                    Date = DateTime.Now,
                    Read = false
                };
                dbContext.Messages.Add(message);
                dbContext.Messages.Add(reply);
                dbContext.Messages.Add(repAgain);
                dbContext.SaveChanges();
            }
        }