操作結果を取得する

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

このページの翻訳は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
                }
            }
        }
    }
}
メモ

失敗した操作の処理方法については、例外処理再試行操作 に関するドキュメントを参照してください。

1回の操作結果の取得

また、特定の操作への参照を保存し、バッチの送信後に検査することもできます。例えば:

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
            }
        }
    }
}
この記事を改善するための提案がある場合は、 お知らせください!