Get full qualified host name in WIX

In one of our install we need to know the full qualified computer name during installation. For that purpose I did create an custom action with a simple vbscript that simple get the computer name and domain name and create the full qualified string and set property FQDN accordingly.

<CustomAction Id="FindHostDomain" Script="vbscript" Return="check">
  <![CDATA[
  Dim Info
  Set Info = CreateObject("AdSystemInfo")
  Dim InfoNT
  Set InfoNT = CreateObject("WinNTSystemInfo")
 
  Session.Property("FQDN") = lcase(InfoNT.ComputerName & "." & Info.DomainDNSName)
  ]]>
</CustomAction>

To execute this script and set FQDN so we can use it in our component’s add this to the install execution sequence.

<InstallExecuteSequence>
  <Custom Action="FindHostDomain" Before="CostInitialize" >Not Installed</Custom>
</InstallExecuteSequence>
0 votes, 0.00 avg. rating (0% score)

Finding compilation error for aspx files

Some time ago I did a bigger refactoring in many of our *.aspx files. The big problem was not the refactoring itself but to find all small typos and similar. If you make a typo or a syntax error in a *.cs file you will get a compilation error when building the application, but that is not the case for *.aspx files. So to increase confidence of my work I decided to use the aspnet_compiler that is used to pre compile a site for performance reasons. It was so successful that we decided to add it to our build infrastructure to catch all of this errors early.
 
