How to create branch under SourceSafe in 5 steps?

сряда, 26 март 2008 г.

Hi guys!

A lot of people (including me of courseJ) had a lot of troubles when they had to create their first branch under SourceSafe. Why? In my opinion this program (talking about version 8.* of SourceSafe) has a lot of problems connected with the friendliness of the UI. Actually I think that it isn't user friendly at all. So here are my bits about solving one of the problems – branching. In the following lines I will provide an algorithm in 5 steps about how to do this activity. I do not know whether there is shorter way to do this but for me this is short enough and the most important thing – it works.

The algorithm is the following. I assume that you are in the database, where is the project you want to branch. Note, that the backward blue diagonals on white background cover some data, which is important only for me.

Step 1: Select the root of your DB, right click on it and select Create Project.




Step 2: Give your new project a name – this will be the name of your new branch. Click OK.




Step 3: Go to the folder you just created – right click on it. Select Share to $/ Your_Branch.




Step 4: Select the project which you want to branch. Check Branch after share (in the bottom) and click Share.




Step 5: You can select new name of the project, which will be branched in your new folder (the one which you created on Step 1). Check Recursive. You can add your Comment in the provided box and then click OK.




After these 5 steps you are ready to wait for your new branch. The speed of actual creating the branch depends on your project size, database, etc.

Hope this helps!

How to get the free available memory with C#? The first sample of using a performance counter.

петък, 21 март 2008 г.

There are a lot of cases in which we as developers want to know how much free memory is there (or the state of some of the other system resources). This can be used for deciding whether we can handle another request, or is there enough memory (and CPU of course) to start some background work meanwhile. A lot of examples can be given about such situations.

Ok, but how we can answer this question in C#?
The approach which I will show is a very good start for diving in the topic of monitoring. What is the way to monitor the system resources in Windows? The answer is: Performance Counters. There are a lot of counters out there which can give a lot of data. Yes, there is no mistake – just pure data. Our task is to observe, collect, manipulate mathematically, etc. this data such that we can extract meaning from it i.e. to transform it in information. Keep in mind that “Performance Monitoring is a complex subject and in some ways more of an art than a science.”
Just for completeness I will add that you can check some of the available counters on your own system /they can differ depending on what have been installed/ from Control Panel ->Administrative Tools -> Performance. There – right click -> Add counter. The following box appears:



OK that’s enough knowledge for you to start observing some counter if you haven’t already in the past.

The counter which we are interested in today is connected with memory, so it should be in Memory performance object. The right counter is one of the following: Available Bytes, Available KBytes, Available MBytes.
"Available Bytes\KBytes\MBytes shows the amount of physical memory, in bytes\kilobytes\megabytes, available to processes running on the computer. It is calculated by adding the amount of space on the Zeroed, Free, and Standby memory lists. Free memory is ready for use; Zeroed memory consists of pages of memory filled with zeros to prevent subsequent processes from seeing data used by a previous process; Standby memory is memory that has been removed from a process' working set (its physical memory) on route to disk, but is still available to be recalled. This counter displays the last observed value only; it is not an average."

How to retrieve data from performance counters in C#? There is a namespace in .NET named System.Diagnostics . There are a bunch of classes which give us the power to play with these counters. It is very straight forward and easy. You can see the simplicity from my sample which is only 3-4 lines of code.



In this manner we can retrieve the free memory with C#.
There are a lot other useful counters out there in Windows such as these for the processor, disk usage, etc. Of course if you have installed .NET framework, there are a lot counters connected with the CLR as a whole.

In the future I am planning covering some of other performance counters and connected classes in .NET so stay turned. Hope this helps!

Something that amazed me - Stereograms

вторник, 18 март 2008 г.

Yes.. it really is true. Stereograms are something that made me feel really strange. First I will give you one of them. Your task is very simple - just stare at it.



Yes.. I know this is jsut a bunch of paper clips. I'll try to give you a hint how to see it. Go near your screen. Stare at it but do not harden your eyes. Just stare. Then move your face out of the screen slowly. After two or three (thousands) of times you will see it. And do not ask me when you will understand that you will see what is there. If you see it you will be sure.

I want to present you a short definiton from Wikipedia: A stereogram is an optical illusion of depth created from flat, two-dimensional image or images. Originally, stereogram referred to a pair of stereo images which could be viewed using stereoscope. Other types of stereograms include anaglyphs and autostereograms.

Here you can find a lot of other stereograms. It is very funny - really!

In some of my next posts I will try to cover the topic of creation of stereograms. You know me - I am a deep diver!

Thanks and do not take a long time staring!

My blog in YOUR language!

вторник, 5 февруари 2008 г.

Hi guys!
I know that there is a time in which you want to read something, which you do not completely understand because of the language in which it is written. As you may do not know I am a great fan of machine translation topic. This automatically leads to the fact that you can now read my blog in a language which you better understand or even in YOUR language. This cool functionality is produced because of who? Google of course :-). (Look under my profile information.)

So lets start blogging more frequently in YOUR language!

Thanks!

P.S. If you know me better you will already know that I will share how you can do this to your own blog/site. Just read the information from here

ScriptManager in a BasePage class.

вторник, 15 януари 2008 г.

Hi guys!
As I don't have much time I will go straight to the problem - how we can put ScriptManager in our BasePage class? You know that when you insert an UpdatePanel to a page and there isn't any ScriptManager it cries for one. When you insert more than one ScriptManager, you are said that there isn't any. As I have researched - there wasn't answer how you can put ScriptManager from a BasePage class and again we were alone ;).

OK here is the solution:



How you can come to this conclusion yourself?
When you open the code of the UpdatePanel you will see that the class has property ScriptManager, which internaly calls ScriptManager.GetCurrent(page) which internaly returns (page.Items[typeof(ScriptManager)] as ScriptManager);

