Using ClickOnce deployment over the web to simplify Windows Form Application deployment

11. January 2013 00:45 by Mrojas in   //  Tags: , , , ,   //   Comments (0)

 

Artinsoft\Mobilize.Net helps legacy application to be modernized using the Windows Forms technology. Doing this upgrade revitalizes your application code and allows you to take advantage of the new platforms features like ClickOnce deployment. 

What is ClickOnce deployment?   

 
"ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction. Visual Studio provides full support for publishing and updating applications deployed with ClickOnce technology if you have developed your projects with Visual Basic and Visual C#.

ClickOnce deployment overcomes three major issues in deployment: 

  •          Difficulties in updating applications. With Microsoft Windows Installer deployment, whenever an application is updated, the user can install an update, an msp file, and apply it to the installed product; with ClickOnce deployment, you can provide updates automatically. Only those parts of the application that have changed are downloaded, and then the full, updated application is reinstalled from a new side-by-side folder. 

  •          Impact to the user's computer. With Windows Installer deployment, applications often rely on shared components, with the potential for versioning conflicts; with ClickOnce deployment, each application is self-contained and cannot interfere with other applications. 

  •          Security permissions. Windows Installer deployment requires administrative permissions and allows only limited user installation; ClickOnce deployment enables non-administrative users to install and grants only those Code Access Security permissions necessary for the application. 

In the past, these issues sometimes caused developers to decide to create Web applications instead of Windows-based applications, sacrificing a rich user interface for ease of installation. By using applications deployed using ClickOnce, you can have the best of both technologies."


Click Once Deployment Strategies 

 

There are 3 deployment strategies: 

  • Install from Web or a Network Share 
  • Install from a CD 
  • Start from the Web or Network share 


Quick Overview 


 

For a quick overview of how to use the ClickOnce deployment take a look at Shahar Gvirtz's post http://weblogs.asp.net/shahar/archive/2008/01/29/how-to-use-clickonce-to-deploy-your-applications.aspx

 

How to use Windows Phone 7 with Lync

16. August 2012 10:39 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

It seems ironic but it seems that it is a little more difficult to configure Windows Phone 7 and 7.5 to work with MS Lync that it is to configure an iPhone or an iPad.

 

Well after trying for a while without success, I found this page: http://leonmeijer.nl/archive/2012/01/25/153.aspx

The steps are (and i quote):

 

Steps:

 

I like Windows Phone, I just think their apps need to be more polished.

Speed up changes in Azure Web Roles

4. June 2012 00:37 by Mrojas in   //  Tags: , , , , , , , ,   //   Comments (0)

A common question I get for people that has just moved to Windows Azure Web Roles, is:

 

I just want to make a little change to a page but publishing takes too long, what can i do?

 

Well, there are several things you can do. Usually what I find is that their publishing takes too long because they need to upload a lot of data.. but why? The database is in Azure, so you don't have to upload it, and a asp.net web site is usually just some binaries and some text files?

 

