Пример #1
0
        public void CompleteItem(T item)
        {
            item.IsCompleted = true;
            if (typeof(T).Equals(typeof(MessageModel)))
            {
                MessageModel message = item as MessageModel;
                if (message == null)
                {
                    return;
                }

                using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                {
                    List <MessageModel> taskList = new List <MessageModel>(message.TaskItemList);
                    foreach (MessageModel taskItem in taskList)
                    {
                        context.Attach <MessageModel>(taskItem);
                        taskItem.IsCompleted = true;
                    }

                    context.Attach <MessageModel>(message);
                    message.IsCompleted = true;
                    context.SubmitChanges();

                    if (message.Recipient != null)
                    {
                        this.SendChanges(message);
                    }
                }
            }
        }
Пример #2
0
        public void SetItemOrder(T itemToSet, T itemBefore, T itemAfter, bool save = false)
        {
            this.HasChanged = true;
            if (!save)
            {
                itemToSet.ItemOrder = this.GetItemOrder(itemBefore, itemAfter);
                return;
            }

            if (typeof(T).Equals(typeof(MessageModel)))
            {
                MessageModel message = itemToSet as MessageModel;
                if (message == null)
                {
                    return;
                }

                using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                {
                    context.Attach <MessageModel>(message);
                    message.ItemOrder = this.GetItemOrder(itemBefore, itemAfter);
                    context.SubmitChanges();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// The logic to load messages is as follows:
        /// 1. Load all the messages in the last one week
        /// 2. Load at least 30 messages
        /// 3. For older messages, show explore older messages
        /// </summary>
        internal void LoadMoreMessages()
        {
            if (this.noMoreMessages)
            {
                return;
            }

            DispatcherHelper.InvokeOnUiThread(() =>
            {
                lock (this)
                {
                    using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                    {
                        if (this.IsLoading)
                        {
                            return;
                        }

                        this.IsLoading  = true;
                        var newMessages = DataSync.Instance.GetMessagesOlderThan(context, this.conversationId, this.Messages[0]);

                        int count = this.AddMessages(newMessages);

                        if (count == 0)
                        {
                            this.noMoreMessages = true;
                        }

                        this.IsLoading = false;
                    }
                }
            },
                                              true /*background*/);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        internal void LoadMessagesForConversations()
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, f) =>
            {
                DispatcherHelper.InvokeOnUiThread(() =>
                {
                    lock (this)
                    {
                        using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                        {
                            var newMessages = DataSync.Instance.GetMessages(context, this.conversationId, 30);
                            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "ConversationMessagesViewModel::LoadMessagesForConversations", "start Add messages"));
                            this.AddMessages(newMessages);
                            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "ConversationMessagesViewModel::LoadMessagesForConversations", "End add messages"));

                            DataSync.Instance.SetLastReadTime(this.conversationId, DateTime.UtcNow, this.IsCurrentyViewing);
                        }
                    }
                });
            };

            worker.RunWorkerAsync();
        }
Пример #5
0
        public void DeleteItem(T item)
        {
            this.IsDeleted = true;
            if (typeof(T).Equals(typeof(MessageModel)))
            {
                MessageModel message = item as MessageModel;

                if (this.DeletedItems == null)
                {
                    this.DeletedItems = new List <MessageModel>();
                }

                if (message == null)
                {
                    return;
                }

                using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                {
                    context.Attach <MessageModel>(message);
                    context.DeleteOnSubmit <MessageModel>(message);
                    context.SubmitChanges();
                }

                this.DeletedItems.Add(message);
            }
        }
Пример #6
0
        public void Test_When_Called_With_Null_Options_Throw_Exceptions()
        {
            // ARRANGE
            using DataContextWrapper dataContextWrapper = new DataContextWrapper(TestUtils.DbContextOptions);

            // ACT
            dataContextWrapper.TestOnModelCreating(null);
        }
