예제 #1
0
        public void SaveDataModel()
        {
            Properties.Settings.Default.RefreshMinutes = settings.RefreshMinutes;
            Properties.Settings.Default.RefreshSeconds = settings.RefreshSeconds;
            Properties.Settings.Default.ShowNotifications = settings.ShowNotifications;
            Properties.Settings.Default.RememberUser = settings.RememberUser;

            if (settings.RememberUser)
            {
                Properties.Settings.Default.Username = userModel.username;
                //dont hash an already hashed password
                if (Properties.Settings.Default.PasswordHash != userModel.password)
                {
                    Properties.Settings.Default.PasswordHash = Crypto.ComputeHash(userModel.password);
                }

                User userInfo = new User();
                userInfo.walls = userModel.walls;
                string userInfoString;
                if (JsonSerializer.Serialize<User>(userInfo, out userInfoString))
                {
                    if (!string.IsNullOrEmpty(userInfoString) && !string.IsNullOrEmpty(userModel.username))
                    {
                        Properties.Settings.Default.UserInfo = Crypto.EncryptStringAES(userInfoString, userModel.username);
                    }
                }
            }

            Properties.Settings.Default.Save();
        }
예제 #2
0
 public DataModel()
 {
     userModel = new Utils.User();
     settings = new MySettings();
 }
예제 #3
0
        public void MergeUserModel(User user)
        {
            if (user.date != null)
            {
                userModel.date = user.date;
            }

            if (user.walls != null)
            {
                if (userModel.walls == null)
                {
                    userModel.walls = new List<Wall>();
                }

                foreach (Wall wall in user.walls)
                {
                    Wall foundWall = WallExists(wall.name);
                    if (foundWall != null)
                    {
                        if (foundWall.messages == null)
                        {
                            foundWall.messages = new List<Message>();
                            continue;
                        }

                        foreach (Message mess in wall.messages)
                        {
                            if(!MessageExists(foundWall, mess.id))
                            {
                                foundWall.messages.Add(mess);
                            }
                        }
                    }
                    else
                    {
                        userModel.walls.Add(wall);
                    }
                }
            }
        }
예제 #4
0
        public Wall MergeAndReturnWallChanges(User user, string returnWallName)
        {
            Wall returnWall = new Wall();
            returnWall.messages = new List<Message>();

            if (user.date != null)
            {
                userModel.date = user.date;
            }

            if (user.walls != null)
            {
                if (userModel.walls == null)
                {
                    userModel.walls = new List<Wall>();
                }

                foreach (Wall wall in user.walls)
                {
                    Wall foundWall = WallExists(wall.name);
                    if (foundWall != null)
                    {
                        if (foundWall.messages == null)
                        {
                            foundWall.messages = new List<Message>();
                        }

                        bool addMessage = false;
                        if(wall.name.Equals(returnWallName))
                        {
                            addMessage = true;
                        }

                        if (wall.messages == null)
                        {
                            foundWall.messages = new List<Message>();
                            continue;
                        }

                        foreach (Message mess in wall.messages)
                        {
                            if (!MessageExists(foundWall, mess.id))
                            {
                                foundWall.messages.Add(mess);
                                if (addMessage)
                                {
                                    returnWall.messages.Add(mess);
                                }
                            }
                        }
                    }
                    else
                    {
                        userModel.walls.Add(wall);
                    }
                }
            }

            return returnWall;
        }
예제 #5
0
        private void OnCreateUserCompleted(RequestUser userRequest, ResponseJson response)
        {
            if (response.value.Equals("success"))
            {
                //reset text error
                createUserView.ErrorText = "";

                //create new user - response request doesn't contain usernames or passwords
                User createdUser = new User();
                createdUser.username = userRequest.username;
                createdUser.password = userRequest.password;
                createdUser.name = userRequest.name;

                //save new user data in model
                dataModel.User = createdUser;

                //load wallView
                parentView.CurrentChildView = wallView;
                wallView.AutoRefreshWorking = true;
            }
            else if (response.value.Equals("fail"))
            {
                createUserView.ErrorText = response.details;
            }
            else
            {
                createUserView.ErrorText = "Unexpected error";
            }
        }
예제 #6
0
        private void ManageNewMessagesNotification(User responseUser)
        {
            if (dataModel.Settings.ShowNotifications)
            {
                int nrNewMessages = 0;
                int nrWallsChanged = 0;
                string lastWallName = "";
                string notificationMessage = "";

                //calculate how many new messages
                if (responseUser.walls != null)
                {
                    foreach (Wall wall in responseUser.walls)
                    {
                        if (wall.messages != null)
                        {
                            if (wall.messages.Count > 0)
                            {
                                int nrOfMessagesFromOthers = 0;
                                foreach (Message mess in wall.messages)
                                {
                                    if (mess.author != dataModel.User.name)
                                    {
                                        nrOfMessagesFromOthers++;
                                    }
                                }

                                if (nrOfMessagesFromOthers > 0)
                                {
                                    nrWallsChanged++;
                                    lastWallName = wall.name;
                                    nrNewMessages += nrOfMessagesFromOthers;
                                }
                            }
                        }
                    }
                }

                //create notification message
                if(nrNewMessages > 0)
                {
                    if (nrNewMessages > 1)
                    {
                        notificationMessage += nrNewMessages.ToString() + " new messages on ";
                        if (nrWallsChanged > 1)
                        {
                            notificationMessage += lastWallName + " and other ";
                            if (nrWallsChanged > 2)
                            {
                                notificationMessage += (nrWallsChanged - 1).ToString() + " walls";
                            }
                            else
                            {
                                notificationMessage += "1 wall";
                            }
                        }
                        else
                        {
                            notificationMessage += lastWallName + " wall";
                        }
                    }
                    else
                    {
                        notificationMessage += "1 new message on " + lastWallName+" wall";
                    }

                    //show notification
                    parentView.ShowNotification(notificationMessage);
                }
            }
        }