public AddinInstallerViewModel(AddinInstallerModel model)
        {
            Model  = model;
            Addins = Model.Addins;
            Title  = "Beta Tools - Beta Installer v." + Assembly.GetExecutingAssembly().GetName().Version;

            CloseCommand     = new RelayCommand <Window>(OnCloseCommand);
            CheckAll         = new RelayCommand(OnCheckAll);
            CheckNone        = new RelayCommand(OnCheckNone);
            InstallCommand   = new RelayCommand <Window>(OnInstall);
            UninstallCommand = new RelayCommand <Window>(OnUninstall);
            WindowLoaded     = new RelayCommand <Window>(OnWindowLoaded);
            WindowClosing    = new RelayCommand <Window>(OnWindowClosing);
            SubmitComment    = new RelayCommand(OnSubmitComment);
        }
        public Result OnStartup(UIControlledApplication application)
        {
            Instance = this;
            m_app    = application;
            var versionNumber = m_app.ControlledApplication.VersionNumber;

            Tasks = new Queue <Action <UIApplication> >();

            application.Idling += OnIdling;

            try
            {
                m_app.CreateRibbonTab(tabName);
            }
            catch
            {
                Log.AppendLog(LogMessageType.WARNING, "Ribbon tab was not created. It might already exist.");
            }

            var panelsVisibility = new Dictionary <string, bool>();

            ViewModel = new AddinInstallerModel(versionNumber);
            foreach (var addin in ViewModel.Addins)
            {
                // (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))
                {
                    if (addin.IsInstalled)
                    {
                        if (File.Exists(ViewModel.InstallDirectory + Path.GetFileName(addin.AddinFilePath)))
                        {
                            try
                            {
                                File.Delete(ViewModel.InstallDirectory + Path.GetFileName(addin.AddinFilePath));
                            }
                            catch
                            {
                                Log.AppendLog(LogMessageType.ERROR, "Could not delete existing Addin Manifest.");
                            }
                        }
                        File.Copy(ViewModel.TempDirectory + Path.GetFileName(addin.AddinFilePath), ViewModel.InstallDirectory + Path.GetFileName(addin.AddinFilePath));

                        if (addin.AdditionalButtonNames != null)
                        {
                            if (panelsVisibility.ContainsKey(addin.Panel))
                            {
                                panelsVisibility.Remove(addin.Panel);
                            }

                            panelsVisibility.Add(addin.Panel, true);
                        }
                    }
                    continue;
                }

                // (Konrad) Temp path dll, to file moved from install location
                // Keeps install location free from being locked by Revit.
                // If addin hasn't been installed yet, we create a button for it,
                // but assign it a Temp.dll reference so that we can re-assign it later.
                var relativePath = addin.DllRelativePath.Replace("Temp\\", "");
                var dllPath      = addin.IsInstalled ? ViewModel.InstallDirectory + relativePath : ViewModel.TempDirectory + "Temp.dll";

                var panel = m_app.GetRibbonPanels("  HOK - Beta").FirstOrDefault(x => x.Name == addin.Panel)
                            ?? m_app.CreateRibbonPanel(tabName, addin.Panel);

                var button = (PushButton)panel.AddItem(new PushButtonData(addin.Name + "_Command", addin.ButtonText, dllPath, addin.CommandNamespace));
                button.LargeImage = addin.Image;
                button.ToolTip    = addin.Description;

                button.Visible = addin.IsInstalled;

                if (panelsVisibility.ContainsKey(addin.Panel))
                {
                    if (panelsVisibility[addin.Panel])
                    {
                        panel.Visible = true;
                    }
                }
                else
                {
                    panel.Visible = panel.GetItems().Any(x => x.Visible);
                }
            }

            currentAssembly = Assembly.GetAssembly(GetType()).Location;
            CreateInstallerPanel();

            return(Result.Succeeded);
        }