手術結果を取得
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
バッチを送信した後client.LastBatch検査すると、そのバッチに含まれるすべての操作のリストが表示されます。
using Sitecore.XConnect; using Sitecore.XConnect.Client; using Sitecore.XConnect.Operations; using System;
namespace Documentation { public class SeeAllExecutedOperations { // Async Example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var newContact = new Sitecore.XConnect.Contact(); client.AddContact(newContact);
Guid channelId = Guid.NewGuid(); string userAgent = "Sample User Agent";
var interaction = new Sitecore.XConnect.Interaction(newContact, InteractionInitiator.Brand, channelId, userAgent);
var fakeItemID = Guid.NewGuid(); var fakeItemVersion = 3;
Sitecore.XConnect.Collection.Model.PageViewEvent pageView = new Sitecore.XConnect.Collection.Model.PageViewEvent(DateTime.UtcNow, fakeItemID, fakeItemVersion, "en") { Duration = new TimeSpan(0, 0, 30), };
interaction.Events.Add(pageView);
client.AddInteraction(interaction);
await client.SubmitAsync();
var allOperations = client.LastBatch;
foreach (IXdbOperation op in allOperations) { // Output operation type var operationType = op.OperationType; // Output status var status = op.Status; } } catch (XdbExecutionException ex) { // Handle exception } } }
// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var newContact = new Sitecore.XConnect.Contact(); client.AddContact(newContact);
Guid channelId = Guid.NewGuid(); string userAgent = "Sample User Agent";
var interaction = new Sitecore.XConnect.Interaction(newContact, InteractionInitiator.Brand, channelId, userAgent);
var fakeItemID = Guid.NewGuid(); var fakeItemVersion = 3;
Sitecore.XConnect.Collection.Model.PageViewEvent pageView = new Sitecore.XConnect.Collection.Model.PageViewEvent(DateTime.UtcNow, fakeItemID, fakeItemVersion, "en") { Duration = new TimeSpan(0, 0, 30), };
interaction.Events.Add(pageView);
client.AddInteraction(interaction);
client.Submit();
var allOperations = client.LastBatch;
foreach (IXdbOperation op in allOperations) { // Output operation type var operationType = op.OperationType; // Output status var status = op.Status; } } catch (XdbExecutionException ex) { // Handle exception } } } } }
単一操作結果を得る
特定の操作への参照を保存し、バッチを提出した後に検査することもできます。例えば:
using Sitecore.XConnect; using Sitecore.XConnect.Client; using Sitecore.XConnect.Operations; using System;
namespace Documentation { public class SeeSingleOperation { // Async Example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var newContact = new Sitecore.XConnect.Contact(); client.AddContact(newContact);
Guid channelId = Guid.NewGuid(); string userAgent = "Sample User Agent";
var interaction = new Sitecore.XConnect.Interaction(newContact, InteractionInitiator.Brand, channelId, userAgent);
var fakeItemID = Guid.NewGuid(); var fakeItemVersion = 3;
Sitecore.XConnect.Collection.Model.PageViewEvent pageView = new Sitecore.XConnect.Collection.Model.PageViewEvent(DateTime.UtcNow, fakeItemID, fakeItemVersion, "en") { Duration = new TimeSpan(0, 0, 30), };
interaction.Events.Add(pageView);
// Save reference to operation var addInteractionOperation = client.AddInteraction(interaction);
await client.SubmitAsync();
if (addInteractionOperation.Result.Status == SaveResultStatus.Conflict) { // Do something } } catch (XdbExecutionException ex) { // Handle exception } } }
// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { var newContact = new Sitecore.XConnect.Contact(); client.AddContact(newContact);
Guid channelId = Guid.NewGuid(); string userAgent = "Sample User Agent";
var interaction = new Sitecore.XConnect.Interaction(newContact, InteractionInitiator.Brand, channelId, userAgent);
var fakeItemID = Guid.NewGuid(); var fakeItemVersion = 3;
Sitecore.XConnect.Collection.Model.PageViewEvent pageView = new Sitecore.XConnect.Collection.Model.PageViewEvent(DateTime.UtcNow, fakeItemID, fakeItemVersion, "en") { Duration = new TimeSpan(0, 0, 30), };
interaction.Events.Add(pageView);
// Save reference to operation var addInteractionOperation = client.AddInteraction(interaction);
client.Submit();
if (addInteractionOperation.Result.Status == SaveResultStatus.Conflict) { // Do something } } catch (XdbExecutionException ex) { // Handle exception } } } }