Import & Export break points in Visual Studio 2010
Posted by shawson in .net, Visual Studio on January 31, 2012
“This will change your life”
… reassured my colleague Mr Carmicheal.
Basically it’s possible in VS2010 (Pro, Premium or Ultimate) to Import & Export sets of break points for projects, handy if you have pieces of code you often have to step through for some reason or another.
The original article can be found here: http://msdn.microsoft.com/en-us/library/dd293657.aspx
In case that page goes AWOL as MSDN pages often do, this is what it said;
To export all breakpoints that match the current search criteria
- In the Breakpoints window toolbar, click the Export all breakpoints matching current search criteria icon.
The Save As dialog box appears.
- In the Save As dialog box, type a name in the File name box.
This is the name of the XML file that will contain the exported breakpoints.
- Note the folder path shown at the top of the dialog box. To save the XML file to a different location, change the folder path shown in that box, or click Browse Folders to browse for a new location.
- Click Save.
To export selected breakpoints
- In the Breakpoints window, select the breakpoints you want to export.
To select multiple breakpoints, hold down the CTRL key and click additional breakpoints.
- Right-click in the breakpoints list, and choose Export selected.
The Save As dialog box appears.
- In the Save As dialog box, type a name in the File name box.
This is the name of the XML file that will contain the exported breakpoints.
- The folder path is shown at the top of the dialog box. To save the XML file to a different location, change the folder path shown in that box, or click Browse Folders to browse for a new location.
- Click Save.
To import breakpoints
- In the Breakpoints window toolbar, click the Import breakpoints from a file icon.
The Open dialog box appears.
- In the Open dialog box, browse to the directory where your file is located, and then type the file name or select the file from the file list.
- Click OK.
Quick & Tiny jQuery Drop Down Menus
Posted by shawson in Javascript, jQuery on January 24, 2012
The Code:
$(document).ready(function () { // Shawsons' Teeny-Tiny Drop Downs!
$('.drop-down-menu li ul').hide().mouseleave(function () {
$(this).hide();
});
$('.drop-down-menu>li>a').mouseenter(function () {
$('ul', $(this).parent().parent()).hide();
$('ul', $(this).parent()).show();
}).mouseleave(function (o) {
if ($(this).parent().has($(o.relatedTarget)).length < 1) {
$('ul', $(this).parent()).hide();
}
});
});
The Markup:
<ul class="drop-down-menu">
<li>Available Actions : </li>
<li><a href="">Menu 1</a>
<ul>
<li><a href="a.htm">a</a></li>
<li><a href="b.htm">b</a></li>
<li><a href="c.htm">c</a></li>
</ul>
</li>
<li><a href="">Menu 2</a>
<ul>
<li><a href="d.htm">d</a></li>
<li><a href="e.htm">e</a></li>
<li><a href="f.htm">f</a></li>
</ul>
</li>
</ul>
Some CSS:
.drop-down-menu { display:block; }
.drop-down-menu li { float:left; padding: 8px; }
.drop-down-menu li a { padding:8px; }
.drop-down-menu li ul
{
position:absolute;
background-color:#fff;
border: 1px solid #999;
border-radius: 0px 7px 7px 7px; -moz-border-radius:0px 7px 7px 7px; -webkit-border-radius:0px 7px 7px 7px;
padding:5px;
}
.drop-down-menu li ul li { float:none; }
.drop-down-menu li ul li a { color:#000; }
.drop-down-menu li ul li:hover { background-color:#F68833; }
Conditional logic in ListView ItemTemplate with DataBinder.Eval
Embarrasingly simple, but something I always seem to forget, and then never blog! I needed to show a tick in a repeater when a row value was -1: Simple! In MVC, with the razor syntax and strongly typed views I’ve grown to love, this is a pinch o’ the proverbial piss- In WebForms rreviously I often resort to setting up an ItemDataBound event handler which hides or shows an image, but to be honest I could not be bothered- this seems such overkill for something as simple as this. Anyway, after some faffing I reminded myself the easiest method is to use an ‘in-line if’ in the ItemTemplate, like so;
<ItemTemplate>
<tr>
<td><%# Eval("CarReg") %></td>
...
<td>
<%# (DataBinder.Eval(Container.DataItem, "NewRepeat") != null && DataBinder.Eval(Container.DataItem, "NewRepeat").Equals(-1) ? "<img src=\"../images/tick.png\" alt=\"tick\" />" : "<img src=\"../images/cross.png\" alt=\"cross\" /")%>
</td>
nodejs debugging with node-inspector on windows
I recently started learning nodejs- the recommended debugging tool seems to be node-inspector. You can grab and install this using npm (the command line node package manager- like nuget for node), making it available to all your projects;
npm install -g node-inspector
Once npm has worked it’as magic, you start node inspector by simply typing node-inspector into the command line- then start your project in node, with the debug flag;
node --debug myfile.js
If all runs as planned, you can then hit the browser on http://localhost:8080/debug?port=5858, as mentioned in the docs.
However when I started node-inspector I received an error;
C:\Users\Shawson>node-inspector
info - socket.io started
warn - error raised: Error: listen EACCES
After some fiddling, I found that changing the default port from 8080 to something else (I chose 124 at random) fixed this issue- I just then had to use the url http://localhost:124/debug?port=5858. This is because I foolishly forgot I have an instance of IIS on my local box which uses this port- a handy find though as I couldn’t find any help online fixing this issue.
IIS 7 Permissions – Application Pool Identity User Accounts
In IIS7- when using app pools which use the app pool identity, you can find the user account (for use with ACL) in the “IIS AppPool” domain- so you can reference the app pool accounts with IIS AppPool\<app pool name>
More info can be found here; http://learn.iis.net/page.aspx/624/application-pool-identities/
Grabbing data from the registry on a remote machine using dot net and WMI
I recently had to write an app which, given a computer name, would grab their telephone extension from a registry key (For the purpose of the code example below, I just grab the CommonFilesDir key from the windows node. There’s a couple of ways you can achieve this- either using RegistryKey.OpenRemoteBaseKey which gave me a whole bunch of permissions issues, plus you need the remote registry and remote administration services active on the server/client OR you can use the Windows Management Instrumentation (WMI) service. I took this route, as it’s a service which is active by default on all of our machines on the domain, and it was easier to get the permissions right.
Before I paste the code, a GOTCHA to beware of, straight from the MSDN here;
The registry provider is hosted in LocalService—not the LocalSystem. Therefore, obtaining information remotely from the subtree HKEY_CURRENT_USER is not possible
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true;
options.Username = "<domain_admin_username>";
options.Password = "<domain_admin_password>";
// http://msdn.microsoft.com/en-us/library/system.management.managementscope.aspx
ManagementScope ms = new ManagementScope("\\\\<computer name>\\root\\default", options);
ms.Connect();
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa390788(v=vs.85).aspx
ManagementClass mc = new ManagementClass("stdRegProv");
mc.Scope = ms;
ManagementBaseObject inParams = mc.GetMethodParameters("GetStringValue");
// there are other methods for grabbing other reg types- see
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa393664(v=VS.85).aspx
inParams["hDefKey"] = RegHive.HKEY_LOCAL_MACHINE;
inParams["sSubKeyName"] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion";
inParams["sValueName"] = "CommonFilesDir";
ManagementBaseObject outParams =
mc.InvokeMethod("GetStringValue", inParams, null);
if (outParams["ReturnValue"].ToString() == "0")
{
Console.WriteLine(outParams["sValue"]);
}
else
{
Console.WriteLine("Error " + outParams["ReturnValue"] + " please refer to http://msdn.microsoft.com/en-us/library/ms681382%28v=3Dvs.85%29.aspx");
}
Console.ReadLine();
This code requires this enum..
public enum RegHive : uint
{
HKEY_CLASSES_ROOT = 0x80000000,
HKEY_CURRENT_USER = 0x80000001,
HKEY_LOCAL_MACHINE = 0x80000002,
HKEY_USERS = 0x80000003,
HKEY_CURRENT_CONFIG = 0x80000005
}
If you receive a COM error back “The RPC server is unavailable”, make sure the target machine’s firewall isn’t blocking the call- this will open the port;
netsh firewall set service RemoteAdmin
Grouped pagination links function in JavaScript
Posted by shawson in Javascript on November 10, 2011
I just created a JavaScript port of an awesome bit of pagination code I first used years and years ago while working in Classic ASP, originally written by Dave Child who I was working with at the time. The original can be found on this site here.
It’s an awesome script when you have 100′s of pages of data (which probably suggests you need to implement some good filtering and search features to save your poor users..) and presents the links like so..
« Prev 1 2 3 … 7 [8] 9 … 208 209 210 Next »
function BuildGroupedPagination(current_page, total_pages, base_url, seperator)
{
var url = base_url;
var strPages = "";
var intMaxPages = 0;
var intMinPages = 0;
var intPaginI = 0;
if (typeof(seperator) == 'undefined')
{
seperator = " ";
}
if (total_pages > 10)
{
if (total_pages > 3)
{
intMaxPages = 3;
}
else
{
intMaxPages = total_pages;
}
for (intPaginI = 1; intPaginI <= intMaxPages; intPaginI++)
{
if (intPaginI == current_page)
{
strPages += "<strong>[" + intPaginI + "]</strong>";
}
else
{
strPages += "<a href=\"" + url + intPaginI + "\">" + intPaginI + "</a>";
}
if (intPaginI < intMaxPages)
{
strPages += seperator;
}
}
if (total_pages > 3)
{
if ((current_page > 1) && (current_page < total_pages))
{
if (current_page > 5)
{
strPages += " ... ";
}
else
{
strPages += seperator;
}
if (current_page > 4)
{
intMinPages = current_page;
}
else
{
intMinPages = 5;
}
if (current_page < total_pages - 4)
{
intMaxPages = current_page;
}
else
{
intMaxPages = total_pages - 4;
}
for (intPaginI = intMinPages - 1 ; intPaginI <= intMaxPages + 1; intPaginI++)
{
if (intPaginI == current_page)
{
strPages += "<strong>[" + intPaginI + "]</strong>";
}
else
{
strPages += "<a href=\"" + url + intPaginI + "\">" + intPaginI + "</a>";
}
if (intPaginI < intMaxPages + 1)
{
strPages += seperator;
}
}
if (current_page < total_pages - 4)
{
strPages += " ... ";
}
else
{
strPages += seperator;
}
}
else
{
strPages += " ... ";
}
for (intPaginI = total_pages - 2; intPaginI <= total_pages; intPaginI++) {
if (intPaginI == current_page) {
strPages += "<strong>[" + intPaginI + "]</strong>";
}
else {
strPages += "<a href=\"" + url + intPaginI + "\">" + intPaginI + "</a>";
}
if (intPaginI < total_pages) {
strPages += seperator;
}
}
}
}
else
{
for (intPaginI = 1; intPaginI <= total_pages; intPaginI++)
{
if (intPaginI == current_page)
{
strPages += "<strong>" + intPaginI + "</strong>";
}
else
{
strPages += "<a href=\"" + url + intPaginI + "\">" + intPaginI + "</a>";
}
if (intPaginI < total_pages)
{
strPages += seperator;
}
}
}
return strPages;
}
Open Windows Firewall ports for SQL Server 2008
Posted by shawson in Batch Scripting, SQL Server, Windows on November 4, 2011
http://support.microsoft.com/kb/968872
As noted in the article, you can run this batch file;
@echo ========= SQL Server Ports =================== @echo Enabling SQLServer default instance port 1433 netsh firewall set portopening TCP 1433 "SQLServer" @echo Enabling Dedicated Admin Connection port 1434 netsh firewall set portopening TCP 1434 "SQL Admin Connection" @echo Enabling conventional SQL Server Service Broker port 4022 netsh firewall set portopening TCP 4022 "SQL Service Broker" @echo Enabling Transact-SQL Debugger/RPC port 135 netsh firewall set portopening TCP 135 "SQL Debugger/RPC" @echo ========= Analysis Services Ports ============== @echo Enabling SSAS Default Instance port 2383 netsh firewall set portopening TCP 2383 "Analysis Services" @echo Enabling SQL Server Browser Service port 2382 netsh firewall set portopening TCP 2382 "SQL Browser" @echo ========= Misc Applications ============== @echo Enabling HTTP port 80 netsh firewall set portopening TCP 80 "HTTP" @echo Enabling SSL port 443 netsh firewall set portopening TCP 443 "SSL" @echo Enabling port for SQL Server Browser Service's 'Browse' Button netsh firewall set portopening UDP 1434 "SQL Browser" @echo Allowing multicast broadcast response on UDP (Browser Service Enumerations OK) netsh firewall set multicastbroadcastresponse ENABLE
Executing sql statements from the command line (SQL Server 2008 R2 Express)
Posted by shawson in SQL Server on November 3, 2011
One of the things I’ve always liked about MySql is its easy to use command line interface. Microsoft Enterprise Manager was always pretty good, and of course SQL Management Studio, so I rarly have to interface with MSSQL using the command line, but when I did, I always used osql. As of SQL 2008 this was replaced by sqlcmd which is very similar to the mysql command line implementation. Basic usage is;
sqlcmd -S server_name\instance_name -U sa -P your_password
You can then type directly into the console, executing a “GO” after each statement to run. I recently used this to enable remote connections on a new install of sql express, like so;
1> exec sys.sp_configure N'remote access', N'1' 2> GO Configuration option 'remote access' changed from 0 to 1. Run the RECONFIGURE statement to install. 1> RECONFIGURE WITH OVERRIDE 2> GO 1> exit
IIS Express hanging when launched from visual studio
Posted by shawson in .net, IIS, URL Rewriting on October 19, 2011
I recently built up a new machine at work and grabbed all my latest projects out of SVN only to find that one of them no longer seemed to start.
Since checkout I hadn’t changed any code, got a clean build, but when the browser window opened it just hung, with no error.
I eventually found this was because I was using the UrlRewrite module on the site (with the rules in the web.config file) but had forgotten to install this component on my IIS on the new machine. An error message would have been nice!