Create() public static method

Creates WiX Condition condition from the given string value.
public static Create ( string value ) : Condition
value string String value of the Condition to be created.
return Condition
Ejemplo n.º 1
0
        void Bind <T>(Expression <Func <T> > expression, When when = When.Before, Step step = null, bool elevated = false)
        {
            var name    = Reflect.NameOf(expression);
            var handler = expression.Compile()() as Delegate;

            const string wixSharpProperties = "WIXSHARP_RUNTIME_DATA";

            if (handler != null)
            {
                if (this.AbortSetupOnUnhandledExceptions.HasValue)
                {
                    var abortOnErrorName = "WIXSHARP_ABORT_ON_ERROR";

                    if (!Properties.Any(p => p.Name == abortOnErrorName))
                    {
                        this.AddProperty(new Property(abortOnErrorName, this.AbortSetupOnUnhandledExceptions.Value.ToString()));
                    }
                }

                //foreach (string handlerAsm in handler.GetInvocationList().Select(x => x.Method.DeclaringType.Assembly.Location))
                foreach (var type in handler.GetInvocationList().Select(x => x.Method.DeclaringType))
                {
                    string location = type.Assembly.Location;

                    //Resolving scriptAsmLocation is not properly tested yet
                    bool resolveInMemAsms = true;

                    if (resolveInMemAsms)
                    {
                        if (location.IsEmpty())
                        {
                            location = type.Assembly.GetLocation();
                        }
                    }

                    if (location.IsEmpty())
                    {
                        throw new ApplicationException($"The location of the assembly for ManagedProject event handler ({type}) cannot be obtained.\n" +
                                                       "The assembly must be a file based one but it looks like it was loaded from memory.\n" +
                                                       "If you are using CS-Script to build MSI ensure it has 'InMemoryAssembly' set to false.");
                    }

                    if (!this.DefaultRefAssemblies.Contains(location))
                    {
                        this.DefaultRefAssemblies.Add(location);
                    }
                }

                this.AddProperty(new Property("WixSharp_{0}_Handlers".FormatWith(name), GetHandlersInfo(handler as MulticastDelegate)));

                string dllEntry = "WixSharp_{0}_Action".FormatWith(name);
                if (step != null)
                {
                    if (elevated)
                    {
                        this.AddAction(new ElevatedManagedAction(dllEntry)
                        {
                            Id             = new Id(dllEntry),
                            ActionAssembly = thisAsm,
                            Return         = Return.check,
                            When           = when,
                            Step           = step,
                            Condition      = Condition.Create("1"),
                            UsesProperties = "WixSharp_{0}_Handlers,{1},{2}".FormatWith(name, wixSharpProperties, DefaultDeferredProperties),
                        });
                    }
                    else
                    {
                        this.AddAction(new ManagedAction(dllEntry)
                        {
                            Id = new Id(dllEntry), ActionAssembly = thisAsm, Return = Return.check, When = when, Step = step, Condition = Condition.Create("1")
                        });
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void Bind <T>(Expression <Func <T> > expression, When when = When.Before, Step step = null, bool elevated = false)
        {
            var name    = Reflect.NameOf(expression);
            var handler = expression.Compile()() as Delegate;

            const string wixSharpProperties = "WIXSHARP_RUNTIME_DATA";

            if (handler != null)
            {
                foreach (string handlerAsm in handler.GetInvocationList().Select(x => x.Method.DeclaringType.Assembly.Location))
                {
                    if (!this.DefaultRefAssemblies.Contains(handlerAsm))
                    {
                        this.DefaultRefAssemblies.Add(handlerAsm);
                    }
                }

                this.Properties = this.Properties.Add(new Property("WixSharp_{0}_Handlers".FormatInline(name), GetHandlersInfo(handler as MulticastDelegate)));

                string dllEntry = "WixSharp_{0}_Action".FormatInline(name);
                if (step != null)
                {
                    if (elevated)
                    {
                        this.Actions = this.Actions.Add(new ElevatedManagedAction(new Id(dllEntry), dllEntry, thisAsm, Return.check, when, step, Condition.Create("1"))
                        {
                            UsesProperties = "WixSharp_{0}_Handlers,{1},{2}".FormatInline(name, wixSharpProperties, DefaultDeferredProperties),
                        });
                    }
                    else
                    {
                        this.Actions = this.Actions.Add(new ManagedAction(new Id(dllEntry), dllEntry, thisAsm, Return.check, when, step, Condition.Create("1")));
                    }
                }
            }
        }