<commit_before>//
//  APIServiceLocator.swift
//  Makespace Inc.
//
//  Created by <NAME> (@darkzlave) on 2/23/17.
//
//

import UIKit
public protocol ServiceLocatorDelegate {
    func authenticationTokenDidExpire()
}

/// Defines the level of loggin we want for our network manager
@objc
public enum SLLogLevel: Int {
    case none //no printing
    case short //print only requests
    case verbose //print request and response bodies
}

open class ServiceLocator: NSObject {
    /// Our Default Networking Client for Alamofire, replace to override our network request implementation
    public static var defaultNetworkClientType: NetworkManager.Type = AlamoNetworkManager.self
    
    /// Our Default behavior for printing network logs
    public static var logLevel:SLLogLevel = .short

    /// Defines a private singleton, all interactions should be done through static methods
    internal static var shared: ServiceLocator = ServiceLocator()
    internal var delegate: ServiceLocatorDelegate?

    internal var currentServices: [String:Service]
    private var loadedServiceTypes: [Service.Type]
    private var configuration: APIConfiguration!
    private var networkManager: NetworkManager!
    private var token: APIToken?

    /// Inits default configuration and network manager
    private init(delegate: ServiceLocatorDelegate? = nil) {
        self.delegate = delegate
        self.currentServices = [String: Service]()
        self.loadedServiceTypes = [Service.Type]()
    }

    /// Resets the ServiceLocator singleton instance
    open class func reset() {
        ServiceLocator.shared = ServiceLocator(delegate: ServiceLocator.shared.delegate)
    }

    /// Reloads token, networkManager and configuration with existing hooked services
    open class func reloadExistingServices() {
        reset()
        
        let serviceTypes = ServiceLocator.shared.loadedServiceTypes
        if let configType = APIConfiguration.apiConfigurationType,
            let authType = APIConfiguration.authConfigurationType,
            let tokenType = APITokenManager.tokenType {
            ServiceLocator.set(services: serviceTypes,
                               api: configType,
                               auth: authType,
                               token: tokenType)<commit_msg>Track existing services before reset<commit_after>//
//  APIServiceLocator.swift
//  Makespace Inc.
//
//  Created by <NAME> (@darkzlave) on 2/23/17.
//
//

import UIKit
public protocol ServiceLocatorDelegate {
    func authenticationTokenDidExpire()
}

/// Defines the level of loggin we want for our network manager
@objc
public enum SLLogLevel: Int {
    case none //no printing
    case short //print only requests
    case verbose //print request and response bodies
}

open class ServiceLocator: NSObject {
    /// Our Default Networking Client for Alamofire, replace to override our network request implementation
    public static var defaultNetworkClientType: NetworkManager.Type = AlamoNetworkManager.self
    
    /// Our Default behavior for printing network logs
    public static var logLevel:SLLogLevel = .short

    /// Defines a private singleton, all interactions should be done through static methods
    internal static var shared: ServiceLocator = ServiceLocator()
    internal var delegate: ServiceLocatorDelegate?

    internal var currentServices: [String:Service]
    private var loadedServiceTypes: [Service.Type]
    private var configuration: APIConfiguration!
    private var networkManager: NetworkManager!
    private var token: APIToken?

    /// Inits default configuration and network manager
    private init(delegate: ServiceLocatorDelegate? = nil) {
        self.delegate = delegate
        self.currentServices = [String: Service]()
        self.loadedServiceTypes = [Service.Type]()
    }

    /// Resets the ServiceLocator singleton instance
    open class func reset() {
        ServiceLocator.shared = ServiceLocator(delegate: ServiceLocator.shared.delegate)
    }

    /// Reloads token, networkManager and configuration with existing hooked services
    open class func reloadExistingServices() {
        let serviceTypes = ServiceLocator.shared.loadedServiceTypes
        reset()
        
        if let configType = APIConfiguration.apiConfigurationType,
            let authType = APIConfiguration.authConfigurationType,
            let tokenType = APITokenManager.tokenType {
            ServiceLocator.set(services: serviceTypes,
                               api: configType,
                               auth: authType,
                               token: tokenType)
{'fraction_non_alphanumeric': 0.06708504652672581, 'fraction_numerical': 0.002164033758926639, 'mean_word_length': 2.8742665549036044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2361089', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1091, 'n_words': 383}