Blog of an overweight SharePoint addict

Thu 20 Dec 07

Spam users..

Filed under: Uncategorized — Reginald @ 3:57 pm

I’ve just been through and deleted several hundred accounts that have been created by obvious spam users. My spam filters are rpetty good and prevent them posting anything, but they still create accounts….

Apologies if anyone has had their account removed in error, I only deleted the obvious looking ones, but you never know..

Adding business hours….

Filed under: Programming, SharePoint, Visual Studio 2005, Workflow — Reginald @ 10:39 am

Part of our workflows have some time critical tasks. In this particular instance, there is a measurable KPI of 12 business hours to respond to an event.

The DateTime construct is very useful for date manipulation, but does not appear to provide an easy way to understand Business Hours. So how to go about tracking this?

The simplest way that I managed to come up with, was to create two methods, One that checks if a given DateTime exists on a business day, the other that checks whether the time falls within business hours, named onBusinessDay() and inBusinessHours() respecitively.

static bool onBusinessDay(DateTime timeToTest)
{
ArrayList mBusinessDays = new ArrayList();
mBusinessDays.Add("Monday");
mBusinessDays.Add("Tuesday");
mBusinessDays.Add("Wednesday");
mBusinessDays.Add("Thursday");
mBusinessDays.Add("Friday");

if (mBusinessDays.Contains(timeToTest.DayOfWeek.ToString()))
{
return true;
}
else
{
return false;
}

}

and-

static bool inBusinessHours(DateTime timeToTest)
{
DateTime businessStart = DateTime.Parse(timeToTest.ToShortDateString() + " 09:00:00");
DateTime businessEnd = DateTime.Parse(timeToTest.ToShortDateString() + " 17:30:00");
if ((timeToTest.CompareTo(businessStart) >= 0) && (timeToTest.CompareTo(businessEnd) <= 0))
{
return true;
}
return false;
}

This returns the value's nicely, but now we have the problem, How do we add the hours and track the business hours accuratley? Remember, DateTime has no concept of business hours.

As part of a learning exercise, I decided to use an Enum to create a Bit Flag set to track the BusinessHours and BusinessDay results. (Remember to declare this outside of your main method.

[Flags]
enum DateHoursCheck : uint
{
inBusinessHours = 0x01, //Bit 0
onBusinessDay = 0x02, //Bit 1
notUsed1 = 0x04, //Bit 2
notUsed2 = 0x08 //Bit 3
}

And finally, we get to the program code itself. In order to track the business hours usage, we just create a For loop that increments Int i until it reaches taskHours - 1, The key here, is that we only increment i, if the hour added results in the testDate being inBusinessHours AND on a businessDay. This way we work around out of hours and weekend issues.

static void Main(string[] args)
{
DateTime startDate;
DateTime testDate;
int taskHours = 12;

DateHoursCheck dhc = new DateHoursCheck();

startDate = DateTime.Now;
testDate = startDate;

//We're going to surround the logic in a big loop construct.
//This will set the task time and then test it for business day and business hours.
//Ifboth are correct, we'll end up with True True, which will end the loop.

for (int i = 0; i < taskHours-1;)
{
//Each time the enum is 11, then we'll inc i.
//This should mean we check each of the 12 business hours.

//Reset the bit flags to 0
dhc = 0;

testDate = testDate.AddHours(1);

if(inBusinessHours(testDate))
{
dhc = dhc | DateHoursCheck.inBusinessHours;
}
if(onBusinessDay(testDate))
{
dhc = dhc | DateHoursCheck.onBusinessDay;
}

if (((dhc & DateHoursCheck.onBusinessDay) == DateHoursCheck.onBusinessDay) &&
((dhc & DateHoursCheck.inBusinessHours) == DateHoursCheck.inBusinessHours))
{
i++;
}
}

Console.WriteLine("New Task Time - " + testDate.ToString());
Console.ReadLine();
}

Tue 11 Dec 07

Time flies!

Filed under: General — Reginald @ 11:32 pm

Good lord, Xmas is upon us almost and I’ve not posted in nearly a month. Slacking on my part! but it has been a busy month, the workflow project has been live for sometime now, and as ever there have been a few bugs creeping in that need to be solved. Phase 2 is due to be launched next week and I’m still doing the re-writes and testing the code in the dev environment at the moment. Due to some scope creep, there are some extra requirements that need to be in place. Some tweeking is still needed on these tho!

And during the downtime? Well my Hot Water cylinder sprung a leak at the weekend, The quote form a plumber to replace it… £575+vat!!!! it’s only 6 years old too!.. very annoying to say the least..

The answer, Wickes 36*18 Copper tank, £179.00 and me doing the fitting.. Not for the faint hearted though if you’re shy of plumbing!!

Reg.

Powered by WordPress