Sunday, October 12, 2014

C#'s yield Keyword

Introduction

The yield keyword in C# represents the only C# interview question I failed to answer -- "What does the yield keyword do in C#?" All I remembered is it had something to do with enumerators.

This post demonstrates the use of the C# keyword, yield. This also covers how to implement an IEnumerable and IEnumerator interface in support of using C#'s foreach keyword. Demonstrating IEnumerable will show the true power of the yield keyword. It takes significantly less code to implement an enumerator with yield than it does with IEnumerable/IEnumerator.

Example

The following code is just a loop that displays all the factorial values for the number 5 (where 5 is the value of the parameter passed to the Factorial method):

foreach (var factor in FactorialManager.Factorial(5))
{
  Console.WriteLine(factor);
}

The output is as follows:


Under the covers the Factorial method implements the IEnumerable or IEnumerable<int> interface and the compiler as part of the foreach keyword invokes IEnumerable.GetEnumerator which returns an IEnumerator or IEnumerator<int>  instance. The IEnumerable and IEnumerator interfaces can be implemented manually or can be implemented by taking advantage of the yield keyword.

Implementing IEnumerable/IEnumerator

The foreach keyword expects the FactorialManager.Factorial method to return a type that implements IEnumerable<int>. The implementation of the FactorialManager class is as follows:

class FactorialManager : IEnumerable<int>
{
  private int _factorialToCompute;

  public FactorialManager(int factorialToCompute)
  {
    _factorialToCompute = factorialToCompute;
  }

  public static IEnumerable<int> Factorial(int factorialToCompute)
  {
    return new FactorialManager(factorialToCompute);
  }

  public IEnumerator<int> GetEnumerator()
  {
    return new FactorialSupport(_factorialToCompute);
  }

  System.Collections.IEnumerator 
    System.Collections.IEnumerable.GetEnumerator()
  {
    return GetEnumerator();
  }
}

The previous code is not complex but it is verbose. The  Factorial method (a class factory) returns an instance of FactorialManager which implements IEnumerable<int>:

  public static IEnumerable<int> Factorial(int factorialToCompute)
  {
    return new FactorialManager(factorialToCompute);
  }


The FactorialManager class instance implemented IEnumerable's GetEnumerator method:

  public IEnumerator<int> GetEnumerator()
  {
    return new FactorialSupport(_factorialToCompute);
  }

GetEnumerator method returns an instance of FactorialSupport. The FactorialSupport class implements the IEnumerator<T> interface therefore it is an appropriate return value for the GetEnumerator method. The IEnumerator<T> interface is defined follows:

public interface IEnumerator<out T> : IDisposable, IEnumerator


The IDisposable requires IEnumerator  to implement:

void Dispose()

The Dispose is used to free unmanaged resources. A factorial implementation has no unmanaged resources so Dispose should just return and do nothing.

The IEnumerator requires IEnumerator<T>  to implement the following property:

T Current { get; }

The Current property will be values such as 1, 2, 6, 24 and 120 depending on the current value returned by the factorial computation. 

The IEnumerator requires IEnumerator<T>  to implement the following methods:

void Reset()
bool MoveNext()

The Reset method initializes the computation. The MoveNext moves to the next iteration. So if the value of Current was 6 (1 * 2 * 3) then MoveNext will set Current to 24 (1 * 2 * 3 * 4).

The FactorialSupport class is implemented as follows:

public class FactorialSupport : IEnumerator<int>
{
  private int _index;

  private int _factorialToCompute;

  private int _factorial;

  public FactorialSupport(int factorialToCompute)
  {
    if (factorialToCompute < 0)
    {
      throw new ArgumentException("Cannot compute factorial for " + 
                                  factorialToCompute.ToString());
    }

    _factorialToCompute = factorialToCompute;
    Reset();
  }

  public int Current
  {
    get { return _factorial; }
  }

