Friday, September 14, 2018

Deleting a Branch/Folder in TFS

One thing that bugs me with TFS source control is having to have local copies of files and folders before you can perform actions on them. One great example where this is a big problem is when deleting a large folder or branch where you don’t already have the items locally.

There is however a trick that will avoid having to download the entire content (which can take ages), and that is to just sync the top level folder. This is achieved from the command line using the tf.exe command line without the recursive option.

  • Open a Visual Studio command prompt
  • type tf get {name of folder}

Returning to Visual Studio you should now be able to delete the folder and check in the change without having to pull down the entire tree content.

This can prove to be a massive time saver!

Tuesday, April 25, 2017

Wow its been a long time

Just realized how long it has been since my last post - September 2012; ouch that is over 4 years!

I would like to say that I have been busy inventing something new, but really I have just been busy at work and home, getting on with life. Thats not to say that I haven’t done anything interesting, however I just haven’t got round to writing any of it down here.

A few of the interesting things I have worked on in this timeframe:

  • Sencha ExtJS
    • Writing a new UI wrapper for our product
    • This makes use of the ExtJS 6 Classic to target desktop and tablets. There is no real requirement to support the product on phones.
    • Creating an package to host social media interactions
  • Facebook Integration
    • Reading an writing to Facebook pages to provide social media interaction
  • Twitter Integration
    • Reading mentions, timelines and running searches, plus tweeting replies to provide a social interaction
    • Makes use of a great library TweetInvi which is hosted on github and available via NuGet.
  • Exchange Integration using Exchange Web Services (EWS)
    • Writing a service component to pull emails from Exchange, providing centralized management
  • Signal R sitting ontop of Redis
    • Providing real time updates to connected clients

I should try to write-up something on these in the near future.

Tuesday, September 4, 2012

File Search in Windows 7

Something that I have felt Microsoft have made much more difficult in the newer versions of Windows is to find specific files. The primary reason for this is now the only search facility is a single search box. On previous versions of Windows pressing Ctrl+F would bring up a search dialog that would present the user with various options for the files they wanted to find.

Recently I needed to find some files on my system, however I wanted better control of the results and I didn’t want to search for a specific file name. In frustration I read the Windows Help topic and this identified that it is actually possible to use special notation inside the search box to control what is being searched for. The online help is not complete (no surprise there!), but it does give some indication as to what is possible.

Basic Search

Just enter the filename or partial filename that is being searched for. Wildcards “*” can also be used.

Find a specific document:

thisisthedocument.doc

Find all documents (.doc, .docx)

*.doc*

File Attribute Search

Results can be filtered based on the file attributes. For example the last modified time of a file:

lastmodifiedtime: 22/02/2012

This fine files with the specific date, however if you want to find files newer than this date you can add the > symbol.

lastmodifiedtime: >22/02/2012

Find in files

The ability to find in files was one of the most useful features within Windows XP, and the ability appeared to have been removed in later versions of Windows. Doing a Google search for the ability to find in files, there are a number of utilities that can be installed that will allow this. One recommended utility is AstroGrep as this provides a nice clean interface and is quick to perform the search.

However following my discoveries around the file attributes search I was beginning to believe that it may be possible to do this within the Windows file search. And it turns out that it is, using the content keyword.

content: “find this is a file”

Only including certain types

In my example looking for files newer than a certain date, it was also including a lot of folders. These can be excluded using the kind keyword.

kind: <>folder

Summary

So it turns out the windows file search is actually a lot more useful than I had thought; sometimes reading the manual or online help does actually pay off!

Wednesday, July 18, 2012

Dust = Excessive CPU Temperature

In the warmer weather of late I have been noticing that the air under my desk (where the computer lives) has been getting fairly warm. So I decided that perhaps I had better check the temperature of my CPU as I am running a mild overclock and don’t want to burn out the CPU.

So I run HWMonitor and I am mildly alarmed at the temperature reading of approximately 50oC and that’s when the computer is sitting idle. After doing some gaming I discover this is reaching the high 70’s, and following a brief stress test with Prime95 it reaches 91oC before I stop the test. These temperatures are checked with CoreTemp also just in case there is an issue with the monitoring tool.

Background: My computer is running an Intel Q6600 overclocked to 3Ghz, Cooler Master TX2 cooler, running inside an Antec 900 case which previously had been keeping everything nice and cool. Or at least it was when I originally did the overclock.

Next port of call was Google to research the expected temperatures that I should be getting and this confirmed my thoughts that I should somewhere in the 30’s when idle and 50-60’s max when at load.

