/// <summary>
        /// Create call stack pattern and either insert into database or match to existing.
        /// Update Associate Buggs.
        /// </summary>
        /// <param name="newCrash"></param>
        private void BuildPattern(Crash newCrash)
        {
            var callstack = new CallStackContainer(newCrash);

            newCrash.Module = callstack.GetModuleName();
            if (newCrash.PatternId == null)
            {
                var patternList = new List <string>();

                try
                {
                    foreach (var entry in callstack.CallStackEntries.Take(CallStackContainer.MaxLinesToParse))
                    {
                        FunctionCall currentFunctionCall;

                        var csEntry = entry;
                        if (_unitOfWork.FunctionRepository.Any(f => f.Call == csEntry.FunctionName))
                        {
                            currentFunctionCall = _unitOfWork.FunctionRepository.First(f => f.Call == csEntry.FunctionName);
                        }
                        else
                        {
                            currentFunctionCall = new FunctionCall {
                                Call = csEntry.FunctionName
                            };
                            _unitOfWork.FunctionRepository.Save(currentFunctionCall);
                            _unitOfWork.Save();
                        }

                        patternList.Add(currentFunctionCall.Id.ToString());
                    }

                    newCrash.Pattern = string.Join("+", patternList);
                }
                catch (Exception ex)
                {
                    var messageBuilder = new StringBuilder();
                    FLogger.Global.WriteException("Build Pattern exception: " + ex.Message.ToString(CultureInfo.InvariantCulture));
                    messageBuilder.AppendLine("Exception was:");
                    messageBuilder.AppendLine(ex.ToString());
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        messageBuilder.AppendLine(ex.ToString());
                    }

                    _slackWriter.Write("Build Pattern Exception : " + ex.Message.ToString(CultureInfo.InvariantCulture));
                    throw;
                }
            }
        }
        /// <summary>
        /// Show detailed information about a crash.
        /// </summary>
        /// <param name="CrashesForm">A form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the crash we wish to show the details of.</param>
        /// <returns>A view to show crash details.</returns>
        public ActionResult Show(FormCollection CrashesForm, int id)
        {
            using (var logTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(CrashId=" + id + ")", bCreateNewLog: true))
            {
                CallStackContainer currentCallStack = null;

                // Update the selected crash based on the form contents
                var currentCrash = _unitOfWork.CrashRepository.GetById(id);

                if (currentCrash == null)
                {
                    return(RedirectToAction("Index"));
                }

                string FormValue;

                FormValue = CrashesForm["SetStatus"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.Status = FormValue;
                }

                FormValue = CrashesForm["SetFixedIn"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.FixedChangeList = FormValue;
                }

                FormValue = CrashesForm["SetTTP"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.Jira = FormValue;
                }

                // Valid to set description to an empty string
                FormValue = CrashesForm["Description"];
                if (FormValue != null)
                {
                    currentCrash.Description = FormValue;
                }

                currentCallStack    = new CallStackContainer(currentCrash);
                currentCrash.Module = currentCallStack.GetModuleName();

                //Set call stack properties
                currentCallStack.bDisplayModuleNames          = true;
                currentCallStack.bDisplayFunctionNames        = true;
                currentCallStack.bDisplayFileNames            = true;
                currentCallStack.bDisplayFilePathNames        = true;
                currentCallStack.bDisplayUnformattedCallStack = false;

                currentCrash.CallStackContainer = new CallStackContainer(currentCrash);

                // Populate the crash with the correct user data
                //_crashRepo.PopulateUserInfo( CurrentCrash );
                //_crashRepo.SubmitChanges();

                var Model = new CrashViewModel {
                    Crash = currentCrash, CallStack = currentCallStack
                };
                Model.GenerationTime = logTimer.GetElapsedSeconds().ToString("F2");
                return(View("Show", Model));
            }
        }
	    /// <summary>
	    /// Create call stack pattern and either insert into database or match to existing.
	    /// Update Associate Buggs.
	    /// </summary>
	    /// <param name="newCrash"></param>
	    private void BuildPattern(Crash newCrash)
	    {
	        var callstack = new CallStackContainer(newCrash);
	        newCrash.Module = callstack.GetModuleName();
	        if (newCrash.PatternId == null)
	        {
	            var patternList = new List<string>();

	            try
	            {
	                foreach (var entry in callstack.CallStackEntries.Take(CallStackContainer.MaxLinesToParse))
	                {
	                    FunctionCall currentFunctionCall;

	                    var csEntry = entry;
	                    if (_unitOfWork.FunctionRepository.Any(f => f.Call == csEntry.FunctionName))
	                    {
                            currentFunctionCall = _unitOfWork.FunctionRepository.First(f => f.Call == csEntry.FunctionName);
	                    }
	                    else
	                    {
	                        currentFunctionCall = new FunctionCall { Call = csEntry.FunctionName };
	                        _unitOfWork.FunctionRepository.Save(currentFunctionCall);
	                        _unitOfWork.Save();
	                    }

	                    patternList.Add(currentFunctionCall.Id.ToString());
	                }

	                newCrash.Pattern = string.Join("+", patternList);
	            }
	            catch (Exception ex)
	            {
                    var messageBuilder = new StringBuilder();
                    FLogger.Global.WriteException("Build Pattern exception: " + ex.Message.ToString(CultureInfo.InvariantCulture));
                    messageBuilder.AppendLine("Exception was:");
                    messageBuilder.AppendLine(ex.ToString());
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                        messageBuilder.AppendLine(ex.ToString());
                    }

                    _slackWriter.Write("Build Pattern Exception : " + ex.Message.ToString(CultureInfo.InvariantCulture));
                    throw;
	            }
	        }
	    }
		/// <summary>
		/// Show detailed information about a crash.
		/// </summary>
		/// <param name="CrashesForm">A form of user data passed up from the client.</param>
		/// <param name="id">The unique id of the crash we wish to show the details of.</param>
		/// <returns>A view to show crash details.</returns>
		public ActionResult Show( FormCollection CrashesForm, int id )
		{
			using( var logTimer = new FAutoScopedLogTimer( this.GetType().ToString() + "(CrashId=" + id + ")", bCreateNewLog: true ) )
			{
				CallStackContainer currentCallStack = null;

				// Update the selected crash based on the form contents
                var currentCrash = _unitOfWork.CrashRepository.GetById(id);
                
				if( currentCrash == null )
				{
					return RedirectToAction( "Index" );
				}

				string FormValue;

				FormValue = CrashesForm["SetStatus"];
				if( !string.IsNullOrEmpty( FormValue ) )
				{
					currentCrash.Status = FormValue;
				}

				FormValue = CrashesForm["SetFixedIn"];
				if( !string.IsNullOrEmpty( FormValue ) )
				{
					currentCrash.FixedChangeList = FormValue;
				}

				FormValue = CrashesForm["SetTTP"];
				if( !string.IsNullOrEmpty( FormValue ) )
				{
					currentCrash.Jira = FormValue;
				}

				// Valid to set description to an empty string
				FormValue = CrashesForm["Description"];
				if( FormValue != null )
				{
					currentCrash.Description = FormValue;
				}

				currentCallStack = new CallStackContainer( currentCrash );
			    currentCrash.Module = currentCallStack.GetModuleName();

				//Set call stack properties
				currentCallStack.bDisplayModuleNames = true;
				currentCallStack.bDisplayFunctionNames = true;
				currentCallStack.bDisplayFileNames = true;
				currentCallStack.bDisplayFilePathNames = true;
				currentCallStack.bDisplayUnformattedCallStack = false;

				currentCrash.CallStackContainer = new CallStackContainer(currentCrash);

				// Populate the crash with the correct user data
				//_crashRepo.PopulateUserInfo( CurrentCrash );
				//_crashRepo.SubmitChanges();

				var Model = new CrashViewModel { Crash = currentCrash, CallStack = currentCallStack };
				Model.GenerationTime = logTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Show", Model );
			}
		}