/// <summary>
        /// Removes addins from the ribbon.
        /// </summary>
        /// <param name="addins"></param>
        public void UninstallAddins(ObservableCollection <AddinWrapper> addins)
        {
            foreach (var addin in addins)
            {
                if (!addin.IsSelected)
                {
                    continue;
                }

                // Reset installed version flag to update datagrid control
                addin.InstalledVersion = "Not installed";
                addin.IsInstalled      = false;

                var app1  = AppCommand.Instance.m_app;
                var panel = app1.GetRibbonPanels("  HOK - Beta").FirstOrDefault(x => x.Name == addin.Panel);

                if (string.IsNullOrEmpty(addin.ButtonText))
                {
                    // no UI addin
                    // remove addin file
                    if (File.Exists(InstallDirectory + Path.GetFileName(addin.AddinFilePath)))
                    {
                        try
                        {
                            File.Delete(InstallDirectory + Path.GetFileName(addin.AddinFilePath));
                        }
                        catch
                        {
                            Log.AppendLog(LogMessageType.ERROR, "Could not delete Addin File. Moving on.");
                        }
                    }

                    // (Konrad) We are using Idling event here for the reason that depending on order
                    // at which these buttons are installed or added to the ribbon, at the moment that
                    // we are adding this particular tool, it could not be ready on the ribbon yet,
                    // button variable will be null and we won't be able to disable it.
                    AppCommand.EnqueueTask(app =>
                    {
                        if (panel != null && addin.AdditionalButtonNames != null)
                        {
                            var splits = addin.AdditionalButtonNames.Split(';');
                            foreach (var name in splits)
                            {
                                var button1 = panel.GetItems().FirstOrDefault(x => x.Name == name);
                                if (button1 != null)
                                {
                                    button1.Visible = false;
                                    panel.Visible   = panel.GetItems().Any(x => x.Visible);
                                }
                            }
                        }
                    });
                }

                // (Konrad) Button needs to be disabled after DLLs were removed since it doesn't work anyways.
                var button = panel?.GetItems().FirstOrDefault(x => x.ItemText == addin.ButtonText);
                if (button != null)
                {
                    button.Visible = false;
                    panel.Visible  = panel.GetItems().Any(x => x.Visible);
                }
            }
        }
        /// <summary>
        /// Adds addins to the ribbon.
        /// </summary>
        /// <param name="addins"></param>
        public void InstallUpdateAddins(ObservableCollection <AddinWrapper> addins)
        {
            foreach (var addin in addins)
            {
                if (!addin.IsSelected)
                {
                    continue;
                }

                // (Konrad) Currently the only way to distinguish between ExternalCommands and ExternalApplications
                // is via "ButtonText" attribute. It should be empty for ExternalApplications.
                if (string.IsNullOrEmpty(addin.ButtonText))
                {
                    // no UI addin
                    // move the addin file
                    if (File.Exists(InstallDirectory + Path.GetFileName(addin.AddinFilePath)))
                    {
                        try
                        {
                            File.Delete(InstallDirectory + Path.GetFileName(addin.AddinFilePath));
                        }
                        catch
                        {
                            Log.AppendLog(LogMessageType.ERROR, "Could not delete Addin File. Moving on.");
                        }
                    }
                    File.Copy(TempDirectory + Path.GetFileName(addin.AddinFilePath), InstallDirectory + Path.GetFileName(addin.AddinFilePath));

                    if (!Directory.Exists(
                            InstallDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name))
                    {
                        Directory.CreateDirectory(
                            InstallDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name);
                        CopyAll(TempDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name,
                                InstallDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name);
                    }
                    else
                    {
                        CopyAll(TempDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name,
                                InstallDirectory + new DirectoryInfo(addin.BetaResourcesPath).Name);
                    }

                    // (Konrad) We are using Idling event here for the reason that depending on order
                    // at which these buttons are installed or added to the ribbon, at the moment that
                    // we are adding this particular tool, it could not be ready on the ribbon yet,
                    // button variable will be null and we won't be able to disable it.
                    AppCommand.EnqueueTask(app =>
                    {
                        var panel = app.GetRibbonPanels("  HOK - Beta").FirstOrDefault(x => x.Name == addin.Panel);
                        if (panel != null && addin.AdditionalButtonNames != null)
                        {
                            var splits = addin.AdditionalButtonNames.Split(';');
                            foreach (var name in splits)
                            {
                                var button = panel.GetItems().FirstOrDefault(x => x.Name == name);
                                if (button != null)
                                {
                                    button.Enabled = false;
                                    panel.Visible  = panel.GetItems().Any(x => x.Visible);
                                }
                            }
                        }
                    });
                }
                else
                {
                    var app    = AppCommand.Instance.m_app;
                    var panel  = app.GetRibbonPanels("  HOK - Beta").FirstOrDefault(x => x.Name == addin.Panel);
                    var button = panel?.GetItems().FirstOrDefault(x => x.ItemText == addin.ButtonText);
                    if (button != null)
                    {
                        button.Visible = true;
                        button.Enabled = false;
                        panel.Visible  = panel.GetItems().Any(x => x.Visible);
                        ((PushButton)button).AssemblyName = InstallDirectory + addin.DllRelativePath;
                    }
                }

                // Reset installed version flag to update datagrid control
                addin.InstalledVersion = addin.Version;
                addin.IsInstalled      = true;
            }
        }