public GameSettingsProfileBase CreateProfile(string name, string color, Guid parentId)
        {
            if (!(!string.IsNullOrWhiteSpace(name)))
            {
                throw new ArgumentNullException("!string.IsNullOrWhiteSpace(name)");
            }
            if (!(!string.IsNullOrWhiteSpace(color)))
            {
                throw new ArgumentNullException("!string.IsNullOrWhiteSpace(color)");
            }
            if (!(parentId != Guid.Empty))
            {
                throw new ArgumentNullException("parentId != Guid.Empty");
            }

            var parent = Profiles.First(x => x.Id == parentId);

            if (_profiles.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new ProfileWithSameNameAlreadyExistsException();
            }

            var profile = new GameSettingsProfile(name, color, parent);

            foreach (var gs in _gameSettings)
            {
                gs.Register(profile);
            }

            _profiles.Add(profile);
            ActiveProfile = profile;

            return(profile);
        }
 public GameSettingsController()
 {
     _profiles = new ReactiveList <GameSettingsProfileBase> {
         new GlobalGameSettingsProfile()
     };
     _activeProfile = _profiles.First();
     Profiles       = _profiles.CreateDerivedCollection(x => x);
     SetupRefresh();
 }
        public void ActivateProfile(Guid uuid)
        {
            if (!(uuid != Guid.Empty))
            {
                throw new ArgumentNullException("uuid != Guid.Empty");
            }

            ActiveProfile = _profiles.First(x => x.Id == uuid);
        }
Пример #4
0
        protected GameSettingsProfile(Guid id, string name, string color, GameSettingsProfileBase parent)
            : base(id, name, color)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            _parent = parent;

            SetupRefresh();
        }
        public void ActivateProfile(string name)
        {
            if (!(!string.IsNullOrWhiteSpace(name)))
            {
                throw new ArgumentNullException("!string.IsNullOrWhiteSpace(name)");
            }

            var profile = _profiles.First(x => x.Name == name);

            ActiveProfile = profile;
        }
        static IEnumerable <IGetData> GetAllProfiles(GameSettingsProfileBase activeProfile)
        {
            if (!(activeProfile != null))
            {
                throw new NullReferenceException("activeProfile != null");
            }

            var profile = activeProfile;

            while (profile != null)
            {
                yield return(profile);

                profile = profile.Parent;
            }
        }
        void OnDeserialized(StreamingContext context)
        {
            _gameSettings = new List <GameSettings>();
            if (_profiles.All(x => x.Id != GlobalGameSettingsProfile.GlobalId))
            {
                _profiles.Insert(0, new GlobalGameSettingsProfile());
            }
            var globalProfile = _profiles.First(x => x.Id == GlobalGameSettingsProfile.GlobalId);

            Profiles       = _profiles.CreateDerivedCollection(x => x);
            _activeProfile = _profiles.First(x => x.Id == _activeProfileGuid);
            foreach (var p in _profiles.Where(p => p.Id != GlobalGameSettingsProfile.GlobalId))
            {
                p.Parent = _profiles.FirstOrDefault(x => x.Id == p.ParentId) ?? globalProfile;
            }

            SetupRefresh();
        }
        public void DeleteProfile(Guid uuid)
        {
            if (!(uuid != Guid.Empty))
            {
                throw new ArgumentNullException("uuid != Guid.Empty");
            }

            if (ActiveProfile.Id == uuid)
            {
                ActiveProfile = _profiles.First();
            }

            var profile = _profiles.First(x => x.Id == uuid);

            _profiles.Remove(profile);
            foreach (var p in _profiles.Where(p => profile.Parent == profile))
            {
                p.Parent = null;
            }
        }
Пример #9
0
 public GameSettingsProfile(string name, string color, GameSettingsProfileBase parent)
     : this(Guid.NewGuid(), name, color, parent)
 {
 }