So I had to do two things - first to lie the UpdatePanel that there is at least one ScriptMangaer, than I had to remove it because I want to add it as first control on the page.

Thats all folks! Hope this helps :-).

How to disable validation group with JavaScript?

събота, 10 ноември 2007 г.

Hi again!
I haven’t blogged from a long time ago – I haven’t had enough time to do all of the stuff that I wanted. But now (at last :-)) I have time for my blog. There are a lot of ideas/problems which I want to share with you! So let’s go to the first one.

What is the problem?
These days comes up the need to disable a bunch of validators on the client side. For example imagine that you have a checkbox which shows/hides a number of textboxes. When the checkbox is checked the user is able to fill the boxes (thus validation is required) and on the other hand when he can’t see/fill the boxes, validators should be turned off. I tried to find an example of how to disable ValidationGroup with JavaScript but I couldn’t.

How we can fix this?
Ok guys let’s solve the problem ourselves. The idea is very simple and straightforward.
1. We have a function provided by Microsoft ValidatorEnable(validator, isEnable) which takes a validator and whether it should be enabled/disabled.
2. What else we have? If we look at the rendered html of a page that contains at least one validator, we will see that all of them are elements of the array Page_Validators.
3. The third thing which we have is the property of each validator named validationGroup.

Now we know how to enumerate all validators in a page, how to enable/disable particular validator and how to ask a validator whether it is part of particular validationGroup. Thus we have enough knowledge to solve the problem.
Below is sample code of an .aspx file. In it you will see two text boxes. Both have required field validator. The second has regular expression validator, too. I have made groups for the validators from a particular type. There are two buttons – the one which enables the required field validators group and the other to disable it. The two buttons call my custom function named (accordingly to Microsoft convension) ValidationGroupEnable. The function enumerates all page’s validators and if a validator is from the given validation group it is enabled/disabled according to the value given to isEnabled. Internally the function HasPageValidators fixes the situation when we doesn’t have any validators (the problem here is that when you don’t have any validators Page_Validators array is not defined and if you try to use it there will be an error).

The code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">

<title>Enable/Disable validation group with JavaScript</title>

<script type="text/javascript">
function HasPageValidators()
{
var hasValidators = false;

try
{
if (Page_Validators.length > 0)
{
hasValidators = true;
}
}
catch (error)
{
}

return hasValidators;
}

function ValidationGroupEnable(validationGroupName, isEnable)
{
if (HasPageValidators())
{
for(i=0; i < Page_Validators.length; i++)
{
if (Page_Validators[i].validationGroup == validationGroupName)
{
ValidatorEnable(Page_Validators[i], isEnable);
}
}
}
}
</script>


</head>
<body>
<form id="form1" runat="server">
<div>

<input type="button" value="Disable required field validators!"
onclick="ValidationGroupEnable('vgRequiredFields', false)" />
<input

type="button" value="Enable required field validators!"
onclick="ValidationGroupEnable('vgRequiredFields', true)" />
<table>
<tr>

<td style="width: 229px">
<asp:Label ID="lblName" runat="server" Text="Name: " /><asp:TextBox ID="txtName" runat="server" />

<asp:RequiredFieldValidator ID="rfvName" runat="server"
ErrorMessage="*" ControlToValidate="txtName"
ValidationGroup="vgRequiredFields" /></td>


</tr>
<tr>
<td style="width: 229px">
<asp:Label ID="lblEmail" runat="server" Text="Email: " /><asp:TextBox ID="txtEmail" runat="server"/>

<asp:RequiredFieldValidator ID="rfvEmail" runat="server"
ErrorMessage="*" ControlToValidate="txtEmail" ValidationGroup="vgRequiredFields" />

<asp:RegularExpressionValidator ID="revEmail" runat="server"
ErrorMessage="!" ControlToValidate="txtEmail" ValidationGroup="vgRegularExpressions"

ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" /></td>
</tr>
</table>
</div>

</form>
</body>
</html>

Conclusion

Hope this helps :-).
P.S. DD you now have what you needed. Keep up the good work! ;-)

ASP.NET LinkButton - when disabled renders not a valid xHTML.

четвъртък, 26 юли 2007 г.

What is the problem with LinkButton control in ASP.NET?
When you disable a LinkButton i.e. set Enabled="false", ASP.NET renders disabled="disabled" which is not a valid xHTML property.

How we can fix this?
If you view the source code of the LinkButton control and more specific the AddAttributesToRender method, you will notice that it adds the disabled attribute when Enabled is set to false. The second thing you will see there is that no matter you have set or not the PostBackUrl property to string.Empty, the method renders href property and link postbacks i.e. every time when the LinkButton is Enabled.

So what functionality does we have to achieve? When the LinkButton is disabled, we get these five things:

0. Get rid of the disabled="disabled" property.
1. The link must not be clickable (=> there will be no postback).
2. The cursor is not a hand, but as the thing under is simple text (=> the user will not expect that it is clickable ).
3. We have no underlining.
4. The color is grey as a disabled link. Here I'll add, that if you want to make it more flexible for design, you can set a css class name in which designers can add the appropriate color.

Therefore the thing which will have to do are respectively:
0. Set control's Enabled property to true.
1. Set the PostBackUrl to javascript:void(0).
2. Set the cursor to be of type text.
3. Set the text-decoration to none.
4. Set the color to grey.

As in my previous post which you can find here, we will achieve this with the help of control adapters. Here is a sample source code:



Conclusion
This solution shows again the power of control adapters - properly rendered controls of some type in the whole web site just with a few lines of code.

 
Vesko Kolev's Blog : IDeveloper -