<commit_before>﻿/*
Copyright 2015-2018 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using TWCore.Diagnostics.Log;
using TWCore.Diagnostics.Status;
using TWCore.Diagnostics.Trace;
using TWCore.Reflection;
using TWCore.Threading;
// ReSharper disable ImpureMethodCallOnReadonlyValueField
// ReSharper disable VirtualMemberNeverOverridden.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global

namespace TWCore
{
    /// <summary>
    /// Default Factories
    /// </summary>
    public abstract class Factories
    {
        private PlatformType _platformType = PlatformType.Unknown;

        #region Properties
        /// <summary>
        /// Activation helper
        /// </summary>
        public IAccessorsFactory Accessors { get; protected set; } = new DefaultAccessorsFactory();
        /// <summary>
        /// Log Item Factory
        /// </summary>
        public CreateLogItemDelegate CreateLogItem { get; protected set; } = BaseCreateLogItem;
        /// <summary>
        /// Default LogEngine factory
        /// </summary>
        public CreateLogEngineDelegate CreateLogEngine { get; protected set; } = () => new DefaultLogEngine();
        /// <summary>
        /// Trace Item Factory
        /// </summary>
        public CreateTraceItemDelegate CreateTraceItem { get; protected set; } = BaseCreateTraceItem;
        /// <summary>
        /// Default TraceEngine factory
        /// </summary>
        public CreateTraceEngineDelegate CreateTraceEngine { get; protected set; } = () => new DefaultTraceEngine();
        /// <summary>
        /// Default StatusEngine factory
        /// </summary>
        public CreateStatusEngineDelegate CreateStatusEngine { get; protected set; } = () => new DefaultStatusEngine();
        /// <summary>
        /// Gets the available assemblies loaded on the AppDomain
        /// </summary>
        /// <returns>Assemblies array</returns>
        public GetAssembliesDelegate GetAssemblies { get; protected set; } = () => throw new NullReferenceException();
        /// <summary>
        /// Gets the available assemblies on the folder
        /// </summary>
        /// <returns>Assemblies array</returns>
        public GetAssembliesDelegate GetAllAssemblies { get; protected set; } = () => throw new NullReferenceException();
        /// <summary>
        /// Gets the platform type
        /// </summary>
        public PlatformType PlatformType
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                if (_platformType != PlatformType.Unknown) return _platformType;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    _platformType = PlatformType.Linux;

                    //Tries to detect a docker container.
                    try
                    {
                        if (File.Exists("/proc/1/cgroup"))
                        {
                            var fileContent = File.ReadAllText("/proc/1/cgroup");
                            if (fileContent.Contains("/docker/"))
                                RunningAsContainer = true;
                        }
                    }
                    catch
                    {
                        //
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    _platformType = PlatformType.Mac;
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    _platformType = PlatformType.Windows;
                return _platformType;<commit_msg>Use Environment variable to detect docker container<commit_after>﻿/*
Copyright 2015-2018 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using TWCore.Diagnostics.Log;
using TWCore.Diagnostics.Status;
using TWCore.Diagnostics.Trace;
using TWCore.Reflection;
using TWCore.Threading;
// ReSharper disable ImpureMethodCallOnReadonlyValueField
// ReSharper disable VirtualMemberNeverOverridden.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global

namespace TWCore
{
    /// <summary>
    /// Default Factories
    /// </summary>
    public abstract class Factories
    {
        private PlatformType _platformType = PlatformType.Unknown;

        #region Properties
        /// <summary>
        /// Activation helper
        /// </summary>
        public IAccessorsFactory Accessors { get; protected set; } = new DefaultAccessorsFactory();
        /// <summary>
        /// Log Item Factory
        /// </summary>
        public CreateLogItemDelegate CreateLogItem { get; protected set; } = BaseCreateLogItem;
        /// <summary>
        /// Default LogEngine factory
        /// </summary>
        public CreateLogEngineDelegate CreateLogEngine { get; protected set; } = () => new DefaultLogEngine();
        /// <summary>
        /// Trace Item Factory
        /// </summary>
        public CreateTraceItemDelegate CreateTraceItem { get; protected set; } = BaseCreateTraceItem;
        /// <summary>
        /// Default TraceEngine factory
        /// </summary>
        public CreateTraceEngineDelegate CreateTraceEngine { get; protected set; } = () => new DefaultTraceEngine();
        /// <summary>
        /// Default StatusEngine factory
        /// </summary>
        public CreateStatusEngineDelegate CreateStatusEngine { get; protected set; } = () => new DefaultStatusEngine();
        /// <summary>
        /// Gets the available assemblies loaded on the AppDomain
        /// </summary>
        /// <returns>Assemblies array</returns>
        public GetAssembliesDelegate GetAssemblies { get; protected set; } = () => throw new NullReferenceException();
        /// <summary>
        /// Gets the available assemblies on the folder
        /// </summary>
        /// <returns>Assemblies array</returns>
        public GetAssembliesDelegate GetAllAssemblies { get; protected set; } = () => throw new NullReferenceException();
        /// <summary>
        /// Gets the platform type
        /// </summary>
        public PlatformType PlatformType
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                if (_platformType != PlatformType.Unknown) return _platformType;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    _platformType = PlatformType.Linux;

                    if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true")
                        RunningAsContainer = true;
                    else
                    {
                        //Tries to detect a docker container.
                        try
                        {
                            if (File.Exists("/proc/1/cgroup"))
                            {
                                var fileContent = File.ReadAllText("/proc/1/cgroup");
                                if (fileContent.Contains("/docker/"))
                                    RunningAsContainer = true;
                            }
                        }
                        catch
                        {
                            //
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    _platformType = PlatformType.Mac;
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    _platformType = PlatformType.Windows;
                return _platformType;
{'fraction_non_alphanumeric': 0.09058965630833425, 'fraction_numerical': 0.0030745580322828594, 'mean_word_length': 1.9267352185089974, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1272316', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2070, 'n_words': 615}