  public void Dispose()
  {
    return; // nothing to do here. 
  }

  object System.Collections.IEnumerator.Current
  {
    get { return this.Current; }
  }

  public bool MoveNext()
  {
    if (_index > _factorialToCompute)
    {
      return false;
    }

    _factorial *= _index;
    _index++;

    return true;
  }

  public void Reset()
  {
    _index = 1;
    _factorial = 1;
  }
}

The previous code just implements an IEnumerator that returns factorial values using Current, MoveNext and Reset.

Implementing support for foreach using FactorialManager and FactorialSupport requires approximately seventy lines of code. This is a lot of code for something as trivial as a factorial computation. 

Implementing an Enumerator with yield

A method, property or operator that returns IEnumerable<int> or IEnumerable may contain the yield keyword. The yield keyword is placed before the break or return keywords and is used as follows.

yield return <expression>;
yield break;

An example where the yield keyword is marked in boldface is as follows:

public static IEnumerable<int> Factorial(int n)
{
  if (n == 0)
  {
    n = 1;
  }

  int value = 1;

  for (int i = 1; i <= n; i++)
  {
    value *= i;
    yield return value;
  }
}

static void Main(string[] args)
{
  foreach (var factor in Factorial(5))
  {
    Console.WriteLine(factor);
  }
}

The Factorial method above (approximately ten lines of code) is all this is required to implement the IEnumerable and IEnumerator interfaces required by foreach. The beauty of the yield keyword is that it instructs the compiler to implement:
  • IEnumerable.GetEnumerator
  • IEnumerator.Dispose
  • IEnumerator.Current
  • IEnumerator.MoveNext
  • IEnumerator.Reset

Conclusion

The yield keyword is not a .NET feature. It is a feature built into the C# compiler designed to making support foreach simpler for developers.

Saturday, October 11, 2014

SQL Server: Correlated Subqueries

The Question

I had an interview via web-meeting recently. I was given access to SQL Manager and I had to solve a set of TSQL programming problems. The first programming task they throw at me is a question, "What is a correlated subquery?" I said, "I do not know" and moved on. It turns out I knew what a correlates subquery was but I just did not know such queries were called that.

This post presents an overview of correlates subqueries in TSQL.

Subqueries

A subquery is just a portion of a query that is evaluated before main part of a query. To understand this, consider the following (from the same job interview):

SELECT *
FROM [TableA] AS A
  INNER JOIN [TableB] AS B
    ON A.[AID] = B.[AID]
  INNER JOIN [TableC] AS C
    ON A.[AID] = C.[AID]
  INNER JOIN [TableD] AS D
    ON A.[AID] = D.[AID]
  INNER JOIN [TableE] AS E
    ON A.[AID] = E.[AID]
WHERE [AName] = 'Smith'

The above query has no sub-query. The interviewer explained, "This query is suffering from poor performance. What would you do to optimize it?" The answer is obvious -- use a subquery to get only the required values from TableA before joining with TableB, TableC and TableD. The subquery that should get evaluated first is:

SELECT *
FROM [TableA] AS A
WHERE [AName] = 'Smith'

The optimized query, including the subquery in its entirety, is below where the subquery is shown in boldface:

SELECT *
FROM (
  SELECT *
  FROM [TableA] AS A
  WHERE [AName] = 'Smith') AS A
  INNER JOIN [TableB] AS B
    ON A.[AID] = B.[AID]
  INNER JOIN [TableC] AS C
    ON A.[AID] = C.[AID]
  INNER JOIN [TableE] AS E
    ON A.[AID] = E.[AID]
  INNER JOIN [TableE] AS E
    ON A.[AID] = E.[AID]

The subquery is executed by SQL Server's optimizer first. This will reduce the number of data values and will potentially improve performance when the outer query is executed. The previous query is a simple subquery or a non-correlated subquery.

Correlated Subqueries

