private void UpdateAlias <T>(T item, Action <T> updateAction, ItemNameParser <T> parser, IUpdateBehaviour behaviour, ISemanticAliases aliases, bool dryRun)
        {
            string newAlias = null;

            try
            {
                var expanded = parser.Expand(item, Vault);
                newAlias = behaviour.UpdateAlias(aliases.Value, expanded);

                if (string.IsNullOrWhiteSpace(newAlias) && string.IsNullOrWhiteSpace(aliases.Value))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error generating new alias for {alias}.", aliases?.Value);
                return;
            }

            try
            {
                if (aliases.Value != newAlias)
                {
                    aliases.Value = newAlias;
                    if (!dryRun)
                    {
                        updateAction(item);
                    }
                }

                var msg = dryRun ? "Would update alias {alias}." : "Updated alias {alias}.";
                Log.Information(msg, aliases?.Value);
            }
            catch (Exception e)
            {
                Log.Error(e, "Error updating aliases {alias}.", aliases?.Value);
            }
        }
Exemple #2
0
 public void TestEmpty()
 {
     Assert.Equal("", _behaviour.UpdateAlias("", ""));
 }
 public void TestNull()
 {
     Assert.Equal("", _behaviour.UpdateAlias(null, ""));
 }