Saturday, July 16, 2011

My Branching and Merging Strategy

Hi,
I would to share with you my way to the best practices for development version management
we always have to keep an isolated environment that is equal to the production environment because we want to keep the ability to make patches to the production environment while the other developers are working on the development iteration

my way is based on two important rules:
  1. Production environment must be equal to the main development environment for enabling production bug fixes over the iteration development

  2. The iteration development will be only in the branch development environment


I'll explain it by a simple scenario as yo can see in the chart below:

chart


legend
So, the scenario is:
1. create a branch development version from the main development version, this action occurred only once
2. in case that you have to fix a minor bug and to update the patch to the production environment, take it from the main development version
3. when the development iteration is over, we have to make merge from the main development version to the branch development version because of the production patch
4. we can update the production environment from the branch development version
5. after the version update we have to make merge from the branch development version to the main development version because we have to keep the main development version equal to the production environment

from this step we have to repeat steps 2-5 for each development iteration

one important tip:
when making the branch action, don't overwrite the configuration files, keep the target version

Monitor your system for free

Hi, I would like to introduce you a very nice system monitoring solution called
Polymon. Polymon is an easy to use software that made up of three primary components:
  • A SQL Server database to store monitor statuses, alerts and general settings.

  • A windows service (PolyMon Executive) that runs monitors on a periodic basis,
    logs results to the database and sends out email notifications.

  • A management/monitoring front-end (PolyMon Manager) that is used to manage
    general settings, monitor definitions, operators, alert rules, etc. and analyze
    historical trends (both monitor counters and statuses).

To start using this tool you have to download the latest setup file from polymon.codeplex.com setup the configuration of the software during the installation wizard and then start define the monitors that you need, then you have to set your email notifications settings, i also use one of the email to sms tools and now i get system alerts to my cell phone, i'll show here this monitors:
  • Disk Monitor - use this monitor type in case that you want to monitor the remaining free space in your system

  • File Monitor - use this monitor type in case that you want to monitor the files count on specific directory

  • MSMQ Monitor - use this monitor type in case that you want to monitor the msmq messaging service, for example, the total messages count in all the queues in the system

  • Ping Monitor - use this monitor type in case that you want to monitor the system health by a ping request

  • SQL Monitor - use this monitor type in case that you want to monitor your sql server datatbase by a structed query

  • Service Monitor - use this monitor type in case that you want to monitor your window service and check if it is still running

  • URL Monitor - use this monitor type in case that you want to monitor the a url and to make a content check on its response

Disk Monitor:

After you have selected Disk Monitor as the type of your monitor
you have to:

  1. Select the hard disk drive to monitor

  2. Set the free space remining for the warning message

  3. Set the free space remining for the failed message


polymon_diskFull





File Monitor:

After you have selected File Monitor as the type of your monitor
you have to:

  1. Select the target directory to monitor

  2. Set the search filter, probably it will be *.[file_extension]

  3. Set the file count for the warning message

  4. Set the file count for the failed message


polymon_filesNo





MSMQ Monitor:

After you have selected Performence Monitor as the type of your monitor
and select MSMQ Service as the category and select Total messages in all queues as the counter, then you have to:

  1. Set the number of messages for the warning message

  2. Set the number of messages for the failed message


polymon_MSMQ





Ping Monitor:

After you have selected Ping Monitor as the type of your monitor
you have to:

  1. Set the ip as the destination of the ping request

  2. Set the number of tries and the number of failures

  3. Set the timeout for the request


polymon_Ping





SQL Monitor:

After you have selected SQL Monitor as the type of your monitor
and wrote a stored procedure in this format you have to:

  1. Set the connection string in setting xml

  2. Set the stored procedure name in setting xml


polymon_SQL1





Service Monitor:

After you have selected Service Monitor as the type of your monitor
you have to:

  1. Set the host where the service is running

  2. Set the service name to monitor


polymon_Srv





URL Monitor:

After you have selected URL Monitor as the type of your monitor
you have to:

  1. Set url to monitor

  2. Set the request timeout

  3. Set the content to check on the response text


polymon_Url

Wednesday, October 20, 2010

