Skip to main content

Posts

Design Patterns - Visitor Pattern

The Visitor Pattern is a solution for a problem where you have many Objects, each Object is similar but you wish to extract information (such as a print statement) on each Object in a different way. E.g. You have a collection of Objects, each of your objects has different member variables and you want some way to call print this info. One way to do it would be to cycle through each object and Call some common method on each such as Print(), this ties the Object tightly to the printing or whatever you are doing, we want to loosly couple the printing or whatever to the object itself, to unbind the Printing from the actual Object we introduce 2 interfaces. The Visitor and the Visitable. The Visitor interface has a Visit(object) method (this is what would print the details). The Visitable interface has an Accept method, this takes the Visiting object as a parameter. The Object we want to print implements the Visitable interface, this has a callback to the implementor of the Visitor Interfa...

Installer (MSI) - Windows Installer general information

Aaron Stebner's Blog Common problems I've found while playing around with the creation of Windows installers is that if you break the uninstaller functionality it's very difficult to uninstall at all. There are a couple of ways to attempt to repair, this 1. Force overwrite of the installer with a known good installer and then uninstall. msiexec.exe /fvecmus 2. Repair the installer with a known good installer (Control Panel->Add/Remove Programs, locate you Applications installer and select "Click here for support Information", then select Repair from the resultant dialog, now point to a new location of a good installer) Then Remove. 3. Use a tool name MsiZip.exe, it's available with the MS Windows SDK , it cleans up the registry (the SDK installation takes quite a while). 4. A Windows Installer Cleanup Utility . The windows installer keeps a list in the OS of files installed by the installer, if you cannot uninstall because windows thinks one of these files ...

BootStrapper BootStrapping

Bootstrapping is the creation of a wrapper installer around already existing installars or files. It's useful if you have multiple installation files that you'll like the user to install in on step. The Bootstrapper itself is a .exe installer file, it also may have .SED file which contains details of the contents of the .exe. There are a few applications out there to generate a bootstrapper, the most simple I've seen is the an app called IEXpress . IExpress Is actually installed on windows (System32/iexpress.exe). This creates an installer, you tell it what files you wish it to include in the installation. I've only played with this so far and it appears to me that the isntaller can only install upto 2 setup.exes. You can include as many files as you like, but the files cannot have the same name, because of this you will probably need to rename your setup.exes to something else because you cannot have 2 files with the same name. After you've included all the files...

dotNET Custom Attributes

Attributes those snippets of code you see in .NET classes in square brackets at the top of Class or Method, one of the most common examples is [WebMethod] to indicate that the current method is a WebMethod . The Attribute is in fact a class that inherits from System.Attribute . The Attribute is read in at Runtime, Reflection takes care of this. Attributes are useful for flagging types, conditions when and when not to use certain methods like the WebMethod.

WiX - Windows Installer XML

