How to set application and session attributes in moqui - moqui

Where would be the places to set application and session attributes in moqui so that they are available for all transition, service and script code to use?
In this instance, where would I initialize an AwsS3Client so that it could be reused?

Most APIs have factory methods for getting singleton objects, or are designed so that objects are created for each use. In those cases you don't need any lifecycle (init/destroy) management.
If you do need that the easiest place to call a script on startup and shutdown is in the Moqui Conf XML file with the after-startup and before-shutdown elements under the webapp-list.webapp element.
Moqui runs in a standard Java Servlet container, so you can also add things to the web.xml file (either before the WAR file is built, or unpackage the WAR file, change the web.xml file, and zip it up again).
Java has more hack-ish approaches like using a class with static initialization, but it isn't as clean as real init/destroy code.
Still, I'd look into the API to see how it is designed to be used. It may be best to use its singleton factory or init an object with each use. Usually it is things more like transaction managers and databases and such that run as services and need real lifecycle management.

Related

Can a dotnet core library app use the appsettings.json file from the consuming application?

Hi I am trying to set up a dotnet core library app that requires certain information from a appsettings.json to run. I understand how to have an application use the appsettings.json file via the builder etc. However I also want my library to use this file for its own configuration. Obviously the consuming app would have to know the settings to have in the appsettings.json file but for my purposes that is not a problem. Does anyone have an example of this working? What I have found so far are not that great and involve loading the appsettings.json every time we instantiate the configuration class in the library. There must be a better way than this.
That's exactly Options are created for!
You should not read settings file - DI will give you strongly-typed class/struct with parameters you need. Loaded from all configured sources (appsettings.json, environment variables etc), and updated automatically (if required/configured).
Check this documentation - sample is pretty short and copy-pasting it here isn't wise.

Is it possible to rewrite silverlight application resources at runtime?

There is ServiceReferences.ClientConfig file that holds different settings of WCF services Silverlight application is using. Nice and easy, except once you set them you cannot change them later without modifying a xap.
I want to make these setting configurable with a less pain.
There are several options:
Add a dedicated section in web.config where an administrator could change them. Transfer these settings to silverlight then rendering object on page. Parse it in silverlight, then build channel manually. Something I'd rather avoid.
It would be nice if we could say silverlight application to load ServiceReferences.ClientConfig not from xap resources, but from a specified uri. That way I could place this config along web.config. Nice. Not possible though.
If I could substitute resource stream resolver, that would work too. Sadly it doesn't seem to be possible either. There is IApplicationResourceStreamResolver, but it's internal.
Maybe there is a way to rewrite application resource stream after a silverlight application is started?
I guess you want to make the servicesclient config file at the runtime.
If that is the case then simply create object of System.ServiceModel.BasicHttpBinding and assign properties and assign service URL to System.ServiceModel.EndpointAddress. This binding object and endpointaddress object can be then assigned to the client object constructor and voila!

Where can I find the arquillian xml configuration documentation?

I've tried to learn the JBoss Arquillian, by following the formal document and got confused about the configuration, the arquillian.xml. Since it is mentioned once here.
Even I also found that there is a specific configuration describes at the container adapters section. It does not cover all elements/properties, e.g. engine and its property list, defaultProtocol, extension and group.
I'm worried and wondered, if there is any further or full explanation for this configuration file or not. Could you please help to shed some light on this configuration?
There's no single page in the Arquillian Reference Guide that contains your answer. This is partly because of the modular and extensible nature of Arquillian - extension can have their own configuration elements and properties.
To start with, the properties for containers are in the Container Adapters Section. Every adapter has it's own page where the container configuration is detailed. For instance, JBoss AS 7 has it's own page for it's container configuration (see the Configuration section on the page), and so do other containers.
Usually, you wouldn't need to configure the protocol yourself, for the values are usually managed by Arquillian, and usually do not require any overrides to be provided via arquillian.xml. But if you need them, they're in the Protocols section and in the child pages.
A group is merely a collection of containers, to used in cases where the container does not support clustering by default. You merely need to list multiple container configurations in a group element, as shown here.
Extension configuration is typically found in the Extensions child-pages.
The defaultProtocol element does not have any page of it's own. It is used to override the protocol specified by a container adapter, for all tests. There are only a few cases where you would need to use this element, most notably when you need to use the Servlet protocol instead of the JMX protocol for JBoss AS 7 (because the Servlet protocol of Arquillian is a more widely used and tested protocol than the JMX one).
A typical use of defaultProtocol would look like:
<defaultProtocol type="Servlet 3.0" />
where the type is the name of the protocol - "Servlet 2.5" and "Servlet 3.0" are valid values. You may also need to add the protocol dependency to your classpath when you change the default protocol of the container.

How to expose information about a running .NET exe?

