<commit_before>﻿namespace Macabre2D.UI.Services {

    using Macabre2D.Framework;
    using Macabre2D.UI.Models;
    using Macabre2D.UI.ServiceInterfaces;
    using Macabre2D.UI.Services.Content;
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;

    public sealed class ProjectService : NotifyPropertyChanged, IProjectService {
        private const string AssetsLocation = @"Assets";
        private readonly IFileService _fileService;
        private readonly ILoggingService _loggingService;
        private readonly ISceneService _sceneService;
        private readonly Serializer _serializer;
        private Project _currentProject;
        private bool _hasChanges;

        public ProjectService(
            Serializer serializer,
            IFileService fileService,
            ILoggingService loggingService,
            ISceneService sceneService) {
            this._serializer = serializer;
            this._fileService = fileService;
            this._loggingService = loggingService;
            this._sceneService = sceneService;
        }

        public Project CurrentProject {
            get {
                return this._currentProject;
            }

            private set {
                if (value != null) {
                    var oldProject = this.CurrentProject;
                    if (this.Set(ref this._currentProject, value) && this._currentProject != null) {
                        this.CurrentProject.PropertyChanged += this.CurrentProject_PropertyChanged;
                    }

                    if (oldProject != null) {
                        oldProject.PropertyChanged -= this.CurrentProject_PropertyChanged;
                    }

                    this.RaisePropertyChanged(nameof(this.HasChanges));
                }
            }
        }

        public bool HasChanges {
            get {
                return this._currentProject != null && (this._hasChanges || this._sceneService.HasChanges);
            }

            set {
                this.Set(ref this._hasChanges, value);
            }
        }

        public async Task<bool> BuildContent(BuildMode mode) {
            var result = true;
            await Task.Run(() => {
                var assets = this.CurrentProject.AssetFolder.GetAllContentAssets();

                foreach (var configuration in this.CurrentProject.BuildConfigurations) {
                    var dllPaths = new[] {
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Newtonsoft.Json.dll",
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Macabre2D.Framework.dll",
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Macabre2D.Project.Gameplay.dll"
                    };

                    configuration.GenerateContent(this._fileService.ProjectDirectoryPath, assets, this.CurrentProject.AssetManager, this.CurrentProject.GameSettings, this._serializer, dllPaths);
                    var contentFilePath = Path.Combine(this._fileService.ProjectDirectoryPath, $"{configuration.Platform.ToString()}.mgcb");
                    var outputDirectory = Path.Combine(this._fileService.ProjectDirectoryPath, "bin", configuration.Platform.ToString(), mode.ToString(), "Content");
                    Directory.CreateDirectory(outputDirectory);

                    var exitCode = ContentBuilder.BuildContent(
                        out var exception,
                        $"/@:{contentFilePath}", $"/platform:{configuration.Platform.ToString()}",
                        $@"/outputDir:{outputDirectory}",
                        $"/workingDir:{this._fileService.ProjectDirectoryPath}");

                    if (exitCode != 0) {
                        result = false;
                        this._loggingService.LogError($"Content could not be built for '{this.CurrentProject.Name}' in '{mode.ToString()}' mode: {exception?.Message}");
                    }<commit_msg>Refactor: adding a new line where it belongs.<commit_after>﻿namespace Macabre2D.UI.Services {

    using Macabre2D.Framework;
    using Macabre2D.UI.Models;
    using Macabre2D.UI.ServiceInterfaces;
    using Macabre2D.UI.Services.Content;
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;

    public sealed class ProjectService : NotifyPropertyChanged, IProjectService {
        private const string AssetsLocation = @"Assets";
        private readonly IFileService _fileService;
        private readonly ILoggingService _loggingService;
        private readonly ISceneService _sceneService;
        private readonly Serializer _serializer;
        private Project _currentProject;
        private bool _hasChanges;

        public ProjectService(
            Serializer serializer,
            IFileService fileService,
            ILoggingService loggingService,
            ISceneService sceneService) {
            this._serializer = serializer;
            this._fileService = fileService;
            this._loggingService = loggingService;
            this._sceneService = sceneService;
        }

        public Project CurrentProject {
            get {
                return this._currentProject;
            }

            private set {
                if (value != null) {
                    var oldProject = this.CurrentProject;
                    if (this.Set(ref this._currentProject, value) && this._currentProject != null) {
                        this.CurrentProject.PropertyChanged += this.CurrentProject_PropertyChanged;
                    }

                    if (oldProject != null) {
                        oldProject.PropertyChanged -= this.CurrentProject_PropertyChanged;
                    }

                    this.RaisePropertyChanged(nameof(this.HasChanges));
                }
            }
        }

        public bool HasChanges {
            get {
                return this._currentProject != null && (this._hasChanges || this._sceneService.HasChanges);
            }

            set {
                this.Set(ref this._hasChanges, value);
            }
        }

        public async Task<bool> BuildContent(BuildMode mode) {
            var result = true;
            await Task.Run(() => {
                var assets = this.CurrentProject.AssetFolder.GetAllContentAssets();

                foreach (var configuration in this.CurrentProject.BuildConfigurations) {
                    var dllPaths = new[] {
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Newtonsoft.Json.dll",
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Macabre2D.Framework.dll",
                        $@"{this._fileService.ProjectDirectoryPath}\bin\{configuration.Platform.ToString()}\{mode.ToString()}\Macabre2D.Project.Gameplay.dll"
                    };

                    configuration.GenerateContent(this._fileService.ProjectDirectoryPath, assets, this.CurrentProject.AssetManager, this.CurrentProject.GameSettings, this._serializer, dllPaths);
                    var contentFilePath = Path.Combine(this._fileService.ProjectDirectoryPath, $"{configuration.Platform.ToString()}.mgcb");
                    var outputDirectory = Path.Combine(this._fileService.ProjectDirectoryPath, "bin", configuration.Platform.ToString(), mode.ToString(), "Content");
                    Directory.CreateDirectory(outputDirectory);

                    var exitCode = ContentBuilder.BuildContent(
                        out var exception,
                        $"/@:{contentFilePath}",
                        $"/platform:{configuration.Platform.ToString()}",
                        $@"/outputDir:{outputDirectory}",
                        $"/workingDir:{this._fileService.ProjectDirectoryPath}");

                    if (exitCode != 0) {
                        result = false;
                        this._loggingService.LogError($"Content could not be built for '{this.CurrentProject.Name}' in '{mode.ToString()}' mode: {exception?.Message}");
                    }
{'fraction_non_alphanumeric': 0.09331111640085694, 'fraction_numerical': 0.0019043084979766722, 'mean_word_length': 1.9556806190643685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3075793', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1886, 'n_words': 367}