public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            // Create local directory
            LocalFiles.CreateLocalDir();

            // Check OpenRFA.org for latest update to online db
            LocalFiles.GetLastUpdateJsonOnline();

            MainWindow appDialog = new MainWindow();

            appDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            // Check if current document is a Revit family
            if (doc.IsFamilyDocument)
            {
                // Only open window if continueCommand is set true
                if (ImportProcess.continueCommand == true)
                {
                    appDialog.ShowDialog();
                }

                // Only executes if the user clicked "OK" button
                if (appDialog.DialogResult.HasValue && appDialog.DialogResult.Value)
                {
                    // Opens configuration window
                    ConfigureImport confDialog = new ConfigureImport();
                    confDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    confDialog.ShowDialog();

                    // Complete import process
                    ImportProcess.ProcessImport(doc, app, confDialog.DialogResult.HasValue, confDialog.DialogResult.Value);

                    // Clear all data in case addin is run again in the same session
                    // TODO: Call this method with every method that uses the datatables?
                    ImportProcess.ClearAllData();
                }

                return(Result.Succeeded);
            }
            else
            {
                MessageBox.Show("The current document must be a Revit family to use this tool.");
                return(Result.Failed);
            }
        }
예제 #2
0
        public MainWindow()
        {
            //// Fields for checking for updates
            //DateTime dbLastUpdated = LocalFiles.UnixTimeStampToDateTime(LocalFiles.GetLastUpdatedDateTime());
            //DateTime localFileUpdated = File.GetLastWriteTimeUtc(LocalFiles.localJsonFile);

            InitializeComponent();

            // Prompt user to download definitions if local files are missing
            if (!File.Exists(LocalFiles.localJsonFile) || !File.Exists(LocalFiles.localSpFile))
            {
                LocalFiles.definitionsUpToDate = false;

                string           messageBoxText = "You must sync with the OpenRFA.org shared parameter defintions to use this add-in. Would you like to sync now?";
                MessageBoxResult result         = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Missing", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                switch (result)
                {
                case MessageBoxResult.Yes:
                    // Download JSON/TXT from OpenRFA.org
                    LocalFiles.DownloadLocalData();
                    RefreshData();

                    LocalFiles.definitionsUpToDate = true;
                    break;

                case MessageBoxResult.No:
                    LocalFiles.definitionsUpToDate = false;
                    //DialogResult = true;
                    break;
                }
            }
            else
            {
                // Store date/times locally to ensure methods are called from all scopes
                DateTime localFileUpdated = LocalFiles.GetLastUpdateJsonLocal();
                DateTime dbLastUpdated    = LocalFiles.GetLastUpdateJsonOnline();

                // Prompt user to updated definitions if local file is outdated
                if (localFileUpdated < dbLastUpdated)

                //&& LocalFiles.dbLastUpdated != LocalFiles.UnixTimeStampToDateTime(000))
                {
                    string messageBoxText = "OpenRFA.org was udpated: " + dbLastUpdated.ToLocalTime().ToString() +
                                            "\nYour last sync: " + localFileUpdated.ToString() +
                                            "\n\nWould you like to sync with OpenRFA.org?";

                    MessageBoxResult result = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Outdated", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    switch (result)
                    {
                    case MessageBoxResult.Yes:
                        // Download JSON/TXT from OpenRFA.org
                        LocalFiles.DownloadLocalData();
                        RefreshData();

                        // Store new values for updated definitions
                        LocalFiles.definitionsUpToDate = true;
                        break;

                    case MessageBoxResult.No:
                        LocalFiles.definitionsUpToDate = false;
                        break;
                    }
                }
                if (dbLastUpdated == LocalFiles.UnixTimeStampToDateTime(000))
                {
                    MessageBox.Show("Can't connect to database. Please ensure you are online.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                // Notify the user that definitions are up to date
                if (localFileUpdated >= dbLastUpdated)
                {
                    LocalFiles.definitionsUpToDate = true;
                    //string messageBoxText = "Your parameter definitions are synced with OpenRFA.org.";
                    //MessageBoxResult result = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Up to Date", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                RefreshData();
            }

            // Notify users of status of parameter definitions
            if (LocalFiles.definitionsUpToDate == true)
            {
                UpdateStatusText("Your parameter definitions are up to date.");
            }
            else
            {
                UpdateStatusText("You parameter definitions are outdated.");
            }
        }