For answering this question I love to use a tool called HDgraph (http://www.hdgraph.com/)

 

 

This tool provides a graphical representation of your hard drive allowing you easily identify which folders are the ones consuming most space.

 

What I usually find is a lot of graphics (jpg, png, gif files), videos (flv, avi), presentations (.pptx) and PDFs files, that are part of the site. No wonder why uploading site changes takes so long.

 

if you do that you are not really taking advantage of all the Azure platform features.

Azure provides a massive storage mechanism and you should take advantage of it.

 

But how do I do that?

 

First Download a tool like Azure Storage Explorer: http://azurestorageexplorer.codeplex.com/

 

 

Create a folder (well well a container)  for example content in Azure and upload your files to that container.

 

And now is time to set your CNAME record to point to your storage. Normally it will be something like making A CNAME content or media point to mycutesite.blob.core.windows.net.

(If you don't remember what a CNAME is lets say is something you configure with your registrar, the people you pay for your domain, so you can make entries to say for example if the browser navigates to www.mycutesite.com then send those requests to mycutesite.cloudapp.net and if they type media.mycutesite.com they it will redirect them to mycutesite.blob.core.windows.net)

 

 

I recommend reading Brandon Werner's excellent for very details quick intro to Windows Azure, from where I took this CNAME entries image.

 http://blogs.msdn.com/b/brandonwerner/archive/2009/11/28/how-to-host-your-site-and-content-on-azure-quickly-and-easily.aspx

 

 

 

Again the idea is that you will remove most of the content of your asp.net solution and change your html so all resources will be downloaded from media.mycutesite.com\content

 

And finally, take advantage of Windows Azure new WebDeploy feature which allows a fast way to modify your pages directly. See (http://blogs.msdn.com/b/cloud/archive/2011/04/19/enabling-web-deploy-for-windows-azure-web-roles-with-visual-studio.aspx)

 

Customizing the Look and Feel or your Windows Forms Applications

27. April 2012 17:05 by Mrojas in   //  Tags: , , , , , ,   //   Comments (0)

Windows forms is still a great technology, but by default is not as flexible as XAML or HTML where you can very easily modify the style of your controls.

But that is not entirely true.

Let's review which options do we have for customizing the look and feel of Windows Forms Applications.

 

Custom Look And Feel

Well the idea is simple. Centralize all the settings for your components and make sure to invoke that logic just after the initializeComponent() method call on the Windows Form constructor.

I will implement a very simple example:

First the class the implements the "theming logic":

using System.Windows.Forms;
using System.Drawing;
public class ApplicationLookAndFeel
{
	static void ApplyTheme(TextBox c)
	{
		c.Font = new Font("Arial",12.0f); c.BackColor=Color.Blue; c.ForeColor = Color.White;
	}
	static void ApplyTheme(Label c)
	{
		c.Font = new Font("Arial", 12.0f); c.BackColor = Color.Black; c.ForeColor = Color.White;
	}
	static void ApplyTheme(Form c)
	{
		c.Font = new Font("Arial", 12.0f); c.BackColor = Color.Black; c.ForeColor = Color.White; 
	}
	
	public static void UseTheme(Form form)
	{
		ApplyTheme(form);
		foreach (var c in form.Controls)
		{
			switch(c.GetType().ToString())
			{
				case "System.Windows.Forms.TextBox":
					ApplyTheme((TextBox)c);
					break;
				case "System.Windows.Forms.Label":
					ApplyTheme((Label)c);
					break;


			}
		}
	}
}
As you see is just very simple code that will just update the settings for all controls, and a simple call in all form constructors and your done:
public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
			ApplicationLookAndFeel.UseTheme(this);
		}
	}
A form like:
 

 

This approach is simple, but could require a lot of work if you have a lot of components, and switching to another look and feel will require a lot of changes, and it does not allow you to customize all of the form.

Customization of non client are (title bar, borders, requires a little more work). You can take a look at Szymon Kobalczyk work in codeplex. There is a lot of information about a setting custom borders for your forms and even a start of a form styling library. 

 

Styling Controls

There are some third-parties that provide some level of Theming/Styling. The main difference is the impact they have on existing applications. I categorize them a Little Changes/Big Changes

 

Little Changes

Visual Styler.NET from http://www.skin-soft.co.uk/

This is an interesting solution, because it allows you to style your Standard Windows Form controls, with very little changes. You just add a control on you main form and that all.  They provide some custom styles and you can built your own. They support styling of ThirdParty Controls but I am not sure how that will work.

 

 

For screen shots and details see: http://www.skin-soft.co.uk/Products/VisualStyler/Overview.aspx

 

More Changes

Telerik Visual Style Builder http://www.telerik.com/products/winforms/visual-style-builder.aspx

 

 

 

DevExpress WinForms Skins http://www.devexpress.com/Products/NET/Controls/WinForms/Skins/

 

 

Infragistics Application Styling http://www.infragistics.com/resources/application-styling.aspx#ApplicationStyling

 

 

I call this "more changes" because all of them are great styling components but in order to style your application you have to use THEIR components. That is change all your TextBox for RadTextBox in the case of Telerik, Button for RadButton, or change your Label for WinLabel and your Button for WinButton for Infragistics and TextEdit for DevExpress...

So it can be a lot of changes. The end result can be stunning, because all of these companies have very very good components, but it is a lot of changes and can affect your application.

 

 But as you can see, Windows Forms still has a lot to offer

Customizing ToolStrip Items

2. April 2012 13:53 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

There are many types of ToolStrip<Control> classes.

But how can you create your own customized version. Let’s say you want a control that prefixes a label before your combo box?
Ok that is very simple, you just extend the ToolStripControlHost class

 

First we create our UserControl:
using System.Windows.Forms;

	public partial class ComboBoxWithLabel : UserControl
	{
		public ComboBoxWithLabel()
		{
			InitializeComponent();
		}

		public string LabelText
		{
			get {return label1.Text;}
			set {label1.Text = value;}
		}

		public ComboBox.ObjectCollection Items
		{
			get
			{
				return comboBox1.Items;
			}
		}
	}

	partial class ComboBoxWithLabel
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Component Designer generated code

		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Dock = System.Windows.Forms.DockStyle.Left;
			this.label1.Location = new System.Drawing.Point(0, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(35, 13);
			this.label1.TabIndex = 0;
			this.label1.Text = "label1";
			// 
			// comboBox1
			// 
			this.comboBox1.Dock = System.Windows.Forms.DockStyle.Right;
			this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.comboBox1.FormattingEnabled = true;
			this.comboBox1.Location = new System.Drawing.Point(35, 0);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(134, 21);
			this.comboBox1.TabIndex = 1;
			// 
			// ComboBoxWithLabel
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.label1);
			this.Name = "ComboBoxWithLabel";
			this.Size = new System.Drawing.Size(169, 22);
			this.ResumeLayout(false);
			this.PerformLayout();

		}

		#endregion

		public System.Windows.Forms.Label label1;
		public System.Windows.Forms.ComboBox comboBox1;
	}
