### File

`src/app/run-code.service.ts`

### Index

###### Properties

- Private baseUrl
- result
- runStatus

###### Methods

- compileFile
- compileQuestionFile
- executeFile
- update
- verifyTestcase

### Constructor

`constructor(httpClient: HttpClient)`
Defined in src/app/run-code.service.ts:20

Parameters :

Name | Type | Optional
httpClient | `HttpClient` | No

### Methods

compileFile
`compileFile(file: File)`
Defined in src/app/run-code.service.ts:29

Parameters :

Name | Type | Optional
file | `File` | No

Returns : `Observable<any>`

compileQuestionFile
`compileQuestionFile(ques: Question, code: string[])`
Defined in src/app/run-code.service.ts:70

Parameters :

Name | Type | Optional
ques | `Question` | No
code | `string[]` | No

Returns : `Observable<any>`

executeFile
`executeFile(file: File, input: string)`
Defined in src/app/run-code.service.ts:37

Parameters :

Name | Type | Optional
file | `File` | No
input | `string` | No

Returns : `Observable<any>`

update
`update(b: boolean)`
Defined in src/app/run-code.service.ts:62

Parameters :

Name | Type | Optional
b | `boolean` | No

Returns : `Observable<any>`

verifyTestcase
`verifyTestcase(file: File, out: string, ind: number, isSubmit: number)`
Defined in src/app/run-code.service.ts:48

Parameters :

Name | Type | Optional
file | `File` | No
out | `string` | No
ind | `number` | No
isSubmit | `number` | No

Returns : `Observable<any>`

### Properties

Private baseUrl
Type : `string`
Default value : `'http://localhost/sfcode/backend/'`
Defined in src/app/run-code.service.ts:20

result
Type : `number`
Default value : `0`
Defined in src/app/run-code.service.ts:19

runStatus
Type : `string`
Default value : `'Compiling...'`
Defined in src/app/run-code.service.ts:18

    import {Injectable} from '@angular/core';
    // import {Problem} from './problem';
    import {Question} from './question';
    import {File} from './file';
    import {Observable, of, throwError} from 'rxjs';
    import {HttpClient} from '@angular/common/http';

    @Injectable({
      providedIn: 'root'
    })
    export class RunCodeService {

      runStatus = 'Compiling...';
      result = 0;
      private baseUrl = 'http://localhost/sfcode/backend/';

      constructor(private httpClient: HttpClient) {
      }

      /*! \brief
        This function is used to post the file data for compilation.
      */

      compileFile(file: File): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'compile.php', file);
      }

      /*! \brief
        This function is used to post the file data and custom input for execution.
      */

      executeFile(file: File, input: string): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'execute.php', {
          file,
          input_data: input
        });
      }

      /*! \brief
        This function is used to verify the testcases while posting the file data and other relaated parameters to the backend.
      */

      verifyTestcase(file: File, out: string, ind: number, isSubmit: number): Observable<any> {
        return this.httpClient.post(this.baseUrl + 'questions/check_output.php', {
          title: file.filename,
          username: file.username,
          out,
          ind,
          isSubmit
        });
      }

      /*! \brief
        This function is used to update the server about the result of user attempt to the question by a boolean.
      */

      update(b: boolean): Observable<any> {
        return this.httpClient.put(this.baseUrl + 'update_correct.php', {b});
      }

      /*! \brief
        This function is for debugging purposes.
      */

      compileQuestionFile(ques: Question, code: string[]): Observable<any> {
        if (Math.floor(Math.random() * 2) === 1) {return of('done'); }
        else {return throwError('error'); }
      }
    }

# result-matching ""

# No results matching ""