Jun 30 2010

Comment by Seth Spearman on Why does the VS 2010 ASP .NET ReportViewer fail to render parameters when a custom RoleProvider is specified?

Chris, I recommend that you change your tags. There is a ssrs tag and a reporting-services tag...maybe that will get you more responses. Seth
Jun 24 2010

RT IronPython tools: Python ID…

RT IronPython tools: Python IDE in Visual Studio http://ironpython.net/tools/ #ironpython #vs2010
Jun 11 2010

Comment by Seth Spearman on Proper way to dispose of Quartz.NET?

MaLio...thanks...you are right. That's an old habit harking back to VBA. Seth
Jun 10 2010

If you are a developer who uses Microsoft tools, please read!

If you are a Microsoft Developer who is a Microsoft Partner and small business owner...this is for you. I am going to keep this short by assuming you already know about MAPS (Microsoft Action Pack Subscription).  If not just google it. What you may not know is that in late June Microsoft is going release a version of MAPS which includes Visual Studio 2010 Professional.  This is significant because no previous MAPS included Visual Studio.  Kewl!! Here is the info. https://partner.microsoft.com/US/program/40138499 The purpose of this email is to let you know that if you pre-register for this MAPS subscription now Microsoft is offering a 15% discount on it...but you have to pre-register between now and June 20. Look at the top of this page and to register. https://partner.microsoft.com/US/program/40132997 Seth
Jun 07 2010

Proper way to dispose of Quartz.NET?

I am using Quartz.NET in an application. What is the proper way to dispose of Quartz.NET.

Right now I am just doing

    if (_quartzScheduler != null)
    {
        _quartzScheduler = null;
    }

Is that enough or should I implement a dispose or something in the jobType class?

Seth

Jun 07 2010

Proper way to dispose of Quartz.NET?

I am using Quartz.NET in an application. What is the proper way to dispose of Quartz.NET.

Right now I am just doing

    if (_quartzScheduler != null)
    {
        _quartzScheduler = null;
    }

Is that enough or should I implement a dispose or something in the jobType class?

Seth

Jun 02 2010

How do you make a Factory that can return derived types?

I have created a factory class called AlarmFactory as such...

1    class AlarmFactory
2    {
3        public static Alarm GetAlarm(AlarmTypes alarmType)  //factory ensures that correct alarm is returned and right func pointer for trigger creator.
4        {
5            switch (alarmType)
6            {
7                case AlarmTypes.Heartbeat:
8                    HeartbeatAlarm alarm = HeartbeatAlarm.GetAlarm();
9                    alarm.CreateTriggerFunction = QuartzAlarmScheduler.CreateMinutelyTrigger;
10                    return alarm;
11
12                   break;
13                default:
14                
15                    break;
16            }
17        }
18    }

Heartbeat alarm is derived from Alarm. I am getting a compile error "cannot implicitly convert type...An explicit conversion exists (are you missing a cast?)". How do I set this up to return a derived type?

EDIT

THANK YOU ALL FOR YOUR ANSWERS. I fixed the compile error within ten minutes which is why i did not post the whole error. But I appreciated the different approaches that were mentioned.

For the record it was "Cannot implicitly convert type 'goAlarmsCS.HeartbeatAlarm' to 'goAlarmsCS.Alarm' An explicit conversion exists (are you missing a cast?)". (I think.) The error was occurring on line 8.

Seth

Jun 02 2010

How do you make a Factory that can return derived types?

        I have created a factory class called AlarmFactory as such...
1    class AlarmFactory
2    {
3        public static Alarm GetAlarm(AlarmTypes alarmType)  //factory ensures that correct alarm is returned and right func pointer for trigger creator.
4        {
5            switch (alarmType)
6            {
7                case AlarmTypes.Heartbeat:
8                    HeartbeatAlarm alarm = HeartbeatAlarm.GetAlarm();
9                    alarm.CreateTriggerFunction = QuartzAlarmScheduler.CreateMinutelyTrigger;
10                    return alarm;
11
12                   break;
13                default:
14                
15                    break;
16            }
17        }
18    }
Heartbeat alarm is derived from Alarm. I am getting a compile error "cannot implicitly convert type...An explicit conversion exists (are you missing a cast?)". How do I set this up to return a derived type? EDIT THANK YOU ALL FOR YOUR ANSWERS. I fixed the compile error within ten minutes which is why i did not post the whole error. But I appreciated the different approaches that were mentioned. For the record it was "Cannot implicitly convert type 'goAlarmsCS.HeartbeatAlarm' to 'goAlarmsCS.Alarm' An explicit conversion exists (are you missing a cast?)". (I think.) The error was occurring on line 8. Seth
Jun 01 2010

