/// <summary>
        /// Set Enclosure flag
        /// </summary>
        /// <param name="obj">ActiveMapViewChangedEventArgs</param>
        private void OnActiveMapViewChanged(ActiveMapViewChangedEventArgs obj)
        {
            if (obj == null || obj.IncomingView == null || obj.IncomingView.Map == null)
            {
                FrameworkApplication.State.Deactivate(EnableEnclosure);
                return;
            }

            QueuedTask.Run(() =>
            {
                using UtilityNetwork un = GetUtilityNetworkFromActiveMap();
                using DiagramManager dm = un?.GetDiagramManager();
                try
                {
                    DiagramTemplate dt = dm?.GetDiagramTemplate(csTemplateName);
                    if (dt == null)
                    {
                        FrameworkApplication.State.Deactivate(EnableEnclosure);
                    }
                    else
                    {
                        FrameworkApplication.State.Activate(EnableEnclosure);
                    }
                }
                catch
                {
                    FrameworkApplication.State.Deactivate(EnableEnclosure);
                }
            });
        }
        /// <summary>
        /// Generate a diagram and apply the EnclosureLayout custom telco layout on its content
        /// </summary>
        /// <param name="cps">Cancelable Progressor Source to show the progression</param>
        /// <returns>An error comment if needed, empty of no error</returns>
        private async Task <string> RunCancelableEnclosure(CancelableProgressorSource cps)
        {
            string         status    = "";
            List <Guid>    listIds   = null;
            NetworkDiagram myDiagram = null;

            await QueuedTask.Run(() =>
            {
                cps.Progressor.Max = 3;

                cps.Progressor.Value  += 0;
                cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                cps.Progressor.Message = "Step 1 – Get Selected Guids";

                try
                {
                    if (m_DiagramManager == null)
                    {
                        UtilityNetwork un = GetUtilityNetworkFromActiveMap();
                        if (un == null)
                        {
                            return;
                        }

                        m_DiagramManager = un.GetDiagramManager();

                        if (m_DiagramManager == null)
                        {
                            return;
                        }
                    }

                    if (m_Template == null)
                    {
                        m_Template = m_DiagramManager.GetDiagramTemplate(csTemplateName);
                        if (m_Template == null)
                        {
                            return;
                        }
                    }

                    listIds = GetSelectedGuidFromActiveMap();
                    if (listIds.Count == 0)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    status = string.Format("Selected guids\n{0}", ExceptionFormat(ex));
                }
            }, cps.Progressor);

            await QueuedTask.Run(() =>
            {
                cps.Progressor.Value  += 1;
                cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                cps.Progressor.Message = string.Format("Step 2 – Generate a diagram based on the '{0}' template", csTemplateName);

                try
                {
                    // generate a diagram
                    myDiagram = m_DiagramManager.CreateNetworkDiagram(diagramTemplate: m_Template, globalIDs: listIds);
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(status))
                    {
                        status = string.Format("Generate diagram\n{0}", ExceptionFormat(ex));
                    }
                    else
                    {
                        status = string.Format("Generate diagram\n{0}", ExceptionFormat(ex));
                    }
                }
            }, cps.Progressor);

            await QueuedTask.Run(() =>
            {
                cps.Progressor.Value  += 1;
                cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                cps.Progressor.Message = "Step 3 – Apply the EnclosureLayout custom telco layout";

                try
                {
                    // apply the telco custom layout
                    EnclosureLayout myLayout = new EnclosureLayout();
                    myLayout.Execute(myDiagram);

                    ShowDiagram(myDiagram);
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(status))
                    {
                        status = string.Format("Apply layout\n{0}", ExceptionFormat(ex));
                    }
                    else
                    {
                        status = string.Format("Apply layout\n{0}", ExceptionFormat(ex));
                    }
                }
            });

            return(status);
        }