다음 예시에는 종료하기 전에 피보나치 수열을 출력하는 샘플 명령이 있습니다. 이 예시를 따라 자동화 프로젝트에 새로운 명령(또는 스크립트)을 추가하세요.
단계
필수 단계 : 계속하기 전에 자동화 프로젝트 범위 안에 빈 *.cs
소스 파일이 있어야 합니다.
먼저 소스 파일의 이름을 지정해야 합니다. 이 예시에서는 파일 이름을 `SimpleScript.cs`로 정했습니다.
이제 다음 샘플 코드를 스크립트에 복사하세요.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutomationTool; namespace SampleScript.Automation { // [Help()] 어트리뷰트를 사용하여 명령과 실행인자를 문서화합니다. [Help("Sample script printing a Fibonacci sequence of values.")] [Help("Usage: SampleScript -Terms=<N>")] [Help("Terms=<N>", "N (int) represents how many terms to compute, and it must be greater than or equal to 1.")] // BuildCommand는 모든 명령의 베이스 클래스입니다. public class SampleCommand : BuildCommand { public override void ExecuteBuild() { // ParseParamInt() 메서드는 이 예시의 명령줄 실행인자를 얻습니다. ParseParam()은 부울을 얻고 ParseParamValue는 스트링을 얻습니다. int NumTerms = ParseParamInt("Terms"); if (NumTerms < 1) { throw new AutomationException("Invalid number of terms specified. Enter -help for syntax."); } else { LogInformation("Fibonnacci sequence:"); int TermA = 1; int TermB = 1; for (int TermIdx = 0; TermIdx < NumTerms; TermIdx++) { LogInformation(" {0}", TermA); int NextTerm = TermA + TermB; TermA = TermB; TermB = NextTerm; } } } } }
마지막으로 명령 프롬프트를 열고
Engine\Build\BatchFiles
로 이동한 다음RunUAT.bat SampleCommand -terms=4
를 입력합니다.
최종 결과
다음과 같은 출력이 표시됩니다.