示例#1
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="direction">Направление</param>
 /// <param name="profile">Профиль</param>
 /// <param name="id">Номер индификации</param>
 public CDirectionWithProfile(CDirection direction, CProfile profile, int id)
 {
     _direction       = direction;
     _priorityProfile = new CPriorityProfile(profile);
     _id = id;
 }
示例#2
0
 /// <summary>
 /// Добавить в список приоритетов профиль
 /// </summary>
 /// <param name="profile">Профиль направления</param>
 public void AddProfile(CProfile profile)
 {
     _profiles.Add(profile);
 }
示例#3
0
        private void Load()
        {
            DataTable dataTableDirection = SelectQuery("SELECT DIRECTION.ID, DIRECTION.NAME, DIRECTION.CODE FROM DIRECTION");
            DataTable dataTableProfile   = SelectQuery("SELECT DIRECTION.ID, PROFILE.NAME, FACULTY.NAME, PROFILE.ID  FROM CATALOG " +
                                                       "JOIN DIRECTION ON CATALOG.ID_DIRECTION = DIRECTION.ID " +
                                                       "JOIN PROFILE ON CATALOG.ID_PROFILE = PROFILE.ID " +
                                                       "JOIN FACULTY ON PROFILE.ID_FACULTY = FACULTY.ID");

            CPriorityDirection priorityDirection;
            List <CDirection>  directions = new List <CDirection>();
            List <CProfile>    profiles   = new List <CProfile>();

            foreach (DataRow dataRowDirection in dataTableDirection.Rows)
            {
                directions.Add(new CDirection((string)dataRowDirection[1], (string)dataRowDirection[2]));
            }
            foreach (DataRow dataRowProfile in dataTableProfile.Rows)
            {
                profiles.Add(new CProfile((string)dataRowProfile[1], (string)dataRowProfile[2], Convert.ToInt32(dataRowProfile[3])));
            }

            List <CDirectionWithProfile> directionWithProfiles = new List <CDirectionWithProfile>();

            for (int i = 0; i < profiles.Count; i++)
            {
                if (directionWithProfiles.Count != 0)
                {
                    if (directionWithProfiles[directionWithProfiles.Count - 1].ID == Convert.ToInt32(dataTableProfile.Rows[i].ItemArray[0]))
                    {
                        directionWithProfiles[directionWithProfiles.Count - 1].PriorityProfile.AddProfile(profiles[i]);
                        continue;
                    }
                }
                CDirection            direction            = directions[Convert.ToInt32(dataTableProfile.Rows[i].ItemArray[0])];
                CProfile              profile              = profiles[i];
                int                   id                   = Convert.ToInt32(dataTableProfile.Rows[i].ItemArray[0]);
                CDirectionWithProfile directionWithProfile = new CDirectionWithProfile(direction, profile, id);
                directionWithProfiles.Add(directionWithProfile);
            }

            priorityDirection = new CPriorityDirection(directionWithProfiles[0]);
            for (int i = 1; i < directionWithProfiles.Count; i++)
            {
                priorityDirection.AddDirection(directionWithProfiles[i]);
            }

            СBasketUserControl basketUserControl = new СBasketUserControl(priorityDirection, true);

            basketUserControl.HorizontalAlignment = HorizontalAlignment.Left;
            basketUserControl.VerticalAlignment   = VerticalAlignment.Top;
            basketUserControl.Margin = new Thickness(0, 79, 0, 0);

            basketUserControl.SetSizeHorizontsly(390);
            basketUserControl.SetSizeVerticals(Height - 150);

            basketUserControl.ButtonAdd += TransferDirectionWithProfile;
            _basketUserControls.Add(basketUserControl);
            ((Grid)this.Content).Children.Add(basketUserControl);

            basketUserControl = new СBasketUserControl();
            basketUserControl.HorizontalAlignment = HorizontalAlignment.Left;
            basketUserControl.VerticalAlignment   = VerticalAlignment.Top;
            basketUserControl.Margin = new Thickness(390, 79, 0, 0);

            basketUserControl.SetSizeHorizontsly(390);
            basketUserControl.SetSizeVerticals(Height - 150);

            basketUserControl.ButtonAdd += TransferDirectionWithProfile;
            _basketUserControls.Add(basketUserControl);
            ((Grid)this.Content).Children.Add(basketUserControl);
        }
