Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, September 14, 2012

ASP.NET MVC form submission with link

While learning about ASP.NET MVC and whether it was possible to use an HTML anchor tag to trigger an HTTP POST request (I didn't want to use a button), I came across this interesting post about the pitfalls of using links for deletion of data:
http://stephenwalther.com/archive/2009/01/21/asp-net-mvc-tip-46-ndash-donrsquot-use-delete-links-because.aspx

It's worth knowing, and this issue highlighted is in a similar vein to SQL injection in URL's.

The intended operation for the link I was creating was to update a database record, so the consequences of using a link are similar to that of a delete operation via a link. In the end, I opted to trigger a form submission via javascript:

@using (Html.BeginForm())
{
    <p>
        <a href="javascript:document.forms[0].submit()">Yes</a> |
        @Html.ActionLink("No", "Details", new { id = Model.Id })
    </p>
}

Wednesday, April 18, 2012

Smart device/.NET CF unit testing: No mocking

Seeing as the .NET Compact Framekwork does not have/support any mocking frameworks available for unit testing, here's a reference for writing your own stubs to fake out your external dependencies when unit testing smart device projects:

http://elegantcode.com/2009/04/29/unit-testingmocking-on-net-cf/

Smart device unit testing: deploying additional resources

A handy reference with different ways of deploying additional resources (e.g. sdf files) to the device/emulator for smart device unit test projects:

http://blogs.msdn.com/b/prativen/archive/2008/02/05/deployment-in-smart-device-unit-tests.aspx

Thursday, April 12, 2012

Unit testing smart device projects - TestContext error

A couple of days ago I started creating unit tests for a Windows Mobile smart device project that I have been working on in Visual Studio 2008. I generated a unit test method for one of the methods in one of the classes and attempted to run the test. This is when I ran into an error that took me several hours to solve, so hopefully posting this helps someone.

The test method failed to run due to the following error:

Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'


Googling the error returned results that suggested it was caused by upgrading a test project from Visual Studio 2005 format to 2008, and that the reference to the UnitTestFramework.dll was still for the old version (8.0) and required updating. This did not apply to me as I had not upgraded my test project from VS2005. So I continued searching.

After hours of searching for other causes for the error without success, I stumbled upon the following references in the smart device project:

Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.Status.dll

Visual Studio was obtaining these references from the following folder:

C:\Program Files\Windows Mobile 5.0 SDK R2\Managed Libraries

However, the smart device project's target platform was the Windows Mobile 6 Professional SDK. I didn't notice this before as I did not originally create the smart device project. So I removed the references to the two DLLs and readded them from the following folder:

C:\Program Files\Windows Mobile 6 SDK\Managed Libraries

After rebuilding the smart device project, running the test method succeeded.

Wednesday, April 27, 2011

Visual Studio Smart Device Projects build slowly

If you are developing a smart device application using either Visual Studio 2005 or 2008, you may be experiencing extremely slow build times every time you make a code change. This can be very frustrating when all you want to do is continually build, deploy and debug. It is most likely that the slow build is being caused by the platform verification task (PVT), which is a post-build task that runs by default. More information can be found here on what the PVT is and why it is required. You can however disable it temporarily as it is not required to be run every time you build your smart device application.

To disable the PVT, you can perform the following steps.
  1. Open the file %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2005) or %windir%\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2008) for editing.
  2. Go to the line which reads:
    ...
    
  3. Change it to:
    ...
    
  4. Add the SkipPlatformVerification environment variable to the system and set it to "true" (To re-enable Platform Verification set the environment variable to "false").
  5. Restart Visual Studio for the changes to take effect (If building from the command line using MSBuild, add /p:SkipPlatformVerification=true to your command line to turn off the task. You can specify the variable in the project file also, so that this information is persisted across sessions).

Source: Visual Studio For Devices blog

Monday, November 15, 2010

IIS7 configuration for hosting WCF services

