アセットの削除

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

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

次のコードを使用して、削除されたアセットを取得するアクションを作成します。

using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Stylelabs.M.Sdk;
using Stylelabs.M.Sdk.Contracts.Base;

var executionId = string.Empty;

LogScriptCalled(Context, MClient);

//Get the Asset ID
var assetId = Context.TargetId.Value;

//Add the executionId to Property Bag
Context.PropertyBag.Add($"{assetId}-executionId", executionId);

//Get the change set (newly added assets)
var changeSet = Context.ChangeTracker.GetChangeSet();
var relationChanges = changeSet.RelationChanges;
var productGalleryRelationChange = relationChanges.FirstOrDefault(x => x.Name == "ProductToGalleryAsset");
var removedProductIds = productGalleryRelationChange.RemovedValues;

if (removedProductIds.Count <= 0)
{
    LogInfo(Context, MClient, $"There are no assets removed from the Product Gallery");
    return;
}

var strRemovedProductIds = string.Join(",", removedProductIds.ToArray());

LogInfo(Context, MClient, $"Product Gallery changed products: { strRemovedProductIds }");

//Add the asset IDs to Property Bag
Context.PropertyBag.Add($"{assetId}-{executionId}-change", strRemovedProductIds);


#region Helpers

void LogScriptCalled(IActionScriptContext context, IMClient client)
{
    executionId = Guid.NewGuid().ToString("N").Substring(0, 6);
    LogInfo(context, client, $"{executionId}: Execution started. Context: {context}");
}

void LogDebug(IActionScriptContext context, IMClient client, string message)
{
    client.Logger.Debug(LogPrefix(context) + message);
}

void LogInfo(IActionScriptContext context, IMClient client, string message)
{
    client.Logger.Info(LogPrefix(context) + message);
}

string LogPrefix(IActionScriptContext context)
{
    return $"{ (context?.TargetId != null ? context.TargetId.Value.ToString() : string.Empty)} | ";
}

#endregion
この記事を改善するための提案がある場合は、 お知らせください!