Using jquery selectors on server side(C#)

Something that i have been looking for a long time
is to use jquery selectors on the server side.
if found a great solution at fizzler project
fizzler is .NET CSS Selector Engine and you can download it from here.
from fizzler site:
A .NET library to select items from a node tree based on a CSS selector. The default implementation is based on HTMLAgilityPack and selects from HTML documents

all you have to is to download fizzler package
and add reference to this dll files:
- Fizzler.Systems.HtmlAgilityPack.dll
- Fizzler.Systems.XmlNodeQuery.dll
- HtmlAgilityPack.dll

here you can see a useful samples:

HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
html.LoadHtml(
@"<html>
<head></head>
<body>
<div id='content'>
<a target='_blank' href='http://yosi-havia.blogspot.com' class='FirstName'>Yosi</a>
<a href='http://yosi-havia.blogspot.com' class='LastName'>Havia</a>
</div>
</body>
</html>");
HtmlNode document = html.DocumentNode;

//@@@ get all elements with content id in html(result: 1 element)
IEnumerable<HtmlNode> list1 = document.QuerySelectorAll("#content");
List<HtmlNode> lst1 = list1.ToList<HtmlNode>();

//@@@ get all elements with FirstName class name in html(result: 1 element)
IEnumerable<HtmlNode> list2 = document.QuerySelectorAll(".FirstName");
List<HtmlNode> lst2 = list2.ToList<HtmlNode>();

//@@@ get all anchor tags in html(result: 2 elements)
IEnumerable<HtmlNode> list3 = document.QuerySelectorAll("a");
List<HtmlNode> lst3 = list3.ToList<HtmlNode>();

//@@@ get all elements in html(result: 6 elements)
IEnumerable<HtmlNode> list4 = document.QuerySelectorAll("*");
List<HtmlNode> lst4 = list4.ToList<HtmlNode>();

//@@@ get element with attribue name 'target' that starts with '_bl' in html(result: 1 element)
IEnumerable<HtmlNode> list5 = document.QuerySelectorAll("a[target^='_bl']");
List<HtmlNode> lst5 = list5.ToList<HtmlNode>();

Saturday, June 19, 2010

c# window service Debugging - the best way!

Very intresting and complicated issue is how to debug c# window service,
i saw many solutions for that but no one of them made me satisfied.

the best solution for that is to use a simple VS macro, the idea is to start the service and then attach to the process in the same macro.

you can see the macro installation instructions in this post
with a few changes:

Tuesday, March 16, 2010

Create attach to process shortcut in VS 2008

Tools -> Attach to Process... -> wait for the dialog -> < select the process > -> press on attach
who has the time and the patience to follow this step every time we want to debug an internt application.
I'll show u how to attach to process in one shortcut press.
for generate the shortcut, follow the steps below:

  1. Open Visual studio

  2. Press Alt+F11 to open MyMacros

  3. Right click on MyMacros-> Add-> Add existing item and browse to this file(change the file extension to .vb)

  4. Now, we have make a shortcut key to this macro, you should go to Tools -> Options and choose Environment -> Keyboard pane

  5. To find our macro we can search for the word macro in the search text box, and select the macro we want(in my case: Macros.MyMacros.AttachingToProcess.AttachToInternetApp)

  6. Choose a shortcut keys for this macro and insert them in the 'Press shortcut keys' text box, i choose ctrl+\ (u have to press them together)

  7. Press on Assign button, and ok, that's all, we finished


Friday, February 12, 2010

Create secure form without captcha

Usually when we want to create a secure form that computer programs cannot pass we use the captcha program.
captcha has a lot of disadvantages, when the main disadvantages is that the captcha is heavy, bother, and make users to run away from our form.
in the idea that i'll show in this post the user cannot notice in any difference from unsecured form.
the steps for the very simple solution is

1. generate a random names to inputs in the form
2. save the names in the session collection at the server side
3. after the user submits the forn, take the inputs names fron rhe session
4. the the inputs values from the request collection with the key names from the session

take a look at this simple example at asp .net but it will work in every server side language:
---------------------------------------------------------------------------------------
the server side code

public partial class _Default : System.Web.UI.Page
{
public string UserNameKey;
public string PasswordKey;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["UserNameKey"] = UserNameKey = Guid.NewGuid().ToString();
Session["PasswordKey"] = PasswordKey = Guid.NewGuid().ToString();
}
}
protected void lnkSend_Click(object sender, EventArgs e)
{
if (Session["UserNameKey"] != null
&& Session["PasswordKey"] != null)
{
string UserNameValue = Request[Session["UserNameKey"].ToString()];
string PasswordValue = Request[Session["PasswordKey"].ToString()];
}
}
}


the html code

<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
User name: <input type="text" name="<%=UserNameKey%>" />
<br />
Password: <input type="password" name="<%=PasswordKey%>" />
<br />
<asp:LinkButton ID="lnkSend" runat="server"
onclick="lnkSend_Click" >Send</asp:LinkButton>
</form>
</body>
</html>

Monday, September 14, 2009

Simple xslt example

In this post i'll show how 2 make a simple xsl transform.
In addition i'll show how to use this xsl elements:

1. XsltArgumentList - pass arguments to the xslt
2. Encoding - declare the outgoing xml encoding
3. xsl:value-of - take the value(inner text) of node
4. xsl:copy-of - copy the inner xml of node
5. xsl:for-each - loop through same nodes
6. xsl:sort - sort nodes by specified node

and in the end of the post there is a c# thread safety class to make xsl transforms

so, this is the origin xml file(Person.xml):

<hPerson>
<Header>

<FirstName>Yosi</FirstName>
<LastName>Havia</LastName>
<Age>30</Age>
<Education>BA</Education>
</Header>
<hChildren>
<hChild>
<hName>Carol</hName>
<hAge>13</hAge>
</hChild>
<hChild>
<hName>Angela</hName>
<hAge>15</hAge>
</hChild>
<hChild>
<hName>Benjamin</hName>
<hAge>17</hAge>
</hChild>
</hChildren>
</hPerson>