I have recently been learning about Windows Communication Foundation Services and when I first tried to host a service in IIS7, I encountered the following error when attempting to navigate to the service URL:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. Detailed Error InformationModule StaticFileModule.
This error is caused by enabling IIS after Visual Studio 2008/2010 and the .NET 3.5/4.0 Framework were installed.  To rectify this:

  1. Open the Visual Studio command prompt as "Administrator".
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.
  3. Run the following command: servicemodelreg –i.
After performing the above steps, navigating to the service URL returned the following error:
HTTP Error 500.21 - Internal Server Error
Handler "svc-Integrated" has a bad module "ManagedPipelineHandler" in its module list
As I had enabled IIS after installing Visual Studio and the .NET Framework, ASP.NET had to be registered in IIS:

  1. Open the Visual Studio command prompt as "Administrator".
  2. Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319.
  3. Run the following command: aspnet_regiis -i
I was then able to successfully load the WCF service URL.

Thursday, July 15, 2010

Find columns with a particular property

Here's a query I found handy when I needed to retrieve a list of columns from any table in a database that is a ROWGUID column.

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
COLUMNPROPERTY
(
OBJECT_ID(QUOTENAME(table_schema) + '.' +
QUOTENAME(table_name)) -- table ID
,column_name
,'IsRowGuidCol'
) = 1
ORDER BY table_name, ordinal_position

You can also replace 'IsRowGuidCol' with any other property listed here.

Thursday, July 8, 2010

Clean up orphaned identity range constraints

Consider the following scenario: You wanted to move a SQL Server database from one server to another, so you detached it from the original server and attached it at the destination. However, the database was replicated using merge replication and you forgot to delete the database's publications before detaching it. Now, after attaching the database, you find that there are leftover orphaned identity range constraints on the previously replicated tables. I was faced with this problem, so I constructed the following script after some searching on the internet.

DECLARE @constraintname SYSNAME
DECLARE @tablename SYSNAME
DECLARE c1 CURSOR FOR
SELECT SysObjects.[Name] AS [Contraint Name] , Tab.[Name] AS [Table Name]
FROM SysObjects
INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab ON Tab.[ID] = Sysobjects.[Parent_Obj]
INNER JOIN sysconstraints ON sysconstraints.Constid = Sysobjects.[ID]
WHERE SysObjects.[Name] LIKE 'repl_identity_range%'
ORDER BY Tab.[Name]

OPEN c1
FETCH NEXT FROM c1 INTO @constraintname, @tablename
WHILE (@@fetch_status <> -1)
BEGIN
EXEC ('ALTER TABLE ' + @tablename + ' DROP CONSTRAINT ' + @constraintname)
FETCH NEXT FROM c1 INTO @constraintname, @tablename
END

DEALLOCATE c1
GO

Wednesday, July 7, 2010

Find text in stored procedures or views

This is a handy query that I found that searches through your SQL Server database stored procedures or views for occurrences of the specified text.

For example, to search for a stored procedure with the text "foo", use the following:

SELECT OBJECT_NAME(id)
FROM syscomments
WHERE lower([text]) LIKE '%foo%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)

To search through views, replace 'IsProcedure' with 'IsView'.

Thursday, June 17, 2010

Computer user stereotypes

As a programmer, my job also entails supporting many users of the software we create. I respond to support requests relating to the software, as well as internal requests for general help with computers and other IT related matters. It can become extremely frustrating when the same questions are asked over and over. In the time that I have dealt with support requests, I have been able to identify common traits in computer user behaviour and compiled a list of categories - this is my perspective.

A. The learner
This is my favourite kind of user - one who requests support only after they have first tried everything they can. The learner is also inquisitive and asks questions that help them expand their knowledge about the software or computers so that they can apply the new knowledge gained in a more generic sense in multiple scenarios. Learners are also proactive and often help to stem the wave of support requests from B's, C's, D's, F's and G's by helping them before they contact me. Sometimes, the learner is also a G, but this can be forgiven because they learn to check their notes/help documents before asking again.

B. The always innocent
These are cunning users, everything they say about an issue must be questioned before being believed. They will often provide very little information and just say that something is not functioning correctly. When asked what steps they took to encounter the issue and it is found they made a mistake, they will feign innocence, become defensive and make a multitude of excuses including:
* Not being told about it before
* The documentation not being adequate
* The process being confusing
"Innocents" are often also C's, D's and G's.

