1. ジョブ・クライアント

EntitiesクライアントからJobsクライアントへの切り替え

日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

ジョブ・クライアントの導入により、M.TargetエンティティおよびM.JobDescriptionエンティティを操作するときに、EntitiesClientおよびQueryingClientの使用をJobClientに置き換える必要があります。

メモ

Jobsクライアントを活用するためにコードを更新するために、より詳細な をいくつか紹介します。

次の例は、Web SDKを使用してM.TargetエンティティとM.JobDescriptionエンティティを操作するときに、EntitiesClientQueryingClientの使用をJobClientに置き換える方法を示しています。

ジョブの説明を取得する

次に、Entitiesクライアントを使用してジョブの説明を取得する例を示します。

// by id
IEntity entity = await _client.Entities.GetAsync(jobDescriptionId);

// by identifier
IEntity entity = await _client.Entitites.GetAsync(jobDescriptionIdentifier);

// by quering 
Query query = Query.CreateQuery(entities =>
     from e in entities 
     where e.DefinitionName == "M.JobDescription"
     select e);
IEntityQueryResult result = await _client.Querying.QueryAsync(query);
IList<IEntity> entities = result.Items;

ジョブ クライアントを使用するには、次のようにコードを更新します。

IEntity entity = await _client.Jobs.GetDescriptionAsync(jobId);

ジョブの説明を保存する

次に、Entitiesクライアントを使用する例を示します。

// create
IEntity entity = await MClient.EntityFactory.CreateAsync("M.JobDescripton");
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'new configuration'}"));
entity.GetRelation<IChildToOneParentRelation>("JobToJobDescription").Parent = jobId;
var entityId = await MClient.Entities.SaveAsync(entity);

// update
IEntity entity = await MClient.Entities.GetAsync(jobDescriptionId);
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'configuration'}"));
var entityId = await MClient.Entities.SaveAsync(entity);

ジョブ クライアントを使用するには、次のようにコードを更新します。

// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.JobDescripton");
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'configuration'}"));
var entityId = await _client.Jobs.SaveDescriptionAsync(jobId, entity);

// update
IEntity entity = await _client.Jobs.GetDescriptionAsync(jobId);
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'new configuration'}"));
var entityId = await _client.Jobs.SaveDescriptionAsync(jobId, entity);

ジョブの説明を削除する

次に、Entitiesクライアントを使用する例を示します。

await _entitiesClient.DeleteAsync(jobDescriptionId);

ジョブ クライアントを使用するには、次のようにコードを更新します。

await _jobsClient.DeleteDescriptionAsync(jobId);

ジョブ・ターゲットのフェッチ

次に、Entitiesクライアントを使用する例を示します。

// by id
IEntity entity = await _client.Entities.GetAsync(jobTargetId);

// by identifier
IEntity entity = await _client.Entitites.GetAsync(jobTargetIdentifier);

// by querying
Query query = Query.CreateQuery(entities =>
     from e in entities 
     where e.DefinitionName == "M.Target"   
       && e.Parent("JobToTarget") == jobId
       && e.Property("Target.State") == "Waiting"
     orderby e.CreatedOn descending 
     select e);
IEntityQueryResult result = await _client.Querying.QueryAsync(query);
IList<Entity> entities = result.Items;

ジョブ・クライアントを使用するには、次のようにコードを更新します。

JobTargetQuery request = new JobTargetQuery(jobId)
{
    State = "Waiting",
    Skip = 0,
    Take = 50,
    Cultures = new[] { new CultureInfo("en-US") }
};
IEntityCollectionResult result = await MClient.Jobs.GetTargetsAsync(request);
IList<IEntity> entities = result.Items;

ジョブ・ターゲットの保存

次に、Entitiesクライアントを使用する例を示します。

// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.Target");
entity.SetPropertyValue("Target.Location", "some location");
entity.SetPropertyValue("Target.Data", JToken.FromObject(new
  {
      some = "data"
  }));
entity.GetRelation<IChildToOneParentRelation>("JobToTarget").Parent = jobId;
await _client.Entities.SaveAsync(entity);

// update
IEntity entity = await _client.Entities.GetAsync(targetId);
entity.SetPropertyValue("Target.Location", "new location");
await _client.Entities.SaveAsync(entity);

ジョブ クライアントを使用するには、次のようにコードを更新します。

// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.Target");
entity.SetPropertyValue("Target.Location", "some location");
entity.SetPropertyValue("Target.Data", JToken.FromObject(new
  {
      some = "data"
  }));
await _client.Jobs.SaveTargetAsync(jobId, entity);

// update
IEntityCollectionResult result =
    await _client.Jobs.GetTargetsAsync(new JobTargetQuery(jobId));
IEntity entity = result.Items.First();
entity.SetPropertyValue("Target.Location", "new location");
await _client.Jobs.SaveTargetAsync(jobId, entity);

ジョブ・ターゲットの削除

次に、Entitiesクライアントを使用する例を示します。

await _client.Entities.DeleteAsync(targetId);

ジョブ クライアントを使用するには、次のようにコードを更新します。

await _client.Jobs.DeleteTargetAsync(jobId, targetId);
この記事を改善するための提案がある場合は、 お知らせください!