/// <summary>
        /// The add basic program to collection.
        /// </summary>
        /// <param name="basicProgramDescription">
        /// The basic program description.
        /// </param>
        /// <param name="processLoadState">
        /// The process load state.
        /// </param>
        private void AddBasicProgramToCollection(DefinitionDescription basicProgramDescription, ProcessLoadState processLoadState = null)
        {
            if (DebugWindowManager.DebugConsoleWindow == null)
            {
                return;
            }

            if (basicProgramDescription == null)
            {
                CustomLogger.LogError(() => "A null basic program description was passed to AddBasicProgramToCollection.");
                return;
            }

            JobManager.RunInDispatcherThread(
                DebugWindowManager.DebugConsoleWindow.Dispatcher,
                DispatcherPriority.Normal,
                delegate
                    {
                        try
                        {
                            if (processLoadState == null)
                            {
                                CustomLogger.LogError(() => "A nullprocessLoadState was passed to AddBasicProgramToCollection.");
                                return;
                            }

                            if (processLoadState.ParentDefinitionDescription == null)
                            {
                                this.Definition = basicProgramDescription;
                                this.ProcessStack.Clear();
                                this.ProcessStack.Push(this.Definition);
                            }
                            else
                            {
                                this.AddItemToCollection(
                                    processLoadState.ParentDefinitionDescription.ProcessCollection,
                                    new ProcessCall
                                        {
                                            Description = processLoadState.HookPoint,
                                            ProcessDescription = basicProgramDescription
                                        });
                            }
                        }
                        catch (Exception ex)
                        {
                            CustomLogger.LogException(
                                ex,
                                "There was a problem adding " + basicProgramDescription.Name + " to the collection.");
                        }
                    });
        }
        /// <summary>
        /// This method will parse out the definition and figure out the type of definition.
        /// </summary>
        /// <param name="processFileName">
        /// The name of the file that contains the process.
        /// </param>
        /// <param name="pName">
        /// The name of the definition.
        /// </param>
        /// <param name="defn">
        /// The definition description.
        /// </param>
        /// <param name="processLoadState">
        /// The information about the definition definition passed from the calling routine.
        /// </param>
        /// <returns>
        /// The <see cref="DefinitionDescription"/>.
        /// </returns>
        private DefinitionDescription CreateProcessDescription(
            string processFileName,
            string pName,
            SBString defn,
            ProcessLoadState processLoadState)
        {
            DefinitionDescription processDescription;
            if (defn == null)
            {
                if (processLoadState.Source == SourceDefinition.Button)
                {
            /*
                    processDescription = new ButtonDefinitionDescription()
                                             {
                                                 Description = processLoadState.HookPoint,
                                                 pName,
                                                 Source
                                             };
            */
                    processDescription = new ButtonDefinitionDescription(
                        processFileName,
                        pName,
                        SourceDefinition.Process,
                        processLoadState.Expression);
                }
                else
                {
                    processDescription = new DefinitionDescription(
                                                processFileName,
                                                pName,
                                                SourceDefinition.Process,
                                                processLoadState.Expression)
                                                {
                                                    IsError = true
                                                };

                }
                return processDescription;
            }

            switch (defn.Extract(1).Value)
            {
                case "I":
                    processDescription = new InputDefinitionDescription(processFileName, pName, processLoadState.Expression, defn);
                    break;
                case "O":
                    processDescription = new OutputDefinitionDescription(processFileName, pName, processLoadState.Expression, defn);
                    break;
                case "P":
                    processDescription = this.CreateParagraphDescription(processFileName, pName, processLoadState.Expression, defn);
                    break;
                case "SCREEN":
                    processDescription = new ScreenDefintion(processFileName, pName, string.Empty, defn);
                    break;
                case "F":
                    processDescription = new FileUpdateDefinitionDescription(processFileName, pName, string.Empty, defn);
                    break;
                case "M":
                    processDescription = new MenuDefinitionDescription(processFileName, pName, string.Empty, defn);
                    break;
                case "S":
                    processDescription = new SelectionProcessDescription(processFileName, pName, SourceDefinition.Process, processLoadState.SysId, defn);
                    break;
                default:
                    processDescription = new DefinitionDescription(
                        processFileName,
                        pName,
                        SourceDefinition.Process,
                        processLoadState.Expression);
                    break;
            }

            return processDescription;
        }
        private void DoAddProcessToCollection(string processFileName, string pName, SBString defn, ProcessLoadState processLoadState, bool isError)
        {
            try
            {
                if (processLoadState == null)
                {
                    return;
                }

                // top of tree so just assign it.
                var processDescription = this.CreateProcessDescription(processFileName, pName, defn, processLoadState);
                processDescription.IsError = isError;

                // Add the definition to the total collection if it is not already there. It should never be there already as
                // we should have bypassed the load if it is.
                lock (this.processCollection)
                {
                    if (!this.processCollection.ContainsKey(processFileName, pName, processDescription.GetType()))
                    {
                        this.processCollection.Add(processDescription);
                    }
                }

                this.AddProcessToCollection(
                    processLoadState.HookPoint,
                    processLoadState.ParentDefinitionDescription,
                    processDescription,
                    processLoadState.Source);
            }
            catch (Exception ex)
            {
                CustomLogger.LogException(
                    ex,
                    string.Format("There was a problem when adding {0} {1} to the collection.", processFileName, pName));
            }
        }
        /// <summary>
        /// The add process to collection.
        /// </summary>
        /// <param name="processFileName">
        /// The process file name.
        /// </param>
        /// <param name="pName">
        /// The p name.
        /// </param>
        /// <param name="defn">
        /// The defn.
        /// </param>
        /// <param name="processLoadState">
        /// The process load state.
        /// </param>
        /// <param name="isError">
        /// The is error.
        /// </param>
        private void AddProcessToCollection(
            string processFileName,
            string pName,
            SBString defn,
            ProcessLoadState processLoadState = null,
            bool isError = false)
        {
            if (DebugWindowManager.DebugConsoleWindow == null || processLoadState == null)
            {
                return;
            }

            if (Thread.CurrentThread == DebugWindowManager.DebugConsoleWindow.Dispatcher.Thread)
            {
                this.DoAddProcessToCollection(processFileName, pName, defn, processLoadState, isError);
            }
            else
            {

            JobManager.RunInDispatcherThread(
                DebugWindowManager.DebugConsoleWindow.Dispatcher,
                DispatcherPriority.Normal,
                ()=> this.DoAddProcessToCollection(processFileName, pName, defn, processLoadState, isError));
            }
        }