Gut instinct was then that something must be wrong with the cooler so started researching replacements. All this did was confuse me as there are so many on the market and no clear recommendation on what is a good value cooler.

It was then that I thought the best approach would be to open up the case and have a check how things looked inside, possibly with the aim of hoovering the inside as I thought maybe the air flow within the case had been disrupted. Obviously anyone who has opened a computer that has been running for a few years will know that a fair level of dust does get drawn into the case and this was the situation here. However I didn’t feel that there was sufficient dust to be causing the issue. It was only on closer inspection of the CPU cooler and having removed the CPU cooler fan that the amount of dust wedged between the cooling fins became apparent. Obviously this is not going to help the cooling as there was likely to be very little air flowing through the fins.

What followed was a brief flurry with the hoover inside the case and around the CPU cooler.

Everything replaced and the case side re-attached start the computer and hey presto, the idle temps are now in the 30’s and under load (Prime95) temps are in the 50’s.

Guess from now on part of my routine will be to annually hoover out the computer!

Thursday, May 24, 2012

Versioning Static Web Content (css & js) in Asp.Net

Often when building or maintaining a web application the supposedly static content turns out not to be that static in real life. The trouble is that is you have applied an aggressive caching policy to improve client perceived performance by marking the content never expiring, any changed static content will never be pulled down by the browser.

The end user can force the browser to re-download the content, and this is something we all as web developers find ourselves doing several times a day, by using the Ctrl+F5 keys. This will force the browser to re-download all items, however is a standard end user going to know to do this? I think not, and more importantly they shouldn’t have to!

Possible Solutions

While googling for methods to achieve this for a project at work, it became apparent that there are two main possibilities within the Asp.Net framework, one of which being much simpler to achieve. Firstly you could employ the url rewriting module to re-write the urls to include a version string. The new url will fool the browser to request the file when the version changes, however this is going to take a hit for every request to actually perform the re-writing.

A simpler, and as it turns out widely used method (stackoverflow being one example), is to just append a version query-string to the end of the url. Within the Asp.Net MVC framework we have the Url.Content extension that will resolve the provided address to a true absolute address. It is possible to write our own method to perform the same function but also append the version string.

Appending a version string

So we can define our own class with our implementation of the Content method. I have chosen to change the name of the method to VersionedContent, to better describe the purpose of the method; and we should continue to use the existing Content method where we do not require the versioning behaviour, such as when referencing third part libraries that already contain versions within their filenames.

   1:  public static class UrlHelperExtensions
   2:  {
   3:      private static string _versionQueryString;
   4:      
   5:      static UrlHelperExtensions()
   6:      {
   7:          Assembly asembly = Assembly.GetExecutingAssembly();
   8:          AssemblyName name = assembly.GetName();
   9:          _versionQueryString = "?v=" + name.Version.GetHashCode().ToString();
  10:      }
  11:      
  12:      public static string VersionedContent(this UrlHelper urlHelper, string url)
  13:      {
  14:          return UrlHelper = urlHelper.Content(url) + _versionQueryString;
  15:      }
  16:  }



Then in the page/view we just need to include the relevent namespace and replace the use of Url.Content with Url.VersionedContent.


Razor View Engine (MVC)


   1:  <link type="text/css" rel="styleSheet" href="@Url.Content("~/content/css/style-base.css")" />

 


Standard View Engine and Regular Aspx Pages


   1:  <link type="text/css" rel="styleSheet" href="<%=Url.Content("~/content/css/style-base.css")%>" />



 


Summary


So as you can see it is actually a simple change to your views to ensure that the static content can be versioned. These links can also be applied to other forms of static content such as images, however images generally do stay more static than the js and css files, so generally this is not required.


One thing to note is that the method of generating the version string based on the version of the assembly is only going to work if the version of the assembly is being changed! I would strongly recommend that you define a version numbering scheme ensure that the version number is changed each time the site is changed.

Friday, May 4, 2012

Strongly Typing Asp.Net MVC Master/Layout Pages

When developing Asp.Net MVC pages it is best practice to strongly type the views so that data passed from the controller can be accessed in a controlled and safe manner.

Strongly Typing Views

This is achieved in a couple of ways depending on which view engine is being used. When adding the view it is possible to choose the data type of the model that is to be used within the view.

Aspx view engine

If you choose to use the aspx view engine then the model class can be selected in the drop down and this will generate the correct markup to strongly type the model to the selected class.

image

The standard aspx view engine employs the markup style notation for defining the type of the Model.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/View.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.CustomerViewModel>" %>

Razor view engine


