Sunday, April 29, 2012

How to disable Yes/No security message of visual studio 2010?

I was not sure about what the heading will be so just put down a rubbish title, if you still not sure about what is going on header the bellow bold paragraphs,

“The current project settings specify that the project will be debugged with specific security permissions.  In this mode, command line arguments will not be passed to the executable.  Do you want to continue debugging anyway?”

Still not sure, ever seen a message like bellow?

image

Ah whey the hell you saw a message like this? simple you have put something in the command line argument, And where its been added, its added on the project properties.

image

Now then, how to get rid of that, the solution is also simple, you got to disable the click once security, how a screen shot is given bellow for your help. If the Check box is enabled by default, just disable it, you wont see that message again.

image 

Note & Disclaimer: I have no idea what will happen after that, I have tested works fine, but in deployment you may see some problem.

Until next time.

Thursday, April 26, 2012

How to make any object selectable in User interface so that it can be bind to Treeview, checkbox list or radio button list?

Today I am going to share a simple trick to make any object selectable in User interface so that it can be bind to Treeview, checkbox list or radio button list. The trick is simple, we have to warp the user custom class with another class named “SelectableData”.

Bellow the code segment is given

public class SelectableData<T>:ANotifyPropertyChanged
{
public SelectableData()
{
_isEnabled = true;
}

private bool _isSelected;
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
OnPropertyChanged("IsSelected");
}
}

private T _data;
protected bool _isEnabled;

public T Data
{
get { return _data; }
set
{
_data = value;
OnPropertyChanged("Data");
}
}

public bool IsEnabled
{
get { return _isEnabled; }
set
{
_isEnabled = value;
OnPropertyChanged("IsEnabled");
}
}
}


Bellow the uses is given.


private void GenerateSelectableOption(string[] selectedOptions)
{
string[] options = new string[] {"Data", "Data1"};

var selectableOptions = new List<SelectableData<string>>();
foreach (var option in options)
{
selectableOptions.Add(new SelectableData<string>
{
Data = option,
IsSelected = selectedOptions.Any(o => o.Equals(option))
});
}

SelectableOptions = selectableOptions;
}

public List<SelectableData<string>> SelectableOptions
{
get { return (List<SelectableData<string>>)GetValue(SelectableOptionsProperty); }
set { SetValue(SelectableOptionsProperty, value); }
}

public static readonly DependencyProperty SelectableOptionsProperty =
DependencyProperty.Register("SelectableOptions", typeof(List<SelectableData<string>>),
typeof(OptionsEditorPresenter), new UIPropertyMetadata(null));


And the Xaml Binding Code is given bellow


<UserControl x:Class="OptionsEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="300" Height="200">
<UserControl.Resources>
<DataTemplate x:Key="OptionsCheckboxTemplate" >
<CheckBox Content="{Binding Data}" IsChecked="{Binding IsSelected}" Margin="0 0 5 0"/>
</DataTemplate>
<DataTemplate x:Key="OptionsRadioButtonTemplate" >
<RadioButton GroupName="options" Content="{Binding Data}" IsChecked="{Binding IsSelected}" Margin="0 0 5 0"/>
</DataTemplate>
<Style x:Key="ItemControlStyle" TargetType="{x:Type ItemsControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Multiselect}" Value="False">
<Setter Property="ItemTemplate" Value="{StaticResource OptionsRadioButtonTemplate}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Multiselect}" Value="True">
<Setter Property="ItemTemplate" Value="{StaticResource OptionsCheckboxTemplate}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding SelectableOptions}" Style="{StaticResource ItemControlStyle}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</UserControl>


Hope this helps, until next time.

Sunday, April 22, 2012

How to disable Attach Security Warning! in Visual Studio 2010?

The problem of security warning

Its been bugging be for quite a while, and still bugging me when I pair with other developers so finally decided to put few notes on this Tips.

Here is what it looks like, it happens in most of the cases when you have WCF Service running and your application use that WCF service which require elevated privilege.

I am sure you have seen the bellow screen shot.

Security Warnning 2

Fix of security warning

The fix is simple, you got to change a registry value.

Security Warnning

The target registry path is located under Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudo\10.0\Dubugger and the key is “DisableAttachSecurityWarning” the default value is “0” and we have to set its value to “1” to get rid of the security warning.

Note that you have to close visual studio before making the change, other wise the value will not get set.

Friday, April 13, 2012

Use Debug Mode's Wink to create simple interactive tutorial or cast.

The primary intention is to create tutorial, if you have ever used Camtasia you can not be satisfied with this small software, but if you think about money you would certainly get convinced about it, because it free!.

And the beauty is you can create interactive tutorial where user will interact with the presentation.

Bellow the official statement is given.

“Wink is a Tutorial and Presentation creation software, primarily aimed at creating tutorials on how to use software (like a tutor for MS-Word/Excel etc). Using Wink you can capture screenshots, add explanations boxes, buttons, titles etc and generate a highly effective tutorial for your users.”

image

