Friday, 23 May 2014

How to determine event subscriptions at runtime

Forgot this again, so thought I'd repost it...

http://consultingblogs.emc.com/merrickchaffer/archive/2011/02/02/how-to-determine-event-subscriptions-at-runtime.aspx

((System.Delegate)myObject.MyEventName).GetInvocationList()

Executing that in the immediate window will spawn you out a list of the attached event handlers to your event at runtime.

Also, if you're trying extract the invocation list of a dotNetBar 11.8.0.1 ButtonItem control's click handler, then the following code is necessary due to the obsfucation of the code that dotNetBar controls have within them. The strange Convert.ToChar(2694) is required in order to ensure that the code page of the C# file remains as ANSI (or Windows 1252), instead of asking you to switch to UTF-8 if you use the actual character code that the private event is stored as.

image

var buttonItem = sender as ButtonItem;
            var clickHandler = string.Empty;
            if (buttonItem != null)
            {

                var clickEvent = typeof(BaseItem).GetField(Convert.ToChar(2694).ToString(CultureInfo.InvariantCulture), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

                if (clickEvent != null)
                {
                    var clickEventDelegate = clickEvent.GetValue(buttonItem) as Delegate;
                    if (clickEventDelegate != null)
                    {
                        var invocationList = clickEventDelegate.GetInvocationList();
                        if (invocationList.Length > 0)
                        {
                            clickHandler = invocationList[0].Method.Name;
                        }
                    }
                }
            }

            MessageBox.Show(
                string.Format(
                    "The click event {0} is yet to be implemented. If you're attached the debugger will now launch",
                    clickHandler), "Click event handler not yet implemented yet", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Debugger.Break();

Wednesday, 21 May 2014

BrowserLink and other new VS 2013 features

Perhaps the most significant enhancement to creating web applications in Visual Studio for many years. Check out how you can edit your pages in line in the browser, and it updates the source code back in visual studio directly, using the new BrowserLink feature...

http://www.asp.net/visual-studio/overview/2013/visual-studio-2013-web-editor-features-browser-link

More features worth a look are all listed under the parent page here...

http://www.asp.net/visual-studio/overview/2013

Remove capitalization from Visual Studio 2012 / 2013 menus

http://blogs.msdn.com/b/zainnab/archive/2012/06/14/turn-off-the-uppercase-menu-in-visual-studio-2012.aspx

Manual Registry Change

Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\
(For Windows 8 Desktop Express go to HKCU\Software\Microsoft\WDExpress\11.0\General) //special thanks to msm8bball for the update
(For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\11.0\General)

  1. Create a new DWORD value called SuppressUppercaseConversion set to 1

or

PowerShell Goodness

In the PowerShell window copy the script below and paste it in then press Enter:
Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\11.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

Tuesday, 20 May 2014

Starting IISExpress from command line

start "" "C:\Program Files (x86)\IIS Express\iisexpress.exe"  /config:"%userprofile%\Documents\IISExpress\config\applicationhost.config"  /site:"RRA.Web.McMuffin" /apppool:"Clr4IntegratedAppPool"

P.S. One of the many benefits I've discovered in starting IISExpress in this way from the command line, is that you get fiddler type page visit logging output for each page request in the resulting console window..

image

Macros in Visual Studio 2012 / 2013

Use the following visual studio extension in order to recreate the macros that you were used to using in VS 2010 and below
http://vlasovstudio.com/visual-commander/
image
Also to run the macro, try using the Ctrl+Q shortcut menu in VS 2013, as follows
image

Or customise your toolbar


The attach to process macro will now look like this as a new Visual Commander command using VB v4.0 language
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class C
    Implements VisualCommanderExt.ICommand

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
        AttachToProcess("MyProcessName.exe", DTE)
    End Sub

    Private Sub AttachToProcess(ByVal ProcessName As String, DTE As EnvDTE80.DTE2, Optional ByVal Script As Boolean = False)
        Try
            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim dbgeng(1) As EnvDTE80.Engine
            If Script Then
                dbgeng(0) = trans.Engines.Item("Script")
                'Array.Resize(dbgeng, 1)
            Else
                dbgeng(0) = trans.Engines.Item("Managed")
            End If
            Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, System.Environment.MachineName).Item(ProcessName)
            Call proc2.Attach2(dbgeng)
        Catch ex As System.Runtime.InteropServices.COMException
            Select Case ex.ErrorCode
                Case -2147352565
                    ShowMessage(ProcessName & " is not currently a running process")
                Case -1989083106
                    ShowMessage("You are already attached to " & ProcessName)
                Case Else
                    ShowMessage("Unhandled error message from Attach to process macro")
            End Select
        Catch ex As System.Exception
            MsgBox("Unhandled exception occurred: " & ex.Message)
        End Try

    End Sub
    Private Sub ShowMessage(ByVal message As String)
        Call MsgBox(message, MsgBoxStyle.Exclamation, "Attach to process macro")
    End Sub


End Class

Friday, 16 May 2014

Unshelving just the items you want in VS2013

Say you have a large shelve set and you only want to unshelve certain file types from that shelve set, like the project references changes you've made.

  1. Find your shelve set
  2. Open it in VS2013
  3. In the filter box type *.csproj
  4. Select all in the results and then right click
  5. Choose Exclude unselected from the context menu
    image
  6. Unshelve the resulting items, which should just be the csproj files.
    image

Using Git with Codeplex

http://codeplex.codeplex.com/wikipage?title=Using%20Git%20with%20CodePlex&referringTitle=Source%20control%20clients

 

Using Git with CodePlex

Git is a distributed version control system that is popular for open source projects. To learn more about how to use Git, the Pro Git site is a great reference. The following is a step-by-step guide to get started using Git for your CodePlex projects.

Step 1: Create your CodePlex project

Log-in to CodePlex and create a project. When selecting the source control, pick Git.

image

Once your project is created, click on the Source Control tab. Click the “Clone” action link to bring up connection details:

image

The clone URL is already selected and you can just type ctrl-C to copy the URL. We’ll be using this later.

Step 2: Set up Git

Download and install the latest Git tools for your operating system:

For the remainder of the guide, we’ll assume that you’re on a Windows system for screenshots.

After you’ve installed Git, you’ll want to provide Git with a username. Git uses this information to keep track of commit history, and CodePlex uses this to match commit history with CodePlex users. To do so, open the Git command line (Git Bash if you chose the default installation options for Git on Windows) and type the following command:

git config --global user.name "CodePlexUsername"

image

Step 3: Clone the repository

Next, you’ll want to set up your repository on your local machine by cloning the repository on CodePlex. In the Git command line, change the directory to a folder where you want to store the source code of your project and then type the following git command:

git clone https://CloneUrl NameOfFolder

where CloneUrl is the Clone URL you noted in Step 1, and NameOfFolder is the name of the folder where you want the source code to be stored. For example:

git clone https://git01.codeplex.com/plastikdreamgit PlastikDreamGit

image

Since you haven’t yet published your project, you’ll have to enter your CodePlex username and password. Because your repository is empty, you’ll get a warning message, but that’s fine.

Step 4: Push to CodePlex

Go to your newly created directory, and add your source code. Stage your changes using git add. For example, let’s say you add a readme file to your directory:

cd PlastikDreamGit

notepad readme.txt

git add readme.txt

image

Commit your changes with a commit message:

git commit -m "my first commit to CodePlex”

image

Push your changes back up to CodePlex.

git push origin master

Type in your CodePlex username and password when prompted.

image

Visit your source code history on the project page and verify that your changes have been pushed by browsing to the source code tab.

image

Thursday, 15 May 2014

Clip.exe and other sysinternals tools

 

Some brilliant little utilities talked about on the sysinternals session from MS TechEd 2014 here

http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/DCIM-B340#fbid=

Also check out https://www.virustotal.com/ which has integration into the latest version of sysinternals process explorer. Latest version can be downloaded from http://live.sysinternals.com. Virus total is a good way of using multiple virus scanners rather than just one to check files that you aren't sure about.

 

Had never heard of clip.exe before… (built into windows by default as well).

C:\Dev\RussellReynolds2010\Main\Solutions\Scripts>clip /?

CLIP

Description:

Redirects output of command line tools to the Windows clipboard.

This text output can then be pasted into other programs.

Parameter List:

/? Displays this help message.

Examples:

DIR | CLIP Places a copy of the current directory

listing into the Windows clipboard.

CLIP < README.TXT Places a copy of the text from readme.txt

on to the Windows clipboard.

More useful tools are:

  1. DU.exe - disk usage check : e.g.
    du -ct | clip.exe
  2. RU.exe - registry usage check : e.g.
    ru -ct -l 3 "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node"

image

Friday, 2 May 2014

WPF binding to static property

Just so I don't forget again, here's how it's done...

xmlns:ValueConverters="clr-namespace:ValueConverters;assembly=Controls"
xmlns:Services="clr-namespace:Infrastructure.Interface.Services;assembly=Infrastructure.Interface"

...

        <ValueConverters:BooleanToVisibilityConverter2 x:Key="booleanToVisibilityConverter2" />
    </ResourceDictionary>

</UserControl.Resources>

...

<StackPanel x:Name="MyStackPanel"
            Orientation="Vertical"
            Visibility="{Binding Source={x:Static Services:UserPreferencesService.Instance}, Path=UseWebAssignment, Converter={StaticResource booleanToVisibilityConverter2}, ConverterParameter=true}">

How to find the last interactive logons in Windows using PowerShell

Use the following powershell script to find the last users to login to a box since a given date, in this case the 21st April 2022 at 12pm un...