Next we just create an extension of the ToolStripControlHost
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System.Drawing.Design;

[DefaultProperty("Items")]
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.All)]
public class MyCustomComboBoxWithLabel : ToolStripControlHost
{
	public MyCustomComboBoxWithLabel()
		: base(new ComboBoxWithLabel())
	{
	}
	[Browsable(false)]
	public ComboBoxWithLabel ComboBoxWithLabel
	{
		get { return base.Control as ComboBoxWithLabel; }
	}
	

	[Browsable(true)]
	[DefaultValue(false)]
	public string LabelText
	{
		get { return ComboBoxWithLabel.LabelText; }
		set { ComboBoxWithLabel.LabelText = value; }
	}

	[Localizable(true)]
	[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
	[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
	public System.Windows.Forms.ComboBox.ObjectCollection Items
	{
		get { return ComboBoxWithLabel.comboBox1.Items; }
		set {
			foreach (var item in value)
			{
				ComboBoxWithLabel.comboBox1.Items.Add(item);
			}
		}
	}
}
 
And Next ...
Well there is not next. You just used it :) And this is how it looks:

Migrating .NET applications to Windows CE

22. March 2012 12:05 by Mrojas in   //  Tags: , , , ,   //   Comments (0)

If you have a .NET application and then find that you need to move your application or
part of it to a Handheld or mobile device based in Windows CE don't worry.

The .NET has what is called the .NET Compact Framework which is in general
.NET for mobile devices. However review some info before you start your development
because it is not necessary the same. 

 

Differences between .NET Framework and Compact Framework

The CF is great but... it is not the .NET Framework. There

are differences take a look at: http://msdn.microsoft.com/en-us/library/2weec7k5.aspx

 

Controls

For a list of .NET Compact Framework Controls

See: http://en.wikipedia.org/wiki/.NET_Compact_Framework_controls

 

Some nice Third Party .NET Framework Controls are:

  • http://beemobile4.net/products/ipack/controls
  • http://www.resco.net/developer/mobileformstoolkit/overview.aspx

Some useful links:

Need remoting in .NET well you should know that CF does not provide Remoting but there

is company that implements it:

http://gotcf.net/

 

You can also use DCOM

http://www.codeproject.com/Articles/13819/Bringing-DCOM-remoting-functionality-to-Windows-CE

 

And for BlueTooth

There are several aproaches for developing BlueTooth with .NET.

1)  Bluetooth programming with Windows Sockers. 

See: http://msdn2.microsoft.com/en-us/library/aa362928(VS.85).aspx

2)   Windows Embedded Source Tools for Bluetooth.  

See: http://www.microsoft.com/windowsembedded/en-us/develop/windows-embedded-ce-6-bluetooth-technology-source-tools.aspx

3)    3rd party solution, A nice library is:

See: http://inthehand.com/content/32feet.aspx

Windows Services in CE

See this post: http://bansky.net/blog/2008/04/services-for-windows-mobile-in-managed-code/ 