A correlated subquery is a subquery that depends on values from the outer query. Technet covers correlated subqueries here Correlated Subqueries. To demonstrate correlated queries, consider a database with tables:
  • Player: this table holds a list of soccer players (football players for you non-Americans)
  • Goal: this table holds a list of goals scored by players
To demonstrate correlated subqueries, a query will be developed that shows all players who have not scored any goals:

SELECT P.[PlayerID], P.[PlayerName]
FROM [Player] AS P
WHERE NOT EXISTS (
  SELECT * 
  FROM [Goal] AS G 
  WHERE P.[PlayerID] = G.[PlayerID])

The outer query contains table Player aliased as P. The subquery contains table Goal aliased as G. The subquery references the table Player from the outer query so the subquery is a correlated subquery. The subquery in this case did not aid performance by reducing the results returned to the outer query. Performance may suffer when using a correlated subquery because the query has to be evaluated for ever row of the outer query.

So yes, I knew how to write a correlated subquery. I just did not know the definition. 


Implementing the query without using a Correlated Subquery

A LEFT JOIN in a subquery  can be used as follows to implement the same query -- all players who have not scored a single goal:

SELECT [PlayerID], [PlayerName]
FROM (
  SELECT P.[PlayerID], P.[PlayerName], G.[GoalID]
  FROM [Player] AS P
    LEFT JOIN [Goal] AS G 
      ON P.[PlayerID] = G.[PlayerID]) AS P
WHERE P.[GoalID] IS NULL

Conclusion

Yes, I moved onto the second interview.

Friday, October 3, 2014

Visual Studio Online (cloud hosted TFS): Accessing Visual Studio Online Bugs/Tasks from Excel

This post is a "how to" covering the steps required to access Visual Studio Online tasks using Excel.

Introduction

Visual Studio Online is a fairly young cloud-based application (released in 2013). With regards to tracking tasks and bugs it does support a variety of configurable reports. Excel by contrast is a more mature reporting generating and data formatting environment (release in 1987). So to take advantage of the Excel, an extremely mature product, Visual Studio Online supports Excel integration. Excel can be used to view tasks/bugs and can even handle the modification of tasks and the creation of new tasks. Excel can also handle bulk import so if you move from Jira (for example) export the bugs to CSV format and then import into Visual Studio Online using Excel.

Excel 2007 and later versions can interface with Team Foundation Service (TFS) and since Visual Studio Online is a cloud-hosted variant of TFS, your minimum Excel version is 2007.

When Excel connects to Visual Studio Online or TFS it uses queries in order to access work items. The general workflow for the interaction between Visual Studio Online and Excel is as follows:

1) Create a Query within the Visual Studio Online instance (web site) or using Team Explorer or using Visual Studio
2) Connect to Visual Studio Online (or TFS) via Excel
3) Retrieve the query results using Excel
4) Add/Modify/Delete work items using Excel
5) Publish changes from Excel to Visual Studio Online (or TFS)

The following shows the steps required in integrating Excel with Visual Studio Online:


The previous diagram is taken MSDN's walk through of how to integrate Excel and Visual Studio Online (Work in Microsoft Excel and Microsoft Project connected to Team Foundation Server). Microsoft's write up is good but it is not as detailed as this posting. Even a person who does not use Visual Studio Online daily (a manager, a product manager, ad hoc QA, et al.) will find every step required to access Visual Studio Online from Excel by following what is documented here.

Signing up for a Visual Studio Online instance was covered by a previous post: Signing up for Visual Studio Online (cloud-based Team Foundation Server).

Prerequisite: Create an Query in Visual Studio Online

As stated previously Excel accesses Visual Studio Online work items through Visual Studio Online queries. Queries are associated with a Visual Studio Online project instance. To view all the queries associated with a Visual Studio Online project perform the following steps:

1) In Internet Explorer navigate to the instance of Visual Studio Online using the instance's URL (the instance in this case is https://AdmiralGraceHopper.visualstudio.com/):