Bellow the feature’s are given

  • Freeware: Distributed as freeware for business or personal use. However if you want to redistribute Wink, you need to get permission from the author.
  • Cross-Platform: Available for all flavours of Windows and various versions of Linux (x86 only).
  • Audio: Record voice as you create the tutorial for explaining better.
  • Input formats: Capture screenshots from your PC, or use images in BMP/JPG/PNG/TIFF/GIF formats.
  • Output formats: Macromedia Flash, Standalone EXE, PDF, PostScript, HTML or any of the above image formats. Use Flash/html for the web, EXE for distributing to PC users and PDF for printable manuals.
  • Multilingual support: Works in English, French, German, Italian, Danish, Spanish, Serbian, Japanese, Brazilian Portuguese and Simplified/Traditional Chinese.
  • Smart Capture Tools: Capture screenshots automatically as you use your PC, based on mouse and keyboard input (great time saver and generates professional captures).
  • Performance/Quality: Creates highly compressed Flash presentations (few kbs to few hundreds of kbs, much smaller than competing commercial products) ideal for using on the web.

After install you have simple tutorial which is made with wink and really helpful to get started with the tool.

image

I would use it and suggest everyone to give a try.

Friday, April 6, 2012

“Long method” is one of the most common code smell!

You wont find a single project where long method code smell is not present. I find often this code smell often in my projects, and developers do not deliberately introduce long methods, it just got introduced along the way when we introduce features.

What happen when you find a long method?

  • You wonder why is this method is so long.
  • You try to understand what the code is doing.
  • You start hate the software because its full of lines after line but no end of the method.
  • You lost the track where you ware before.
  • And so on.

You can list hundreds of line like the above listing about long method, the story will go on and on. here is what “Wikipedia” has to say about the long method,

Long method: a method, function, or procedure that has grown too large.”

Bellow an example of a long method is given

void SolutionLinkBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
var pageName = e.Url.ToString().Split('/').LastOrDefault();
if (IsLinkToTmeTool(pageName))
{
if (pageName != null)
{
var toolName = Regex.Replace(pageName, TMEToolPrefixPattern, "", RegexOptions.IgnoreCase);
e.Cancel = true;
if (PackageLoader.Instance.IsToolAvaiableForCurrentUser(toolName))
{
ToolManager.Value.ActivateToolCommand.Execute(toolName);
}
else
{
new Lazy<IMessageBoxPresenter>().Value.Show(
StringTable.ToolNotAvailableErrorMessageText, StringTable.ToolNotAvailableErrorMessageTitle, DialogButton.OK);
return;
}
}
}
else
{
var queryString = e.Url.Query;
const string pattern = @"^\?.*POwner=(?<Owner>[^&]+)";
var match = Regex.Match(queryString, pattern, RegexOptions.IgnoreCase);
if (match.Success)
{
var ownerPackageId = match.Groups["Owner"].Value;
var allowedPackageIds = PackageLoader.Instance.GetAllowedPackageIds().ToList();
if (allowedPackageIds.Contains(ownerPackageId) == false)
{
e.Cancel = true;
new Lazy<IMessageBoxPresenter>().Value.Show( StringTable.PageNotAvailableErrorMessageText, StringTable.PageNotAvailableErrorMessageTitle, DialogButton.OK);
return;
}
}
}
}



Bellow a edited version of the code is given. where the code is refactored with extract method and looks more understandable, even though you can refactor the code to a much simpler version, but this is given there as an example.


void SolutionLinkBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
var pageName = e.Url.ToString().Split('/').LastOrDefault();
if (IsLinkToTmeTool(pageName))
LoadLinkedTool(e, pageName);
else
HandleOtherLink(e);
}

private static void HandleOtherLink(WebBrowserNavigatingEventArgs e)
{
var queryString = e.Url.Query;
const string pattern = @"^\?.*POwner=(?<Owner>[^&]+)";
var match = Regex.Match(queryString, pattern, RegexOptions.IgnoreCase);
if (match.Success == false)
return;
var ownerPackageId = match.Groups["Owner"].Value;
var allowedPackageIds = PackageLoader.Instance.GetAllowedPackageIds().ToList();
if (allowedPackageIds.Contains(ownerPackageId) == false)
{
e.Cancel = true;
DisplayMessage(StringTable.PageNotAvailableErrorMessageText, StringTable.PageNotAvailableErrorMessageTitle);
}
}

private static void DisplayMessage(string message, string title)
{
var messageBoxPresenter = new Lazy<IMessageBoxPresenter>();
messageBoxPresenter.Value.Show(message,title, DialogButton.OK);
}

private void LoadLinkedTool(WebBrowserNavigatingEventArgs e, string pageName)
{
if (pageName != null)
{
var toolName = Regex.Replace(pageName, TMEToolPrefixPattern, "", RegexOptions.IgnoreCase);
e.Cancel = true;
if (PackageLoader.Instance.IsToolAvaiableForCurrentUser(toolName))
ToolManager.Value.ActivateToolCommand.Execute(toolName);
else
DisplayMessage(StringTable.ToolNotAvailableErrorMessageText,StringTable.ToolNotAvailableErrorMessageTitle);
}
}


There are lot of refactoring tips and techniques to handle long method, and this is just the tip of the iceberg, this is just an example you can do many things and there are huge possibilities. Until next time me Md. Masudur Rahman Signning out.