Пример #7
0
 protected void Application_Start()
 {
     Database.SetInitializer(new Models.PersonDbInitialization());
     DataContextWrapper.getInstance();
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
        public void Customize(IFixture fixture)
        {
            var db = fixture.Create<DataContext>();
            var wrapper = new DataContextWrapper(db);
            fixture.Register<IDataContextWrapper>(() => wrapper);

            var scopeFactory = new DataContextScopeFactory(wrapper);
            fixture.Register<IDataContextScopeFactory>(() => scopeFactory);
        }
        public void Customize(IFixture fixture)
        {
            var db      = fixture.Create <DataContext>();
            var wrapper = new DataContextWrapper(db);

            fixture.Register <IDataContextWrapper>(() => wrapper);

            var scopeFactory = new DataContextScopeFactory(wrapper);

            fixture.Register <IDataContextScopeFactory>(() => scopeFactory);
        }
Пример #10
0
        public void Test_With_PreConfiguration_Options()
        {
            // ARRANGE
            using DataContextWrapper contextWrapper = new DataContextWrapper(TestUtils.DbContextOptions);
            ModelBuilder modelBuilder = new ModelBuilder(new ConventionSet());

            // ACT
            contextWrapper.TestOnModelCreating(modelBuilder);

            // ASSERT
            Assert.IsTrue(true);
        }
Пример #11
0
        /// <summary>
        /// Read Messages from the database and convert them to conversations
        /// </summary>
        private void ReadConversationFromLocalDB()
        {
            using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
            {
                List <ConversationModel> conversationList = DataSync.Instance.GetConversations();

                if (this._conversations != null)
                {
                    foreach (ConversationModel cm in conversationList)
                    {
                        //ConversationModel  cm = DataSync.Instance.GetConversationFromMessage(context, m);

                        ConversationModel existing = this.GetConversationFromConversationId(cm.ConversationId);
                        if (existing != null)
                        {
                            if (existing.LastPostUtcTime < cm.LastPostUtcTime ||
                                string.Compare(existing.LastPostPreview, cm.LastPostPreview, StringComparison.OrdinalIgnoreCase) != 0 ||
                                existing.UnreadCount != cm.UnreadCount)
                            {
                                DispatcherHelper.InvokeOnUiThread(() =>
                                {
                                    this.Conversations.Remove(existing);
                                    this.Conversations.Add(cm);
                                });
                            }

                            continue;
                        }

                        int senderId = -1;
                        foreach (UserModel user in cm.ConversationParticipants)
                        {
                            if (user != null && user.Id != UserSettingsModel.Instance.UserId &&
                                (!cm.IsGroupConversation || user.UserType == UserType.Group))
                            {
                                senderId = user.Id;
                            }
                        }

                        if (!this.recipientConversationMap.ContainsKey(senderId))
                        {
                            this.recipientConversationMap.Add(senderId, cm);
                        }

                        DispatcherHelper.InvokeOnUiThread(() =>
                        {
                            this._conversations.Add(cm);
                        });
                    }
                }
            }
        }
Пример #12
0
        public ActionResult AddPerson(string name, string lastName, string age)
        {
            //       return View("Index");
            // return View("~/Views/Add/AddPerson.cshtml");
            Person person = new Person()
            {
                Name     = name,
                LastName = lastName,
                Age      = Int32.Parse(age),
                Time     = DateTime.Now,
            };

            DataContextWrapper.AddPerson(person);
            return(RedirectToAction("Index"));
        }
Пример #13
0
        public ActionResult EditPerson(int id, string name, string lastName, string age)
        {
            Person tmp = DataContextWrapper.FindId(id);

            Person person = new Person()
            {
                Id       = id,
                Name     = name != string.Empty ? name : tmp.Name,
                LastName = lastName != string.Empty ? lastName : tmp.LastName,
                Age      = age != string.Empty ? Int32.Parse(age) : tmp.Age,
                Time     = DateTime.Now,
            };

            DataContextWrapper.EditPerson(id, person);
            return(RedirectToAction("Index", "Home"));
        }
Пример #14
0
        public static void AddIsTaskMessage()
        {
            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                var messages = (from message in context.Table<MessageModel>()
                                where (message.MessageType != (long)MessageType.Conversation)
                                orderby message.PostDateTimeUtcTicks descending
                                select message);

                foreach (MessageModel message in messages)
                {
                    message.IsTaskMessage = (message.MessageFlags & MessageFlags.Task) == MessageFlags.Task;
                }

                context.SubmitChanges();
            }
        }