and the library is available here:

http://managedserviceswm.codeplex.com/



 

Problem Adding Service Reference to Windows Phone Application

1. July 2011 13:26 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

There is a little problem with my mango :(
Every time I try to add a reference to a Web Service I end up with an empty Reference.cs.

Sad. The  bug has already being sent to MS see: https://connect.microsoft.com/VisualStudio/feedback/details/624612/add-service-reference-service-proxy-class-gen-tool-bug

The workaround:

Use the SlSvcUtil.exe that can be found at:

C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Tools

Just call it with like:


SlSvcUtil.exe http://localhost:50002/DBServices.svc?wsdl

NOTE: For some reason I have found that the 7.1 version of the tool crashes with a StackOverflow.
If it happens to you just use the 7.0 version

VB6 Windows Service

2. June 2011 04:30 by Mrojas in General  //  Tags: , , , , , , , ,   //   Comments (0)

How do you write a Windows Service in VB6?

Althought this is not a recommend practice due to the stability issues and VB6 support, if for
any reason you need to do this I provide a guide of how to do that in VB6 and how do the same thing
in VB.NET and C#.

Using the NTSVC.ocx

This is an OCX implement by Mauricio Ordonez some time ago.
It is very simple to use. You just drop it on a form and add some code to your VB6.

Example: VB6 Form with the NTSVC.ocx control

Private Sub Form_Load()
Me.Visible = False
    Dim strDisplayName As String

On Error GoTo Err_Load

    strDisplayName = NTService1.DisplayName
   
    If Command = "-install" Then
        ' Enable interaction with desktop.
        NTService1.Interactive = True
       
        If NTService1.Install Then
MsgBox strDisplayName & " installed successfully"
        Else
            MsgBox strDisplayName & " failed to install"
        End If
        End
   
    ElseIf Command = "-uninstall" Then
        If NTService1.Uninstall Then
            MsgBox strDisplayName & " uninstalled successfully"
        Else
            MsgBox strDisplayName & " failed to uninstall"
        End If
        End
   
    ElseIf Command = "-debug" Then
        NTService1.Debug = True
   
    ElseIf Command <> "" Then
        MsgBox "Invalid command option"
        End
   
    End If
   
    ' Connect service to Win32 services controller.
    NTService1.StartService
   
Err_Load:
    ' Error starting service
   
End Sub


Private Sub Timer1_Timer()
MsgBox "hola"
End Sub

 

NOTE: Remember that VB6 is not a supported platform and that even if it is true
that you can still run VB6 code in Windows Vista and Windows 7 MS does not support this
platform anymore.

How can I convert my VB6 service to .NET?

To create a Windows Service in VB.NET follow this steps.

1. First you need to create a Windows Service Project:

a. Open Visual Studio 2010

b. Go to the File\New\Project….

c. Select the Windows Service Template

d. And you just put your code in the OnStart method:

Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        ExecuteWindowsServiceCode()
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

    Private Sub ExecuteWindowsServiceCode()
        'TODO Add Some Code
    End Sub

End Class
 

e. Another typical thing to do in Windows Service is to add a Timer Control, you you can have
your windows service performs some actions every number of seconds. To do that, drag a
Timer Control on your Service component, execute the Start method of the timer control on the OnStart method and
handle the Tick event:

 

 

 

Public Class Service1

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Timer1.Start()
        ExecuteWindowsServiceCode()
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Timer1.Stop()
    End Sub

    Private Sub ExecuteWindowsServiceCode()
        'TODO Add Some Code
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        MsgBox("Viva la vida Loca!")
    End Sub
End Class

If you need to recover some of your code from your VB6 project, download our Visual Basic Conversion Tool VBUC tool.

 

How do I Install my Windows Service?

In general you just need to use the command line utility installutil.exe for more details see this other post.

The Mango is close!!!

24. May 2011 03:04 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

Jejeje. Well if you are a phone developer, either an iOS guy who is thinking on offering
his/her apps in the MS Marketplace or just someone with a great interest in Windows Phone
then you should know what mango is.

Mango is a new update for the Windows Phone, and it will mean a lot for developers,
because if you already liked WP7 you will love MANGO.

 

VIDEO LINK 

 

Mango means HTML5 yes!
Mango means Multitasking!
Mango means Hands-free messaging, did you ever
wanted to send SMS without using your fingers, now you can!

I don’t think is mentioned in this video but Mango is also SQLCE a great alternative
for Android and iPhone developers who were using sqllite.

Convert iOS to Windows Phone 7; SQLite

23. May 2011 05:00 by Mrojas in General  //  Tags: , , , , , , , ,   //   Comments (0)

In iOS SQLite is part of the Core Services and you can easily integrate it in your applications.
Even in Android you have access to this platform.

If you don’t know what SQ Lite this is a quote from www.sqlite.org:

“SQLite is a software library that implements a self-contained, serverless, zero-configuration,transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.“

So what is your equivalent in WP7. Well if you want to wait the Mango Release of Windows Phone 7
will include Sql Server Compact Edition, so that will provide a fairly good and supported platform, but
in the meantime I recommend that you check http://wp7sqlite.codeplex.com/

Windows Azure Connect Endpoint Software versions supported

17. May 2011 08:55 by Mrojas in General  //  Tags: , , , , , , , , , , , , ,   //   Comments (0)

A common doubt when using you want to use Azure Connect is which platforms does it support.
Remember that in order to establish a VPN between your On-Premises computer and a Web/Worker Role
you need to install a client pieces of software.
But which are the supported platforms.
Normally what you can do is just download it and then if you get something like
”Not a valid Win32 application” it means that it is not supported.

From the MSDN site (http://msdn.microsoft.com/en-us/library/gg508836.aspx in the Prerequisites section ) it is stated that:

Windows Azure Connect supported platforms:

Windows 2003 and Windows XP are not supported.

It is supported in Windows Vista, Windows 7, Windows 2008 and Windows 2008 R2

More on iOS / XCode / Objective-C Migration Methods and Multiple Parameters to C#

6. May 2011 03:16 by Mrojas in General  //  Tags: , , , , , , , , , , , , , , ,   //   Comments (0)

On a previous post I was describing how some basic Objective-C elements were mapped to C#.
In particular I showed how the @interface and @implementation definitions are to be mapped in .Net, including basic properties.
In this post I will show a little about how methods are migrated.

There are several things to analyze when moving Objective-C code to C# it might be simple but can be a complicated
task. Objective-C is a language created under the inspiration of SmallTalk. And in Smalltalk programmer do not think of
method calls but instead of message sending and that is something to keep in mind when doing this migration.
Also all methods are virtual and even if there are access restriction in Objective-C I will map those methods to
public for simplicity sake.

In the previous post we had:

FIRSTFIRST

Fraction.h
#import <Foundation/NSObject.h>
@interface Fraction: NSObject {
    int numerator;
    int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(int) numerator;
-(int) denominator;
@end

And

Fraction.m

#import "Fraction.h"
#import <stdio.h>

@implementation Fraction
-(void) print {
    printf( "%i/%i", numerator, denominator );
}

-(void) setNumerator: (int) n {
    numerator = n;
}

-(void) setDenominator: (int) d {
    denominator = d;
}

-(int) denominator {
    return denominator;
}

-(int) numerator {
    return numerator;
}
@end

And that example shows properties and methods with no parameter. OK. Now lets just focus on methods with 0, 1 and more parameters.

MethodsExample.h

#import <Foundation/NSObject.h>
@interface MethodsExample: NSObject {

}
-(void) print;
-(int) multiplyByTwo: (int) n ;
-(void) multiplyTwoNumers: (int) a andSecondNumber: b;
@end
 
MethodsExample.m
#import "MethodsExample.h"
#import <stdio.h>

@implementation MethodsExample
-(void) print {
    printf( "Hola mundo\n" );
}

-(int) multiplyByTwo: (int) n {
    return n * 2;
} -(int) multiplyTwoNumbers: (int) a andSecondNumber (int) b { return a * b;
} @end
And calling those functions will be:
#import <stdio.h>
#import "MethodsExample.h"

int main( int argc, const char *argv[] ) {
    // create a new instance
    MethodsExample *m = [[MethodsExample alloc] init];
    [m print]; 
int result; result = [m multiplyByTwo: 1]; result = [m multiplyTwoNumbers: 1 andSecondNumber: 5]; // free memory [m release]; return 0; }
This little example shows some of the particularities of Objective-C. 
In Objetive-C all parameters starting from the second parameter can have
what is called a label and labels are similar to namedParameter. Ok lets go ahead and map that class.
using System;

public class MethodsExample
{
    public virtual print() {
        Console.WriteLine("Hola mundo\n");
    }
    public virtual int multiplyByTwo(int n)
    {
      return n * 2;
    }
    //AproachOne
    public virtual int multiplyTwoNumber(int a,int andSecondNumber)
    {
        return a * andSecondNumber;
    }
    //AproachTwo
    //I just renamed as multiplyTwoNumber2 to avoid compilation errors.
    //The idea is that you will choose one of the two aproaches
    //or define a criteria for the instances where aproach one should be used
    //instead of approach two
    public virtual int multiplyTwoNumber(int a,int andSecondNumber)
    {
        int n = andSecondNumber;
        //This aproach will be better if you have a lot of code in the method
        //and you prefer to keep the original arg name
        return a * n;
    }

}
So the thing here is what to use as the parameter name, the label or the argument name. 
In the example you can see the two approaches in the multiplyTwoNumbers case.
 And calling the methods is simple and the named parameters syntax can be exploited.
using System;

public static class Program
{
    public static int Main(string[] argv ) {
        // create a new instance
        var m = new MethodsExample();
        m.print();
        int result;
        result = m.multiplyByTwo(1);
        result = m.multiplyTwoNumbers(1,andSecondNumber: 5); //using named parameters
        // free memory
        m.release();
        return 0;
    }
}
REMEMBER: This is just a glimpse of some mapping concepts from Objective-C to C#. 
There are many subtle details in this kind of migration and is my belief that only
an automated tool is able to process all those details in an effectively and more error-free
than a manual approach. For example in objective-c if m is null that will not cause any error if you
do something like [m print] and in C# that will throw an error. However a migration tool could determine
if the variable will have a value before its use and avoid adding unnecessary if (m!=null) statements.
We will examine this and other details in following posts. I hope this little examples give you enough information

for playing around migrating some Objective-C code. And if it gets too complicated just send me an email!!!

Windows Azure Migration: Database Migration, Post 1

2. April 2011 18:14 by Mrojas in   //  Tags: , , , , , , , , , ,   //   Comments (0)

WheWhen you are doing an azure migration, one of the first thing you must do is
collect all the information you can about your database.
Also at some point in your migration process you might consider between migration to
SQL Azure or Azure Storage or Azure Tables.

Do do all the appropriate decisions you need to collect at least basic data like:

  • Database Size
  • Table Size
  • Row Size
  • User Defined Types or any other code that depends on the CLR
  • Extended Properties

Database Size

You can use a script like this to collect some general information:

create table #spaceused(
databasename varchar(255),
size varchar(255),
owner varchar(255),
dbid int,
created varchar(255),
status varchar(255),
level int)

insert #spaceused (databasename , size,owner,dbid,created,status, level)  exec sp_helpdb

select * from #spaceused for xml raw
drop table  #spaceused
 

When you run this script you will get an XML like:

<row databasename="master" 
size=" 33.69 MB" 
owner="sa" 
dbid="1" 
created="Apr 8 2003" 
status="Status=ONLINE, ..." 
level="90"/>
<row databasename="msdb" 
size=" 50.50 MB" 
owner="sa" 
dbid="4" 
created="Oct 14 2005" 
status="Status=ONLINE, ..." 
level="90"/>
<row databasename="mycooldb" 
size=" 180.94 MB" 
owner="sa" 
dbid="89" 
created="Apr 22 2010" 
status="Status=ONLINE, ..." 
level="90"/>
<row databasename="cooldb" 
size=" 10.49 MB" 
owner="sa" 
dbid="53" 
created="Jul 22 2010" 
status="Status=ONLINE, ..." 
level="90"/>
<row databasename="tempdb" 
size=" 398.44 MB" 
owner="sa" dbid="2" 
created="Feb 16 2011" 
status="Status=ONLINE, ..." 
level="90"/>

And yes I know there are several other scripts that can give you more detailed information about your database
but this one answers simple questions like

Does my database fits in SQL Azure?
Which is an appropriate SQL Azure DB Size?

Also remember that SQL Azure is based on SQL Server 2008 (level 100).

80 = SQL Server 2000

90 = SQL Server 2005

100 = SQL Server 2008


If you are migrating from an older database (level 80 or 90) it might be necessary to upgrade first.

This post might be helpful: http://blog.scalabilityexperts.com/2008/01/28/upgrade-sql-server-2000-to-2005-or-2008/

Table Size

Table size is also important.There great script for that:

http://vyaskn.tripod.com/sp_show_biggest_tables.htm

If you plan to migrate to Azure Storage there are certain constraints. For example consider looking at the number of columns:

You can use these scripts: http://www.novicksoftware.com/udfofweek/vol2/t-sql-udf-vol-2-num-27-udf_tbl_colcounttab.htm (I just had to change the alter for create)

Row Size

I found this on a forum (thanks to Lee Dice and Michael Lee)

DECLARE @sql        VARCHAR (8000)
        , @tablename  VARCHAR (255)
        , @delim      VARCHAR (3)
        , @q          CHAR (1)

  SELECT @tablename = '{table name}'
       , @q         = CHAR (39)

  SELECT @delim = ''
       , @sql   = 'SELECT '

  SELECT @sql   = @sql
                + @delim
                + 'ISNULL(DATALENGTH ([' + name + ']),0)'
       , @delim = ' + '
  FROM   syscolumns
  WHERE  id = OBJECT_ID (@tablename)
  ORDER BY colid

  SELECT @sql = @sql + ' rowlength'
              + ' FROM [' + @tablename + ']'
       , @sql =  'SELECT MAX (rowlength)'
              + ' FROM (' + @sql + ') rowlengths'
  PRINT @sql
  EXEC (@sql)

Remember to change the {table name} for the name of the table you need

User Defined Types or any other code that depends on the CLR

Just look at your db scripts at determine if there are any CREATE TYPE statements with the assembly keyword.
Also determine if CLR is enabled with a query like:

select * from sys.configurations where name = 'clr enabled'

If this query has a column value = 1 then it is enabled.

Extended Properties

Look for calls to sp_addextendedproperty dropextendedproperty OBJECTPROPERTY and sys.extended_properties  in your scripts.

Doing Backups in Windows Azure

17. March 2011 03:47 by Mrojas in   //  Tags: , , ,   //   Comments (0)

When we migrate our customers to Azure, we want them to take advantage of
this rich platform.

Even for a simple deployment you get a Windows Azure Storage Account,
and that account means up to 100TB of storage!!!!! So take advantage of that.

One common thing that any enterprise needs is backups.
You need to backups of you email files, databases, documents, etc.

Sometimes you can have a dedicated server for storing that data, but
all hard drives can fail, so you will need to make several copies of your
backup information, probably use a RAID disk, make backups of your backups
on tape, DVD, etc…

What if you could just use your cloud storage, which is triplicated in secure datacenters?

Well you can!

There are currently several solutions.

For example in codeplex you will find projects like: http://myazurebackup.codeplex.com

MyAzureBackup provides simple to use web user interface.
I have even extended some of its functionality to work with a Windows Service that uses
a FileWatcher to upload files from a directory.
And it is easy to use this application as a base for your backup infrastructure adding some
security functionality like encrypting files.

So go ahead and explore all the new posibilities you have with cloud computing

Tracking Bugs in Windows 7

11. March 2011 04:05 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

Is very common that a user calls you to report a bug,
but it takes you a long time to understand what really happened.

Well Windows 7 has a great tool call the Problem Step Recorder.

This post will provide a good intro using this tool: http://www.blog.jbi.in/tipsntricks/how-to-use-problem-steps-recorder-in-windows-7/

 

 

Azure Migration: ASP.NET Site with Classic Pipeline mode

Recently while we were performing the migration of a blog engine in ASP.NET to Azure we had to deal with some issues with
the differences between IIS6 and IIS7.

Windows Azure Web Roles, use IIS7, with Integrated Pipeline mode and that is a breaking change for some ASP.NET sites.

The are at least two main changes:

 

First  is for HTTP modules and handlers.(This info was taken from: http://arcware.net/use-a-single-web-config-for-iis6-and-iis7/)

" For IIS6, they were configured in the <system.web> section, as such:

 

        <httpModules>
            <add name="..." type="..." />
            <add name="..." type="..." />
            <add name="..." type="..." />
        </httpModules>

        <httpHandlers>
                 <add  verb="..." path="..." type="..." />
                 <add  verb="..." path="..." type="..." />
        </httpHandlers>

However, to get these to work in IIS7 you must *move them* from the <system.web> section to the new <system.webServer> section, which is what IIS7 requires when running in Integrated Pipeline mode (it’s not needed for Classic Pipeline mode)

 

So instead of the above you have this instead:

<system.webServer>
    </modules>
        <add name="..." type="..." />
    </modules>
    <handlers accessPolicy="Read, Write, Script, Execute">
        <add verb="...." name="..." path="..." type="..." />

</handlers>
</system.webServer>

Notice there are a couple slight changes, which means you can;t just copy and paste
these as-is from <system.web> into <system.webServer>:

<httpModules> and <httpHandlers> have been renamed to <modules> and <handlers>, respectively.

Each handler in IIS7 requires a name attribute. If you don;t specify it, you'll get an error message.

The handlers node has an optional, but good-to-define accessPolicy attribute.
This value depends on your handlers, so use the ones that are right for you."

Second
There are some restrictions in IIS7 when you are running in Integrated mode.
For example you cannot do calls to the request property of an HttpContext object.
All calls to HttpContext.Current.Request will have a problem because Request will be null.

You can see more details here:

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

 

Coldfusion cfdocument bug with images and Windows Authentication

4. March 2011 16:52 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

If you are running your Coldfusion Server with IIS7 and you use Windows Authentication you should be aware that you might
encouter a bug if you try to use a cfdocument tag like:

 <cfdocument format="pdf">

Hello World <img src="images/world.png">

</cfdocument>

The problem here is that Coldfusion will use http to get the image when building the PDF, and because this site uses Windows Authentication it crashes.

How to solve it?

 <cfdocument format="pdf" localUrl="true">

Hello World <img src="images/world.png">

</cfdocument>

This solves this bug and also improves perfomance because CF will convert images/world.png to a physical path like file://E:/images/world.png

Running Coldfusion on a Web Server Role

4. March 2011 15:43 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

I have been playing around with one of my test Azure Web Roles to determine
if it is possible to run it inside Azure, using a Web Role not just a VM Role.

So far I have been able to run Coldfusion 8 in a Web Role, but I have not been able to fully automate this task,
I had to do a remote desktop to the Web Role and perform the following tasks:

  • Add Features to the Web Roles particulary II6 Management Compatibility
  • Make sure that the Handlers for CFM, CFML, CFC are inplace

IIS Handler CF

  • And make sure that the ISAPI is ok:
  • Once all that is set you can run Coldfusion 8 in your Web Role. Now we just need to automate all the CF8 installation in a Web Role,
    but that will be something another post

 

Problems installing the Windows Phone 7 Tools

1. March 2011 04:18 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

If you are getting ready to migrate your applications to Windows Phone,
you have to install all the neccesary Windows Phone Stuff.

However you might have incompatibilities in your dev machine.

This post: http://blogs.msdn.com/b/astebner/archive/2010/07/12/10037442.aspx

Is great. I used it to identity why the installation tool insisted that
I had a Windows Phone Emulator installed in my machine. It seems that it looked for something like XDE.

So if you have this same issue or something similar just take a look at that post, it might be of great help

Get Exact Text Width C#

15. December 2009 08:13 by Mrojas in   //  Tags: , , , , , , , , ,   //   Comments (0)

 I was recently trying to get the exact width of a string. And I found that the Graphics.MeasureString does not give an exact result.

I finally found Pierre Arnaud

post in Code Project, which gave me a good explaination and solution of what was happening.

You can see in the image Pierre put in his post:

 That Graphics.measurestring will return a size that might be bigger that the actual drawn size, this is due some GDI+ details that he explains in that post.

I really like the second proposed solution:

static public int MeasureDisplayStringWidth(Graphics graphics, string text,Font font)
{
    System.Drawing.StringFormat format  = new System.Drawing.StringFormat ();
    System.Drawing.RectangleF   rect    = new System.Drawing.RectangleF(0, 0,1000, 1000);
    System.Drawing.CharacterRange[] ranges  = { new System.Drawing.CharacterRange(0, text.Length) };
    System.Drawing.Region[]         regions = new System.Drawing.Region[1];

    format.SetMeasurableCharacterRanges (ranges);
    regions = graphics.MeasureCharacterRanges (text, font, rect, format);
    rect    = regions[0].GetBounds (graphics);

    return (int)(rect.Right + 1.0f);
}

 

 

Categories