Latest Release ('Rosario' November CTP msdn) now has Visual Studio Integration. WiX Tutorial (tramontana). WiX documentation (sourceforge). WiX and Visual Studio (msdn forum). WiX integration in Visual Studio using Votive (Votive blog). WiX integration (msdn). WiX Forum. Building setup packages for Visual Studio project templates and starter kits ( Aaron Stebner's WebBlog) WiX Tallow tool WiX is a methodology to write installers. WiX has a compiler/linker (candle/light) which may give the installer writer some validation before deployment. The contents of the end installer (.msi) are edited using an XML file. I haven't found WiX to be advantageous over the ordinary Visual Studio Setup Project. Visual Studios SDK has a project template (from Votive) for creating WiX installers. This project template gives you the skeletol wix file to start and the build commands are built into the project, all you've to do is create new GUIDs ,these guids are only for the installer,...

Visual Studio Extensibility

http://feeds.delicious.com/rss/learnerplates/extensibility Extending the Visual Studio IDE means adding custom functionality to the IDE, this could be custom TextEditors, Add Ins to the Tools menu, Writing to the Output Console, basically anything that will require you to add or write to any component in the Visual Studio IDE. Extending the Visual Studio IDE is not for the faint hearted. It is implemented with a Visual Studio Extensibility SDK downloadable from link 1 below. It's implemented using COM interfaces (not very nice). There are 5 points of contact for Extensibility issues 1. MSDN Visual Studio SDK homepage. 2. MSDN documentation. 3. MSDN Extensibility Forum . 4. Dr. Ex's Weblog . 5. MZ-Tools. There are also webcasts available from msdn . I recommend watching some of the webcasts especially the Managed Package Framework as the explain briefly how some of the Class Attributes work with RegPkg.exe and how important the GUIDs are. GUIDs The GUIDs are static and each con...

ASP.NET, terms, filetypes, examples

http://feeds.delicious.com/rss/learnerplates/httpmodule http://feeds.delicious.com/rss/learnerplates/httphandler ASP.NET is the .NET version of ASP, this new version adds more functionality. ASP and ASP.NET are web development frameworks which allow you the developer to access and manipulate HTML before Posting it up to the client. Both frameworks allow you to access HTML controls (e.g. TextField) using the directive "script runat="server"" . This gives you a reference to the HTML control, that the user sees in their browser, from the server side. You also have control over the Http Requests and Responses, allowing you to analyze responses sent back, errors and cookies etc can be transmitted over HTTP. ASP was lacking in that you could not separate the scripting logic from the HTML front end of the file. ASP.NET allows you to move your logic (written in any .NET language) to a separate file, this is referred to as CodeBehind. The codebehind can be accessed in the as...

dotNET - Lists comparisons and Predicates

Here's something I've found very useful but at first found very difficult to understand. When trying to find certain contents of a list you have a few options open to you. The first is to enumerate through the list and do a comparison of each value in the list, this is the old way to do things: foreach (string sf in sourceFiles) { if (sf.Contains("DBAccess.js")) containsDBAccess = true; } .NET has provided a better implementation using Predicates. Predicates are implemented with delegates. You implement your Predicate with with a Function which takes a single parameter, a string, and returns bool. e.g. private static bool FindDBAccess(string s) { return s.Contains("DBAccess.js"); } and use this in the List.Find like so if (sourceFiles.Find(FindDBAccess) == null) {........ } The string 's' passed as a para...

dotNET - CLR Profiling and memory management

The .NET CLR manages the memory allocated by .NET managed applications. The CLR implements Garbage Collection. This GC can run into problems and may not run as well as it should if you implement your applications in certain ways. GC problems may manifest themselves as a slowdown in the application, this maybe due to the GC spending time trying to manage memory which is fragmented, in very large segments or objects with many references. The CLR manages the memory by using a pointer to the memory addresses, these pointers must do alot of work particularly if an object has many references, each reference requires a pointer. You can invoke the GC with the System.GC class. GC.collect(). There are some tools and code classes available to monitor memory. One of these is a class called Perfmon (performance monitor), to use this you add a Perfmon instance in your class, this instance gets incremented each time the GC gets used on that object. You may then query the Perfmon object to find which ...

dotNET - Protect IP, Obfuscation (Obfuscate)

Obfuscation is a methodology to make it more difficult to reverse-engineer your assemblies. It's achieved by scrambling and removing some of the contents of the assembly. Scrambling maybe just renaming of methods (it does not rename methods which are public to other assemblies outside). It may also remove unnecessary Metadata such as Property descriptors. There are various levels of Obfuscation and these can all be set in the Obfuscation application of your choice. Obfuscated assemblies maybe accompanied by a Map file, a kind of settings file for the Obfuscation application.This map file may contain the renaming pattern you have used and is input to the Obfuscator application, it is useful if you wish to patch a system with say one assembly, and you want your new assembly to be obfuscated in the same way as the application. Under Construction Thwart Reverse Engineering of Your Visual Basic .NET or C# Code

dotNET - Debugging

Debugging with .NET MSIL assemblies Visual Studio and debugging the CLR are different, I'll talk about both. MSIL Assemblies Assemblies compiled with .NET tools such as the CLR compiler are compiled into a file which contains MSIL (Microsoft Intermediate Language). At runtime the contents of the assembly are loaded into the CLR and ran as machine code. When you compile an assembly in debug a PDB file is generated alongside the DLL or EXE you've just created. The link between these 2 files is that the PDB contains the line numbers of the methods and classes as well as the file names of the original source code that created the assembly. When you launch the debugger in Visual Studio the assembly is loaded into the Debugger (similar to the CLR) along with the PDB file. The debugger now uses your PDB file contents to match the running code found in the assembly to locations in source files (hopefully in your present project). CLR CLR Inside Out (msdn magazine) .NET Framework Tools:...

dotNET - Use app.config ApplicationSettings and UserSettings

When using Settings in an Assembly or .exe you can use the Settings Designer to generate a config file using Settings. The Settings Designer provides a wrapper class which allows you to provide defaults and access the config data using Properties. But what if you're not working inside that Assembly or .exe? this presents a problem. If your loading the Assembly externally and want to access that Assembly's .config file you'll probably wish to use something in the System.Configuration namespace... unfortunately it's not of much use if you've created the .config file from the Settings Designer in Visual Studio!! This is because the Designer creates Sections and ApplicationSettings and UserSettings, the System.Configuration namespace does not provide a method to access these (it has a method to access AppSettings which are a different thing. Below I've written a workaround which locates the app.config and accesses the ApplicationSettings and UserSettings using XML i...

Windows Miscellaneous

Virtual PC Creating a Virtual PC using another machines Virtual Hard Disk Make a copy of the other machines .vhd file. Copy to the local machine and point the new Virtual PC to the .vhd. SID will have to be run on the new Virtual PC in order to change the name of the machine, as it will still have the name of the original machine the vhd was taken from. http://www.microsoft.com/technet/sysinternals/Security/NewSid.mspx HTML DOM Inspector http://www.sharewareconnection.com/download-ie-dom-inspector-from-sharecon.html

dotNET - VS 2005 Web Deployment Projects + Installer (MSI) creation

You've got your Web Project in Visual Studio and you want to create a way to provide it as an installation. There are 2 ways to do this: 1. Create a Web Deployment Project from your Web Project and then use the output of this as the input to another project, a Setup Project. After you've achieved this you'll have an MSI installer file which has configurable elements, these configurable elements will be dictated by yourself when creating the Web Deployment Project and the Setup Project. 2. Create a WebSetup project from your Web Project. After you've achieved this you'll have an MSI installer file. Option 2 is the simpler option. The difference between the 2 options is that the first provides extra control using the Deployment project, such things a MSBuild and assembly type deployment. If you choose option 1 then: You can quickly create a Web Deployment Project by right-clicking the Web Project in the Visual Studio Solution Explorer. This will copy the contents of y...

IIS admininstration Miscellaneous

http://feeds.delicious.com/rss/learnerplates/iis How to access the IIS Metadase programmatically. Parser for IIS logs A script to extract data from log files (can be IIS log files) using SQL Query format. http://www.microsoft.com/technet/community/columns/profwin/pw0505.mspx The script can be downloaded at http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en

Cookies and FormsAuthentication

Cookies Cookies are simply a file stored in the client machine which are sent up and down to and from the server with every Request and Response. The Cookie is used to store some client information such as details of their past session. It allows the Client to return to a webpage and have information already available to them without having to start from scratch. The Cookie is first sent down from the Server and is stored somewhere on the Client's hard-drive. It's up to the Web Application developer to do the Cookie processing on the Server side. The Cookie can be accessed from the Request as the Cookie is a property of the HttpRequest, Request.Cookie["cookiename"]; One problem I've encountered with Cookies is that all the cookies associated with your application get Posted from the Client on each Request, this adds to the amount of data sent as you can imagine. There is a solution however, in order to ensure a Cookie is only sent from Client to Server when a cert...

Setup Programs Installer creation using VS2005

Setup Programs Installer creation using VS2005 Getting Started with Setup Projects (SimpleTalk). Visual Studio Setup Projects and Custom Actions (Simple Talk). Updates to Setup Projects (SimpleTalk). To create an Installer using Visual Studio you must create a Setup Project. A setup project contents are files and outputs of other projects in the solution. The Setup Project template can be found in the Visual Studio New Project dialog under Other Projects->Setup and Deployment->Setup Project. Tip! To debug installation or just see what's happening in the background and view system variable values use the msiexec logger, it logs everything that's happening on installation, it can also be used for uninstall install: msiexec /i yourinstaller .msi /l* yourinstaller .log or verbose msiexec /i yourinstaller .msi /l*v yourinstaller .log uninstall: msiexec /uninstall yourinstaller .msi /l* yourinstaller .log or verbose msiexec /uninstall yourinstaller .msi /l*v yourinstaller .lo...