示例#4
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="profile">Профиль направления</param>
 public CPriorityProfile(CProfile profile)
 {
     _profiles = new List <CProfile>();
     _profiles.Add(profile);
 }
示例#5
0
        /// <summary>
        /// Получить информацию профиля
        /// </summary>
        /// <param name="index">Приоритетный номер</param>
        /// <returns>Профиль</returns>
        public CProfile GetProfile(int index)
        {
            CProfile profile = _profiles[index - 1];

            return(new CProfile(profile.Name, profile.Faculty, profile.ID));
        }
示例#6
0
        public static bool SendProfileData(SProfileData profile)
        {
            CProfile newProfile;
            CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);

            if (existingProfile != null)
            {
                newProfile = new CProfile
                {
                    ID         = existingProfile.ID,
                    FilePath   = existingProfile.FilePath,
                    Active     = existingProfile.Active,
                    Avatar     = existingProfile.Avatar,
                    Difficulty = existingProfile.Difficulty,
                    UserRole   = existingProfile.UserRole,
                    PlayerName = existingProfile.PlayerName
                };
            }
            else
            {
                newProfile = new CProfile
                {
                    Active   = EOffOn.TR_CONFIG_ON,
                    UserRole = EUserRole.TR_USERROLE_NORMAL
                };
            }

            if (profile.Avatar != null)
            {
                newProfile.Avatar = _AddAvatar(profile.Avatar);
            }
            else if (newProfile.Avatar == null || newProfile.Avatar.ID == -1)
            {
                newProfile.Avatar = CProfiles.GetAvatars().First();

                /*CAvatar avatar = new CAvatar(-1);
                 * avatar.LoadFromFile("Profiles\\Avatar_f.png");
                 * CProfiles.AddAvatar(avatar);
                 * newProfile.Avatar = avatar;*/
            }

            if (!string.IsNullOrEmpty(profile.PlayerName))
            {
                newProfile.PlayerName = profile.PlayerName;
            }
            else if (!string.IsNullOrEmpty(newProfile.PlayerName))
            {
                newProfile.PlayerName = "DummyName";
            }

            if (profile.Difficulty >= 0 && profile.Difficulty <= 2)
            {
                newProfile.Difficulty = (EGameDifficulty)profile.Difficulty;
            }

            if (profile.Type >= 0 && profile.Type <= 1)
            {
                EUserRole option = profile.Type == 0 ? EUserRole.TR_USERROLE_GUEST : EUserRole.TR_USERROLE_NORMAL;
                //Only allow the change of TR_USERROLE_GUEST and TR_USERROLE_NORMAL
                const EUserRole mask = EUserRole.TR_USERROLE_NORMAL;
                newProfile.UserRole = (newProfile.UserRole & mask) | option;
            }

            if (!string.IsNullOrEmpty(profile.Password))
            {
                if (profile.Password == "***__CLEAR_PASSWORD__***")
                {
                    newProfile.PasswordSalt = null;
                    newProfile.PasswordHash = null;
                }
                else
                {
                    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                    byte[] buffer = new byte[32];
                    rng.GetNonZeroBytes(buffer);
                    byte[] salt           = buffer;
                    byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(profile.Password), salt);

                    newProfile.PasswordSalt = salt;
                    newProfile.PasswordHash = hashedPassword;
                }
            }

            if (existingProfile != null)
            {
                CProfiles.EditProfile(newProfile);
                CProfiles.Update();
                CProfiles.SaveProfiles();
            }
            else
            {
                CProfiles.AddProfile(newProfile);
            }

            return(true);
        }
