private static async Task HandleAutomatedCustomization(CustomizationHelper helper) { var sourceIdStr = helper.EnsureValid(helper.StringValueOf(helper.Context.AdditionalProperties, "Id"), s => s != null, $"The source Id is missing in the customization context: {helper.Context}"); var sourceVariables = helper.ArrayValueOf(helper.Context.AdditionalProperties, "Variables"); //Get source Id helper.EnsureValid(int.TryParse(sourceIdStr, out var sourceId), v => v, $"The source Id<{sourceIdStr}> coming from the customization context is not convertible to an interger"); var source = (await helper.GetSources(new[] { sourceId })).FirstOrDefault(); if (source is null) { helper.SendFeedback($"The source with Id<{sourceId}> does not exist in the database"); if (!helper.WhatIf) { return; } //In whatif mode, create a fake source source = new Source { Id = 0, EanNumber = "FAKE EAN", ClientData = JObject.Parse("{'No client data'}"), Name = "FAKE NAME", SiteId = 0, SiteName = "NO SITE" }; } await Process(source, sourceVariables, helper, false); }
private static bool SingleSourceIdIsSpecified(CustomizationHelper helper) { return(!string.IsNullOrEmpty(helper.StringValueOf(helper.Context.AdditionalProperties, "Id"))); }