LDSTechForumProjects

Recommended .NET Development Standards Quick Reference

This article is in a draft stage.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lds.Stack.Library;

namespace Lds.GA.MemberTracker.Services
{
   /// <summary>
   /// Implements member tracking functionality.
   /// </summary>
   public sealed class MemberTracker : IMemberTracker
   {
      private const string FakeMrn = "98349835943884";


      private int _memberTrackingCount;
  

 
      /// <summary>
      /// Occurs when a member has been tracked.
      /// </summary>
      public event EventHandler MemberTracked;
  
      /// <summary>
      /// Constructor
      /// </summary>
      public MemberTrackerService()
      {
      }
     
      /// <summary>
      /// Gets or sets the type of member to track.
      /// </summary>
      public MemberType MemberTypeToTrack { get; set; }

      /// <summary>
      /// Resets member tracking count;
      /// </summary>
      public void Reset()
      {
            _memberTrackingCount = 0;
      }


      #region IMemberTracker Members
      /// <summary>
      /// Tracks the member by the specified LDS Account identifier.
      /// </summary>
      /// <param name="ldsAccountId">LDS Account identifier of the member to track.</param>
      public void TrackMember(long ldsAccountId)
      {
            MemberType memberType;
            string memberRecordNumber;
 
            memberType = GetMemberType(ldsAccountId);
            memberRecordNumber = GetMrn(ldsAccountId);
           
            using (SomeFileResource)
            {
                 //Make sure to use using statements with resources that
                 //implement IDisposable so that they are automatically disposed of when
                 //they go out of scope
 
            }
 
            if (memberType == this.MemberTypeToTrack)
            {
                  _memberTrackingCount++;

                  if (MemberTracked != null)
                  {
                        MemberTracked(this, new EventArgs());
                  }
            }
      }
      #endregion IMemberTracker Members 

 
      /// <summary>
      /// Gets the member record number of the member by the specified LDS Account identifier.
      /// </summary>
      /// <param name="ldsAccountId">Identifier of the member whose MRN to retrieve.</param>
      /// <returns>MRN of the specified member.</returns>
      [OperationContract]
      private string GetMrn(long ldsAccountId)
      {
            return FakeMrn;
      }

 
      /// <summary>
      /// Gets the type of the member by the specified LDS Account identifier.
      /// </summary>
      /// <param name="ldsAccountId">Identifier of the member whose type to retrieve.</param>
      /// <returns>Member type of the specified member.</returns>
      private MemberType GetMemberType(long ldsAccountId)
      {
            try
            {
                  return MemberType.HundredPercentHomeTeacher;
            }
            catch (Exception ex)
            {
                  throw new MemberTrackingException("Failed to retrieve member's type.", ex);
            }
      }
   }
}
This page was last modified on 6 December 2012, at 16:27.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.