Пример #1
0
        public void Create(string profileId, ProfileData profileData)
        {
            _log.Info($"Create new profile '{profileId}'");

            if (_profiles.ContainsKey(profileId))
            {
                _log.Error($"Profile with name '{profileId}' already exists in cache!");
                throw new InvalidProfileNameException();
            }

            if (!ValidateProfileId(profileId))
            {
                _log.Error("Invalid profile id!");
                throw new InvalidProfileNameException();
            }

            if (!ValidateVersion(profileData.FullVersion))
            {
                _log.Error($"Cant create profile {profileId}. Invalid version!");
                throw new InvalidProfileVersionException();
            }

            var profileDir = Path.Combine(_profilesPath, profileId);

            if (!Directory.Exists(profileDir))
            {
                Directory.CreateDirectory(profileDir);
            }

            _json.WriteFile(profileData, Path.Combine(profileDir, ProfileIndexName));
            _profiles.Add(profileId, profileData.Clone());
        }
Пример #2
0
        public void UpdateData(string profileId, ProfileData profileData)
        {
            _log.Info($"Update profile {profileId}");

            if (!_profiles.ContainsKey(profileId))
            {
                _log.Error($"Profile with name '{profileId}' does not exist in cache!");
                throw new InvalidProfileNameException();
            }

            _json.WriteFile(profileData, Path.Combine(_profilesPath, profileId, ProfileIndexName));
            _profiles[profileId] = profileData.Clone();
        }