示例#7
0
        public static void Update()
        {
            lock (_QueueMutex)
            {
                while (_Queue.Count > 0)
                {
                    SChange change = _Queue.Dequeue();
                    switch (change.Action)
                    {
                    case EAction.LoadProfiles:
                        _LoadProfiles();
                        _ProfilesChanged = true;
                        _AvatarsChanged  = true;
                        break;

                    case EAction.LoadAvatars:
                        _LoadAvatars();
                        _AvatarsChanged = true;
                        break;

                    case EAction.AddProfile:
                        CProfile newProf = change.Profile;
                        if (newProf == null)
                        {
                            break;
                        }

                        newProf.ID = Guid.NewGuid();
                        if (newProf.Avatar == null)
                        {
                            newProf.Avatar = _Avatars.Values.First();
                        }
                        else if (newProf.Avatar.ID < 0)
                        {
                            newProf.Avatar.ID = _AvatarIDs.Dequeue();
                            _Avatars.Add(newProf.Avatar.ID, newProf.Avatar);
                            _AvatarsChanged = true;
                        }
                        newProf.SaveProfile();
                        _Profiles.Add(newProf.ID, newProf);

                        _ProfilesChanged = true;
                        break;

                    case EAction.EditProfile:
                        if (change.Profile == null)
                        {
                            break;
                        }

                        if (!IsProfileIDValid(change.Profile.ID))
                        {
                            return;
                        }

                        _Profiles[change.Profile.ID] = change.Profile;
                        _ProfilesChanged             = true;
                        break;

                    case EAction.DeleteProfile:
                        if (!IsProfileIDValid(change.ProfileID))
                        {
                            break;
                        }

                        _DeleteProfile(change.ProfileID);
                        _ProfilesChanged = true;
                        break;

                    case EAction.AddAvatar:
                        if (change.Avatar == null)
                        {
                            break;
                        }

                        change.Avatar.ID = _AvatarIDs.Dequeue();
                        _Avatars.Add(change.Avatar.ID, change.Avatar);
                        _AvatarsChanged = true;
                        break;

                    case EAction.EditAvatar:
                        if (change.Avatar == null)
                        {
                            break;
                        }

                        if (!IsAvatarIDValid(change.Avatar.ID))
                        {
                            return;
                        }

                        _Avatars[change.Avatar.ID] = change.Avatar;
                        _AvatarsChanged            = true;
                        break;
                    }
                }
            }

            if (_ProfileChangedCallbacks.Count == 0)
            {
                return;
            }

            var flags = EProfileChangedFlags.None;

            if (_AvatarsChanged)
            {
                flags = EProfileChangedFlags.Avatar;
            }

            if (_ProfilesChanged)
            {
                flags |= EProfileChangedFlags.Profile;
            }

            if (flags != EProfileChangedFlags.None)
            {
                int index = 0;
                while (index < _ProfileChangedCallbacks.Count)
                {
                    try
                    {
                        _ProfileChangedCallbacks[index](flags);
                    }
                    catch (Exception)
                    {
                        _ProfileChangedCallbacks.RemoveAt(index);
                    }
                    index++;
                }
            }
            _AvatarsChanged  = false;
            _ProfilesChanged = false;
        }
示例#8
0
 private static int _AlphaNumericCompareByPlayerName(CProfile a, CProfile b)
 {
     return(_PadNumbersInString(a.PlayerName).CompareTo(_PadNumbersInString(b.PlayerName)));
 }
示例#9
0
        private async static void _LoadProfiles()
        {
            _LoadAvatars();

            var knownFiles = new List <string>();

            if (_Profiles.Count > 0)
            {
                var ids = new Guid[_Profiles.Keys.Count];
                _Profiles.Keys.CopyTo(ids, 0);
                foreach (Guid id in ids)
                {
                    if (_Profiles[id].LoadProfile())
                    {
                        knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath));
                    }
                    else
                    {
                        _Profiles.Remove(id);
                    }
                }
            }

            if (CConfig.UseCloudServer)
            {
                string json = JsonConvert.SerializeObject(new { Key = CConfig.CloudServerKey });

                var    content        = new StringContent(json, Encoding.UTF8, "application/json");
                string responseString = "";
                var    response       = await _Client.PostAsync(CConfig.CloudServerURL + "/api/getProfiles", content);

                responseString = await response.Content.ReadAsStringAsync();

                CProfile[] CloudProfiles = JsonConvert.DeserializeObject <CProfile[]>(responseString);
                Console.Write(CloudProfiles);
                foreach (CProfile profile in CloudProfiles)
                {
                    _Profiles.Add(profile.ID, profile);
                }
            }
            else
            {
                var files = new List <string>();

                foreach (string path in CConfig.ProfileFolders)
                {
                    files.AddRange(CHelper.ListFiles(path, "*.xml", true, true));
                }

                foreach (string file in files)
                {
                    if (knownFiles.Contains(Path.GetFileName(file)))
                    {
                        continue;
                    }

                    var profile = new CProfile();

                    if (profile.LoadProfile(file))
                    {
                        _Profiles.Add(profile.ID, profile);
                    }
                }
            }
            _ProfilesChanged = true;
        }
示例#10
0
 private static int _CompareByPlayerName(CProfile a, CProfile b)
 {
     return(String.CompareOrdinal(a.PlayerName, b.PlayerName));
 }