2) If the credentials for the appropriate Microsoft account associated with the Visual Studio Online instance have not been entered, a user will be prompted to enter them:


3) Once the Microsoft Account credentials have been entered for the Visual Studio Online instance, the browser will be redirected to the main screen for the instance:


4) Under "Recent projects & teams" a list of projects is displayed. For this example the project MarkI is selected. If the desired project is not visible under the most recent list, click on the Browse button to select the appropriate Visual Studio Online project:


6) The MarkI project is shown above. To view the queries associated with the instance click on the WORK menu (not the Work "How to" help entry):


7) When the WORK menu item is selected the Backlogs and Queries tabs are visible. By default Queries are visible as follows:


The previous screenshot shows the default queries of the Mark1 project. These are the queries will ultimately be visible to an Excel workbook when accessing the Visual Studio Online instance https://AdmiralGraceHopper.visualstudio.com and the Mark1 project. 

Additional queries can be created for use in Visual Studio Online or to be accessed via Excel by clicking on the New dropdown and selecting New query:


For this example (using Excel to access Visual Studio Online) the default queries for the MarkI project will be used.

Connecting Excel to Visual Studio Online

The following steps are required to support Visual Studio Online's integration with Excel:

1) Install Team Explorer (see the previous post Visual Studio Online (cloud-hosted TFS) for non-Visual Studio Developers). If Visual Studio is installed this step can be skipped as Visual Studio includes the TFS Excel add-in.

2) Launch Excel 2007 or any later version and create a new "Blank worksheet" which appears as follows in Excel 2013:


3) Select the TEAM ribbon which is as follows:


4) If the Team ribbon is not visible, see the section at the end of this posted "Re-enabling the TEAM Ribbon"

5) To connect to Visual Studio Online or TFS click on the TEAM | New List button which causes the Connect to Team Foundation Server dialog to be displayed:


6) From the Connect to Team Foundation Server dialog click on the Servers button thus displaying the Add/Remove Team Foundation Server dialog:


7) From the Add/Remove Team Foundation Server dialog click on the Add button thus displaying the Add Team Foundation Server dialog:


8) Under the textbox labeled, "Name or URL of Team Foundation Server:" enter the URL associated with the desired Visual Studio Online instance (for this example the Visual Studio Online URL is https://AdmiralGraceHopper.visualstudio.com/):



9) Once the Visual Studio Online instance URL is specified, click on OK thus displaying a "Sign in" dialog to sign into said Visual Studio Online instance where the appropriate Microsoft account ID and password can be entered:


10) Enter the Microsoft account name and password:



11) Click on the Sign In button:



12) When a valid Sign In credentials are entered then the Add/Remove Team Foundation Server is displayed again with the freshly entered Visual Studio Online URL highlighted. Simply click on Close:



13) From the Connect to Team Foundation Server dialog, select the appropriate Team Project (e.g. MarkI) and click on Connect.

At this stage Excel is connected to a Visual Studio Online project but has yet to retrieve work items using a Visual Studio Online query.

Select a Query to Import into Excel

Once a connection is established using the Connect to Team Foundation Server dialog (initially displayed by clicking on the New List button on the TEAM ribbon), the New List dialog is displayed:



Clicking on the ... button next to Query List drop down reveals the Select Query dialog:



Expanding the folders in the Select Query dialog reveals all the queries from the MarkI project:


Select the Product Backlog query and click the Select Query dialog's OK button. With the Select Query dialog closed the New List dialog is active again:


Clicking on the OK button of the New List dialog will cause Sheet 1 of the workbook to retrieve the work items associated with the Mark1/Shared Queries/Product Backlog query:


Re-enabling the TEAM Ribbon

1) In Excel click on the File menu (it is not a ribbon as no ribbon is displayed when File is clicked on):


2) Click on Options thus displaying the Excel Options dialog:



3) From the categories along the left side of the dialog, select Add-Ins:


4) Notice under "Active Application Add-Ins" that there is no add-in named "Team Foundation Add-in". To enable the Team Foundation Add-in select "Com Add-Ins" from the Manage drop down and click on Go:



5) This displays the COM Add-Ins dialog:



6) Click on the checkbox next to the Team Foundation Add-in entry and click on OK:


7) Clicking on OK returns to the workbook view of Excel where the TEAM menu entry should be visible (see above). This means the TEAM capabilities are enabled since Team Foundation Add-In is enabled.

Subsequently selecting File | Options | Add-In displays the Excel Options | Add-Ins where the Team Foundation Add-In is listed under Active Application Add-ins:





Thursday, September 18, 2014

Visual Studio Online (cloud hosted TFS): Setup a Preferred (alternative) email on which to Receive Alert Notifications

Like a significant number of developers, I use a single Microsoft ID (single email address) for multiple Visual Studio Online repositories. Enter into this Visual Studio Online alerts which get sent by default to the email address associated with the Microsoft ID. When working a company it makes sense to send alerts to the corporate email even if you're Microsoft ID is your personal email address.

This posting demonstrates how to associate a "preferred email" address so alerts are sent to the preferred email address instead of the email associated with the logged in Microsoft ID. This sounds like a great feature but beware the following: the preferred email address is associated with the Microsoft ID. This means that every Visual Studio Online instance will send alerts to the specified preferred email. The preferred email address is not Visual Studio Online instance-specific.

To set the alternate email for all instances of Visual Studio accessed by the Microsoft ID, log in to the Visual Studio instance:


Click on the logged in username which shows a menu including menu items My profile and Sign out:



Notice below in the User Profile dialog, the preferred email address can be specified:


Once the preferred email address has been modified, click on the Save changes button in order to commit the changes.

After the preferred email address has been changed, an email will be sent to the preferred email address. A user must click on the email's conformation link thus verifying the preferred email and giving Visual Studio the green light to send alert related emails to the preferred email address.





Wednesday, September 3, 2014

Windows Store Applications: Simulating Application Suspending, Restoring and Terminating in Visual Studio

During debugging it is desirable to access the code that handles state management: suspending, terminating, and restoring an application. Visual Studio allows these states to be simulated. The suspend, restore and terminate states obviously apply to Windows Store applications. The states and state transitions of a Windows Store applications are as follows:


The Debug Location toolbar facilitates Visual Studio's ability to simulate run states for Windows Store applications. To verify that the Debug Location toolbar is enabled, right click on Visual Studio menus. The Debug Location menu item should appear as checked in the context menu displayed. Shown below is a screenshot from Visual Studio 2013 where the Debug Location toolbar is not checked and hence currently visible:



The Debug Location toolbar can also be displayed using menus: View | Toolbars | Debug Location.

When visible the Debug Location toolbar is as follows (the Debug Location toolbar below is split for readablity):




The steps to simulate events in Visual Studio (suspending, terminating and restoring) are as follows:

  • Run the Windows Store application in the debugger: Debug | Start Debugging or shortcut, F5
  • Return to Visual Studio by pressing Alt-Tab
  • Click on the Lifecycle Events drop down on the Debug Location task bar



The items under the Lifecycle Events drop down ("Suspend", "Resume" and "Suspend and shutdown") correspond to the Windows Store application run state to be simulated by Visual Studio.

Saturday, August 30, 2014

PowerShell: Getting the Drive Letter for a PowerShell Script

A quick search online reveals there are a large number of ways to return the current path of the PowerShell script being run. PowerShell 3 introduced the automatic variable, $PSCommandPath. An example is as follows (script file, ShowPathInfo.ps1):

Write-Output "`$PSCommandPath:  $PSCommandPath";

The output from this command is as follows:



In previous snippet of PowerShell note the use of the Grave accent character before $PSCommandPath (e,.g. `$PSCommandPath). This escape character suppresses $PSCommandPath being interpreted as a variable and instead prints the string literal. For those who cannot find the grave accent (it is to the left of the 1 key or as http://soinoticedthis.blogspot.com/ shows in one blog post):



Displaying the drive letter is a matter of executing (script file, ShowDriveLetter.ps1):

$DriveLetter = $PSCommandPath[0];
Write-Output "Drive Letter:  $DriveLetter";

The output from this is as follows:

The $PSCommandPath automatic variable will not work if you are using PowerShell 2. This version of PowerShell is native to Windows 7 and Windows Server 2008 R2. PowerShell 2 is available in Windows XP upgrade to Service Pack 3, Windows Server 2003 upgraded to Service Pack 2 and Windows Vista upgraded to Service Pack 1.

If you are limited to PowerShell 2 consider the following (script: ShowPathInfoPowerShell2.ps1):

function WhatHappensNestedInAFunction()
{
  Write-Output("Function invoked `$MyInvocation.ScriptName: " + 
    $MyInvocation.ScriptName);
  Write-Output("Function invoked `$MyInvocation.Path: " + 
    $MyInvocation.MyCommand.Path);  
}

Write-Output("Script invoked `$MyInvocation.ScriptName: " + 
  $MyInvocation.ScriptName);
Write-Output("Script invoked `$MyInvocation.Path: " + 
  $MyInvocation.MyCommand.Path);  
WhatHappensNestedInAFunction ;

The output from the script is as follows:


This means in PowerShell 2 you have to use the following to get the script name within the script:'s body:

$MyInvocation.MyCommand.Path  

It also means in PowerShell 2 you have to use the following to get the script name within a function:

$MyInvocation.ScriptName

To simplify this, it is simpler to just create a function that uses $MyInvocation.ScriptName to return the script path:

function GetScriptPath()
{
  return $MyInvocation.ScriptName;
}

Once the script path is know, getting the driver letter is trivial (as was previously demonstrated).

Friday, August 29, 2014

Visual Studio Online (cloud hosted TFS): Unlimited (no cost) users can Create/Access Bugs/Tasks

Microsoft has created a new category of free users for Visual Studio Online (VSOL), namely Stakeholders. This user type has the ability create bugs/tasks and view the status of bugs/tasks including generating reports with regard to bugs/tasks. Even a company that has no desire to use VSOL for source code control has a free, cloud-based bug/tracking and project management software provided by Microsoft.

Thus far the lowest tier of licenses for Visual Studio Online was the "Basic License." Each VSOL account comes with five Basic user accounts for free and each additional is $20 per month (as of August 2014, see: Visual Studio Online User Plans). With this minimum account type comes access to source code control and the project management aspects of VSOL found under a project's Work menu item. This includes creating bugs/tasks and generating reports related to bugs/tasks. An example of the Work menu for a project configured with process template "Microsoft Visual Studio Scrum 2013.3:



For every engineer requiring access to source code control there is a plethora of product managers, QA engineers, non-coding managers and other "stack holders" who require access to the functionality found under the Work menu. Add to this alpha and beta users that require bug creating capabilities and the cost used to be significant. As stated an unlimited number of such users can be added at no cost, simply assign the user to the free Stackholder license type (see below):


The previous screenshot shows user Keyser Soeze being converted from a Basic user (with source code access) to a Stackholder.

S. Somasegar (Corporate vice president of the Developer Division at Microsoft) wrote an excellent blog entry introducing this new feature of VSOL: Visual Studio Online - Stakeholder License

There is no free service comparable to Visual Studio Online that provides the following:
  • 5 free Basic users with access to source code and Work functionality (tasks/bugs)
  • Unlimited free Stackholder users with access to Work functionality (tasks/bugs)


Thursday, August 7, 2014

Managing the size of Screen Artifacts for High Resolution Displays