The razor view engine employs a much cleaner approach to typing the model. Again the class for the model can be selected in the drop down in the Add View dialog, like the one shown below.


image


This will generate code similar to that shown below, that uses the new @model razor notation to type the view to the specified class.

@model MvcApplication1.Models.CustomerViewModel

Master / Layout pages


There are a number of reasons that you may want to strongly type the model on the master page, as doing this is preferable to using TempData or ViewData directly. Depending on the model semantics that you are building it may be that all pages need to build a top level menu, however this is built from dynamic data. In this case it would make sense to make this data available in the model, and also add the code to generate the menu to the layout or master page, as it is not desirable to replicate this on multiple pages.


Anyone that has created a new layout / master page will realise that when adding a layout or master view you are not asked about strongly-typing the view. However just because you are not asked doesn’t mean that it isn’t possible!


The usual method of adding a new layout or master page is to choose the add new item, menu item and this will allow you to choose the type of view to add, and generate the view from the visual studio file template.


With a couple of tweaks to the generated code it is possible to strongly-type the master/layout page and get all the benefits that this brings.


Standard inheritance rules apply here!


As long as you follow basic inheritance rules strongly typing the model on the master/layout page is perfectly safe.


The thing to remember is that all models used on views that use the master/layout page must derive from the model defined on the master/layout page. Obvious really isn’t it!


So for example using the following classes


image


It is possible to strongly type the master/layout views to use the BaseViewModel class. Allowing the base classes Message property to be used directly within the master/layout page.


Aspx view engine


Utilize the System.Web.Mvc.ViewMasterPage<T> generic base class to specify the type of the model.

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<MvcApplication1.Models.BaseViewModel>" %>
<!DOCTYPE html>
<
html>
<
head runat="server">
<
title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
</
head>
<
body>
<
div>
<
asp:ContentPlaceHolder ID="MainContent" runat="server">
<%: Model.Message %>
</asp:ContentPlaceHolder>
</
div>
</
body>
</
html>

Razor view engine


Utilize the same @model notation as used in the view page to specify the type of the model.

@model MvcApplication1.Models.BaseViewModel
<!DOCTYPE html>
<
html>
<
head>
<
meta charset="utf-8" />
<
title>@ViewBag.Title</title>
<
link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<
script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<
script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</
head>
<
body>
<
div class="message">
<
p>@Model.Message</p>
</
div>
@RenderBody()
</body>
</
html>

Summary


That's all there is to it! Have fun changing all your master/layout pages to be strongly typed! Obviously if the layout/master page is only being used for layout then there is no benefit in doing this. However with the real life pages that I have experience in building the master/layout pages nearly always need so data which could be on the model.

Saturday, April 7, 2012

Force new session in browser

I recently happened on this when investigating an issue for a customer.

Generally end users have very little control over whether the browser decides to begin a new user session when revisiting a website/web-application or whether it uses a current session (which may be open in another browser instance or tab). Often the end user will not care about this but sometimes they will as it may have undesirable effects on what they are attempting to do.

For example when attempting to use multiple different user accounts to access an application such as logging into two different Gmail accounts. In this scenario you may want to log in more than once without loosing your previous session.

One method and probably the most obvious would be to use a completely different browser, such as IE and Chrome. This provides the added benefit of being able to easily identify the two different sessions from the Windows Taskbar. However this is not always possible especially in a locked down enterprise environment where only a single browser may be available.

Internet Explorer 8 Onwards

From Internet Explorer 8 onwards it is possible to force a new Window to use a new session, using the, ‘New Session’ item on the file menu.

image

For those who are calling out that there is no menu in IE8+, try clicking the ALT key on the keyboard and hey presto the menu appear as if by magic!

Alternatively this can be achieve from the command line or shortcut by appending the –nomerge command line option. This will launch a new Internet Explorer window without sharing the session information.

“C:\Program Files (x86)\Internet Explorer\iexplore.exe” –nomerge

Alternative browsers

This post was triggered from an issue in a customers environment, where they were using Internet Explorer, however the session behaviour described above is apparent in all the popular browsers.

Google Chrome

It is possible to open a new window without without the history and a new session by using the Incognito mode. ‘New Incognito Window’ from the wrench tool on the toolbar, or using the Ctrl+Shift+N keyboard shortcut.

This will open a new window in a new session, however it will also have the impact that no cookies or history will be stored once the session is ended.

If more control is required then a browser extension can be installed to allow management of the various session that are in use within the browser.

Firefox

An equivalent is not provided out of the box for Firefox, however it is achievable using a browser extension, such as IE Tab, which uses the IE Engine to render the tab contents so that two different sessions can be active at one time.