Example (just replace the C:\apps\MySite to your output directory when building your site/app.
C:\Program Files (x86)\Microsoft Visual Studio 11.0>aspnet_compiler -p C:\apps\MySite -v /

0 votes, 0.00 avg. rating (0% score)

Dynamically load and execute JavaScript method

This is a simple solution to load a JavaScript dynamically and call a method when done. For more advance solution take a look at requirejs.
 
1. Check what protocol we are currently using to ensure we are using a secure connection if current page is using secure connection to load our new JavaScript file.
2. Create a new script element
3. Create a callback function with a simple counter that will ensure that we only execute the new method once
4. Attach the new created callback function to onreadystatechange to be used be Internet Explorer and onload for other browsers. In onreadystatechange we add additional checks of the state to ensure we are only calling the callback when the dynamically script is completely loaded.
5. The last thing that is need is to add the new created script element to the header of current page.

var src;
if (document.location.protocol === ""https:"")
{
  src = 'https://mysite.com/thescript.js';}
else
{
  src = 'https//mysite.com/thescript.js';
}
        
var script = document.createElement('script');
script.src = src;
script.type = 'text/javascript';
        
var head = document.getElemenscriptByTagName('head')[0];
var called= 0;
var callback = function()
{
  if( called== 0)
  {
    called++;
    MethodInTheScript();
  }
};
 
// Inter explorer 
script.onreadystatechange = function()
{
  if (this.readyState == 'complete')
  {
    callback();
  }
}
 
//Other browsers
script.onload = callback;       
head.appendChild(script);
0 votes, 0.00 avg. rating (0% score)

System.UnauthorizedAccessException: Access to the path is denied when using System.OI.FileStream

During a recent deployment to production environment we started to get System.UnauthorizedAccessException on places we hade not seen it before. After some debugging a pattern appeared. The problem is that if you don’t use the FileStream constructor with FileAccess parameter you will get FileAccess.ReadWrite selected by default. So in our cases the User account running our service did only have read access to the file with is correct since we are only expecting to read from the file.

using (FileStream fs = new FileStream(filePath, FileMode.Open))
{}

Make sure, you ask for what you really need. If your application needs only Read access to a file, make sure to specify that in your FileStream constructor.

using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{}
0 votes, 0.00 avg. rating (0% score)

HowTo add new key to appsettings with WIX

When adding a new key for appsettings you need to split the action in 3 steps.
1. Create the new empty “add” element
2. Create and set the “key” attribute. The tricky part here is how to add the “key” to new created “add” element from step one. One way is to assume that the new created “add” element is the only element without a “key” attribute
3. Create and set the “value” attribute.

<util:XmlFile 
  Id='conf1' 
  Action="createElement" 
  ElementPath="//configuration/appSettings" 
  Name="add" 
  File="[INSTALLDIR]Web.config" 
  Sequence="1" />
<util:XmlFile 
  Id='conf2' 
  Action="setValue" 
  ElementPath="//configuration/appSettings/add[\[]not(@key)[\]]"
  Name="key" 
  Value="NewConfig" 
  File="[INSTALLDIR]Web.config" 
  Sequence="2" />
<util:XmlFile 
  Id='conf3' 
  Action="setValue" 
  ElementPath="//configuration/appSettings/add[\[]@key='NewConfig'[\]]"
  Name="value" 
  Value="the new value" 
  File="[INSTALLDIR]Web.config"
  Sequence="3" />
0 votes, 0.00 avg. rating (0% score)

HowTo to set appsettings during installation using WIX

The point where most people have a hard time is remembering is to escape brackets. This to ensure WIX will not think it a property. If you forget to-do this you may end up in a situation where “config2″ value will bet set on “config1″ instead. See a correct example bellow

[ should be [\[]
] =should be [\]]

<Component Id='UpdateConfig' Guid='A89D47AF-7DBE-4a8d-9848-F35C78FD95ED' DiskId='1' KeyPath="yes">
  <util:XmlFile Id='config1' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[]@key='FirstKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE1]" />
  <util:XmlFile Id='config2' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[@key='SecondKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE2]" />
</Component>

And the example web.config

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="FirstKey" value="oldvalue"/>
    <add key="SecondKey" value="oldvalue"/>
  </appSettings>
</configuration>
0 votes, 0.00 avg. rating (0% score)

Shortcut keys for running tests in Visual Studio

One of my most used shortcuts in Visual Studio is CTRL+R,T to debug the current test method from the code and CTRL+R,A to execute all tests. Here’s the help topic: How to: Run Selected Tests

To run tests from your test code file, by using the keyboard
1. In Visual Studio, open the source-code file that contains your test methods.
2. Click to define the testing scope: Place the cursor in a test method, in a test class, or outside the scope of a test class.
3. You can use the following keyboard shortcuts to run tests based on that scope.

CTRL + R, then press T This runs the tests in the current scope. That is, it runs the current test method, all the tests in the current test class, or all the tests in the namespace, respectively.
CTRL + R, then press C This runs all the tests in the current test class.
CTRL + R, then press N This runs all tests in the current namespace.

To run tests from source code files in your solution, by using the keyboard
1. In Visual Studio, open a source code file anywhere in your solution.
2. You can use the following keyboard shortcuts to run tests from that file.

Ctrl + R, then press A Runs all the tests in all test projects.
Ctrl + R, then press D Runs all tests that were run in the last test run.
Ctrl + R, then press F Runs all tests in the last test run that did not pass.

0 votes, 0.00 avg. rating (0% score)

HowTo update appsettings programmatically

Recently I was writing functional test for an application that read settings from the appsettings element in App.Config. The problem was that the application under test was expecting to react different based on the settings so need a way to alter the values between tests. I ended up writing bellow code for it

private static void SetAppSettings(string key, string value)
{
   Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
   config.AppSettings.Settings[key].Value = value;
   config.Save(ConfigurationSaveMode.Modified);
   ConfigurationManager.RefreshSection("appSettings");
}
0 votes, 0.00 avg. rating (0% score)

Scrumy on Softpedia

Today I happen to find out that Scrumy have been added to Softpedia’s library of software. It’s nice to see that people are interested in my project and that they have even rated it with 5 stars.

http://www.softpedia.com/get/Programming/Components-Libraries/Scrumy.shtml

0 votes, 0.00 avg. rating (0% score)

Connect to multiple NST with RTC

If you are in a situation where you are switching between different NST on daily basis and are getting tired on changed server from RTC every time, here is the solution. You can create different RTC configuration files per NST.

Step by step for windows 7
1. Copy the C:\Users\”user name”\AppData\Roaming\Microsoft\Microsoft Dynamics NAV\70\ClientUserSettings.config file to a directory you like
2. Update the newly copied configuration file
For example:
<add key=”Server” value=”[NSTSERVER]” />
<add key=”ServerInstance” value=”[second instance]” />
<add key=”ClientServicesPort” value=”7048″ />
3. Right click on the desktop and click on New->Shortcut
4. Brows to the installation directory for RTC. Example : “C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe”
5. Click Next
6. Change the name of the shortcut if needed
7. Click Finish
8. Find the newly created shortcut on the desktop and right click on it and pick properties
9. Update the “Target” to for example: “C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client\Microsoft.Dynamics.Nav.Client.exe” -settings:”C:\\.config“
10. Click Save
11. Now you can easly connect RTC to any NST you want by simple clicking on right shortcut.

Extra tips
If you want to add the shortcut to the start menu. Simply copy the newly created shortcut from the desktop to C:\Users\”user name”\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

0 votes, 0.00 avg. rating (0% score)

Next Page »

wegge_rubi@mailxu.com