C. The accuser
There are very few accusers (from my experience), but they do exist. Accusers will play the lawsuit card and they will play it very quickly, practically immaturely. They will threaten to sue your company because the software they bought from you "isn't working". These threats are mostly likely empty and are made in an attempt to exert some dominance because they think the customer is always right. After some further discussion and being shown what they need to do to overcome their issue, accusers will then back off rather sheepishly. Accusers can also be B's, D's and G's.

D. The one who finds it too difficult
The typical attitude of D's is "this issue is software/computer related, therefore it's not my problem and I don't need to attempt to overcome it myself." They will immediately approach you with their problem as soon as they encounter it. Also, because I'm a programmer, they assume I am the IT support department and can answer every IT related question under the sun. That's like assuming that all Arabs are terrorists and know how to construct a bomb. D's can also be B's, C's and G's.

E. The one who will never understand
These users can be annoying and a source of extreme frustration, but cannot be blamed entirely. Despite their best efforts to understand how overcome their issue, they will never "get it". A support call with an E often starts of with me attempting to give them step by step instructions, which they will fail to be able to comprehend or follow. After an alternative process is spelled out to them, E's will still fail to understand. From this point, I have no option but to end the interaction by asking them to seek the help of one of their colleagues.

F. The dangerous
F users are those that know the basic concepts about computers and software. What makes them dangerous is that they will call me for support, explain their issue and then preempt my response by suggesting "possible" causes or solutions that are unrelated or irrelevant. Not only is this a huge waste of time for both of us, it might also detract from them actually comprehending what I have to say because they are so self absorbed in their "solution". Dangerous users can also be quick to take action when I am giving them instructions, they might perform extra steps that are actually detrimental to the chance of a successful outcome. Dangerous users can also be B's, C's, D's and G's.

G. The illiterate
Illiterates are one of the worst. They seem to lack the ability to read anything, whether it be a pop-up message or written instructions. If a confirmation message window appears, they will click OK without reading. If written instructions are supplied, they will conveniently not notice or claim they did not receive them. As illiterates are quite common, they are often also A's, B's, C's, D's and F's.

Here is a Venn style diagram of how I think the above user groups are structured.


Please let me know if you think there are any user stereotypes that I have missed.

Saturday, June 5, 2010

Balsamiq

My manager showed me this great tool for making UI mockups today.  It's called Balsamiq and is available as both a web and desktop application.


More information on Balsamiq can be found here: http://www.balsamiq.com/products/mockups

Thursday, May 13, 2010

Visual Studio 2010, Crystal Reports, GAC... ARGHH!

I wrestled with this issue along with my workmate for quite a few hours, so hopefully this helps someone out there.

With the recent release of Visual Studio 2010, we took the opportunity to install it at work and migrate our solution across from Visual Studio 2008. We decided to leave Visual Studio 2008 installed as you can have side by side installations of 2008 and 2010. After installation was complete, we managed to get our solution and its projects converted successfully. We thought everything was going well, and it was up till this point...

We then went to build the solution and this was when Visual Studio 2010 started complaining that it could not find the Crystal Report assemblies that our projects reference. There was that big fat ugly exclamation mark in a yellow triangle icon next to each of the Crystal assemblies in the reference list. Visual Studio could not find any of the Crystal Report XI Release 2 assemblies in the GAC, even though they were there.

Perplexed, we searched the internet for a solution but could not find anything documenting our problem. Eventually, we realised that there was an entry in Add/Remove Programs called "Crystal Reports Basic for Visual Studio 2008". This must have been installed with Visual Studio 2008. Upon uninstalling this and reopening our solution in Visual Studio 2010, the Crystal assemblies were all detected in the GAC by the projects.

Monday, June 1, 2009

Google Wave

Google are developing a new communication and collaboration tool that will run through the web browser. I'm keen to try this out and looking forward to its release.

Here is a preview.


http://wave.google.com/