private void UpdateParameters(Document doc)
 {
     try
     {
         if (null != selectedIssue && null != selectedComment)
         {
             foreach (int elementId in selectedIssue.ElementDictionary.Keys)
             {
                 ElementProperties ep  = selectedIssue.ElementDictionary[elementId];
                 bool parameterUpdated = ParameterUtil.UpdateBCFParameters(m_doc, ep, selectedIssue, selectedComment);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to update parameters by selected issues.\n" + ex.Message, "Update Parameters", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        public void Execute(UIApplication app)
        {
            try
            {
                m_doc = app.ActiveUIDocument.Document;

                switch (Request.Take())
                {
                case RequestId.None:
                    return;

                case RequestId.ReadLinkedFileInfo:
                    break;

                case RequestId.UpdateLinkedFileInfo:
                    bool updated = DataStorageUtil.UpdateLinkedBCFFileInfo(m_doc, bcfFileDictionary);
                    Dictionary <string, Dictionary <string, IssueEntry> > dictionary = new Dictionary <string, Dictionary <string, IssueEntry> >();

                    int numCat = categoryNames.Count;
                    AbortFlag.SetAbortFlag(false);
                    progressWindow = new ProgressWindow("Loading BCF issues and images...");
                    progressWindow.Show();

                    foreach (string markupId in bcfFileDictionary.Keys)
                    {
                        LinkedBcfFileInfo bcfInfo = bcfFileDictionary[markupId];
                        if (bcfDictionary.ContainsKey(markupId))
                        {
                            dictionary.Add(markupId, bcfDictionary[markupId]);
                        }
                        else
                        {
                            Dictionary <string, IssueEntry> issueDictionary = GetBCFIssueInfo(m_doc, bcfInfo);
                            if (issueDictionary.Count > 0)
                            {
                                dictionary.Add(markupId, issueDictionary);
                            }
                        }
                    }
                    if (progressWindow.IsActive)
                    {
                        progressWindow.Close();
                    }

                    bcfDictionary = dictionary;

                    if (numCat != categoryNames.Count)
                    {
                        System.IO.MemoryStream stream = BCFParser.CreateCategoryStream(categoryNames);
                        if (null != stream)
                        {
                            Google.Apis.Drive.v2.Data.File file = FileManager.UpdateSpreadsheet(stream, categorySheetId, bcfProjectId);
                        }

                        List <BuiltInCategory> bltCategories = catDictionary.Values.ToList();
                        bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories);

                        foreach (string catName in categoryNames)
                        {
                            var catFound = from category in categoryInfoList where category.CategoryName == catName select category;
                            if (catFound.Count() == 0)
                            {
                                CategoryInfo catInfo = new CategoryInfo(catName, true);
                                categoryInfoList.Add(catInfo);
                            }
                        }
                    }

                    if (null != walkerWindow)
                    {
                        walkerWindow.BCFFileDictionary = bcfFileDictionary;
                        walkerWindow.BCFDictionary     = bcfDictionary;
                        walkerWindow.CategoryInfoList  = categoryInfoList;
                        walkerWindow.CurrentIndex      = 0;
                        walkerWindow.DisplayLinkedBCF();
                    }

                    bool updatedId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId);
                    schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false);

                    if (null != walkerWindow)
                    {
                        walkerWindow.SchemeInfo = schemeInfo;
                        walkerWindow.DisplayColorscheme(schemeInfo);
                    }

                    break;

                case RequestId.ReadProjectId:
                    bcfProjectId = ParameterUtil.GetBCFProjectId(app);
                    break;

                case RequestId.UpdateProjectId:
                    bool updatedProjectId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId);
                    break;

                case RequestId.ReadBCFParameterInfo:
                    break;

                case RequestId.UpdateBCFParameterInfo:
                    bool updatedParameters = ParameterUtil.UpdateBCFParameters(m_doc, currentElement, selectedIssue, selectedComment);
                    break;

                case RequestId.UpdateAction:
                    bool actionUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Action, currentElement.Action);
                    break;

                case RequestId.UpdateResponsibility:
                    bool responsibilityUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Responsibility, currentElement.ResponsibleParty);
                    break;

                case RequestId.CreateIssue:
                    break;

                case RequestId.UpdateViews:
                    IsolateElement(isIsolateOn, m_doc);
                    CreateSectionBox(isSectionBoxOn, m_doc);
                    HighlightElement(isHighlightOn, m_doc);
                    break;

                case RequestId.UpdateParameterByComment:
                    UpdateParameters(m_doc);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to execute an external event.\n" + ex.Message, "Execute Event", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return;
        }