예제 #1
0
        private void PostSave()
        {
            CleanSerializableFile(Properties.Resources.PreviewSavePath);

            UserPreviewSerializableList prev = GetPreviewSerList();

            //try {
            //    foreach (var inneritem in this.PreviewsPanel.Children) {
            //        if (inneritem is UserDialogPreviewButton) {
            //            UserDialogPreviewButton item = inneritem as UserDialogPreviewButton;
            //            prev.userPreviewSerializables.Add(new UserPreviewSerializable() { ID = item.ID, PhoneNumber = item.PhoneNumber, PictureURL = item.PictureURL, UserName = item.UserName });
            //        }
            //    }

            //}
            //catch (Exception ex) {
            //    MessageBox.Show(ex.Message);
            //}

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserPreviewSerializableList));

            using (FileStream fs = new FileStream(Properties.Resources.PreviewSavePath, FileMode.OpenOrCreate))
            {
                xmlSerializer.Serialize(fs, prev);
            }
        }
예제 #2
0
        public static UserPreviewSerializableList GetPreviewListInfo()
        {
            UserPreviewSerializableList userPreviewSerializableList = new UserPreviewSerializableList();

            XmlSerializer formatter = new XmlSerializer(typeof(UserPreviewSerializableList));

            using (FileStream fs = new FileStream(Properties.Resources.PreviewSavePath, FileMode.OpenOrCreate)) {
                userPreviewSerializableList = (UserPreviewSerializableList)formatter.Deserialize(fs);
            }

            return(userPreviewSerializableList);
        }
예제 #3
0
        public static void UpdatePreviewByMsg(UserPreviewSerializableList userPreviewSerializableList)
        {
            UserPreviewSerializableList uPSL = userPreviewSerializableList;

            if (File.Exists(Properties.Resources.PreviewSavePath))
            {
                File.Delete(Properties.Resources.PreviewSavePath);
            }

            XmlSerializer formatter = new XmlSerializer(typeof(UserPreviewSerializableList));

            using (FileStream fs = new FileStream(Properties.Resources.PreviewSavePath, FileMode.OpenOrCreate)) {
                formatter.Serialize(fs, uPSL);
            }
        }
예제 #4
0
        private UserPreviewSerializableList GetPreviewSerList(long ID = long.MaxValue, Message msg = null)
        {
            UserPreviewSerializableList userPreviewSerializableList = new UserPreviewSerializableList();

            try
            {
                foreach (var inneritem in this.PreviewsPanel.Children)
                {
                    if (inneritem is UserDialogPreviewButton)
                    {
                        UserDialogPreviewButton item = inneritem as UserDialogPreviewButton;
                        UserPreviewSerializable userPreviewSerializable = new UserPreviewSerializable()
                        {
                            ID          = item.ID,
                            PhoneNumber = item.PhoneNumber,
                            PictureURL  = item.PictureURL,
                            UserName    = item.UserName,
                            LastMSG     = new Message()
                            {
                                SendDateTime = item.DateTimePreviewer, MessageText = item.TextPreview, MessageContentUrl = item.PictureURL, SenderName = item.UserName, MyTurn = item.MyTurn
                            }
                        };
                        userPreviewSerializableList.userPreviewSerializables.Add(userPreviewSerializable);
                        if (ID != long.MaxValue)
                        {
                            userPreviewSerializable.LastMSG = msg;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(userPreviewSerializableList);
        }