<commit_before>﻿using System.Globalization;
using System.Linq;
using System.Text;
using NPSharp.CommandLine.Server.Database;

namespace NPSharp.CommandLine.Server
{
    internal class BrightstarDatabaseFileServingHandler : IFileServingHandler
    {
        private readonly BrightstarDatabaseContext _db;

        public BrightstarDatabaseFileServingHandler(BrightstarDatabaseContext database)
        {
            //_database = database;
            _db = database;
        }

        public byte[] ReadUserFile(NPServerClient client, string file)
        {
            var resultEnum =
                _db.UserFiles.Where(
                    uf =>
                        uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) &&
                        uf.FileName == file);

            return resultEnum.Any() ? resultEnum.Single().FileData : null;
        }

        public byte[] ReadPublisherFile(NPServerClient client, string file)
        {
            var resultEnum =
                _db.PublisherFiles.Where(pf => pf.FileName == file);

            return resultEnum.Any() ? resultEnum.Single().FileData : null;
        }

        public void WriteUserFile(NPServerClient client, string file, byte[] data)
        {
            var resultEnum =
                _db.UserFiles.Where(
                    uf =><commit_msg>Fallback to default file contents if the file doesn't exist yet.<commit_after>﻿using System.Globalization;
using System.Linq;
using System.Text;
using NPSharp.CommandLine.Server.Database;

namespace NPSharp.CommandLine.Server
{
    internal class BrightstarDatabaseFileServingHandler : IFileServingHandler
    {
        private readonly BrightstarDatabaseContext _db;

        public BrightstarDatabaseFileServingHandler(BrightstarDatabaseContext database)
        {
            //_database = database;
            _db = database;
        }

        public byte[] ReadUserFile(NPServerClient client, string file)
        {
            var resultEnum =
                _db.UserFiles.Where(
                    uf =>
                        uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) &&
                        uf.FileName == file);

            return resultEnum.Any() ? resultEnum.Single().FileData : GetDefaultUserFile(file);
        }

        public byte[] ReadPublisherFile(NPServerClient client, string file)
        {
            var resultEnum =
                _db.PublisherFiles.Where(pf => pf.FileName == file).ToArray();

            return resultEnum.Any() ? resultEnum.Single().FileData : GetDefaultPublisherFile(file);
        }

        public void WriteUserFile(NPServerClient client, string file, byte[] data)
        {
            var resultEnum =
                _db.UserFiles.Where(
                    uf =>
{'fraction_non_alphanumeric': 0.08197303051809794, 'fraction_numerical': 0.0, 'mean_word_length': 2.0475675675675675, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3827860', 'n_tokens_mistral': 733, 'n_tokens_neox': 687, 'n_words': 150}