Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var context    = new PhonebookEntities();
            var chanannels = context.Channels
                             .Select(c => new
            {
                c.Name,
                ChannelMessages = c.ChannelMessages.Select(m => new
                {
                    m.Content,
                    m.DateTime,
                    m.User.Username
                })
            })
                             .ToList();

            chanannels.ForEach(m =>
            {
                Console.WriteLine("{0}\n--Messages--", m.Name);
                var messages = m.ChannelMessages;
                foreach (var channelMessage in messages)
                {
                    Console.WriteLine("Content:{0},DateTime:{1:dd/MM/yyyy hh:mm:ss},User{2}",
                                      channelMessage.Content,
                                      channelMessage.DateTime,
                                      channelMessage.Username);
                }
            });
        }
Ejemplo n.º 2
0
        private static void ProcessMessage(PhonebookEntities context, JsonMessage messege)
        {
            if (messege.Content == null)
            {
                throw new ArgumentException("Content is required!");
            }

            if (messege.DateTime == null)
            {
                throw new ArgumentException("DateTime is required!");
            }

            if (messege.Recipient == null)
            {
                throw new ArgumentException("Recipient is required!");
            }

            if (messege.Sender == null)
            {
                throw new ArgumentException("Sender is required!");
            }

            var userMessage = new UserMessage()
            {
                Content = messege.Content,
                DateTime = (DateTime)messege.DateTime,
                Sender = context.Users.FirstOrDefault(u => u.Username == messege.Sender),
                Recipiant = context.Users.FirstOrDefault(u => u.Username == messege.Recipient),
            };

            context.UserMessages.AddOrUpdate(userMessage);
            context.SaveChanges();
            Console.WriteLine("Message \"{0}\" Imported", userMessage.Content);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var context = new PhonebookEntities();
            var chanannels = context.Channels
                .Select(c => new
                {
                    c.Name,
                    ChannelMessages = c.ChannelMessages.Select(m => new
                    {
                        m.Content,
                        m.DateTime,
                        m.User.Username
                    })
                })
                .ToList();

            chanannels.ForEach(m =>
            {
                Console.WriteLine("{0}\n--Messages--", m.Name);
                var messages = m.ChannelMessages;
                foreach (var channelMessage in messages)
                {
                    Console.WriteLine("Content:{0},DateTime:{1:dd/MM/yyyy hh:mm:ss},User{2}",
                        channelMessage.Content,
                        channelMessage.DateTime,
                        channelMessage.Username);
                }
            });
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            var context = new PhonebookEntities();

            var serializer = new JavaScriptSerializer();
            var json = File.ReadAllText("../../../messages.json");
            var messeges = serializer.Deserialize<JsonMessage[]>(json);
            foreach (var messege in messeges)
            {
                try
                {
                    ProcessMessage(context, messege);
                }
                catch (ArgumentException ex)
                {
                    Console.Error.WriteLine("Error: {0}", ex.Message);
                }
            }
        }