Пример #15
0
        public void DeleteItem(T item)
        {
            if (typeof(T).Equals(typeof(MessageModel)))
            {
                MessageModel message = item as MessageModel;
                if (message == null)
                {
                    return;
                }

                using (DataContextWrapper <YapperDataContext> context = new DataContextWrapper <YapperDataContext>())
                {
                    if (message.TaskItemList != null)
                    {
                        foreach (MessageModel taskItem in message.TaskItemList)
                        {
                            context.Attach <MessageModel>(taskItem);
                            context.DeleteOnSubmit <MessageModel>(taskItem);
                        }
                    }

                    var existingQuery = from m in context.Table <MessageModel>()
                                        where m.MessageId == message.MessageId
                                        select m;

                    MessageModel existing = existingQuery.FirstOrDefault();

                    if (existing != null)
                    {
                        context.DeleteOnSubmit <MessageModel>(existing);
                    }

                    context.SubmitChanges();
                    // send a message only if it is shared
                    if (message.Recipient != null)
                    {
                        this.SendChanges(message, true);
                    }
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Get the most recent 20 messages in a conversations
        /// </summary>
        /// <param name="conversationId">ConversationId</param>
        /// <returns></returns>
        public IEnumerable<MessageModel> GetMessagesOlderThan(DataContextWrapper<YapperDataContext> context, Guid conversationId, MessageModel oldMessage, int pageSize = 5)
        {
            lock (this)
            {
                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessagesOlderThan", "start"));
                var messages = (from message in context.Table<MessageModel>()
                                where (message.ConversationId == conversationId &&
                                       message.PostDateTimeUtcTicks <= oldMessage.PostDateTimeUtcTicks)
                                orderby message.PostDateTimeUtcTicks descending
                                select message).Take(pageSize);

                Dictionary<int, UserModel> userMessageCache = new Dictionary<int, UserModel>();
                foreach (MessageModel m in messages)
                {
                    UserModel senderUser = this.GetUser(m.SenderId);
                    if (senderUser == null)
                    {
                        senderUser = new UserModel() { Id = m.SenderId, Name = Strings.UnknownUser };
                    }

                    UserModel recipientUser = this.GetUser(m.RecipientId);
                    if (senderUser == null)
                    {
                        senderUser = new UserModel() { Id = m.RecipientId, Name = Strings.UnknownUser };
                    }

                    m.Sender = senderUser;
                    m.Recipient = recipientUser;
                }

                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessagesOlderThan", "end"));

                return messages;
            }
        }
Пример #17
0
        /// <summary>
        /// Get the most recent 20 messages in a conversations
        /// </summary>
        /// <param name="conversationId">ConversationId</param>
        /// <returns></returns>
        public List<MessageModel> GetMessagesNewerThan(long sinceUtcTime)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessagesOlderThan", "start"));
                    var messages = (from message in context.Table<MessageModel>()
                                    where (message.MessageFlags != MessageFlags.Task) &&
                                          (message.MessageFlags != MessageFlags.TaskItem) &&
                                          (message.MessageFlags != MessageFlags.TaskInfo) &&
                                          (message.ClientVisibleTimeTicks > sinceUtcTime)
                                    select message);

                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessagesOlderThan", "end"));

                    return messages.ToList();
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Get the most recent 20 messages in a conversations
        /// </summary>
        /// <param name="conversationId">ConversationId</param>
        /// <returns></returns>
        public MessageModel GetMessageFromClientId(Guid messageId, DataContextWrapper<YapperDataContext> context = null)
        {
            bool shouldDispose = false;
            if (context == null)
            {
                shouldDispose = true;
                context = new DataContextWrapper<YapperDataContext>();
            }

            try
            {
                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessage", "start"));
                var messages = (from message in context.Table<MessageModel>()
                                where (message.ClientMessageId == messageId)
                                select message);

                if (messages.Count<MessageModel>() != 0)
                {
                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessage", "end"));
                    MessageModel message = messages.FirstOrDefault<MessageModel>();
                    if (message != null)
                    {
                        message.Sender = this.GetUser(message.SenderId);
                        message.Recipient = this.GetUser(message.RecipientId);
                    }

                    return message;
                }

                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetMessage", "end"));
                return null;
            }
            finally
            {
                if (shouldDispose)
                {
                    context.Dispose();
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Get the most recent 20 messages in a conversations
        /// </summary>
        /// <param name="conversationId">ConversationId</param>
        /// <returns></returns>
        public List<MessageModel> GetAllTasks()
        {
            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetAllTasks", "start"));
                var messages = (from message in context.Table<MessageModel>()
                                where (message.MessageType != (long)MessageType.Conversation && message.IsTaskMessage == true)
                                orderby message.PostDateTimeUtcTicks descending
                                select message);

                foreach (MessageModel m in messages)
                {
                    UserModel senderUser = this.GetUser(m.SenderId, context);

                    UserModel recipientUser = this.GetUser(m.RecipientId, context);

                    if (senderUser != null)
                    {
                        m.Sender = senderUser;
                    }

                    if (recipientUser != null)
                    {
                        m.Recipient = recipientUser;
                    }
                }

                Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetAllTasks", "end"));

                return messages.ToList();
            }
        }
Пример #20
0
        /// <summary>
        /// Send new message
        /// </summary>
        public MessageModel CreateTask(MessageModel message)
        {
            if (!message.IsTaskMessage.Value && !message.IsTaskItemMessage)
            {
                return null;
            }

            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                context.Table<MessageModel>().InsertOnSubmit(message);

                context.SubmitChanges();
                Messenger.Default.Send<NewTaskSavedEvent>(new NewTaskSavedEvent() { Task = message });

                return message;
            }
        }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataContextScopeFactory"/> class.
 /// </summary>
 /// <param name="wrapper">The wrapper.</param>
 public DataContextScopeFactory(DataContextWrapper wrapper)
 {
     _wrapper = wrapper;
 }
Пример #22
0
        /// <summary>
        /// Read Messages from the database and convert them to conversations
        /// </summary>
        private void ReadConversationFromLocalDB()
        {
            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                List<ConversationModel> conversationList = DataSync.Instance.GetConversations();

                if (this._conversations != null)
                {
                    foreach (ConversationModel cm in conversationList)
                    {
                        //ConversationModel  cm = DataSync.Instance.GetConversationFromMessage(context, m);

                        ConversationModel existing = this.GetConversationFromConversationId(cm.ConversationId);
                        if (existing != null)
                        {
                            if (existing.LastPostUtcTime < cm.LastPostUtcTime ||
                                string.Compare(existing.LastPostPreview, cm.LastPostPreview, StringComparison.OrdinalIgnoreCase) != 0 ||
                                existing.UnreadCount != cm.UnreadCount)
                            {
                                DispatcherHelper.InvokeOnUiThread(() =>
                                    {
                                        this.Conversations.Remove(existing);
                                        this.Conversations.Add(cm);
                                    });

                            }

                            continue;
                        }

                        int senderId = -1;
                        foreach (UserModel user in cm.ConversationParticipants)
                        {
                            if (user != null && user.Id != UserSettingsModel.Instance.UserId &&
                                (!cm.IsGroupConversation || user.UserType == UserType.Group))
                            {
                                senderId = user.Id;
                            }
                        }

                        if (!this.recipientConversationMap.ContainsKey(senderId))
                        {
                            this.recipientConversationMap.Add(senderId, cm);
                        }

                        DispatcherHelper.InvokeOnUiThread(() =>
                            {
                                this._conversations.Add(cm);
                            });
                    }
                }
            }
        }
Пример #23
0
        public static void AddUnreadCount()
        {
            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                var messages = (from message in context.Table<MessageModel>()
                                where (message.MessageType == (long)MessageType.Conversation)
                                orderby message.PostDateTimeUtcTicks descending
                                select message);

                foreach (MessageModel message in messages)
                {
                    message.UnreadCount = 0;
                }

                context.SubmitChanges();
            }
        }
Пример #24
0
        /// <summary>
        /// The logic to load messages is as follows:
        /// 1. Load all the messages in the last one week
        /// 2. Load at least 30 messages
        /// 3. For older messages, show explore older messages
        /// </summary>
        internal void LoadMoreMessages()
        {
            if (this.noMoreMessages)
            {
                return;
            }

            DispatcherHelper.InvokeOnUiThread(() =>
            {
                lock (this)
                {
                    using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                    {
                        if (this.IsLoading)
                        {
                            return;
                        }

                        this.IsLoading = true;
                        var newMessages = DataSync.Instance.GetMessagesOlderThan(context, this.conversationId, this.Messages[0]);

                        int count = this.AddMessages(newMessages);

                        if (count == 0)
                        {
                            this.noMoreMessages = true;
                        }

                        this.IsLoading = false;
                    }
                }
            },
            true/*background*/);
        }
Пример #25
0
        public void SetTaskCompleted(Guid clientId)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    int i = 5;
                    while (i > 0)
                    {
                        try
                        {
                            MessageModel m = this.GetMessageFromClientId(clientId, context);
                            m.IsCompleted = true;
                            m.LastTaskUpdaterId = this.userSettings.Me.Id;
                            context.SubmitChanges();
                            break;
                        }
                        catch (ChangeConflictException ce)
                        {
                        }

                        --i;
                    }
                }
            }
        }
