AppDomain and Process
http://odetocode.com/Articles/305.aspx
Extension Methods
http://msdn.microsoft.com/en-us/library/bb383977.aspx
Top 25 Most Dangerous Programming Errors
http://cwe.mitre.org/top25/
Linq Examples
http://msdn.microsoft.com/en-us/vcsharp/aa336747.aspx#sumGrouped
Wednesday, 21 April 2010
Monday, 8 March 2010
RIP IE6
Well, as you all may have known by now, IE6 was been laid to rest with an open invite to all who wanted to say good bye to IE6. Its a sad scenario, since it has given so much to the online community, though killing Netscape on its way. But, i am really happy that this has now happened and big corporate companies stop supporting IE6. And now, we can start looking towards HTML5.
Here are few links to go through:
Wednesday, 24 December 2008
Update: AutoComplete using YUI
Previously i had written about how i had made a wrapper control for .net from YUI. In that control i still had to write some javascripts and thus needed some hard work before the control was in a working condition. Now, I have made it into a class library and doesn't require any javascript to be written. Add the dll as a reference and you can use this control like a normal control.
Here is the download link http://abhishekshrestha.posterous.com/autocomplete-yui-net-source
Here is the download link http://abhishekshrestha.posterous.com/autocomplete-yui-net-source
Wednesday, 17 December 2008
Some useful .net specific links
I have few links that may be helpful to you guys:
1. Turning an .ascx User Control into a Redistributable Custom Control
http://msdn.microsoft.com/en-us/library/aa479318.aspx
http://msdn.microsoft.com/en-us/library/aa479318.aspx
if you don't want to go through the msdn article, here is a links to a shorter article on creating custom control from user control
2. Ten must have tools for .net developer
3. Visual Studio keyboard shortcuts
4. Static Code Analysis (FxCop is a great tool to go with)
5. Guidelines for Names in .net (Naming conventions)
6. jQuery Intellisense in VS 2008 (Scott Gu)
http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx
7. code navigation and generation improvements
http://visualstudiogallery.msdn.microsoft.com/d491911d-97f3-4cf6-87b0-6a2882120acf/
7. code navigation and generation improvements
http://visualstudiogallery.msdn.microsoft.com/d491911d-97f3-4cf6-87b0-6a2882120acf/
Labels:
asp.net,
C#,
software development
Monday, 15 December 2008
Timer application on .net c#
In some projects i have worked, there have been requiremts of console application which runs on the background and does(requests) some processing at a certain interval of time. For example, if you have a newsletter subscription system in you site, you may want to send news at 8:00 AM every monday. For this, a console application will run as a schedule task or windows service and if set as schedule task, it will runt at that particular scheduled time.
Now, say for example, you newletter subscription for 3 types of newsletters, one is sent every monday 8 A.M, the second one is sent every Monday-Wednesday and the third one is sent everyday. Since, its newsletter and has the same database of subscribers but only differs in the subscripttion type (which definesd which trpe of newsletter to sent to the subscriber). And most importantly you do not want to write 3 different console applications (or timers) with almost same logic.Extending the newsletters, now say, you want to process(or request) a database call every 10 mins. So, we have 4 different implementation at different time intervals.
Requirements:
1. Application running in background like a timer
2. More than one process request with independent time intervals
High level Logic:
1. Get the list of process requests
2. Check if it is time to make that request
3. If it is time then make a request
1. Getting the list of process requests:
Create an XML file with the following settings,
<?xml version="1.0" encoding="utf-8" ?>
<ProcessList>
<Process Name="NewsletterMonday">
<Times>
<Time Value="8:30 AM" ClockType="_12Hr" />
</Times>
<Days Type="Selected">
<Day Value="Monday" />
</Days>
</Process>
<Process Name="NewsletterMondayToWednesday">
<Times>
<Time Value="10:30 PM" ClockType="_12Hr"/>
</Times>
<Days Type="Range">
<Day Value="Monday" />
<Day Value="Wednesday" />
</Days>
</Process>
<Process Name="NewsletterAllDays">
<Times>
<Time Value="15:00" ClockType="_24Hr"/>
</Times>
<Days Type="All" />
</Process>
<Process Name="DatabaseCallEveryTenMinsAllDays">
<Times>
<Time Value="10" ClockType="Min"/>
</Times>
<Days Type="All" />
</Process>
</ProcessList>
This seetings xml defines what type of process are there and the time to make the
process request.
process request.
2. Check if it is time to make that request:
private bool isProcessRequestDay()
{
bool isProcessRequestDay= false;
switch (_Days.Type)
{
case DayType.All:
isRefreshDay = true;
break;
case DayType.Range:
isProcessRequestDay = (DateTime.Today.DayOfWeek >= _Days[0].Value && DateTime.Today.DayOfWeek <= _Days[_Days.Count - 1].Value);
break;
case DayType.Selected:
foreach (Day day in _Days)
{
if (day.Value == DateTime.Today.DayOfWeek)
{
isProcessRequestDay= true;
break;
}
}
break;
}
return isProcessRequestDay;
}
_Days is a Generic List
the value from < type="----"> from the settings xml. [Note: You will have
to load the settings to the its corresponding classes. ]
Now, get the date and time at which the process request should be made
private DateTime getMinProcessRequestDateTime(DateTime currentDateTime)
{
int min = 0, hr = 0, sec = 0;
int year = currentDateTime.Year;
int month = currentDateTime.Month;
int day = currentDateTime.Day;
DateTime minProcessRequestDateTime = DateTime.MinValue;
foreach (ProcessRequestTime ProcessRequestTime in _ProcessRequestTimes)
{
DateTime tempProcessRequestDateTime = DateTime.MaxValue;
switch (ProcessRequestTime.ClockType)
{
case ClockType._24Hr:
string[] time24Hr = ProcessRequestTime.Value.Split(Constants.SeperatorColon);
hr = Convert.ToInt32(time24Hr[0]);
min = Convert.ToInt32(time24Hr[1]);
tempProcessRequestDateTime = new DateTime(year, month, day, hr, min, 0);
if (!(currentDateTime > tempProcessRequestDateTime))
{
tempProcessRequestDateTime = tempProcessRequestDateTime.AddDays(-1);
}
break;
case ClockType._12Hr:
string[] time12Hr = ProcessRequestTime.Value.Split(Constants.SeperatorSingleSpace);
if (time12Hr[1].Equals(Constants.DateTimeMeridianPM, StringComparison.InvariantCultureIgnoreCase))
{
hr = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[0]);
}
else if (time12Hr[1].Equals(Constants.DateTimeMeridianAM, StringComparison.InvariantCultureIgnoreCase))
{
hr = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[0]);
if (hr >= 12) { hr -= 12; }
}
min = Convert.ToInt32(time12Hr[0].Split(Constants.SeperatorColon)[1]);
tempProcessRequestDateTime = new DateTime(year, month, day, hr, min, 0);
if (!(currentDateTime > tempProcessRequestDateTime))
{
tempProcessRequestDateTime = tempProcessRequestDateTime.AddDays(-1);
}
break;
case ClockType.Hr:
hr = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour - hr).AddMinutes(currentDateTime.Minute);
break;
case ClockType.Min:
min = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour).AddMinutes(currentDateTime.Minute - min);
break;
case ClockType.Sec:
sec = Convert.ToInt32(ProcessRequestTime.Value);
tempProcessRequestDateTime = new DateTime(year, month, day);
tempProcessRequestDateTime = tempProcessRequestDateTime.AddHours(currentDateTime.Hour).AddMinutes(currentDateTime.Minute).AddSeconds(currentDateTime.Second - sec);
break;
}
//Assigning the maximum datetime less than the current date
if (tempProcessRequestDateTime > minProcessRequestDateTime)
{ minProcessRequestDateTime = tempProcessRequestDateTime; _DataSource = ProcessRequestTime.DataSource; }
}
return minProcessRequestDateTime;
}
Now, get the date and time when the last process request was made,
DateTime lastProcessRequestDateTime = {from database or file or memory};
Now, check if last request made before the time calculated for next request,
bool isProcessRequestTime = (minProcessRequestDateTime >= lastProcessRequestDateTime);
If the last request made was before the current calculated time for request, then it means that now is the time to make a new request. Otherwise, if the last request made is after the current calulated time for next request, then the schedule time for process request has already been made.
3. If it is time then make a request
if(isProcessRequestTime)
{
//Call the process
// database call or web service call or http request call
}
Hope this give some logic into how you can write a single application with process request settings that runs on background to make different process request for different time intervals.
If you require code for this example, please mail me or give your mail id in the comment section. I'll will send you the whole code for this application.
Subscribe to:
Comments (Atom)