2

The Sitecore Content Hub documentation provides an example script that does not compile.

When trying to run the script, it encounters several compile errors. For instance:

Build error screenshot

Error CS0103: The name 'entities' does not exist in the current context (Line 7, Columns 31 and 52)
Error CS0029: Cannot implicitly convert type 'long' to 'bool' (Line 16, Column 5)
Error CS1026: ) expected (Line 16, Column 34)
Error CS1002: ; expected (Line 16, Column 35 and Line 37, Column 41)
Error CS7017: Member definition, statement, or end-of-file expected (Line 16, Column 35)
Error CS8917: The delegate type could not be inferred. (Line 37, Column 18)
Error CS1955: Non-invocable member 'IChildToManyParentsRelation' cannot be used like a method. (Line 37, Column 41)

Has anyone else encountered this issue or knows how to resolve it?

1 Answer 1

3

The issue is that angle brackets were removed from the script. This has been reported to the Sitecore Docs team. The following script compiles. The only modification is the introduction of the missing angle brackets:

using System.Linq;
using System.Threading.Tasks;
using Stylelabs.M.Base.Querying;
using Stylelabs.M.Base.Querying.Linq;
 
var assetId = Context.TargetId;

// Check if public links don't exist yet
var query = Query.CreateQuery(entities => from e in entities
  where e.DefinitionName == "M.PublicLink"
  && e.Parent("AssetToPublicLink") == assetId.Value
  && e.Property("Resource") == "downloadOriginal"
  && e.Property("IsDisabled") == false
  select e);
query.Take = 1;

var result = await MClient.Querying.QueryIdsAsync(query);
if (result.TotalNumberOfResults >  0)
{
  MClient.Logger.Info("Public links already exist for asset with id '" + assetId + "'");
  return;
}

// Create public links
await CreateForRendition("downloadOriginal", assetId.Value);
MClient.Logger.Info("Created public link 'downloadOriginal' for asset with id '" + assetId + "'");

async Task CreateForRendition(string rendition, long assetId)
{
  var publicLink = await MClient.EntityFactory.CreateAsync("M.PublicLink");

  if (publicLink.CanDoLazyLoading())
  {
    await publicLink.LoadMembersAsync(new PropertyLoadOption("Resource"), new RelationLoadOption("AssetToPublicLink"));
  }

  publicLink.SetPropertyValue("Resource", rendition);

  var relation = publicLink.GetRelation<IChildToManyParentsRelation>("AssetToPublicLink");
  if (relation == null)
  {
    MClient.Logger.Error("Unable to create public link: no AssetToPublicLink relation found.");
    return;
  }

  relation.Parents.Add(assetId);

  await MClient.Entities.SaveAsync(publicLink);
  return;
}



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.