<commit_before>﻿using Realms.Sync;
using System;
using System.Threading.Tasks;
using TIKSN.Configuration;
using TIKSN.FileSystem;

namespace TIKSN.Data.Realm
{
    public class RealmUnitOfWorkFactory : IRealmUnitOfWorkFactory
    {
        private readonly IKnownFolders _knownFolders;
        private readonly IPartialConfiguration<SyncRealmOptions> _syncRealmOptions;
        private User _user;

        protected RealmUnitOfWorkFactory(IPartialConfiguration<SyncRealmOptions> syncRealmOptions, IKnownFolders knownFolders)
        {
            _syncRealmOptions = syncRealmOptions ?? throw new ArgumentNullException(nameof(syncRealmOptions));
            _knownFolders = knownFolders ?? throw new ArgumentNullException(nameof(knownFolders));
        }

        public async Task<IRealmUnitOfWork> CreateAsync()
        {
            var syncRealmOptions = _syncRealmOptions.GetConfiguration();

            if (_user == null)
                throw new InvalidOperationException("User is not logged int yet.");

            var syncConfig = new SyncConfiguration(_user, new Uri(syncRealmOptions.ServerURL), _knownFolders.LocalAppData.GetFileInfo(syncRealmOptions.Path).PhysicalPath);
            var realm = await Realms.Realm.GetInstanceAsync(syncConfig);
            return new RealmUnitOfWork(realm);
        }

        public async Task LoginAsync(Credentials credentials)
        {
            var syncRealmOptions = _syncRealmOptions.GetConfiguration();

            if (_user != null)
                throw new InvalidOperationException("Please log out first, before another login.");

            _user = await User.LoginAsync(credentials, new Uri(syncRealmOptions.ServerURL)).ConfigureAwait(false);
        }

        public async Task LogoutAsync()
        {
            await _user.LogOutAsync();

            _user = null;
        }
    }
}<commit_msg>constractor fix<commit_after>﻿using Realms.Sync;
using System;
using System.Threading.Tasks;
using TIKSN.Configuration;
using TIKSN.FileSystem;

namespace TIKSN.Data.Realm
{
    public class RealmUnitOfWorkFactory : IRealmUnitOfWorkFactory
    {
        private readonly IKnownFolders _knownFolders;
        private readonly IPartialConfiguration<SyncRealmOptions> _syncRealmOptions;
        private User _user;

        public RealmUnitOfWorkFactory(IPartialConfiguration<SyncRealmOptions> syncRealmOptions, IKnownFolders knownFolders)
        {
            _syncRealmOptions = syncRealmOptions ?? throw new ArgumentNullException(nameof(syncRealmOptions));
            _knownFolders = knownFolders ?? throw new ArgumentNullException(nameof(knownFolders));
        }

        public async Task<IRealmUnitOfWork> CreateAsync()
        {
            var syncRealmOptions = _syncRealmOptions.GetConfiguration();

            if (_user == null)
                throw new InvalidOperationException("User is not logged int yet.");

            var syncConfig = new SyncConfiguration(_user, new Uri(syncRealmOptions.ServerURL), _knownFolders.LocalAppData.GetFileInfo(syncRealmOptions.Path).PhysicalPath);
            var realm = await Realms.Realm.GetInstanceAsync(syncConfig);
            return new RealmUnitOfWork(realm);
        }

        public async Task LoginAsync(Credentials credentials)
        {
            var syncRealmOptions = _syncRealmOptions.GetConfiguration();

            if (_user != null)
                throw new InvalidOperationException("Please log out first, before another login.");

            _user = await User.LoginAsync(credentials, new Uri(syncRealmOptions.ServerURL)).ConfigureAwait(false);
        }

        public async Task LogoutAsync()
        {
            await _user.LogOutAsync();

            _user = null;
        }
    }
}
{'fraction_non_alphanumeric': 0.07286364854004822, 'fraction_numerical': 0.0, 'mean_word_length': 2.955508474576271, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4931344', 'n_tokens_mistral': 1010, 'n_tokens_neox': 975, 'n_words': 215}