Design Question – how do you break the dependency between classes using an interface?

Hello, I apologize in advance but this will be a long question.

I'm stuck. I am trying to learn unit testing, C#, and design patterns - all at once. (Maybe that's my problem.) As such I am reading the Art of Unit Testing (Osherove), and Clean Code (Martin), and Head First Design Patterns (O'Reilly).

I am just now beginning to understand delegates and events (which you would see if you were to troll my SO questions of recent). I still don't quite get lambdas.

To contextualize all of this I have given myself a learning project I am calling goAlarms. I have an Alarm class with members you'd expect (NextAlarmTime, Name, AlarmGroup, Event Trigger etc.)

I wanted the "Timer" of the alarm to be extensible so I created an IAlarmScheduler interface as follows...

public interface AlarmScheduler
{
    Dictionary<string,Alarm> AlarmList { get; }
    void Startup();
    void Shutdown();
    void AddTrigger(string triggerName, string groupName, Alarm alarm);
    void RemoveTrigger(string triggerName);
    void PauseTrigger(string triggerName);
    void ResumeTrigger(string triggerName);
    void PauseTriggerGroup(string groupName);
    void ResumeTriggerGroup(string groupName);
    void SetSnoozeTrigger(string triggerName, int duration);
    void SetNextOccurrence (string triggerName, DateTime nextOccurrence);
}

This IAlarmScheduler interface define a component that will RAISE an alarm (Trigger) which will bubble up to my Alarm class and raise the Trigger Event of the alarm itself. It is essentially the "Timer" component.

I have found that the Quartz.net component is perfectly suited for this so I have created a QuartzAlarmScheduler class which implements IAlarmScheduler.

All that is fine. My problem is that the Alarm class is abstract and I want to create a lot of different KINDS of alarm. For example, I already have a Heartbeat alarm (triggered every (int) interval of minutes), AppointmentAlarm (triggered on set date and time), Daily Alarm (triggered every day at X) and perhaps others.

And Quartz.NET is perfectly suited to handle this.

My problem is a design problem. I want to be able to instantiate an alarm of any kind without my Alarm class (or any derived classes) knowing anything about Quartz. The problem is that Quartz has awesome factories that return just the right setup for the Triggers that will be needed by my Alarm classes. So, for example, I can get a Quartz trigger by using TriggerUtils.MakeMinutelyTrigger to create a trigger for the heartbeat alarm described above. Or TriggerUtils.MakeDailyTrigger for the daily alarm.

I guess I could sum it up this way. Indirectly or directly I want my alarm classes to be able to consume the TriggerUtils.Make* classes without knowing anything about them. I know that is a contradiction, but that is why I am asking the question.

I thought about putting a delegate field into the alarm which would be assigned one of these Make method but by doing that I am creating a hard dependency between alarm and Quartz which I want to avoid for both unit testing purposes and design purposes. I thought of using a switch for the type in QuartzAlarmScheduler per here but I know it is bad design and I am trying to learn good design.

If I may editorialize a bit. I've decided that coding (predefined) classes is easy. Design is HARD...in fact, really hard and I am really fighting feeling stupid right now. I guess I want to know if you really smart people took a while to really understand and master this stuff or should I feel stupid (as I do) because I haven't grasped it better in the couple of weeks/months I have been studying.

You guys are awesome and thanks in advance for your answers.

Seth

Jun 01 2010

Is there a way to know in VB.NET if a handler has been registered for an event?

In C# I can test for this...

public event EventHandler Trigger;
protected void OnTrigger(EventArgs e)
{
    if (Trigger != null)
        Trigger(this, e);
}

Is there a way to do this in VB.NET? Test for null I mean?

MORE INFO

I forgot to mention. I have classes written in C# but I am writing my unit tests in VB.NET.

I am trying this in the unit test...

If myObject.Trigger IsNot Nothing Then  
    ''#do something
End If

This is causing a compile time error which says ... "Public Event Trigger is an Event and cannot be called directly. Use the RaiseEvent statement to raise an event."

Seth