> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure Functions Context 모델을 사용하는 PlayFab CloudScript

> 스크립트가 ExecuteFunction, 예약된 작업, 플레이어 또는 엔티티를 통해 실행될 때 Azure Functions에 노출되는 PlayFab CloudScript context 모델에 대한 참조입니다.

# 자습서: CloudScript context 모델 사용

PlayFab은 API를 통한 실행, 예약된 작업을 통한 실행, PlayStream 이벤트를 통한 실행, 플레이어의 세그먼트 진입 및 종료 등 여러 메커니즘을 통해 스크립트를 실행합니다. 많은 경우, 스크립트가 실행되는 컨텍스트는 실행 방식에 중요합니다. 예를 들어, 스크립트가 대신 실행되고 있는 플레이어의 Player ID를 아는 것입니다. 스크립트가 실행되는 컨텍스트는 사용 가능한 데이터 모델을 결정하고, 스크립트에서 사용되는 컨텍스트별 데이터를 제공합니다.

이 자습서에서는 다음 방법을 배웁니다.

<Note>
  \[!div class="checklist"]
</Note>

>

<Note>
  * 공유 context 모델 사용 \* ExecuteFunction API를 통해 실행할 때 context 모델 사용 \* 예약된 작업을 통해 실행할 때 context 모델 사용 \* 플레이어 컨텍스트에서 실행할 때 context 모델 사용 \* 엔티티 컨텍스트에서 실행할 때 context 모델 사용
</Note>

## 공유 Title Authentication context 모델 사용