Most Windows users set the size of their screen artifacts (text and other displayed items) to small. For the case of a high resolution display, the icons on the screen (for example) would appear to be microscopic if a size of small were specified.  The article addresses how to manage the size of displayed elements.

Evolution: from a Behemoth CRT to 4K 39-inch LCD

A large number of developer remember paying $2000 for a 21-inch CRT style monitor. This leviathan of a tube-based monitor weighed eighty pounds and sported a resolution of 1600x1200. Within a few years, a large number of developers shelled out $2000 for a 1920x1200 24-inch LCD.

Comparatively, monitors are so cheap now they are almost free. The norm for a monitor now is a twenty-four inch LCD running at 1920x1080 albeit at about a 7% of the cost originally paid for such a monitor. If we take this resolution and double both the horizontal and vertical dimension we get 3840x2160 or a 4K monitor. A quality 39-inch 4K monitor is actually quite reasonably priced $339.

NewEgg, Walmart and Amazon (along with other merchants) sell Seiki’s SE39UY04 39-Inch 4K Ultra HD 120Hz LED TV at $339:


Seiki’s SE39UY04 is an excellent development monitor. I cannot critique it as a “gaming monitor” as I write code and rarely play games.

A 39-inch monitor 4K is not the only trend in high resolution displays. Microsoft’s Surface 3 Pro is a 12-inch screen at a resolution of 2160x1440. Both of these displays require that screen artifacts be set to larger versus small.

Managing the Size of Screen Artifacts

Windows is designed to handle this resolution by changing Control Panel | Appearance and Personalization:



From the Appearance and Personalization dialog select Make text and other items larger or smaller:


Clicking on Make text and other items larger or smaller shows the Display dialog:


For a standard 1920x1080 monitor, the value for “Change the size of all items” is typically set to Smaller. For the Microsoft Surface 3 Pro, the value for “Change the size of all items” is set as demonstrated above. For a monitor such as 39-inch 4K monitor. The value of “Change the size of all items” should be set to Larger.

The Caveat: You must logout for settings to take affect

On Windows 8.1 and Windows 8, changing the value of “the size of all items” requires a user to log in and log out in order to have the change in setting be recognized. This seems like an innocuous requirement, but consider a developer with a 39-inch 4K monitor at home running a half dozen applications (currently set to display large text). When he arrives at work, he uses remote desktop to log in to his home machine. His work monitor is 1920x1080. Under this level of resolution the text appears gargantuan. In order to make the screen readable, he has to change “the size of all items” which requires a log out and a re-log in. All the currently running applications will be exited (such as a long running debugging session that cannot easily be saved).

Thursday, July 10, 2014

Visual Studio Online (cloud hosted TFS): Deleting a Team Project

I often create temporary projects to test automating the build. The test projects ultimately need to get deleted which is where TFSDeleteProject comes in (Delete a team project [TFSDeleteProject]). The command-line to delete a Visual Studio Online project is as follows:

TFSDeleteProject /collection:https:/<your vanity name here>.visualstudio.com/DefaultCollection "your project name"

In a previous posting, Visual Studio Online was subscribed to  using the vanity URL, admiralgracehopper.visualstudio.com. Using TFSDeleteProejct to delete a project named ATestProject from admiralgracehopper.visualstudio.com would be handled as follows:

TFSDeleteProject /collection:https:https://admiralgracehopper.visualstudio.com ATestProject

Tuesday, July 8, 2014

Visual Studio 2013 now supports Installer Projects

Desktop applications and Windows Services have relied on Visual Studio's installer projects. The installer projects (to state the obvious) allowed an installer to be created for an application. This reliance on installer projects lasted until Visual Studio 2012 when Microsoft ceased supporting installer projects.

On June 15, 2014, Microsoft released version 1.0.0.0 of Microsoft Visual Studio Installer Projects. To quote Microsoft's download web page, "This official Microsoft extension provides support for Visual Studio Installer Projects in Visual Studio 2013."

