Exemplo n.º 1
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.");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Downloads online JSON/TXT and refreshes data
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSync_Click(object sender, RoutedEventArgs e)
 {
     // Download JSON/TXT from OpenRFA.org
     LocalFiles.DownloadLocalData();
     RefreshData();
 }