Friday, December 6, 2013

Boolean dependency property and its default value.

What’s up community, today I going to share a very basic trick that I learned while working on a wizard control. I would rather say that is a convention that i didn’t know previously. probably all the the WPF developer knows it, but just in case anyone needed it and wondering why its not working.

Enough talk, lets get in to the business, so i was developing a custom control, precisely a reusable wpf wizard control. And I introduced a dependency property for two mode of the UI here is how it looks.

public bool ShouldIgnoreStep
{
get { return (bool)GetValue(ShouldIgnoreStepProperty); }
set { SetValue(ShouldIgnoreStepProperty, value); }
}

public static readonly DependencyProperty ShouldIgnoreStepProperty =
DependencyProperty.Register(
"ShouldIgnoreStep", typeof(bool), typeof(RiteqWizardPage),
new PropertyMetadata(false, OnPropertyChanged));

private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RiteqWizardPage riteqWizardPage
= d as RiteqWizardPage;
if (e.Property.Name.Equals("ShouldIgnoreStep"))
{
if (e.NewValue != e.OldValue)
{
if (riteqWizardPage != null)
{
riteqWizardPage.OnShouldIgnoreStepChanged();
}
}
}
}


I started to use the property and set the properties value in codes. The first one that i used in the same container worked okay. But the subsequent controls in the same container was not getting property set as I have dependent code when the dependency property is changed I wish to do some work. But the OnPropertyChanged event on the other instance of the control returning always the default value.


I was about the pull all my hairs out, but suddenly it strikes in my head, the problem is the default value that I set to the dependency property.


Then I tried with default value to “null”, and it worked!. Wallah!. Well offcourse I had to use nullable bool to be able to set its default value to null.


In my opinion you should always use default property as to null unless you have some condition that requires to set default value.


public bool? ShouldIgnoreStep
{
get { return (bool?)GetValue(ShouldIgnoreStepProperty); }
set { SetValue(ShouldIgnoreStepProperty, value); }
}

public static readonly DependencyProperty ShouldIgnoreStepProperty =
DependencyProperty.Register(
"ShouldIgnoreStep", typeof(bool?), typeof(RiteqWizardPage),
new PropertyMetadata(null, OnPropertyChanged));

private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RiteqWizardPage riteqWizardPage
= d as RiteqWizardPage;
if (e.Property.Name.Equals("ShouldIgnoreStep"))
{
if (e.NewValue != e.OldValue)
{
if (riteqWizardPage != null)
{
riteqWizardPage.OnShouldIgnoreStepChanged();
}
}
}
}

Cheers! and happy coding.

Tuesday, November 26, 2013

Optimize the size of xap file an easy way.

Your silverlight projects .xap file is getting bigger, this happens because of some assembly issues. And ofcourse there are some ways to optimize it.

http://blogs.telerik.com/miromiroslavov/posts/10-09-15/5-ways-to-reduce-your-xap-size.aspx

The above article shows few popular ways to reduce the size of xap file.

I had a xap file what was almost 4 mb in size. so I decided to do some optimization.

First thing i did is to remove all unused references and control references. fortunately resharper has some good feature on this. I right clicked on the project and selected “Optimize Reference” and removed all unnecessary references.

Now my xap file is reduce to 1.6 mb. that is almost 200% reduced. awesome.

image

Next there are some option for assembly caching, if you go you the silverlight tab of the project you would see that there is a checkbox for “Reduce XAP size by using…….” Just check it and recompile it. 

image

Next what happen is all the other assemblies that is been used are zipped and added in client bin folder. and reduce the xap file size to negligible.

image

But that does not help that much I guess as the total is still about 1.6 mb. any its a feature and we can used it.

Until next time cheers!.

Update: Checkout this kick ass article to get crazy on size reduction

http://blogs.telerik.com/xamlteam/posts/08-05-13/increasing-the-compression-ratio-of-the-xap-files.aspx

Saturday, October 19, 2013

Unlock password protected pdf files: pdfunlock.