Subsequent to this, developers who had moved to Visual Studio 2012 or Visual Studio 2013 were forced to use Install Shield Limited Edition or WiX in order to create installers for "desktop applications" (non-store applications). Another approach to delivering installer projects was to build code in Visual Studio 2013 and create the installer projects using Visual Studio 2010.

There is a blog with regard to Visual Studio and specifically Visual Studio Installer Projects Extension. Numerous comments under this blog ask whether the installer projects extensions work with Visual Studio 2012. That remains to be seen -- for those unable to move from Visual Studio 2012 to Visual Studio 2013.

Wednesday, June 4, 2014

Getting Visual Studio 2010 SP1 to run on Windows 8 and Windows 8.1

A variety of projects I work on still require Visual Studio 2010 which is patched with SP1. Most machines I worked on are Windows 8.1 because Windows 8 and above supports 64-bit virtual machines under Hyper-V (the most critical feature for developers under Windows 8).

By default Visual Studio 2010 with SP1 may not run on Windows 8 or Windows 8.1. Microsoft provides a patch that allows to execute on said operating systems: Update for Microsoft Visual Studio 2010 Service Pack 1 (KB2736182).

Microsoft does provide an overview of the previous patch and the issues it addresses: A GDR update for Visual Studio 2010 SP1 is available to add compatibility support for Visual Studio 2012 and Windows 8.

Wednesday, April 23, 2014

Access 2013: Protecting the Programmatic Elements of a Database

This posting presents ways to protect an Access database so that users cannot edit the underlying database. This means a user should not be able to edit the VBA code, reports and forms of an Access database. The user should be able to run the database. Additionally, the user should not be able to edit the underlying tables.

Convert Database to Execute-Only Mode


The most straight forward way to project an Access database (*.accdb file) is to save it as an executable, namely a file with an accde extension. This is achieved by selecting Save As from access and saving the *.accdb file with an *.accde extension as follows. An example of Access 2013's Save As dialog is as follows:




Once the accde file type has been select, click on the Save As button.

The standard file extension (referred to as an Access 2007 file type) is *.accdb. This extension replaced the *.mdb extension used by per-Access 2007 versions of Access. The *.accde extension is also a valid Access 2007 extension. When a file is saved as *.accde, the file is in execute only mode. An Access database in execute only mode the following behavior:

  • The VBA code is compiled and not included in the distributed database
  • Forms cannot be modified
  • Reports cannot be modified.

Even though the Access database is converted into an executable (*.accde extension), a copy of Access is still required to run the file.

Access Runtime

It is possible to distribute an Access application without requiring Access to be physically installed. From a cost stand-point this is a tremendous savings. It also means that user cannot directly access the tables and queries of the underlying database, since Access is not installed. This does not prevent them from installing Access.

Executing an Access application without requiring Microsoft Access is achieved using the Microsoft Access Runtime found at: Microsoft Access 2010 Runtime. The Access Runtime can run database with either an *.accdb or *.accde extension.

The runtime means that the application will but a user will not have access to the design related toolsbut the Access project will execute.

Runtime Behavior on a Machine on which Access is Installed


It is possible to determine how an application behaves when running under the Access Runtime even if Accss is installed. The Access application (MSAccess.exe) supports a command line option, /Runtime. specifying the /Runtime options means Microsoft Access will run an Access application as if the application were running under the Access Runtime.

For example using full Microsoft Access 2013 it would be possible to run fun.accdb as if it was running under the Access Runtime using the following command:

"C:\Program Files\Microsoft Office 15\root\office15\MSACCESS.EXE" fun.accdb /Runtime

It would also be possible to run an Access executable such as fun.accde as if it was running under the Access Runtime using the following command:

"C:\Program Files\Microsoft Office 15\root\office15\MSACCESS.EXE" fun.accde /Runtime