and this is the xslt file(Person.xslt):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml- declaration="yes"/>
<xsl:param name="Gender"></xsl:param>
<xsl:template match="/">
<Person>
<Gender>
<xsl:choose>
<xsl:when test="$Gender='1'">
Male
</xsl:when>
<xsl:otherwise>
Female
</xsl:otherwise>
</xsl:choose>
</Gender>
<xsl:copy-of select="/hPerson/Header"/>
<Data>
<Children>
<xsl:for-each select="/hPerson/hChildren/hChild">
<xsl:sort select="hName" />
<Child>
<FirstName>
<xsl:value-of select="hName"/>
</FirstName>
<Age>
<xsl:value-of select="hAge"/>
</Age>
</Child>
</xsl:for-each>
</Children>
</Data>
</Person>
</xsl:template>
</xsl:stylesheet>

the output xml look like this:

<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Gender>
Male
</Gender>
<Header>
<FirstName>Yosi</FirstName>
<LastName>Havia</LastName>
<Age>30</Age>
<Education>BA</Education>
</Header>
<Data>
<Children>
<Child>
<FirstName>Angela</FirstName>
<Age>15</Age>
</Child>
<Child>
<FirstName>Benjamin</FirstName>
<Age>17</Age>
</Child>
<Child>
<FirstName>Carol</FirstName>
<Age>13</Age>
</Child>
</Children>
</Data>
</Person>

this is a thread safety c# class to make xsl transforms

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace XSLT
{
class XsltObj
{
protected static XslCompiledTransform _oXslTransform;
protected static object _oSyncXsl = new object();
public string FormatXmlWrapper(string sEncoding, XsltArgumentList
oXsltArgumentList,XmlDocument oOriginXmlDoc, string sXslPath)
{
string sRetVal = null;
if (_oXslTransform == null)
{
LoadXslWrapper(sXslPath, ref _oXslTransform, ref _oSyncXsl);
}
//@@@ make the transform
try
{
sRetVal = TransformData(sEncoding, _oXslTransform, oOriginXmlDoc,
oXsltArgumentList);
}
catch (Exception ex)
{
throw ex;
}
return sRetVal;
}
protected void LoadXslWrapper(string sXslPath,
ref XslCompiledTransform oXslTransform, ref object oSyncXsl)
{
lock (oSyncXsl)
{
if (oXslTransform == null)
{
XslCompiledTransform oTempXslTransform =
new XslCompiledTransform();
//@@@ get the xml path from configuration
LoadXsl(sXslPath, ref oTempXslTransform);
oXslTransform = oTempXslTransform;
}
}
}
protected void LoadXsl(string sXslPath, ref XslCompiledTransform
oXslCompiledTransform)
{
//@@@ load the xsl document(only once)
XmlDocument xslDocument = new XmlDocument();
XmlUrlResolver urlResolver = new XmlUrlResolver();
urlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
xslDocument.XmlResolver = urlResolver;
try
{
//@@@ load the xsl document
xslDocument.Load(sXslPath);
XPathNavigator oXPathNavigator = xslDocument.CreateNavigator();
oXslCompiledTransform.Load(oXPathNavigator,
XsltSettings.TrustedXslt, urlResolver);
}
catch (Exception ex)
{
throw ex;
}
}
protected string TransformData(string sEncoding, XslCompiledTransform
oXslTransform, XmlDocument xmlDocument, XsltArgumentList argumentList)
{
StringBuilder sb = new StringBuilder();
string sDeclaration;
//@@@ decide the xml declaration up to the Encoding
if (string.IsNullOrEmpty(sEncoding))
sDeclaration = "version=\"1.0\"";
else
sDeclaration = "version=\"1.0\" encoding=\"" + sEncoding + "\"";
//@@@ make the xsl Transform
using (XmlWriter output = XmlWriter.Create(sb))
{
output.WriteProcessingInstruction("xml", sDeclaration);
XPathNavigator oXPathNavigator = xmlDocument.CreateNavigator();
oXslTransform.Transform(oXPathNavigator, argumentList, output);
return sb.ToString();
}
}
}
}

to activate this object use this code:

static void Main(string[] args)
{
XsltObj oXsltObj = new XsltObj();
XsltArgumentList oXsltArgumentList = GetXsltArguments();
XmlDocument oXmlDocument = new XmlDocument();
string sXmlPath = @"Person.xml";
string sXslPath = @"Person.xslt";
oXmlDocument.Load(sXmlPath);
string sXml = oXsltObj.FormatXmlWrapper("UTF-8", oXsltArgumentList,
oXmlDocument, sXslPath);
}
protected static XsltArgumentList GetXsltArguments()
{
//@@@ create the arguments for the xsl
XsltArgumentList list = new XsltArgumentList();
list.AddParam("Gender", string.Empty, "1");
return list;
}