Hey Juraj,
This is the Macro Rule condition code:
return {_has}Document.LCARSHasProjectMetaData()
And this is the macro's code itself:
MacroMethod updateProjectMetaData = new MacroMethod("LCARSHasProjectMetaData", LCARSHasProjectMetaData)
{
Comment = "Returns true if project has metadata. Attempts to retrieve if it does not.",
Type = typeof(bool),
AllowedTypes = new List<Type>() { typeof(TreeNode) },
MinimumParameters = 1
};
updateProjectMetaData.AddParameter("document", typeof(TreeNode), "Project document");
MacroMethods.RegisterMethod(updateProjectMetaData);
public static object LCARSHasProjectMetaData(params object[] parameters)
{
switch (parameters.Length)
{
case 1:
return LCARSHasProjectMetaData(parameters[0] as TreeNode);
}
return null;
}
public static bool LCARSHasProjectMetaData(TreeNode node)
{
var id = ValidationHelper.GetString(node["ProjectID"], String.Empty);
if (!String.IsNullOrWhiteSpace(id))
{
var manager = Dependencies.CreateManager();
var has = manager.HasProjectMetaData(id);
return has;
}
return false;
}
Behind manager.HasProjectMetaData, this is the only code that would use a user context that I know of:
var provider = new TreeProvider();
var parameters = new NodeSelectionParameters();
parameters.Where = string.Format("ProjectID = '{0}'", id);
parameters.SiteName = this.settingsProvider.SiteName;
parameters.ClassNames = this.settingsProvider.ProjectClassName;
parameters.AliasPath = null;
parameters.SelectOnlyPublished = false;
var node = provider.SelectSingleNode(parameters);
if (node != null)
{
return TreeNode.New<Project>(node, this.settingsProvider.ProjectClassName, provider);
}
return null;