}//RunLocally private static void UploadIfNecessary() { var dmLite = Server.Return((IDisconnectedServer s) => s.GetDisconnectedMachine(Environment.MachineName)); switch (dmLite?.Retrieve().State) { case DisconnectedMachineState.Faulted: { string message = @"The last import had en exception. You have two options: - Contact IT and wait until they fix the uploaded database - Restart the application and work locally AT YOUR OWN RISK"; MessageBox.Show(message, "Last import failed", MessageBoxButton.OK, MessageBoxImage.Exclamation); Environment.Exit(0); break; } case DisconnectedMachineState.Fixed: { string message = "Good News!!\r\nThe IT department already fixed your last upload so you can continue working."; MessageBox.Show(message, "Upload fixed", MessageBoxButton.OK, MessageBoxImage.Information); if (File.Exists(DisconnectedClient.UploadBackupFile)) { File.Delete(DisconnectedClient.UploadBackupFile); } if (File.Exists(DisconnectedClient.DatabaseFile)) { LocalServer.DropDatabase(Settings.Default.LocalDatabaseConnectionString); } Server.Execute((IDisconnectedServer ds) => ds.ConnectAfterFix(DisconnectedMachineEntity.Current)); break; } case null: case DisconnectedMachineState.Connected: { if (File.Exists(DisconnectedClient.DownloadBackupFile) || File.Exists(DisconnectedClient.DatabaseFile)) { string message = "The server does not expect you to be disconnected, but you have a local database.\r\nRemove you local database manually (loosing your work) or contact IT department."; MessageBox.Show(message, "Unexpected situation", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } break; } case DisconnectedMachineState.Disconnected: { if (File.Exists(DisconnectedClient.DownloadBackupFile)) { File.Delete(DisconnectedClient.DownloadBackupFile); Server.Execute((IDisconnectedServer ds) => ds.SkipExport(DisconnectedMachineEntity.Current)); } else { if (File.Exists(DisconnectedClient.DatabaseFile)) { ProgressWindow.Wait("Waiting", "Backing up...", () => { LocalServer.BackupDatabase( Settings.Default.LocalDatabaseConnectionString, DisconnectedClient.UploadBackupFile); }); } if (File.Exists(DisconnectedClient.UploadBackupFile)) { if (new UploadProgress().ShowDialog() == false) { MessageBox.Show("Contact IT to fix the error", "Failed import", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); } LocalServer.DropDatabase(Settings.Default.LocalDatabaseConnectionString); File.Delete(DisconnectedClient.UploadBackupFile); } } break; } } }//UploadIfNecessary