<commit_before>﻿///<reference path="../references.ts" />

module SupportCenter {
    "use strict";

    export interface IDetectorsService {
        getDetectors(resource: Resource): ng.IPromise<DetectorDefinition[]>;
        getDetectorResponse(resource: Resource, detectorName: string): ng.IPromise<DetectorResponse>;
        getDetectorResponseWithDates(resource: Resource, detectorName: string, startTime: Date, endTime: Date): ng.IPromise<DetectorResponse>;
        getDetectorWiki(detectorName: string): ng.IPromise<string>;
        getDetectorSolution(detectorName: string): ng.IPromise<string>;

        detectorsList: DetectorDefinition[];
    }

    export interface ICache<T> {
        [K: string]: T;
    }

    export class DetectorsService implements IDetectorsService {

        private detectorsResponseCache: ICache<DetectorResponse>;
        private detectorsWikiCache: ICache<string>;
        private detectorsSolutionCache: ICache<string>;
        private detectorsListCache: ICache<DetectorDefinition[]>;
        public detectorsList: DetectorDefinition[];

        static $inject = ['TimeParamsService', '$q', '$http'];

        constructor(private TimeParamsService: ITimeParamsService, private $q: ng.IQService, private $http: ng.IHttpService) {
            this.detectorsResponseCache = {};
            this.detectorsWikiCache = {};
            this.detectorsSolutionCache = {};
            this.detectorsListCache = {};
            this.detectorsList = [];
        }

        getDetectors(resource: Resource): ng.IPromise<DetectorDefinition[]> {

            var detectors: DetectorDefinition[] = [];
            var deferred = this.$q.defer<DetectorDefinition[]>();

            if (angular.isDefined(this.detectorsListCache["detectorList"])) {
                deferred.resolve(this.detectorsListCache["detectorList"]);
                return deferred.promise;
            }

            var self = this;

            this.$http({
                method: "GET",
                url: UriPaths.DiagnosticsPassThroughAPIPath(),
                headers: {
                    'GeoRegionApiRoute': UriPaths.ListDetectorsPath(resource),
                    'IsInternal': this.TimeParamsService.IsInternal
                }
            })
                .success((data: any) => {

                    if (angular.isDefined(data) && angular.isDefined(data.Value)) {

                        _.each(data.Value, function (item: any) {

                            if (angular.isDefined(item.Properties)) {

                                var detector = new DetectorDefinition(
                                    item.Properties.Name,
                                    item.Properties.DisplayName,
                                    item.Properties.Description,
                                    item.Properties.Rank,
                                    item.Properties.IsEnabled, -1);

                                detectors.push(detector);
                            }
                            else {
                                var detector = new DetectorDefinition(
                                    item.Name,
                                    item.DisplayName,
                                    item.Description,
                                    item.Rank,
                                    item.IsEnabled, -1);

                                detectors.push(detector);
                            }
                        });

                        self.detectorsListCache["detectorList"] = detectors;
                        self.detectorsList = detectors;
                        deferred.resolve(self.detectorsList);
                    }
                    else {
                        deferred.reject(new ErrorModel(0, "Value field not present in Get Detectors Api response"));
                    }
                })
                .error((err: any) => {
                    deferred.reject(ErrorModelBuilder.Build(err));
                });

            return deferred.promise;
        }<commit_msg>Update Get Detectors call to handle envelope or no envelope<commit_after>﻿///<reference path="../references.ts" />

module SupportCenter {
    "use strict";

    export interface IDetectorsService {
        getDetectors(resource: Resource): ng.IPromise<DetectorDefinition[]>;
        getDetectorResponse(resource: Resource, detectorName: string): ng.IPromise<DetectorResponse>;
        getDetectorResponseWithDates(resource: Resource, detectorName: string, startTime: Date, endTime: Date): ng.IPromise<DetectorResponse>;
        getDetectorWiki(detectorName: string): ng.IPromise<string>;
        getDetectorSolution(detectorName: string): ng.IPromise<string>;

        detectorsList: DetectorDefinition[];
    }

    export interface ICache<T> {
        [K: string]: T;
    }

    export class DetectorsService implements IDetectorsService {

        private detectorsResponseCache: ICache<DetectorResponse>;
        private detectorsWikiCache: ICache<string>;
        private detectorsSolutionCache: ICache<string>;
        private detectorsListCache: ICache<DetectorDefinition[]>;
        public detectorsList: DetectorDefinition[];

        static $inject = ['TimeParamsService', '$q', '$http'];

        constructor(private TimeParamsService: ITimeParamsService, private $q: ng.IQService, private $http: ng.IHttpService) {
            this.detectorsResponseCache = {};
            this.detectorsWikiCache = {};
            this.detectorsSolutionCache = {};
            this.detectorsListCache = {};
            this.detectorsList = [];
        }

        getDetectors(resource: Resource): ng.IPromise<DetectorDefinition[]> {

            var detectors: DetectorDefinition[] = [];
            var deferred = this.$q.defer<DetectorDefinition[]>();

            if (angular.isDefined(this.detectorsListCache["detectorList"])) {
                deferred.resolve(this.detectorsListCache["detectorList"]);
                return deferred.promise;
            }

            var self = this;

            this.$http({
                method: "GET",
                url: UriPaths.DiagnosticsPassThroughAPIPath(),
                headers: {
                    'GeoRegionApiRoute': UriPaths.ListDetectorsPath(resource),
                    'IsInternal': this.TimeParamsService.IsInternal
                }
            })
                .success((data: any) => {


                    if (angular.isDefined(data) && angular.isDefined(data.Value)) {

                        _.each(data.Value, function (item: any) {

                            if (angular.isDefined(item.Properties)) {

                                var detector = new DetectorDefinition(
                                    item.Properties.Name,
                                    item.Properties.DisplayName,
                                    item.Properties.Description,
                                    item.Properties.Rank,
                                    item.Properties.IsEnabled, -1);

                                detectors.push(detector);
                            }
                            else {
                                
                            }
                        });
                    }
                    else if (angular.isDefined(data)) {
                        _.each(data, function (item: any) {
                            var detector = new DetectorDefinition(
                                item.Name,
                                item.DisplayName,
                                item.Description,
                                item.Rank,
                                item.IsEnabled, -1);

                            detectors.push(detector);
                        });
                    }
                    else {
                        deferred.reject(new ErrorModel(0, "Invalid Get Detectors Api response"));
                    }

                    self.detectorsListCache["detectorList"] = detectors;
                    self.detectorsList = detectors;
                    deferred.resolve(self.detectorsList);
                })
                .error((err: any) => {
                    deferred.reject(ErrorModelBuilder.Build(err));
                });

            return deferred.promise;
        }
{'fraction_non_alphanumeric': 0.09309309309309309, 'fraction_numerical': 0.0007207207207207207, 'mean_word_length': 1.429530201342282, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6526864', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1850, 'n_words': 336}