Wix install with multiple services, and I don't how many - wix

I need to install my windows service, and have at least one instance of it. The user decides how many services they will have. But which approach will I take?
Try to make my ServiceInstall foreach the number of windows services or install them with an customization via installutil?
and then I have to solve so it does not install duplicates. But I can make an xml file that contains the service names to be installed, and read from there.
But I have read that people don't like using foreach in wix because it complicates stuff much more, and some people say installutil isn't good either. But since I don't know how many services it will be I have to solve it something like this.
And with installutil i won't get rollback either?
Does anyone know another approach?

You can run custom action which patches your MSI including service elements to install. This approach allows you to read service names from wherever you want and install as many services as you need.
Though it would be quite non-trivial for those who read your installer source code later. And to be honest I've never used this approach. But it should work...

I ended up doing this
public static void Main(string[] args)
{
if (System.Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
break;
case "uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase.Run(new WindowsService());
}
}
}
making my service installable and uninstallable on its own and then made customactions to install and uninstall them

Related

What happened to net.minecraft.class_746?

I am working on a fabric mod with java that requires commands such as ".command" and to do so requires my program accesses sent messages. After looking at some code by other people that have done what I am trying to do, I notice that they all use net.minecraft.class_746 as a mixin. I have been trying to as well on Minecraft 1.18.1 but after going through the net.minecraft directory, I found that there is only class_6567 and class_6148 as well as many other packages. I have been digging through the other files but I have not found anything to achieve what I want. I am not able to find anything to access all sent messages. Any help would be appreciated. Thanks!
After about an hour of digging, I found the ClientPlayerEntity class. It seems to work just like class_746 and I was able to get my desired result. If anyone needs it, here is a basic portion of code:
#Mixin( ClientPlayerEntity.class )
public class ChatMixin {
#Inject(method={"sendChatMessage"}, at={#At("HEAD")}, cancellable=true)
public void sendChatMessage(final String message, final CallbackInfo ci) {
if(message.equalsIgnoreCase(".command")) {
ci.cancel();
}
}
}

Can I determine `IsDevelopment` from `IWebJobsBuilder`

Very much an XY problem, but I'm interested in the underlying answer too.
See bottom for XY context.
I'm in a .NET Core 3 AzureFunctions (v3) App project.
This code makes my question fairly clear, I think:
namespace MyProj.Functions
{
internal class CustomStartup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var isDevelopment = true; //Can I correctly populate this, such that it's true only for local Dev?
if(isDevelopment)
{
// Do stuff I wouldn't want to do in Prod, or on CI...
}
}
}
}
XY Context:
I have set up Swagger/Swashbuckle for my Function, and ideally I want it to auto-open the swagger page when I start the Function, locally.
On an API project this is trivial to do in Project Properties, but a Functions csproj doesn't have the option to start a web page "onDebug"; that whole page of project Properties is greyed out.
The above is the context in which I'm calling builder.AddSwashBuckle(Assembly.GetExecutingAssembly()); and I've added a call to Diagnostics.Process to start a webpage during Startup. This works just fine for me.
I've currently got that behind a [Conditional("DEBUG")] flag, but I'd like it to be more constrained if possible. Definitely open to other solutions, but I haven't been able to find any so ...
While I am not completely sure that it is possible in azure functions I think that setting the ASPNETCORE_ENVIRONMENT application setting as described in https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings should allow you to get whether the environment is set as production or development by injecting a IHostEnvironment dependency and checking
.IsDevelopment()
on the injected dependency.

