<commit_before>import { EditModeHelper } from './../../shared/Utilities/edit-mode.helper';
import { Component, Input, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { Subscription as RxSubscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/zip';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';

import { ErrorIds } from './../../shared/models/error-ids';
import { ErrorEvent, ErrorType } from './../../shared/models/error-event';
import { SiteConfig } from './../../shared/models/arm/site-config';
import { NotificationIds, Constants } from './../../shared/models/constants';
import { CacheService } from './../../shared/services/cache.service';
import { Site } from './../../shared/models/arm/site';
import { ArmObj } from './../../shared/models/arm/arm-obj';
import { AppNode } from './../../tree-view/app-node';
import { TreeViewInfo } from './../../tree-view/models/tree-view-info';
import { ArmService } from '../../shared/services/arm.service';
import { PortalService } from '../../shared/services/portal.service';
import { BroadcastService } from '../../shared/services/broadcast.service';
import { BroadcastEvent } from '../../shared/models/broadcast-event'
import { FunctionsService } from '../../shared/services/functions.service';
import { GlobalStateService } from '../../shared/services/global-state.service';
import { AiService } from '../../shared/services/ai.service';
import { SelectOption } from '../../shared/models/select-option';
import { PortalResources } from '../../shared/models/portal-resources';
import { FunctionApp } from './../../shared/function-app';
import { FunctionAppEditMode } from '../../shared/models/function-app-edit-mode';
import { SlotsService } from '../../shared/services/slots.service';
import { HostStatus } from './../../shared/models/host-status';

@Component({
  selector: 'function-runtime',
  templateUrl: './function-runtime.component.html',
  styleUrls: ['./function-runtime.component.scss']
})
export class FunctionRuntimeComponent implements OnDestroy {
  public site: ArmObj<Site>;
  public memorySize: number | string;
  public dirty: boolean;
  public needUpdateExtensionVersion;
  public extensionVersion: string;
  public latestExtensionVersion: string;
  public dailyMemoryTimeQuota: string;
  public dailyMemoryTimeQuotaOriginal: string;
  public showDailyMemoryWarning: boolean = false;
  public showDailyMemoryInfo: boolean = false;
  public functionApp: FunctionApp;
  public exactExtensionVersion: string;

  public functionStatusOptions: SelectOption<boolean>[];
  public needUpdateRoutingExtensionVersion: boolean;
  public routingExtensionVersion: string;
  public latestRoutingExtensionVersion: string;
  public apiProxiesEnabled: boolean;
  private proxySettingValueStream: Subject<boolean>;
  private functionEditModeValueStream: Subject<boolean>;
  public showTryView: boolean;

  private _viewInfoStream = new Subject<TreeViewInfo>();
  private _viewInfo: TreeViewInfo;
  private _viewInfoSub: RxSubscription;
  private _appNode: AppNode;

  public functionAppEditMode: boolean = true;
  public functionAppEditModeOptions: SelectOption<boolean>[];

  private _isSlotApp: boolean = false;
  public slotsStatusOptions: SelectOption<boolean>[];
  public slotsAppSetting: string;
  public slotsEnabled: boolean;
  private slotsValueChange: Subject<boolean>;
  private _numSlots: number = 0;

  constructor(
    private _armService: ArmService,
    private _cacheService: CacheService,
    private _portalService: PortalService,
    private _broadcastService: BroadcastService,
    private _functionsService: FunctionsService,
    private _globalStateService: GlobalStateService,
    private _aiService: AiService,
    private _translateService: TranslateService,
    private _slotsService: SlotsService
  ) {

    this.showTryView = this._globalStateService.showTryView;
    this._viewInfoSub = this._viewInfoStream
      .switchMap(viewInfo => {
        this._viewInfo = viewInfo;
        this._globalStateService.setBusyState();

        this._appNode = (<AppNode>viewInfo.node);

            return Observable.zip(
                this._cacheService.getArm(viewInfo.resourceId),
                this._cacheService.postArm(`${viewInfo.resourceId}/config/appsettings/list`, true),
                this._appNode.functionAppStream,
                  this._slotsService.getSlotsList(viewInfo.resourceId),
                (s: Response, a: Response, fa: FunctionApp, slots: ArmObj<Site>[]) => ({ siteResponse: s, appSettingsResponse: a, functionApp: fa, slotsList: slots }))
                .mergeMap(result => {
                    return Observable.zip(result.functionApp.getFunctionAppEditMode(), result.functionApp.getFunctionHostStatus(),
                        (editMode: FunctionAppEditMode, hostStatus: HostStatus) => ({ editMode: editMode, hostStatus: hostStatus }))
                          .map(r => ({
                              siteResponse: result.siteResponse,
                              appSettingsResponse: result.appSettingsResponse,
                              functionApp: result.functionApp,
                              editMode: r.editMode,
                              hostStatus: r.hostStatus,
                              slotsList: result.slotsList
                            })
                       );
                });
        })
        .do(null, e => {
          this._aiService.trackException(e, 'function-runtime');
        })
        .retry()
        .subscribe(r => {
            let appSettings: ArmObj<any> = r.appSettingsResponse.json();

            this.functionApp = r.functionApp;
            this.site = r.siteResponse.json();
            this.exactExtensionVersion = r.hostStatus.version;
            this._isSlotApp = SlotsService.isSlot(this.site.id);
            this.dailyMemoryTimeQuota = this.site.properties.dailyMemoryTimeQuota
                ? this.site.properties.dailyMemoryTimeQuota.toString()
                : '0';

            if (this.dailyMemoryTimeQuota === '0') {<commit_msg>Handle null host object in function-runtime component<commit_after>import { EditModeHelper } from './../../shared/Utilities/edit-mode.helper';
import { Component, Input, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { Subscription as RxSubscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/observable/zip';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';

import { ErrorIds } from './../../shared/models/error-ids';
import { ErrorEvent, ErrorType } from './../../shared/models/error-event';
import { SiteConfig } from './../../shared/models/arm/site-config';
import { NotificationIds, Constants } from './../../shared/models/constants';
import { CacheService } from './../../shared/services/cache.service';
import { Site } from './../../shared/models/arm/site';
import { ArmObj } from './../../shared/models/arm/arm-obj';
import { AppNode } from './../../tree-view/app-node';
import { TreeViewInfo } from './../../tree-view/models/tree-view-info';
import { ArmService } from '../../shared/services/arm.service';
import { PortalService } from '../../shared/services/portal.service';
import { BroadcastService } from '../../shared/services/broadcast.service';
import { BroadcastEvent } from '../../shared/models/broadcast-event'
import { FunctionsService } from '../../shared/services/functions.service';
import { GlobalStateService } from '../../shared/services/global-state.service';
import { AiService } from '../../shared/services/ai.service';
import { SelectOption } from '../../shared/models/select-option';
import { PortalResources } from '../../shared/models/portal-resources';
import { FunctionApp } from './../../shared/function-app';
import { FunctionAppEditMode } from '../../shared/models/function-app-edit-mode';
import { SlotsService } from '../../shared/services/slots.service';
import { HostStatus } from './../../shared/models/host-status';

@Component({
  selector: 'function-runtime',
  templateUrl: './function-runtime.component.html',
  styleUrls: ['./function-runtime.component.scss']
})
export class FunctionRuntimeComponent implements OnDestroy {
  public site: ArmObj<Site>;
  public memorySize: number | string;
  public dirty: boolean;
  public needUpdateExtensionVersion;
  public extensionVersion: string;
  public latestExtensionVersion: string;
  public dailyMemoryTimeQuota: string;
  public dailyMemoryTimeQuotaOriginal: string;
  public showDailyMemoryWarning: boolean = false;
  public showDailyMemoryInfo: boolean = false;
  public functionApp: FunctionApp;
  public exactExtensionVersion: string;

  public functionStatusOptions: SelectOption<boolean>[];
  public needUpdateRoutingExtensionVersion: boolean;
  public routingExtensionVersion: string;
  public latestRoutingExtensionVersion: string;
  public apiProxiesEnabled: boolean;
  private proxySettingValueStream: Subject<boolean>;
  private functionEditModeValueStream: Subject<boolean>;
  public showTryView: boolean;

  private _viewInfoStream = new Subject<TreeViewInfo>();
  private _viewInfo: TreeViewInfo;
  private _viewInfoSub: RxSubscription;
  private _appNode: AppNode;

  public functionAppEditMode: boolean = true;
  public functionAppEditModeOptions: SelectOption<boolean>[];

  private _isSlotApp: boolean = false;
  public slotsStatusOptions: SelectOption<boolean>[];
  public slotsAppSetting: string;
  public slotsEnabled: boolean;
  private slotsValueChange: Subject<boolean>;
  private _numSlots: number = 0;

  constructor(
    private _armService: ArmService,
    private _cacheService: CacheService,
    private _portalService: PortalService,
    private _broadcastService: BroadcastService,
    private _functionsService: FunctionsService,
    private _globalStateService: GlobalStateService,
    private _aiService: AiService,
    private _translateService: TranslateService,
    private _slotsService: SlotsService
  ) {

    this.showTryView = this._globalStateService.showTryView;
    this._viewInfoSub = this._viewInfoStream
      .switchMap(viewInfo => {
        this._viewInfo = viewInfo;
        this._globalStateService.setBusyState();

        this._appNode = (<AppNode>viewInfo.node);

            return Observable.zip(
                this._cacheService.getArm(viewInfo.resourceId),
                this._cacheService.postArm(`${viewInfo.resourceId}/config/appsettings/list`, true),
                this._appNode.functionAppStream,
                  this._slotsService.getSlotsList(viewInfo.resourceId),
                (s: Response, a: Response, fa: FunctionApp, slots: ArmObj<Site>[]) => ({ siteResponse: s, appSettingsResponse: a, functionApp: fa, slotsList: slots }))
                .mergeMap(result => {
                    return Observable.zip(result.functionApp.getFunctionAppEditMode(), result.functionApp.getFunctionHostStatus(),
                        (editMode: FunctionAppEditMode, hostStatus: HostStatus) => ({ editMode: editMode, hostStatus: hostStatus }))
                          .map(r => ({
                              siteResponse: result.siteResponse,
                              appSettingsResponse: result.appSettingsResponse,
                              functionApp: result.functionApp,
                              editMode: r.editMode,
                              hostStatus: r.hostStatus,
                              slotsList: result.slotsList
                            })
                       );
                });
        })
        .do(null, e => {
          this._aiService.trackException(e, 'function-runtime');
        })
        .retry()
        .subscribe(r => {
            let appSettings: ArmObj<any> = r.appSettingsResponse.json();

            this.functionApp = r.functionApp;
            this.site = r.siteResponse.json();
            this.exactExtensionVersion = r.hostStatus ? r.hostStatus.version : '';
            this._isSlotApp = SlotsService.isSlot(this.site.id);
            this.dailyMemoryTimeQuota = this.site.properties.dailyMemoryTimeQuota
                ? this.site.properties.dailyMemoryTimeQuota.toString()
                : '0';

            if (this.dailyMemoryTimeQuota === '0') {
{'fraction_non_alphanumeric': 0.12737254901960784, 'fraction_numerical': 0.00047058823529411766, 'mean_word_length': 3.085549503364306, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 39, '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': '2501947', 'n_tokens_mistral': 3351, 'n_tokens_neox': 3324, 'n_words': 727}