Read connection String Data source, User ID and Password and add the values to the variables in NSIS - textbox

I am trying to read connection string from web.config file and put those values in a textbox using nsis.
I have three variables
var WebConnectionString
Var WebUserID
Var WebPassword
I just need to read Data Source, User ID, Password and add those values to the variables.
Could some one please help me with this.
I am able to read these connectionstrings using Powershell and put those values in a text file. When I tried to read values in the text file and put them in the Variables using read value by line number.
I need this values to execute SQL script. When I tried to execute
ExecWait `"$TEMP\UpdateSQL.bat" "$WebConnectionString" "$WebUserID" "$WebPassword" "$TEMP\upgrade.sql"
The ExecWait command is taking the parameters as
Execute: "C:\Users\Alan\AppData\Local\Temp\UpdateSQL.bat" 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\' '(local)\SQLExpress' 'User' 'admin123!'
here is the config file:
<configuration>
<connectionStrings>
<add name="SQLConnectionString" connectionString="Data Source=(local)\SQLExpress;Initial Catalog=VitalSigns;User ID=User;Password=admin123!;Persist Security Info=True;multipleactiveresultsets=true; Min Pool Size=20;Max Pool Size=500; Connection Timeout=30;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Thank you!!

There are multiple NSIS XML plugins you can use to read XML files.

Related

Specify directory for Serilog rolling file path

Consider this app.config appSetting entry:
<add key="serilog:write-to:RollingFile.pathFormat"
value="ServerServiceApp-{Date}.log" />
This is done at app startup:
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.Enrich.WithThreadId()
.CreateLogger();
This is in a Windows service app. The log file ends up here:
C:\Windows\SysWOW64
Clearly, we’d rather have the log file end up in the same directory that houses this service’s .exe (customers don’t want us writing stuff to SysWOW64). But how?
We need the ReadFrom.AppSettings in there so that the customer can supply serilog settings in the app.config, as necessary.
Is there some way to change the directory used for the log file after the ReadFrom.AppSettings has been done?
Would be awesome if we could say something like:
<add key="serilog:write-to:RollingFile.pathFormat"
value="{ApDomainBaseDirectory}\ServerServiceApp-{Date}.log" />
(And where is {Date}, which can be put in the file path, documented?)
Just put this before the creation of LoggerConfiguration:
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
Then File.path will be constructed based on the project root path.
The best place for services to write their logs is %PROGRAMDATA% which, by default, is in C:\ProgramData\.
Try:
<add key="serilog:write-to:RollingFile.pathFormat"
value="%PROGRAMDATA%\ServerService\Logs\log-{Date}.txt" />
(Program Files is usually considered to be read-only, and writing stuff here will lead to oddities being left behind unexpectedly during uninstall.)

How can we use variables in wxl file [duplicate]

I need to use variable in WIX localization file WIXUI_en-us.wxl.
I tried use it like this:
<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product $(var.InstallationVersionForGUI) is already installed</String>
But it doesn't work. And when I declared property and used it this way:
<String Id="Message_SomeVersionAlreadyInstalled" Overridable="yes">A another version of product [InstallationVersionForGUI] is already installed</String>
doesn't work either.
Where was I wrong?
Thanks for help and your time.
Localization strings are processed at link time, so you can't use $(var) preprocessor variables. Using a [property] reference is supported, as long as the place where the localization string is used supports run-time formatting (e.g., using the Formatted field type).
Your second method should work just fine. This is the same method used by the default .wxl files.
For example, in your .wxl file you would declare your string:
<String Id="Message_Foo">Foo blah blah [Property1]</String>
And in your .wxs file, you declare the property. If you wish, you can declare the property to match a WiX variable (which it sounds like you're trying to do)
<Property Id="Property1">$(var.Property1)</Property>
I was trying to get localization file to use variables. Came across this post:
There are different layers of variables in WiX (candle's preprocessor
variables, Light's WixVariables/localization variables/binder
variables, and MSI's properties). Each have different syntax and are
evaluated at different times:
Candle's preprocessor variables "$(var.VariableName)" are evaluated
when candle runs, and can be set from candle's commandline and from
"" statements. Buildtime environment
properties as well as custom variables can also be accessed similarly
(changing the "var." prefix with other values).
Light's variables accessible from the command-line are the
WixVariables, and accessing them is via the "!(wix.VariableName)"
syntax. To access your variable from your commandline, you would need
to change your String to: This build was prepared on
!(wix.BuildMachine)
If you instead need to have the BuildMachine value exist as an MSI
property at installation time (which is the "[VariableName]" syntax)
you would need to add the following to one of your wxs files in a
fragment that is already linked in:
Now, the environment variable COMPUTERNAME always has held the name of
my build machines in the past, and you can access that this way:
$(env.COMPUTERNAME). So, you can get rid of the commandline addition
to light.exe and change your wxs file like this:
<WixProperty Id="BuildMachine" Value="$(env.COMPUTERNAME)"/>
Preprocessor variables $(var.VariableName) are are processed at link time, so ideally you would use [PropertyName] which would be defined on the main Product element.
The issue sometimes is that property is not yet defined, for instance using the product name on the localization file seems not posible.
This solution was done aiming to only type the product name once given "Super product" as product name:
In case of running through visual studio extension:
Project properties -> Build -> Define variables -> "MyProductName=Super product" (No quotes)
In case of runing from cmd or some other place:
On Light.exe, add -d"MyProductName=Super product"
Into the localization .wxl file:
<String Id="Description" Overridable="yes">Description of !(wix.MyProductName)
to make it more interesting</String>
I have an aditional config file .wxi I include on other files to have some vars, for instance, here i had hardcoded the value but now it's harcoded on the variable definition and I use the given value:
<?xml version="1.0" encoding="utf-8"?>
<Include>
<!-- Define the product name preprocesor variable -->
<?define ProductName="!(wix.ProductNameDefVar)" ?>
<!-- From this point, can use the preprocesor var -->
<?define ProductName_x64="$(var.ProductName) (64bit)" ?>
<?define ProductName_x32="$(var.ProductName) (32bit)" ?>
<?define CompanyDirName = "My company name" ?>
</Include>
Finally, the place where the localization value where the localization text was not interpolating, is like this:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!-- Include the config file with the preprocesor var -->
<?include $(sys.CURRENTDIR)\Config.wxi?>
<!-- Main product definition -->
<Product Id="$(var.ProductCode)"
Name="$(var.ProductName)"
Language="!(loc.Language)"
Version="$(var.BuildVersion)"
Manufacturer="!(loc.Company)"
UpgradeCode="$(var.UpgradeCode)">
<!-- Package details -->
<!-- Here, Description was not interpolating -->
<Package InstallerVersion="200"
Compressed="yes"
InstallScope="perMachine"
Platform="$(var.Platform)"
Manufacturer="!(loc.Company)"
Description="!(loc.Description)"
Keywords="!(loc.Keywords)"
Comments="!(loc.Comments)"
Languages="!(loc.Language)"
/>
[...]

Possible to add attributes via NcML to non-cached THREDDS datasets?

For several years on our THREDDS Data Server (TDS) we've been happily using the cache="false" functionality on datasetRoot to tell the TDS not to cache several netcdf files.
<service name="allServices" serviceType="Compound" base="">
<service name="ncdods" serviceType="OpenDAP" base="/thredds/dodsC/"/>
<service name="HTTPServer" serviceType="HTTPServer" base="/thredds/fileServer/"/>
<service name="iso" serviceType="ISO" base="/thredds/iso/"/>
<service name="uddc" serviceType="UDDC" base="/thredds/uddc/"/>
</service>
<datasetRoot path="FVCOM" location="/http/www/CODFISH/Data/FVCOM/" cache="false"/>
<dataset name="NECOFS GOM2 Forecast" ID="gom2_nocache" serviceName="allServices"
urlPath="FVCOM/NECOFS/Forecasts/NECOFS_GOM2_FORECAST.nc" dataType="Grid"/>
The reason we don't want to ever cache these files is that every day these daily forecast files get overwritten with files that have the same name, but different data.
But now we have a need to add and modify the attributes of these datasets. In particular, we would like to add the global attribute
<attribute name="cdm_data_type" value="any"/>
Can we modify attributes via NcML when the dataset to be modified is contained in this kind of datasetRoot construct?

MvcRoutingShim plugin has no effect

I'm using the ImageResizer module in an ASP.NET MVC 4 project, along with the plugins SqlReader and MvcRoutingShim.
When I try to access the URL ~/databaseimages/123.jpg (for example), I just get the standard error 404 - The resource cannot be found.
My expectation was that ImageResizer would handle that request and try to read the image from the database, but it doesn't even try to connect (I used SQL Profiler to verify this).
What can be wrong?
This is the output of /resizer.debug:
Image resizer diagnostic sheet 26-06-2012 20:42:57
1 Issues detected:
(Warning): To potentially see additional errors here, perform an image resize request.
You are using paid bundles: Cloud Bundle, Performance Bundle
Registered plugins:
ImageResizer.Plugins.Basic.DefaultEncoder
ImageResizer.Plugins.Basic.NoCache
ImageResizer.Plugins.Basic.ClientCache
ImageResizer.Plugins.Basic.Diagnostic
ImageResizer.Plugins.Basic.SizeLimiting
ImageResizer.Plugins.MvcRoutingShim.MvcRoutingShimPlugin
ImageResizer.Plugins.SqlReader.SqlReaderPlugin
ImageResizer.Plugins.DiskCache.DiskCache
Configuration:
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="SqlReader" prefix="~/databaseimages/" connectionString="database" idType="UniqueIdentifier" blobQuery="SELECT Content FROM Images WHERE ImageID=#id" modifiedQuery="Select ModifiedDate, CreatedDate From Images WHERE ImageID=#id" existsQuery="Select COUNT(ImageID) From Images WHERE ImageID=#id" requireImageExtension="false" cacheUnmodifiedFiles="true" extensionPartOfId="false" vpp="true" untrustedData="false" />
<add name="DiskCache" />
</plugins>
</resizer>
(...)
In your Web.config file, you declared that image IDs are all GUIDs: idType="UniqueIdentifier", yet used a integer in the url: localhost:50272/databaseimages/123.jpg.
<add name="SqlReader" prefix="~/databaseimages/" connectionString="database"
idType="UniqueIdentifier" requireImageExtension="false"
cacheUnmodifiedFiles="true" extensionPartOfId="false"
vpp="true" untrustedData="false" />
If you're not specifying a GUID in the URL, the request will be ignored. Change idType to a different data type, like Int, or use the correct data type in the URL.
Source: http://imageresizing.net/plugins/sqlreader

Replacing value in an XML file using Ant

I'm trying to automize my android build process. For that, I want to change the app name in an XML file. the code is something like this
<resources>
<string name="app_name">Realta Connections</string>
</resources>
Now I want to replace the name 'Realta Connections' by something else at build time, a name which I would give at build time. The name can be 'Realta Connections' or anything else, so I need to detect the name="app_name" and replace the content inside it. I tried looking for how to do it but couldn't find the precise way. How can I do that? Please help.
It is probaly easiest to have a fixed value, which will be replaced. This will allow the use of the replace task:
You need replacetoken/replacevalue and the Strings inside ![CDATA[]] because of the xml characters.
<replace casesensitive="false"
file="../KS.build/ivy.properties">
<replacetoken><![CDATA[<string name="app_name">Realta Connections</string>]]></replacetoken>
<replacevalue><![CDATA[<string name="app_name">Something else</string>]]></replacevalue>
</replace>
Otherwise there is no normal ant solution (repleaceregex doesn't allow nested CDATA replacements).
Links:
Ant replace task
I know this question is quite old, but here is an idea. This seems like it's not really a purely ant solution, but you can embed a script in ant using the <scriptdef> tag.
Here is a function you can use to search for something in an XML file and store the result in a property:
<scriptdef name="xpath-query" language="javascript">
<attribute name="query"/>
<attribute name="xmlfile"/>
<attribute name="property"/>
<![CDATA[
importClass(java.io.FileInputStream);
importClass(javax.xml.xpath.XPath);
importClass(javax.xml.xpath.XPathConstants);
importClass(javax.xml.xpath.XPathFactory);
importClass(org.xml.sax.InputSource);
importClass(java.lang.System);
var exp = attributes.get("query");
var filename = attributes.get("xmlfile");
var xpath = XPathFactory.newInstance().newXPath();
var input = new InputSource(new FileInputStream(filename));
var value = xpath.evaluate(exp, input, XPathConstants.STRING);
self.project.setProperty( attributes.get("property"), value );
System.out.println("Copied this value:" + value + " to this property:" + attributes.get("property"));
]]>
</scriptdef>
Then you could get the current name of the app by using the xpath-query task you just defined:
<xpath-query query='pathToResources\resources\string[#name="app_name"]' xmlFile="app.xml" property="appName" />
Then the app name will be stored in the property appName.
From there you could do regex replace on the xml file using the app name.
<replaceregexp file="app.xml" match="${appName}" replace="${newAppName}" />
The potential down-side of this particular approach is that if you have the same app name string somewhere else in the XML file the regex replace may replace something you didn't intend.
You could probably define the <scriptdef> to do the replacement rather than just storing what was found in a property, but I had this portion of code handy already.
When dealing with XML in ANT I always recommend the xmltask. For your requirement see xml task manual replace
A little Xpath knowledge won't hurt, see:
http://zvon.org/xxl/XPathTutorial/
http://www.w3schools.com/xpath/
try this code, it works for me
<target name="change-app-name">
<replaceregexp file="res/values/strings.xml" match='name="app_name"(.*)'
replace='name="app_name">Something Else<\/string>'/>
</target>

Resources