How to implement rollback using Wixsharp (Wix#) installer

I'm new in MSI installers, wix and wixsharp. I need to implement installer with some actions during the installation process (like call some *.exe or set up task scheduler and so on). Bu in case of any problems and exceptions I need a rollback all installed items.
How to implement a rollback using Wixsharp (Wix#) ? I found no information on the page of this porject.
I can't figure out the practical difference between custom action and before\after install event handler. What for do I need to use exactly custom action, instead of isuage of AfterInstall even handler in wix# ?
The author of wix# helped me with rollback using permissions elevations and third party referencies to assemblies (most difficult case).
Full answer is here: https://wixsharp.codeplex.com/discussions/646337
in common way rollback can be done like this:
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
{
try
{
//do your stuff
}
catch (Exception ex)
{
e.Session.Log(ex.Message);
e.Result = ActionResult.Failure;
}
}

Possible to Have Multiple Try/Catch Blocks Within Each Other in a SSIS Script?

I have a project that I'm working on and I wanted to double check before going through the work of coding and testing if this was even possible. What I'm attempting to do is something along the lines of:
try {
// Do stuff
try {
// Do other stuff
}
catch {
// Fail silently
}
// Do more stuff
}
catch (...) {
// Process error
}
Is it possible to have try/catch's within try/catch's? Most languages allow this but when I attempted to search the web I could not, for the life of me, find any answers.
Thanks
An SSIS script task is C# (or VB.NET). C# allows this, ergo SSIS allows this.
Having written a few SSIS Script Tasks in my time, I'd encourage you to take advantage of Raising Events in the Script Task.
Depending on your version + deployment model + invocation method, you might want to also turn on the native SSIS Logging. Project Deployment Model (in 2012+) provides native logging. Otherwise, you will need to specify the events you'd like to log as well as the logging provider(s) you'd like to use with them. This would need to be done as part of package development. Otherwise, I like a DTEXEC call with /REP EWI will ensure Errors, Warnings and Information events are logged to the console/SQL Agent.

Conversion of V2 Ninject Binding to V3

I've been banging my head at this for about 8 hours now, and I just can't seem to find a simple explanation on how to change my custom bootstrapper for ninject (Last worked on the code back in v2.x.x.x) to the new v3.0.0.0 syntax.
I currently have the following:
public class NinjectCustomBootStrapper : NinjectNancyBootstrapper
{
protected override Ninject.IKernel GetApplicationContainer()
{
return Program.MyContainer;
}
}
in a septate class, and :
public static IKernel MyContainer
{
get { return _myContainer ?? (_myContainer = CreateKernel()); }
set { _myContainer = value; }
}
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<CardMonitorService>().ToSelf().InSingletonScope();
return kernel;
}
in my main program 'Program.c' in a command line app.
Iv'e since updated ninject to V3.0.0.0 only to find that there's been some breaking changes. I'll admit I don't use ninject very often (I usually use structuremap), and the only reason this project does is I didn't write it originally.
Since I've upgraded Ninject, now when the app is started up I get the following exception:
Method not found: 'Ninject.Syntax.IBindingWhenInNamedWithOrOnSyntax`1<!0>
Ninject.Syntax.IBindingToSyntax`1.ToConstant(!0)'.
After a ton of searching and researching, the closest I've been able to find is this:
http://sharpfellows.com/post/Ninject-Auto-registration-is-changing-in-version-3.aspx
Which while it points me in the right direction, still isn't quite a solution as I'm not using a custom binding generator.
So my question is this.
How do I rewrite the above so that my project once again works and the WCF service when called gets the correct singleton binding handed to it when a request comes in. Going back to ninject 2 is not an option, as other dependencies in the project that have been added have forced the v3 upgrade and these add new functionality that's been requested hence why I'm working on it.
For reference this is a .NET4 build, running on NancyFX with a self hosting WCF setup as a windows service using Topshelf to provide the SCM interface.
Cheers
Shawty
Addendum to clear things up a little
This is an existing project that was originally written sometime back, I've been asked to add some new features to the project.
As part of adding these new features I have been required to upgrade the version of Ninject being used from an earlier version to V3.0.0.0 as newer dependencies added to the project require the newer version of Ninject.
Under the previous V2 of Ninject the code I have given above worked fine, with no issues, since the project has had Ninject V3 added I now get the exception as described above.
I cannot go back to the earlier version of Ninject as that will mean not being able to add the new functionality that I'm adding.
From the research I've done so far the sharpfellows link above is the closest explanation of my issue that I've managed to find so far on the internet.
I don't use Ninject very often, so I've not got the background to know what's changed between V2 & V3 that (based on my research) is the cause of my issue.
I need to know how to change my code written under V2 (and shown above) so that it works under V3.
MissingMethodException is usually a deployment problem. You compile against a different assembly than you deploy. Check that you deployed the same version and same build.
So after a week or so it turns out that the problem was that the Nancy dev team broke binary comparability with the latest version of ninject (or vice versa) :-)
There is a GitHub pull request to fix this available at :
https://github.com/NancyFx/Nancy.Bootstrappers.Ninject/pull/6
However the next version 'Nancy.Bootstrapper.Ninject' 0.12 will be out on NuGet soon which will have the fix implemented.