Пример #26
0
        public int GetUnreadCount(Guid conversationId)
        {
            using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
            {
                var conversation = from c in context.Table<MessageModel>()
                                   where c.MessageType == MessageType.Conversation &&
                                         c.ConversationId == conversationId
                                   orderby c.LastUpdateTimeUtcTicks descending
                                   select c;

                if (conversation.Any())
                {
                    MessageModel c = conversation.FirstOrDefault();
                    return (c != null && c.UnreadCount.HasValue) ? c.UnreadCount.Value : 0;
                }

                return 0;
            }
        }
Пример #27
0
        public List<MessageModel> GetTaskCount(long sinceUtcTicks)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetAllTasks", "start"));
                    var messages = (from message in context.Table<MessageModel>()
                                    where (message.MessageType != (long)MessageType.Conversation && (message.MessageFlags & MessageFlags.Task) == MessageFlags.Task &&
                                           message.ClientVisibleTimeTicks > sinceUtcTicks)
                                    select message);

                    return messages.ToList();
                }
            }
        }
Пример #28
0
        public IEnumerable<MessageModel> GetTaskItems(Guid taskId)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetTaskList", "start"));
                    var messages = (from message in context.Table<MessageModel>()
                                    where (((MessageModel)message).PollMessageId == taskId)
                                    select message);

                    foreach (MessageModel m in messages)
                    {
                        UserModel senderUser = this.GetUser(m.SenderId, context);

                        UserModel recipientUser = this.GetUser(m.RecipientId, context);

                        if (senderUser != null)
                        {
                            m.Sender = senderUser;
                        }

                        if (recipientUser != null)
                        {
                            m.Recipient = recipientUser;
                        }
                    }

                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync::GetTaskList", "end"));
                    return messages.ToList();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DataContextScopeFactory"/> class.
 /// </summary>
 /// <param name="wrapper">The wrapper.</param>
 public DataContextScopeFactory(DataContextWrapper wrapper)
 {
     _wrapper = wrapper;
 }
