示例#1
0
 public void SetUserInfoEx(UserInfoEx info)
 {
     bigAvatarPanel.BackgroundImage = info.AvatarBig;
     smallAvatarPanel.BackgroundImage = info.AvatarSmall;
     aboutRichTextBox.Text = info.About;
     ContactListUtils.UnpackContacts(info.Contacts, contactsListView);
 }
示例#2
0
        public void GetUserInfo()
        {
            dbInfo = new UserInfoEx
            {
                Id = 1,
                AvatarBigFileName = "AvatarBig.png",
                AvatarSmallFileName = "AvatarSmall.png",
                AboutFileName = "About.rtf",
                Contacts = "*****@*****.**",
                AvatarBig = SystemIcons.Information.ToBitmap(),
                AvatarSmall = SystemIcons.Warning.ToBitmap(),
                About = "About"
            };

            cache = new UserInfoExCache(source.Object);
            var path = ExecutablePath.ExecPath + "\\files";
            Assert.IsTrue(Directory.Exists(path), "cache directory " + path + " not found");

            // 1st test
            // db with 3 files, cache is empty
            calls.Clear();
            cache.GetUserInfo(1);
            Assert.AreEqual(4, calls.Count, "1: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "1: GetUserBriefInfo not found");
            Assert.IsTrue(calls.Contains("ReadFile " + dbInfo.AvatarBigFileName), "1: ReadFile AvatarBigFileName not found");
            Assert.IsTrue(calls.Contains("ReadFile " + dbInfo.AvatarSmallFileName), "1: ReadFile AvatarSmallFileName not found");
            Assert.IsTrue(calls.Contains("ReadFile " + dbInfo.AboutFileName), "1: ReadFile AboutFileName not found");

            // 2nd test
            // db with 3 files, cache is filled
            calls.Clear();
            cache.GetUserInfo(1);
            Assert.AreEqual(1, calls.Count, "2: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "2: GetUserBriefInfo not found");

            // 3rd test
            // 1 file is changed in db, cache is filled
            dbInfo.AvatarBig = SystemIcons.Error.ToBitmap();
            calls.Clear();
            cache.GetUserInfo(1);
            Assert.AreEqual(2, calls.Count, "3: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "3: GetUserBriefInfo not found");
            Assert.IsTrue(calls.Contains("ReadFile " + dbInfo.AvatarBigFileName), "3: ReadFile AvatarBigFileName not found");

            // 4th test
            // 1 file deleted from db, then added, cache is filled
            dbInfo.AvatarBigFileName = null;
            dbInfo.AvatarBig = null;
            calls.Clear();
            cache.GetUserInfo(1);
            Assert.AreEqual(1, calls.Count, "4.1: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "4.1: GetUserBriefInfo not found");
            calls.Clear();
            dbInfo.AvatarBigFileName = "AvatarBig.png";
            dbInfo.AvatarBig = SystemIcons.Error.ToBitmap();
            cache.GetUserInfo(1);
            Assert.AreEqual(1, calls.Count, "4.2: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "4.2: GetUserBriefInfo not found");
        }
示例#3
0
 public UserInfoEx GetUserInfo()
 {
     var result = new UserInfoEx();
     var rows = userInfoFastGrid.GetRowValues<Cortege2<string, string>>(false).ToList();
     result.Id = rows.FirstOrDefault(pair => pair.a == "ID").b.ToInt(0);
     result.AvatarBig = bigAvatarPanel.BackgroundImage as Bitmap;
     result.AvatarSmall = smallAvatarPanel.BackgroundImage as Bitmap;
     result.About = aboutRichTextBox.Text;
     result.Contacts = ContactListUtils.PackContacts(contactsListView);
     return result;
 }
示例#4
0
 private void OnUserInfoExReceive(UserInfoEx info)
 {
     if (info == null)
         return;
     var form = new UserInfoForm();
     var user = AllUsers.Instance.GetUser(info.Id) ?? new User {ID = info.Id};
     form.SetUser(user);
     form.SetUserInfoEx(info);
     //form.SetReadOnly(engine.CurrentUserId != info.Id);
     form.SetReadOnly(true);
     if (form.ShowDialog(this) == DialogResult.Cancel)
         return;
     engine.SetUserInfoEx(form.GetUserInfo());
 }
示例#5
0
 private void UserInfoExReceived(UserInfoEx info)
 {
     if (isStopping)
         return;
     try
     {
         BeginInvoke(new Action<UserInfoEx>(OnUserInfoExReceive), info);
     }
     catch (Exception)
     {
     }
 }
示例#6
0
 private UserInfoEx SetUserInfo(UserInfoEx info)
 {
     calls.Add(string.Format("SetUserInfo {0}", info.Id));
     if (info.Id != dbInfo.Id)
         return null;
     if (info.AvatarBigHashCode != dbInfo.AvatarBigHashCode)
         dbInfo.AvatarBig = info.AvatarBig;
     if (info.AvatarSmallHashCode != dbInfo.AvatarSmallHashCode)
         dbInfo.AvatarSmall = info.AvatarSmall;
     if (info.AboutHashCode != dbInfo.AboutHashCode)
         dbInfo.About = info.About;
     dbInfo.Contacts = info.Contacts;
     if (dbInfo.AvatarBig != null)
     {
         if (string.IsNullOrEmpty(dbInfo.AvatarBigFileName))
             dbInfo.AvatarBigFileName = "AvatarBig.png";
     }
     else
         dbInfo.AvatarBigFileName = null;
     if (dbInfo.AvatarSmall != null)
     {
         if (string.IsNullOrEmpty(dbInfo.AvatarSmallFileName))
             dbInfo.AvatarSmallFileName = "AvatarSmall.png";
     }
     else
         dbInfo.AvatarBigFileName = null;
     if (dbInfo.About != null)
     {
         if (string.IsNullOrEmpty(dbInfo.AboutFileName))
             dbInfo.AboutFileName = "About.png";
     }
     else
         dbInfo.AboutFileName = null;
     var result = new UserInfoEx
         {
             Id = dbInfo.Id,
             AvatarBigFileName = dbInfo.AvatarBigFileName,
             AvatarSmallFileName = dbInfo.AvatarSmallFileName,
             AboutFileName = dbInfo.AboutFileName,
             Contacts = dbInfo.Contacts,
             AvatarBigHashCode = dbInfo.AvatarBigHashCode,
             AvatarSmallHashCode = dbInfo.AvatarSmallHashCode,
             AboutHashCode = dbInfo.AboutHashCode
         };
     return result;
 }
示例#7
0
        public void SetVoidUserInfo()
        {
            var sourceVoid1 = new Mock<IAccountStatistics>();
            sourceVoid1.Setup(s => s.GetUserInfo(It.IsAny<int>())).Returns<int>(GetUserInfo);
            sourceVoid1.Setup(s => s.GetUsersBriefInfo(It.IsAny<List<int>>())).Returns<List<int>>(ids =>
            {
                calls.Add(string.Format("GetUserBriefInfo {0}", 1));
                return null;
            });
            sourceVoid1.Setup(s => s.SetUserInfo(It.IsAny<UserInfoEx>())).Returns<UserInfoEx>(SetUserInfo);
            sourceVoid1.Setup(s => s.ReadFiles(It.IsAny<List<string>>())).Returns<List<string>>(names => null);
            sourceVoid1.Setup(s => s.WriteFile(It.IsAny<string>(), It.IsAny<byte[]>())).Returns<string, byte[]>(WriteFile);

            cache = new UserInfoExCache(sourceVoid1.Object);

            calls.Clear();
            cache.SetUserInfo(new UserInfoEx
            {
                Id = 1,
                Contacts = "*****@*****.**",
                AvatarBig = SystemIcons.Information.ToBitmap(),
                AvatarSmall = SystemIcons.Warning.ToBitmap(),
                About = "About"
            });

            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "2: GetUserBriefInfo not found");

            dbInfo = new UserInfoEx
            {
                Id = 1,
                AvatarBigFileName = "AvatarBig.png",
                AboutFileName = "About.rtf",
                Contacts = "*****@*****.**",
                AvatarBig = SystemIcons.Information.ToBitmap(),
                AvatarSmall = SystemIcons.Warning.ToBitmap(),
                About = "About"
            };
            sourceVoid1.Setup(s => s.GetUsersBriefInfo(It.IsAny<List<int>>())).Returns<List<int>>(GetUsersBriefInfo);
            cache = new UserInfoExCache(sourceVoid1.Object);
            cache.SetUserInfo(new UserInfoEx
            {
                Id = 1,
                Contacts = "*****@*****.**",
                AvatarBig = SystemIcons.Information.ToBitmap(),
                AvatarSmall = SystemIcons.Warning.ToBitmap(),
                About = "About"

            });
        }
示例#8
0
        public void SetUserInfo()
        {
            cache = new UserInfoExCache(source.Object);
            dbInfo = new UserInfoEx {Id = 1};
            var info = new UserInfoEx
                {
                    Id = 1,
                    Contacts = "*****@*****.**",
                    AvatarBig = SystemIcons.Information.ToBitmap(),
                    AvatarSmall = SystemIcons.Warning.ToBitmap(),
                    About = "About"
                };

            // 1st test
            // db is empty, cache is empty
            calls.Clear();
            cache.SetUserInfo(info); // info with 3 files
            Assert.AreEqual(2, calls.Count, "1: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "1: GetUserBriefInfo not found");
            Assert.IsTrue(calls.Contains("SetUserInfo 1"), "1: SetUserInfo not found");

            // 2nd test
            // db with 3 files, cache is filled
            info.AvatarBig = SystemIcons.Error.ToBitmap();
            calls.Clear();
            cache.SetUserInfo(info); // info with 3 files, 1 file changed
            Assert.AreEqual(3, calls.Count, "2: request count mismatch");
            Assert.IsTrue(calls.Contains("GetUserBriefInfo 1"), "2: GetUserBriefInfo not found");
            Assert.IsTrue(calls.Contains("WriteFile " + dbInfo.AvatarBigFileName), "2: GetUserBriefInfo not found");
            Assert.IsTrue(calls.Contains("SetUserInfo 1"), "2: SetUserInfo not found");

            // 3rd test
            // db with 3 files, cache is filled
            info.AvatarBig = null;
            info.AvatarSmall = null;
            info.About = null;
            calls.Clear();
            cache.SetUserInfo(info); // info with no files
            Assert.AreEqual(1, calls.Count, "3: request count mismatch");
            Assert.IsTrue(calls.Contains("SetUserInfo 1"), "3: SetUserInfo not found");
        }
 private UserInfoEx CreateUserInfoEx(USER_INFO info, bool full)
 {
     var result = new UserInfoEx();
     result.Id = info.Id;
     result.AvatarBigFileName = info.AvatarBig;
     // if full reading is enabled, then hash codes will be set automatically with setting data
     if (info.FILE_BIG != null)
     {
         if (full)
             result.AvatarBigData = info.FILE_BIG.Data;
         else
             result.AvatarBigHashCode = info.FILE_BIG.HashCode ?? UserInfoEx.ComputeHash(result.AvatarBigData);
     }
     result.AvatarSmallFileName = info.AvatarSmall;
     if (info.FILE_SMALL != null)
     {
         if (full)
             result.AvatarSmallData = info.FILE_SMALL.Data;
         else
             result.AvatarSmallHashCode = info.FILE_SMALL.HashCode ?? UserInfoEx.ComputeHash(result.AvatarSmallData);
     }
     result.AboutFileName = info.About;
     if (info.FILE_ABOUT != null)
     {
         if (full)
             result.AboutData = info.FILE_ABOUT.Data;
         else
             result.AboutHashCode = info.FILE_ABOUT.HashCode ?? UserInfoEx.ComputeHash(result.AboutData);
     }
     result.Contacts = info.Contacts;
     return result;
 }
示例#10
0
 public void SetUserInfoEx(UserInfoEx info)
 {
     QueueRequest(new ChatRequest(RequestCode.SetUserInfoEx, new List<object> {info}, -1));
 }
 // если файловые данные (аватары, текст) не меняются, то передается null и действительная хеш-сумма
 public UserInfoEx SetUserInfo(UserInfoEx info)
 {
     UserInfoEx result;
     using (var context = DatabaseContext.Instance.Make())
     {
         try
         {
             var dbUserInfo = context.USER_INFO.Find(info.Id);
             var userInfoAdded = false;
             var fileChanged = false;
             if (dbUserInfo == null)
             {
                 dbUserInfo = new USER_INFO();
                 dbUserInfo.Id = info.Id;
                 userInfoAdded = true;
             }
             // big avatar
             if (dbUserInfo.AvatarBig == null)
             {
                 if (info.AvatarBig != null) // insert
                     dbUserInfo.AvatarBig = context.FILE.Add(CreateBitmap(info.AvatarBig)).Name;
             }
             else if (dbUserInfo.FILE_BIG.HashCode != info.AvatarBigHashCode)
                 if (info.AvatarBig == null) // delete
                 {
                     context.FILE.Remove(dbUserInfo.FILE_BIG);
                     dbUserInfo.AvatarBig = null;
                 }
                 else // update
                 {
                     if (UpdateBitmap(dbUserInfo.FILE_BIG, info.AvatarBig))
                         fileChanged = true;
                 }
             // small avatar
             if (dbUserInfo.AvatarSmall == null)
             {
                 if (info.AvatarSmall != null) // insert
                     dbUserInfo.AvatarSmall = context.FILE.Add(CreateBitmap(info.AvatarSmall)).Name;
             }
             else if (dbUserInfo.FILE_SMALL.HashCode != info.AvatarSmallHashCode)
                 if (info.AvatarSmall == null) // delete
                 {
                     context.FILE.Remove(dbUserInfo.FILE_SMALL);
                     dbUserInfo.AvatarSmall = null;
                 }
                 else // update
                 {
                     if (UpdateBitmap(dbUserInfo.FILE_SMALL, info.AvatarSmall))
                         fileChanged = true;
                 }
             // about
             if (dbUserInfo.About == null)
             {
                 if (info.About != null) // insert
                     dbUserInfo.About = context.FILE.Add(CreateText(info.About)).Name;
             }
             else if (dbUserInfo.FILE_ABOUT.HashCode != info.AboutHashCode)
                 if (info.About == null) // delete
                 {
                     context.FILE.Remove(dbUserInfo.FILE_ABOUT);
                     dbUserInfo.About = null;
                 }
                 else // update
                 {
                     if (UpdateText(dbUserInfo.FILE_ABOUT, info.About))
                         fileChanged = true;
                 }
             if(fileChanged)
                 context.SaveChanges();
             dbUserInfo.Contacts = info.Contacts;
             if (userInfoAdded)
                 context.USER_INFO.Add(dbUserInfo);
             context.SaveChanges();
             result = CreateUserInfoEx(dbUserInfo, false);
         }
         catch (Exception ex)
         {
             Logger.Error("AccountEfficiencyCache.SetUserInfo", ex);
             return null;
         }
     }
     return result;
 }
示例#12
0
        private void EditExisting()
        {
            var login = AccountStatus.Instance.Login;
            if (string.IsNullOrEmpty(login)) return;
            if (string.IsNullOrEmpty(oldPassword)) return;
            if (editedUser == null) return;
            if (editedAccount == null) return;

            // собрать данные
            var user = new PlatformUser
            {
                Email = tbEmail.Text,
                Login = tbLogin.Text,
                Name = tbName.Text,
                Surname = tbSurname.Text,
                Patronym = tbPatronym.Text,
                Phone1 = tbPhone1.Text,
                Phone2 = tbPhone2.Text,
                Description = tbDescription.Text,
                Password = tbPassword.Text
            };
            var maxLeverage = tbMaxLeverage.Text.ToFloatUniform();

            bool loginIsBusy;
            var resp = MainForm.serverProxyTrade.proxy.ModifyUserAndAccount(login, oldPassword,
                                                                              user, editedAccount.ID, maxLeverage, out loginIsBusy);
            if (loginIsBusy)
            {
                MessageBox.Show(string.Format(Localizer.GetString("MessageLoginInUse"), user.Login));
                return;
            }

            if (resp == AuthenticationResponse.AccountInactive ||
                resp == AuthenticationResponse.InvalidAccount ||
                resp == AuthenticationResponse.WrongPassword ||
                resp == AuthenticationResponse.ServerError)
            {
                var msg = Localizer.GetString("MessageUnableToUpdate") + " - " +
                    EnumFriendlyName<AuthenticationResponse>.GetString(resp);
                MessageBox.Show(msg, Localizer.GetString("TitleError"));
            }

            // обновить дополнительные данные о пользователе
            try
            {
                var userInfoExSource =
                    new UserInfoExCache(TradeSharpAccountStatistics.Instance.proxy, TerminalEnvironment.FileCacheFolder);
                var info = new UserInfoEx
                    {
                        Id = editedUser.ID,
                        AvatarBig = bigAvatarPanel.BackgroundImage as Bitmap,
                        AvatarSmall = smallAvatarPanel.BackgroundImage as Bitmap,
                        About = aboutRichTextBox.Text,
                        Contacts = ContactListUtils.PackContacts(contactsListView)
                    };
                userInfoExSource.SetUserInfo(info);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Localizer.GetString("TitleServerError"),
                    Localizer.GetString("TitleError"));
                Logger.Info("Ошбика при записи дополнительной информации о пользователе", ex);
                return;
            }
            MessageBox.Show(Localizer.GetString("MessageDataSuccessfulyUpdated"),
                Localizer.GetString("TitleConfirmation"),
                MessageBoxButtons.OK,
                MessageBoxIcon.Asterisk);
        }
示例#13
0
 private void UserInfoExReceivedInternal(UserInfoEx info)
 {
     if (UserInfoExReceived != null)
         UserInfoExReceived(info);
 }
示例#14
0
 public void SetUserInfoEx(UserInfoEx info)
 {
     chatSender.SetUserInfoEx(info);
 }
示例#15
0
        // изменение информации о пользователе
        public UserInfoEx SetUserInfo(UserInfoEx info)
        {
            UserInfoEx dbInfo;
            // делаем запрос на имена файлов, если файловые данные изменились, но не удалились
            if (info.AvatarBig != null && info.AvatarSmall != null && info.About != null)
            {
                var usersInfo = dataSource.GetUsersBriefInfo(new List<int> {info.Id});
                if (usersInfo == null || usersInfo.Count == 0)
                {
                    Logger.Info("UserInfoExCache.SetUserInfo: server error on GetUsersBriefInfo");
                    return null;
                }
                dbInfo = usersInfo[0] ?? info;
            }
            else
                dbInfo = info;

            // обновляем кэш для AvatarBig
            if (!string.IsNullOrEmpty(dbInfo.AvatarBigFileName) && info.AvatarBigData != null)
            {
                info.AvatarBigFileName = dbInfo.AvatarBigFileName;
                if (SetFile(info.AvatarBigFileName, info.AvatarBigData))
                {
                    // исключаем AvatarBig: будем передавать null и действительную хеш-сумму
                    var hashCode = info.AvatarBigHashCode;
                    info.AvatarBig = null;
                    info.AvatarBigHashCode = hashCode;
                }
            }

            // обновляем кэш для AvatarSmall
            if (!string.IsNullOrEmpty(dbInfo.AvatarSmallFileName) && info.AvatarSmallData != null)
            {
                info.AvatarSmallFileName = dbInfo.AvatarSmallFileName;
                if (SetFile(info.AvatarSmallFileName, info.AvatarSmallData))
                {
                        // исключаем AvatarSmall: будем передавать null и действительную хеш-сумму
                        var hashCode = info.AvatarSmallHashCode;
                        info.AvatarSmall = null;
                        info.AvatarSmallHashCode = hashCode;
                }
            }

            // обновляем кэш для About
            if (!string.IsNullOrEmpty(dbInfo.AboutFileName) && info.AboutData != null)
            {
                info.AboutFileName = dbInfo.AboutFileName;
                if (SetFile(info.AboutFileName, info.AboutData))
                {
                    // исключаем About: будем передавать null и действительную хеш-сумму
                    var hashCode = info.AboutHashCode;
                    info.About = null;
                    info.AboutHashCode = hashCode;
                }
            }

            var result = dataSource.SetUserInfo(info);
            // сервер на передал имена файлов
            if (info.AvatarBigData != null && string.IsNullOrEmpty(result.AvatarBigFileName) ||
                info.AvatarSmallData != null && string.IsNullOrEmpty(result.AvatarSmallFileName) ||
                info.AboutData != null && string.IsNullOrEmpty(result.AboutFileName))
            {
                Logger.Info("UserInfoExCache.SetUserInfo: server error on SetUserInfo");
                return result;
            }
            // сервер передал файловые данные
            if(result.AvatarBig != null || result.AvatarSmall != null || result.About != null)
            {
                Logger.Info("UserInfoExCache.SetUserInfo: server returned extra data on SetUserInfo");
            }

            // записываем файлы, которых раньше не было, и которым теперь сервер задал имена
            try
            {
                if (string.IsNullOrEmpty(dbInfo.AvatarBigFileName) && info.AvatarBigData != null)
                    File.WriteAllBytes(path + "\\" + result.AvatarBigFileName, info.AvatarBigData);
                if (string.IsNullOrEmpty(dbInfo.AvatarSmallFileName) && info.AvatarSmallData != null)
                    File.WriteAllBytes(path + "\\" + result.AvatarSmallFileName, info.AvatarSmallData);
                if (string.IsNullOrEmpty(dbInfo.AboutFileName) && info.About != null)
                    File.WriteAllBytes(path + "\\" + result.AboutFileName, info.AboutData);
            }
            catch (Exception ex)
            {
                Logger.Info("UserInfoExCache.SetUserInfo: error caching files", ex);
            }
            return result;
        }