I am developing a Business Object using CSLA .NET to perform Conversion from/to Hijri/Gregorian Calendar. Although there is a class in .NET for this purpose, but, still there is a good chance there will be a mistake by at least one day +/- in few cases. In any case, I may depend on this class for conversion, when needed. On the other hand, I already developed this conversion logic under MS Access, and I want to re-use parts of the work done of it in .NET.
I will post the BO specs summary here to give you an idea about the requirement, so that I can get your feedback, and I will be posting questions mainly related to how to make this BO most efficient, because eventually it will be exposed via a web service.
The Database:
I am storing the required data in tables in MS Access DB, and following is a sample of such tables:
tDOW
| DOW |
DOWArb |
DOWEng |
| 1 |
سبت |
Sat |
| 2 |
أحد |
Sun |
| 3 |
إثنين |
Mon |
| 4 |
ثلاثاء |
Tue |
| 5 |
أربعاء |
Wed |
| 6 |
خميس |
Thu |
| 7 |
جمعة |
Fri |
tHMonth
| HMnth |
HMnthNameArb |
HMnthNameEng |
DftDays |
| 1 |
محرم |
Muharram |
29 |
| 2 |
صفر |
Safar |
30 |
| 3 |
ربيع الأول |
Rabii' I |
29 |
| 4 |
ربيع الآخر |
Rabii' II |
29 |
| 5 |
جمادى الأولى |
Jumada' I |
30 |
| 6 |
جمادى الآخرة |
Jumada' II |
29 |
| 7 |
رجب |
Rajab |
29 |
| 8 |
شعبان |
Sha'ban |
30 |
| 9 |
رمضان |
Ramadan |
30 |
| 10 |
شوال |
Shawal |
29 |
| 11 |
ذو القعدة |
Dhul-Qa'dah |
30 |
| 12 |
ذو الحجة |
Dhu Al-Hijja |
30 |
Following is the main conversion table which is updated/initialized at the beginning of each new Hijri Year and when needed (mainly at the beginning of Ramadan):
tHYearMonth
| HYear |
HMnth |
DaysCnt |
FromDateGrg |
ToDateGrg |
| 1429 |
1 |
29 |
10/01/2008 |
07/02/2008 |
| 1429 |
2 |
30 |
08/02/2008 |
08/03/2008 |
| 1429 |
3 |
29 |
09/03/2008 |
06/04/2008 |
| 1429 |
4 |
29 |
07/04/2008 |
05/05/2008 |
| 1429 |
5 |
30 |
06/05/2008 |
04/06/2008 |
| 1429 |
6 |
29 |
05/06/2008 |
03/07/2008 |
| 1429 |
7 |
29 |
04/07/2008 |
01/08/2008 |
| 1429 |
8 |
30 |
02/08/2008 |
31/08/2008 |
| 1429 |
9 |
30 |
01/09/2008 |
30/09/2008 |
| 1429 |
10 |
29 |
01/10/2008 |
29/10/2008 |
| 1429 |
11 |
30 |
30/10/2008 |
28/11/2008 |
| 1429 |
12 |
30 |
29/11/2008 |
28/12/2008 |
BO Class Specs:
Class Name: HijriGreg
Class Member:
- LastTimeDataLoaded: The date/time the data was loaded from
- DayOfWeek: DataSet/DataView loaded from the related table above.
- HijriMonth: DataSet/DataView loaded from the related table above.
- HijriYearMonth: DataSet/DataView loaded from the related conversion table above.
Do you have any comment on how to represent the above data in .NET ? I was thinking to use XML, bu I need a quick and easy way to perform look-up which is probably better done using DataView? I need help in this area.
Comments about Class Members:
I want to load the above DataSet/Views once and make them available to all users (Application Scope) to make it more efficient by minimizing Database Access Operations.
Only for the DataSet of HijriYearMonth Conversion Table must be re-loaded say once every few days or something like that, because it may change at the beginning of every month at worst case.
I can make the above members as Public Shared, but this will violate the concept of Encapsulation, so how I can define them in such a way to make them persistent and available to all the users of the application ? Of course, in this case I have to Synchronize the Locks to the shared resources to make it thread safe. I need help in this area.
Initialization Methods:
I think the initialization methods should be called when needed and must be private. For example:
- Sub HijriGreg.InitializeIfNeeded(): It will check if the class variables are Nothing, and load each each one at a time. For the case of the HijriYearMonth Conversion Table, it will check if the data is expired (using LastTimeDataLoaded) and re-loaded if needed.
- Method/Function HijriGreg.GetHijriFromGreg(...) as String:
- Input: GregDateDMY, a String Variable of input Gregorian Date in DD/MM/YYYY format.
- Output: Returns a String of HijtiDateDMY in DD/MM/YYY format.
I am not sure if this method will be Shared or not ? I need help in this area..
- Method/Function HijriGreg.GetGregFromHijri(...) as String:
- Input: HijriDateDMY, a String Variable of Hijri Date in DD/MM/YYYY format.
- Output: Returns a String of HijtiDateDMY in DD/MM/YYY format.
I am not sure if this method will be Shared or not ? I need help in this area..
The algorithms for the above methods are available with me and already implemented in VBA and it is working properly for the past 5 years.
How to make the BO HijriGreg visible to all users:
Should I create an instance of the HijriGreg Object and store it in Application(..) variable ? So that in the subsequent calls to this object, it can be restored from the Application Variable Objects.
How to make such process thread safe ?
I need help in this area.
After implementing this BO, I need to wrap it in a Web Service. I will talk about this later.
Thank you for your help in advance.
Tarek.