스크립트를 실행하는 방법에 관계없이, Title Authentication context는 항상 제공됩니다. 여기에는 스크립트를 실행하는 데 사용되는 Title ID와 Entity Token([GetEntityToken](https://learn.microsoft.com/en-us/rest/api/playfab/authentication/authentication/get-entity-token) 참조)이 포함됩니다. 이 컨텍스트를 알면 Server API를 사용하여 스크립트에서 PlayFab으로 추가 API 호출을 할 수 있습니다.

```C# theme={null}
// Shared models
public class TitleAuthenticationContext
{
    public string Id { get; set; }
    public string EntityToken { get; set; }
}
```

## ExecuteFunction API를 통해 실행할 때 context 모델 사용

[ExecuteFunction API](https://learn.microsoft.com/en-us/rest/api/playfab/cloudscript/server-side-cloud-script/execute-function)를 사용하여 스크립트를 실행하면, 제공되는 context에는 다음 정보가 포함됩니다.

* 호출자의 Entity Profile
* Title Authentication Context
* 실행되는 함수의 일부로 PlayStream 이벤트가 전송되는지 여부를 나타내는 부울
* 스크립트 호출 시 사용된 함수 인수

```C# theme={null}
// Models via ExecuteFunction API
public class FunctionExecutionContext<T>
{
    public PlayFab.ProfilesModels.EntityProfileBody CallerEntityProfile { get; set; }
    public TitleAuthenticationContext TitleAuthenticationContext { get; set; }
    public bool? GeneratePlayStreamEvent { get; set; }
    public T FunctionArgument { get; set; }
}

public class FunctionExecutionContext : FunctionExecutionContext<object>
{
}
```

## 예약된 작업을 통해 실행할 때 context 모델 사용

[예약된 작업](/services/playfab/data-analytics/acting-data/scheduled-tasks)을 사용하여 스크립트를 실행하면, 제공되는 context에는 다음 정보가 포함됩니다.

* Scheduled Task Name Id
* PlayStream 이벤트 스택을 포함하는 이벤트 이력
* Title Authentication Context
* 실행되는 함수의 일부로 PlayStream 이벤트가 전송되는지 여부를 나타내는 부울
* 스크립트 호출 시 사용된 함수 인수

```C# theme={null}
// Models via Scheduled task
public class PlayStreamEventHistory
{
    public string ParentTriggerId { get; set; }
    public string ParentEventId { get; set; }
    public bool TriggeredEvents { get; set; }
}

public class ScheduledTaskFunctionExecutionContext<T>
{
    public PlayFab.CloudScriptModels.NameIdentifier ScheduledTaskNameId { get; set; }
    public Stack<PlayStreamEventHistory> EventHistory { get; set; }
    public TitleAuthenticationContext TitleAuthenticationContext { get; set; }
    public bool? GeneratePlayStreamEvent { get; set; }
    public T FunctionArgument { get; set; }
}

public class ScheduledTaskFunctionExecutionContext : ScheduledTaskFunctionExecutionContext<object>
{
}
```

## 플레이어 컨텍스트에서 실행할 때 context 모델 사용

Player PlayStream 이벤트, 세그먼트 진입 또는 종료, 또는 세그먼트 기반 예약된 작업의 일부로 스크립트를 실행할 때, 제공되는 context에는 다음 정보가 포함됩니다.

* Player Profile
* 플레이어 프로필이 잘렸는지를 나타내는 부울.
  * Player Profile이 2048바이트를 초과하면 잘립니다. 이 경우, 전체 프로필을 검색하려면 프로필 API(서버, 클라이언트 또는 엔티티 API)를 사용해야 합니다.
* 스크립트를 트리거한 PlayStream 이벤트.
* 실행되는 함수의 일부로 PlayStream 이벤트가 전송되는지 여부를 나타내는 부울
* 스크립트 호출 시 사용된 함수 인수

```C# theme={null}
// Models via Player PlayStream event, entering or leaving a 
// player segment or as part of a player segment based scheduled task.
public class PlayerPlayStreamFunctionExecutionContext<T>
{
    public PlayFab.CloudScriptModels.PlayerProfileModel PlayerProfile { get; set; }
    public bool PlayerProfileTruncated { get; set; }
    public PlayFab.CloudScriptModels.PlayStreamEventEnvelopeModel PlayStreamEventEnvelope { get; set; }
    public TitleAuthenticationContext TitleAuthenticationContext { get; set; }
    public bool? GeneratePlayStreamEvent { get; set; }
    public T FunctionArgument { get; set; }
}

public class PlayerPlayStreamFunctionExecutionContext : PlayerPlayStreamFunctionExecutionContext<object>
{
}
```

## Entity PlayStream 이벤트, 엔티티 세그먼트 진입/종료 또는 엔티티 세그먼트 기반 예약된 작업의 일부로 실행할 때 context 모델 사용

Entity PlayStream 이벤트, 엔티티 세그먼트 진입 또는 종료, 또는 엔티티 세그먼트 기반 예약된 작업의 일부로 스크립트를 실행할 때, 제공되는 context에는 다음 정보가 포함됩니다.

* Entity Profile
* 스크립트를 트리거한 PlayStream 이벤트.
* 실행되는 함수의 일부로 PlayStream 이벤트가 전송되는지 여부를 나타내는 부울

```C# theme={null}
// Models via Entity PlayStream event, entering or leaving an 
// entity segment or as part of an entity segment based scheduled task.
public class EventFullName
{
    public string Name { get; set; }
    public string Namespace { get; set; }
}

public class OriginInfo
{
    public string Id { get; set; }
    public DateTime? Timestamp { get; set; }
}

public class EntityPlayStreamEvent<T>
{
    public string SchemaVersion { get; set; }
    public EventFullName FullName { get; set; }
    public string Id { get; set; }
    public DateTime Timestamp { get; set; }
    public PlayFab.CloudScriptModels.EntityKey Entity { get; set; }
    public PlayFab.CloudScriptModels.EntityKey Originator { get; set; }
    public OriginInfo OriginInfo { get; set; }
    public T Payload { get; set; }
    public PlayFab.ProfilesModels.EntityLineage EntityLineage { get; set; }
}

public class EntityPlayStreamEvent : EntityPlayStreamEvent<object>
{
}

public class EntityPlayStreamFunctionExecutionContext<TPayload, TArg>
{
    public PlayFab.ProfilesModels.EntityProfileBody CallerEntityProfile { get; set; }
    public EntityPlayStreamEvent<TPayload> PlayStreamEvent { get; set; }
    public TitleAuthenticationContext TitleAuthenticationContext { get; set; }
    public bool? GeneratePlayStreamEvent { get; set; }
    public TArg FunctionArgument { get; set; }
}

public class EntityPlayStreamFunctionExecutionContext : EntityPlayStreamFunctionExecutionContext<object, object>
{
}
```

<Note>
  전체 [CloudScript using Azure Functions helper class](https://github.com/PlayFab/PlayFab-Samples/blob/master/Samples/CSharp/AzureFunctions/CS2AFHelperClasses.cs)를 다운로드할 수 있습니다.
</Note>


## Related topics

- [Azure Functions를 사용하는 PlayFab CloudScript 빠른 시작 가이드](/ko/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/quickstart.md)
- [PlayFab CloudScript using Azure Functions](/ko/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/index.md)
- [Azure Functions를 사용하는 CloudScript의 로컬 디버깅](/ko/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/local-debugging-for-cloudscript-using-azure-functions.md)
- [Winter Starfall PlayFab 데모 게임 개요](/ko/services/playfab/demo-game/overview.md)
- [CloudScript](/ko/services/playfab/live-service-management/service-gateway/automation/cloudscript/index.md)
