import { Injectable } from '@angular/core' ; import { Headers , Http , Request } from '@angular/http' ; import { ArmObj } from '../../../../shared/models/arm/arm-obj' ; import { Site } from '../../../../shared/models/arm/site' ; import { PublishingCredentials } from '../../../../shared/models/publishing-credentials' ; import { BehaviorSubject } from 'rxjs/BehaviorSubject' ; import { Observable } from 'rxjs/Observable' ; export enum ConsoleTypes { CMD = 1 , PS = 2 , BASH = 3 , SSH = 4 } @ Injectable ( ) export class ConsoleService { private _resourceIdSubject = new BehaviorSubject < string > ( '' ) ; private _siteSubject = new BehaviorSubject < ArmObj < Site > > ( undefined ) ; private _publishingCredentialsSubject = new BehaviorSubject < ArmObj < PublishingCredentials > > ( undefined ) ; constructor ( private _http ) { } /**
     *  Send the resource ID to child components
     */ sendResourceId ( resourceId ) { this . _resourceIdSubject . next ( resourceId ) ; } /**
     *  Send the site object to child components
     */ sendSite ( site ) { this . _siteSubject . next ( site ) ; } /**
     *  Send the publishing credentials' object to child components
     */ sendPublishingCredentials ( publishingCredentials ) { this . _publishingCredentialsSubject . next ( publishingCredentials ) ; } /**
     *  Get resourceID
     */ getResourceId ( ) { return this . _resourceIdSubject . asObservable ( ) ; } /**
     *  Get Site object as Observable
     */ getSite ( ) { return this . _siteSubject . asObservable ( ) ; } /**
     *  Get publishing credentials as Observable
     */ getPublishingCredentials ( ) { return this . _publishingCredentialsSubject . asObservable ( ) ; } param method param url param body param headers send ( method , url , body ? , headers ? ) { const request = new Request ( { url : url , method : method , search : null , headers : headers , body : body ? body : null , } ) ; return this . _http . request ( request ) ; } /**
     * Find all the strings which start with the given string, 'cmd' from the given string array
     * Incase the string is empty, the inital array of strings is returned.
     */ findMatchingStrings ( allFiles , cmd ) { if ( ! cmd || cmd === '' ) { return allFiles ; } const ltOfDir = [ ] ; cmd = cmd . toLowerCase ( ) ; allFiles . forEach ( element => { if ( element . toLowerCase ( ) . startsWith ( cmd ) ) { ltOfDir . push ( element ) ; } } ) ; return ltOfDir ; } }