I have been doing some works with pdf files auto fill with itextsharp. one of the file that client gave me was secure and password protected. When ever I try to open this using Adobe Acrobat Pro. Its shows that it have to be opened by Adobe life cycle designer.

Then I installed Adobe life cycle designer and tried opening it, unfortunately end up getting a password window and couldn’t  proceed.

Then of course googled it and found this awesome web where you can unlock pdf online.

http://www.pdfunlock.com/

Cheers!

Thursday, September 12, 2013

Visual studio 2012 Blue Theme

Dear Community, I believe lot of the die hard fan of Microsoft development platform  wondered why visual studio 2012 got rid of the blue theme, in my personal opinion i really liked it, then while working and viewing videos in channel 9  I discovered that we can have different different colors theme in visual studio, and that’s  been there from the beginning.

Man I am stupid, should have figured it out that they have some kind of plan for that. Any way the easies way to get this blue theme going again in visual studio is to use extension.

How to get the blue theme?

Go to visual studio 2012’s extension manager and then search for “Color” in online category.

image

You will find couple of interesting extortions, Download the “Visual Studio 2012 Color Theme Editor”

image

The download and install will begin instantaneously, after that the Visual studio will be required to restart.

After restart you will get option like the below where you can choose your color theme. Choose the right one. In my case I have chosen “Blue”.

image

You can also customized the theme and create your own theme, but that is a whole other story. Until next time. Happy coding.

Friday, August 2, 2013

Team foundation server windows explorer extension

We all used svn that’s for sure for personal use or perhaps company policy to use it doesn't matter, in source control race TFS is getting behind. At lease i felt it, but some recent improvements now taking this back bench product to front bench.

For instance we can have git like behavior in tfs if we want, cool right?. But today I wish to share a different type of tool that can ease the tfs experience a little bit better, in fact its a windows explorer extension, named “Microsoft Visual Studio Team Foundation Server 2012 Power Tools”

You guys can download it from “http://visualstudiogallery.msdn.microsoft.com/b1ef7eb2-e084-4cb8-9bc7-06c3bad9148f

I have used it and its kind of can give you a feeling like tortoise. It has overlay icons just like svn.

image

Now some critic, the extension has relatively slow in performance, at least in my system. It doesn't have branching or switching stuff like other source control extensions, its primitive but at least now we have an extension.

I got excided to realize that now i can add documents folders and other stuff in tfs without need to open visual studio. so its cool and if we all start using it hopefully more feature will be available in future. 

Thursday, July 4, 2013

Thousands of warning! in visual studio 2012? Why?

So what happen is, I had my XML documentation file checkbox in build tab of project was checked. And I had few service references in my project.

As you can guess all of the service ref has around more than 2000 methods, since this checkbox was checked all the public methods of service proxy class was giving a warning about summery of the function.

image

It was frustrating to see that amount of warning in my project, Then unchecked the checkbox and wallah all the warning are gone.

Inner peace is on,,,,

Friday, February 1, 2013

Set value of input type password or asp.net textbox where TextMode="password".

Old school stuff, probably everyone knows it, still sharing because had a little bit trouble tackling this. Thought its very easy and it is,

Why we need this? Here is why, you have a cookie where you save username and password for later use, and of course the cookies are encrypted.

Now you retrieve the cookie found that a user login info is there and user checked the “Remember Me” stuff. You need to set to both username and password in the text fields and pre-populate those.

In my case the password field is html markup.

 

<input id="password" type="password" placeholder="Password" required="required" runat="server"
clientidmode="Static" value="" />
 
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
Text="*" ErrorMessage="*" ControlToValidate="password" ForeColor="Red"></asp:RequiredFieldValidator>

Now I set the code from c# as below run the app didn’t worked.

1. password.Value = "1234567890";
2. password.Attributes.Add("value","1234567890");

After trying the first case I realized that its not going to work, then googled it found few suggestions that adding as attribute should work. No luck here also, I wonder why it didn’t worked in few of the posts developers are saying that it works, but in my case it didn’t. Finally take a D Tour and Used javascript the nail the bad boy.


Step one:

Page.ClientScript.RegisterStartupScript(this.GetType(),"statusup","SetDefaultPass('1234567890');",true);
Step Two:

<script language="javascript" type="text/javascript">
function SetDefaultPass(parameters) {
try {
document.getElementById('password').value = parameters;
} catch (e) {
alert(e);
}
}
</script>

That’s its this fine finally it worked like magic. no issue now.


Hope this helps to some lame, like me some day :D.


Cheers!

Friday, January 11, 2013

Recover the SA Password of SQL Server 2008

Found a simple steps to recover SA password of SQL Server 2008. Its handy already tried and successful to recover the password of my sql server enterprise.

What happen is, I found a computer from client side where there is sql server installed but don’t have sa password. And some how windows authentication doesn’t work.

So did little R&D and then found out this guy already noted down the steps how to recover it. so thanks for sharing the article.

Below link is given.

http://v-consult.be/2011/05/26/recover-sa-password-microsoft-sql-server-2008-r2/

Detailed explanations are given on the blog. so cheers!

Thursday, January 3, 2013

WCF Service Optimization: An interesting technique to split your *.svc.cs file to have more manageable WCF service

Introduction

WCF (Windows communication foundation) is the service layer foundation and the base of SOA in Microsoft dot net, what will happen when you have a huge WCF service consisting of 5000 operation contract. This is not unreal at all, if you design a service bus for a large intranet application, where 1000 employee using your application and doing day to day operation and your WCF service hits per second is about 2000. You can do so many thing to optimize it, first of all you can cluster the service and then apply load balance. So horizontal scaling is a solution.

Now if you are given a task to optimize the operation and each time you need to look at the service you have to find it in a large class where you have about 5000 operation contract. How developers will maintain this huge code base?

Fortunately we have few solutions to that problem

Today we are going to see 1st of many solution

split your *.svc.cs file

This does not help in optimization of the service rather managing the file and the codebase. First of all I would split the svc file in to several pieces. Each will contain in about 100 methods, still we would have 20 files for the svc file, its kind of sounds different but, would help managing 2000 methods, each file will contain domain specific methods for the service.

How we do it?

We will add class with almost same name as the service, for instance if we have a WCF service named “myservice.svc” then the code behind file is  “myservice.svc.cs”. Off Course its not necessary to have svc.cs file with the wcf service we can have only the declaration.

Below a code example is given,This is how a real world service which is out of refactoring and maintain for a while looks like.

image

Figure: Log Class of 2000 method

In above screenshot If you carefully look at the scrollbar of the method dropdown of the visual studio, you will have an idea how much its doing.

So now we need to optimize this in perspective of code management. As we already discussed the technique. we will split this in to several pieces, luckily we have a partial class concept in c#, so we would split this in to several pieces according to class responsibility domain.

Naming convention for the partial class. “myservice.[responsibilityDomain].svc.cs” that’s the filename of the class. In practical case I have named on of my partial class as “ReliantDataConnect.CandidateOffer.svc.cs” I have moved all the methods related to CandidateOffer in this file.

Now Lets say we have added another partial class file name “ReliantDataConnect.Resource.svc.cs” using the following wizard window.

image

Figure: Add a new class

And after moving the related methods in the partial class the partial class may look like below screen shot.

image

Now problem is the partial class will be visible in solution explorer as a isolated file rather part of the WCF Service. Below how it looks like after adding the file.

image

Now if we can add this file as a dependent file of the ReliantDataConnect.svc file this will save us form watching isolated file, and make a combined file. Here is how we do it.

Make a file dependent on another file in visual studio

First of all we have to open the project file in note pad or text pad or note pad ++ which ever you like. Then find the file name that we added “ReliantDataConnect.Resource.svc.cs”, finally add DependentUpon Child node and specify the file name in our case its “RelaintDataConnect.svc” Now saved the file. Close it. If visual studio is open it should already warn you that file is been modified outside and reload is necessary. Reload to proceed.

image

After reload you will see that the file is now part of svc file.

image

Cool right?. Well for now you can go and browse other blog, I will get busy with creating 20 more class file for this project. Until next time.

Masudur Rahman is out.