Пример #30
0
        public void SetLastReadTime(MessageModel message)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync", "Start update last read time"));

                    context.Attach<MessageModel>(message);
                    message.LastReadTime = DateTime.Now;
                    context.SubmitChanges();

                    Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "DataSync", "End update last read time"));
                }
            }
        }
Пример #31
0
 public ActionResult DeletePerson(int id)
 {
     DataContextWrapper.DeletePerson(id);
     return(RedirectToAction("Index"));
 }
Пример #32
0
        public void SetTaskName(MessageModel message, string name, Guid parentId)
        {
            lock (this)
            {
                using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                {
                    int i = 5;
                    while (i > 0)
                    {
                        try
                        {
                            MessageModel m = this.GetMessageFromClientId(message.ClientMessageId, context);
                            if (m == null)
                            {
                                context.InsertOnSubmit<MessageModel>(message);
                                m = message;
                            }
                            else if (!string.IsNullOrEmpty(m.TaskName))
                            {
                                m.LastTaskUpdaterId = UserSettingsModel.Instance.Me.Id;
                            }

                            m.TaskName = name;
                            m.PollMessageId = parentId;
                            m.ItemOrder = message.ItemOrder;
                            m.LastUpdateTime = DateTime.Now;
                            context.SubmitChanges();
                            break;
                        }
                        catch (ChangeConflictException ce)
                        {
                        }

                        --i;
                    }
                }
            }
        }
Пример #33
0
        /// <summary>
        /// 
        /// </summary>
        internal void LoadMessagesForConversations()
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (o, f) =>
            {
                DispatcherHelper.InvokeOnUiThread(() =>
                {
                    lock (this)
                    {
                        using (DataContextWrapper<YapperDataContext> context = new DataContextWrapper<YapperDataContext>())
                        {
                            var newMessages = DataSync.Instance.GetMessages(context, this.conversationId, 30);
                            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "ConversationMessagesViewModel::LoadMessagesForConversations", "start Add messages"));
                            this.AddMessages(newMessages);
                            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "ConversationMessagesViewModel::LoadMessagesForConversations", "End add messages"));

                            DataSync.Instance.SetLastReadTime(this.conversationId, DateTime.UtcNow, this.IsCurrentyViewing);
                        }
                    }
                });
            };

            worker.RunWorkerAsync();
        }