Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            ////todo: this sets the ResourceAssembly of Revit itself, so it will break other addins that try to set or access the ResourceAssembly
            if (System.Windows.Application.ResourceAssembly == null)
            {
                System.Windows.Application.ResourceAssembly = Assembly.GetExecutingAssembly();
            }

            //Set up tab and panel
            String tabName = "DK";

            try //an exception will be thrown if the tab already exists
            {
                application.CreateRibbonTab(tabName);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException e)
            {
                //ignore
            }

            //setup the ui on the Ribbon
            PushButtonData AutoOptionsConfigCommandPushButtonData =
                new PushButtonData(
                    "AutoOptionsConfigCommandButton", //name of the button
                    "Auto Options",                   //text on the button
                    FileLocations.AssemblyFullPath,
                    "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommand"
                    );

            AutoOptionsConfigCommandPushButtonData.AvailabilityClassName =
                "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommandAvailability";
            AutoOptionsConfigCommandPushButtonData.LargeImage =
                new BitmapImage(new Uri("pack://application:,,,/resources/ao_large.jpg"));

            RibbonPanel AutoOptionsRibbonPanel = application.CreateRibbonPanel(tabName, "Auto Options");

            AutoOptionsRibbonPanel.AddItem(AutoOptionsConfigCommandPushButtonData);

            //assign the dispatcher object using the singleton instance. The singleton will be initialized at this time
            dispatcher = AutoOptionsDispatcher.Instance;
            //load the settings to use in this session
            IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();

            dispatcher.SetOptions(settingsRepo.LoadAutoOptions());
            //register the event handler
            application.ControlledApplication.FailuresProcessing += dispatcher.AutoOptionsFailureHandler;

            return(Result.Succeeded);
        }
        Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            ////FileLocations.AddInDirectory = application.ControlledApplication.AllUsersAddinsLocation + @"\AutoOptions\";
            //String msg = String.Empty;
            ////todo: this sets the ResourceAssembly of Revit itself, so it will break other addins that try to set or access the ResourceAssembly
            if (System.Windows.Application.ResourceAssembly == null)
            {
                //msg += "Resource Assembly is Null -- Setting\n";
                System.Windows.Application.ResourceAssembly = Assembly.GetExecutingAssembly();
            }
            //msg += "Resource Assembly: " + System.Windows.Application.ResourceAssembly.FullName + "\nExecuting Assembly: " + Assembly.GetExecutingAssembly().FullName + "\n";
            //TaskDialog.Show("AutoOptions", msg);


            //setup the ui on the Ribbon
            PushButtonData AutoOptionsConfigCommandPushButtonData =
                new PushButtonData(
                    "AutoOptionsConfigCommandButton", //name of the button
                    "Auto Options",                   //text on the button
                    FileLocations.AssemblyFullPath,
                    "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommand"
                    );

            AutoOptionsConfigCommandPushButtonData.AvailabilityClassName =
                "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommandAvailability";
            AutoOptionsConfigCommandPushButtonData.LargeImage =
                new BitmapImage(new Uri("pack://application:,,,/resources/ao_large.jpg"));

            RibbonPanel AutoOptions2014RibbonPanel = application.CreateRibbonPanel("Auto Options");

            AutoOptions2014RibbonPanel.AddItem(AutoOptionsConfigCommandPushButtonData);

            //assign the dispatcher object using the singleton instance. The singleton will be initialized at this time
            dispatcher = AutoOptionsDispatcher.Instance;
            //load the settings to use in this session
            IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();

            dispatcher.SetOptions(settingsRepo.LoadAutoOptions());
            //register the event handler
            application.ControlledApplication.FailuresProcessing += dispatcher.AutoOptionsFailureHandler;



            return(Result.Succeeded);
        }