I have a .NET exe that I wrote and it has a couple properties that I made public and want to expose.
I want to shell this exe (Process.Start()) and then somehow reference this exe and get access to these public properties. These properties expose information about the running exe.
I know how to shell to the exe. And I know how to add a reference to the exe from my project that I want to use this object. But how do I get access to the properties of this running exe?
I hope I am explaining myself well.
If you do know the answer maybe you could just tell me what the standard method is to expose properties of a running exe to another application at run-time.
Thanks for any help!
It does not work that way.
The only ways to share data between processes are pipes (Process.Start() can redirect standard input, standard output, and standard error), shared memory (not available in pure managed code), the exit code, and filesystem or network communications mechanisms.
In your specific case I'd guess that named pipe is the technique you want.
Personally I've never used named pipe but I have used redirect standard input and standard output.
Have you considered exposing the objects to PowerShell so that you can call the object from PowerShell?
Expose the object:
runspace.SessionStateProxy.SetVariable("ObjectName", ObjectName)
Then a PS script could call:
$ IDLevel.ObjectName
In this object then you could have some simple "getter" methods that would return information about the exe.
I like this approach as not only can you get the info. but if you want, you can expose methods which will allow you to make changes to the object based on the info. returned.
The standard "Windows way" to do what you describe is to expose PerfMon counters and update them regularly.
Your EXE can host a WCF service. This service can expose operations (not properties) that can expose this information about the running EXE.
You can write a simple WMI.NET Provider Extension for your first App that exposes the configuration settings to WMI... then other programs can monitor and alter the settings...
WMI.NET Provider Extension Scenarios
http://msdn.microsoft.com/en-us/library/bb885141(v=vs.90).aspx
How to Expose Configuration Settings Through WMI
http://msdn.microsoft.com/en-us/library/bb404687(v=vs.90).aspx
Windows has many different providers for monitoring and managing Windows settings. You can register a new namespace for your application, then use PowerShell or System.Management.Instrumentation in another .NET application to monitor that namespace.

Programmatically configuration of endpoints vs. web/app.config

Has any put much thought into this? Personally, I think managing endpoints in configuration files are a pain. Are there any pros/cons to doing one over the other?
Only points in favour of configuration files from me.
Managing endpoints in configuration files mean that you don't have to update your application if (or perhaps I should say when) the endpoints change.
You can also have several instances of the application running with different endpoints.
I tend to like the config approach myself too, other than the config file can get pretty big.
The one thing I have noticed with WCF configuration is that there is a lot of stuff that you can do from code that you can't do in XML config without adding your own custom extensions. In other words, doing config in code will allow more flexibility, of course you could also just code your own extensions and use those from configuration.
However, do note that there is what I would consider a 'bug' in Visual Studio that if you start making your own extensions and including them in XML, then VS won't like your config file any more and will tag them as errors, and then if you try to add a new service through the wizards, it will fail to add the endpoint to the configuration.
This is sort of a followup to my own answer:
After months of having everything in xml configuration, I'm changing everything to construct the endpoints and bindings in code. I found a really good case for having it in code;
When you want to have a deployable / sharable .dll that contains WCF clients.
So for example if you have a CommonClients.dll that contains all your WCF interfaces and contracts to communicate with some remote server, then you don't want to also say "here is 100 lines of xml that you also have to drop into your app.config for every client to make it work". Having it all constructed in code works out much better in this case.
There is also a "feature" of .NET 3.5 where if you have some wcf extensions, you have to specify the fully qualified assembly name. This means that if your assembly containing the extensions changes the version nnumber, you have to go change the assembly name in the config file too. It is supposedly fixed in .NET 4 to use a short assembly name and not require the full name.
Offhand, an endpoint in a config file doesn't need to be recompiled when it's changed. This also means that you just need to update your config file when moving an application from Development to UAT to Production.
If your just coding something for your own use at home, then there's no real difference. However in a business environment, having the enpoint defined in your config file saves all sorts of headaches.
When using an app.config, your application does not need to be recompiled to adjust to a change. Also it can be resused in multiple situations with the exact same code. Finally, hardcoding your endpoints (or anything subject to change) is poor coding practice. Don't fear the configuration file, it's declarative programming. You say, "I want to use this endpoint." and it does the work for you.
I generally do programmatic configuration, as I don't want to expose my applications internal structure the the user. The only thing I keep configurable is service address, but even this I keep in userSettings section, not system.ServiceModel.
I prefer and recommend the configuration file approach. It offeres a lot of flexibility by allowing to make change to your server without the need to recompile the applcation.
If you need security, you can encrypt the config file.
The biggest worry with plain config files could be that it can be accidentally (or on purpose) modified by the end user causing your app to crash. To overcome this you could make some tests in code to check the configuration is ok in the config file and if not, initialize it programatically to some defaults. I presented how you could do that in another answer to this question.
It's just a question of how much flexibility you need.
Usually I prefer the config file approach.
Check out the .NET StockTrader app. It uses a repository to store config data and has a separate app to manage the configuration. The setup and structure is pretty advanced and there's a fair bit of head scratching for anyone like me that only has the basics of WCF configuration so far, but I would say it's worth a look.