Func<Session, ActionResult> and ProgressTextAttribute for ManagedAction

Mar 15, 2016 at 2:28 PM
Как насчет того чтобы создать конструктор для ManagedAction:
public ManagedAction(Func<Session, ActionResult> funcName, ....)
который берет имя метода и вызывает базовый конструктор
например
new ManagedAction(CustomActions.MyAction, ...)

class CustomActions
{

[CustomAction]
[ProgressText("Text in ProgressDlg")]
public static ActionResult  MyAction(Session session)
{}
}
еще в этом конструкторе можно вычислить ProgressTextAttribute и поместить в XML как в примере:
http://stackoverflow.com/questions/1286967/in-wix-is-it-possible-to-update-the-status-text-when-executing-custom-actions
Coordinator
Mar 15, 2016 at 9:59 PM
It is a good idea. Will definitely do it in the next release.
Though the ManagedUI events offer you even better (except 'progress text') support:
project.Load += msi_Load;
project.BeforeInstall += msi_BeforeInstall;
project.AfterInstall += msi_AfterInstall;
...
static void msi_Load(SetupEventArgs e)
{
    MessageBox.Show(e.ToString(), "Load");
}

static void msi_BeforeInstall(SetupEventArgs e)
{
    MessageBox.Show(e.ToString(), "BeforeInstall");
}

static void msi_AfterInstall(SetupEventArgs e)
{
    MessageBox.Show(e.ToString(), "AfterExecute");
}
Coordinator
Mar 17, 2016 at 11:48 AM
The latest codebase (commit:16cde819ed99) now contains the constructors that take delegates instead of string literals as method name:
var project = new Project("CustomActionTest",
        new Dir(@"%ProgramFiles%\My Company\My Product", new File("setup.cs")),
        new ManagedAction(CustomActions.MyAction, Return.check, When.After, Step.InstallInitialize, Condition.NOT_Installed));
I had to mark almost all old constructors as obsolete thus it will be a bit messy until I phase them out in 1-2 releases. Thought it is still manageable.

As for 'ProgressTextAttribute' it's tempting but not possible. This attribute has to be supplied as C# compile. Meaning that the build script cannot inject a new attribute into itself. Unfortunately WiX DTF (managed CA hosting) doesn't support any dynamic resolution and solely relies on hardcodded attributes.
Mar 21, 2016 at 9:57 AM
Спасибо.
Я бы оставил старые конструкторы, каши не просят.

А если заменить атрибут на другой? например, System.ComponentModel.DescriptionAttribute?
Coordinator
Mar 21, 2016 at 10:32 AM
I am leaving a single constructor taking a string as an action name. It will be handy for the all "plan B" situations. The rest of them need to to go. Otherwise the API is becoming too messy. If I don't take them out there will be 25 constructors (instead of 13).

>А если заменить атрибут на другой? например, System.ComponentModel.DescriptionAttribute?
Won't help.

First problem is that DTF compiler/packager expects exactly "ProgressTextAttribute".

But the second problem is more fundamental. It's just not possible for the assembly to modify it's own metadata at runtime. It's like lifting yourself above the ground by pulling your own hair. Like Baron Munchausen did :)