patterncsharpMinor
Interface for a CRM system
Viewed 0 times
interfacesystemforcrm
Problem
I have a CRM system that has Notes, Payments, DairyEvents and anything else that needs to be bolt on over time.
I created an
This is the simplest form of code I have started with:
That is fine, as long as one of the controllers doesn't throw and error, then the whole Interface collapses. I had something similar happen on a another project, production environment, where a single provider went haywire due a bug on their system, amongst several other providers that were being interfaced with and worked fine. It wouldn't be so bad if it didn't crash all 600+ sites, just because of that mistake somebody else made.
I don't want to do try catches around every single addrange - I think that is just cluttering. Also, with integration like that, you build things to work, but exceptions happens here and there.
What is a proper way of taking data from various sources, controllers or integration, adding them to a collection of items for the interface? That way, if something fails in the middle, it won't bring down the entire page, or even worse, the whole framework.
I created an
ITimeline interface that has a datetime and message method and implemented them on those models.This is the simplest form of code I have started with:
public static List GetAll(long personID)
{
List timelineEvents = new List();
timelineEvents.AddRange(Controllers.FollowUp.GetAll(personID));
//add more to the list as the system grows
return timelineEvents;
}That is fine, as long as one of the controllers doesn't throw and error, then the whole Interface collapses. I had something similar happen on a another project, production environment, where a single provider went haywire due a bug on their system, amongst several other providers that were being interfaced with and worked fine. It wouldn't be so bad if it didn't crash all 600+ sites, just because of that mistake somebody else made.
I don't want to do try catches around every single addrange - I think that is just cluttering. Also, with integration like that, you build things to work, but exceptions happens here and there.
What is a proper way of taking data from various sources, controllers or integration, adding them to a collection of items for the interface? That way, if something fails in the middle, it won't bring down the entire page, or even worse, the whole framework.
Solution
The error should be caught where it occurs, namely in the controller. If possible try to implement something like this
The advantage of this approach is that the error does not get swallowed up silently by some try-catch-statement. You get a Boolean return value from
If you cannot alter the
TimelineEventCollection personTimelineEvents; // Change to the appropriate collection type.
if (Controllers.FollowUp.TryGetAll(personID, out personTimelineEvents)) {
timelineEvents.AddRange(personTimelineEvents);
}The advantage of this approach is that the error does not get swallowed up silently by some try-catch-statement. You get a Boolean return value from
TryGetAll telling you if all went right. At the same time the basic error handling happens in a low level method and not in your list filling routine.If you cannot alter the
Controllers.FollowUp class, you can still write an extension method giving you the same functionality.Code Snippets
TimelineEventCollection personTimelineEvents; // Change to the appropriate collection type.
if (Controllers.FollowUp.TryGetAll(personID, out personTimelineEvents)) {
timelineEvents.AddRange(personTimelineEvents);
}Context
StackExchange Code Review Q#47267, answer score: 4
Revisions (0)
No revisions yet.