use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method saveFileToAzure.
@AzureOperation(name = "appservice|file.save", params = { "appServiceFile.getName()" }, type = AzureOperation.Type.SERVICE)
private void saveFileToAzure(final AppServiceFile appServiceFile, final String content, final Project project) {
final AzureString title = AzureOperationBundle.title("appservice|file.save", appServiceFile.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask<>(project, title, false, () -> {
final IAppService appService = appServiceFile.getApp();
final AppServiceFile target = appService.getFileByPath(appServiceFile.getPath());
final boolean deleted = target == null;
final boolean outDated = !deleted && ZonedDateTime.parse(target.getMtime()).isAfter(ZonedDateTime.parse(appServiceFile.getMtime()));
boolean toSave = true;
if (deleted) {
toSave = DefaultLoader.getUIHelper().showYesNoDialog(null, String.format(FILE_HAS_BEEN_DELETED, appServiceFile.getName()), APP_SERVICE_FILE_EDITING, Messages.getQuestionIcon());
} else if (outDated) {
toSave = DefaultLoader.getUIHelper().showYesNoDialog(null, String.format(FILE_HAS_BEEN_MODIFIED, appServiceFile.getName()), APP_SERVICE_FILE_EDITING, Messages.getQuestionIcon());
}
if (toSave) {
appService.uploadFileToPath(content, appServiceFile.getPath());
PluginUtil.showInfoNotification(APP_SERVICE_FILE_EDITING, String.format(FILE_HAS_BEEN_SAVED, appServiceFile.getName()));
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method fillGrid.
public void fillGrid() {
setUIState(true);
final AzureString title = AzureOperationBundle.title("blob.list", blobContainer.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
progressIndicator.setIndeterminate(true);
if (directoryQueue.peekLast() == null) {
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
}
blobItems = StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.peekLast());
if (!queryTextField.getText().isEmpty()) {
for (int i = blobItems.size() - 1; i >= 0; i--) {
BlobItem blobItem = blobItems.get(i);
if (blobItem instanceof BlobFile && !blobItem.getName().startsWith(queryTextField.getText())) {
blobItems.remove(i);
}
}
}
AzureTaskManager.getInstance().runLater(() -> {
pathLabel.setText(directoryQueue.peekLast().getPath());
DefaultTableModel model = (DefaultTableModel) blobListTable.getModel();
while (model.getRowCount() > 0) {
model.removeRow(0);
}
for (BlobItem blobItem : blobItems) {
if (blobItem instanceof BlobDirectory) {
model.addRow(new Object[] { UIHelperImpl.loadIcon("storagefolder.png"), blobItem.getName(), "", "", "", blobItem.getUri() });
} else {
BlobFile blobFile = (BlobFile) blobItem;
model.addRow(new String[] { "", blobFile.getName(), UIHelperImpl.readableFileSize(blobFile.getSize()), new SimpleDateFormat().format(blobFile.getLastModified().getTime()), blobFile.getContentType(), blobFile.getUri() });
}
}
setUIState(false);
blobListTable.clearSelection();
});
} catch (AzureCmdException ex) {
String msg = "An error occurred while attempting to query blob list." + "\n" + String.format(message("webappExpMsg"), ex.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method uploadFile.
private void uploadFile(final String path, final File selectedFile) {
final AzureString title = AzureOperationBundle.title("blob.upload", selectedFile, blobContainer.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
final BlobDirectory blobDirectory = directoryQueue.peekLast();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(selectedFile));
progressIndicator.setIndeterminate(false);
progressIndicator.setText("Uploading blob...");
progressIndicator.setText2("0% uploaded");
try {
final CallableSingleArg<Void, Long> callable = new CallableSingleArg<Void, Long>() {
@Override
public Void call(Long uploadedBytes) throws Exception {
double progress = ((double) uploadedBytes) / selectedFile.length();
progressIndicator.setFraction(progress);
progressIndicator.setText2(String.format("%s%% uploaded", (int) (progress * 100)));
return null;
}
};
Future<Void> future = ApplicationManager.getApplication().executeOnPooledThread(new Callable<Void>() {
@Override
public Void call() throws AzureCmdException {
try {
StorageClientSDKManager.getManager().uploadBlobFileContent(connectionString, blobContainer, path, bufferedInputStream, callable, 1024 * 1024, selectedFile.length());
} finally {
try {
bufferedInputStream.close();
} catch (IOException ignored) {
}
}
return null;
}
});
while (!future.isDone()) {
Thread.sleep(500);
progressIndicator.checkCanceled();
if (progressIndicator.isCanceled()) {
future.cancel(true);
bufferedInputStream.close();
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, blobDirectory)) {
if (blobItem instanceof BlobFile && blobItem.getPath().equals(path)) {
StorageClientSDKManager.getManager().deleteBlobFile(connectionString, (BlobFile) blobItem);
}
}
}
}
try {
directoryQueue.clear();
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
for (String pathDir : path.split("/")) {
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.getLast())) {
if (blobItem instanceof BlobDirectory && blobItem.getName().equals(pathDir)) {
directoryQueue.addLast((BlobDirectory) blobItem);
}
}
}
} catch (AzureCmdException e) {
String msg = "An error occurred while attempting to show new blob." + "\n" + String.format(message("webappExpMsg"), e.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, e);
}
AzureTaskManager.getInstance().runLater(() -> fillGrid());
} catch (Exception e) {
Throwable connectionFault = e.getCause();
Throwable realFault = null;
if (connectionFault != null) {
realFault = connectionFault.getCause();
}
progressIndicator.setText("Error uploading Blob");
String message = realFault == null ? null : realFault.getMessage();
if (connectionFault != null && message == null) {
message = "Error type " + connectionFault.getClass().getName();
}
progressIndicator.setText2((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : message);
}
} catch (IOException e) {
PluginUtil.displayErrorDialogAndLog(message("errTtl"), "An error occurred while attempting to upload Blob.", e);
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class SpringCloudStreamingLogManager method showStreamingLog.
public void showStreamingLog(Project project, SpringCloudApp app, String instanceName) {
final SpringCloudStreamingLogConsoleView consoleView = consoleViewMap.computeIfAbsent(instanceName, name -> new SpringCloudStreamingLogConsoleView(project, name));
final AzureString title = AzureOperationBundle.title("springcloud|log_stream.start", instanceName);
AzureTaskManager.getInstance().runInBackground(new AzureTask<>(project, title, false, () -> {
try {
consoleView.startLog(() -> {
try {
return getLogStream(app, instanceName, 0, 10, 0, true);
} catch (final IOException | HttpException e) {
return null;
}
});
StreamingLogsToolWindowManager.getInstance().showStreamingLogConsole(project, instanceName, instanceName, consoleView);
} catch (final Throwable e) {
AzureMessager.getMessager().error(e.getMessage(), "Failed to start streaming log");
consoleView.shutdown();
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class SpringCloudStreamingLogManager method closeStreamingLog.
public void closeStreamingLog(String instanceName) {
final AzureString title = AzureOperationBundle.title("springcloud|log_stream.close", instanceName);
AzureTaskManager.getInstance().runInBackground(new AzureTask<>(null, title, false, () -> {
final SpringCloudStreamingLogConsoleView consoleView = consoleViewMap.get(instanceName);
if (consoleView != null && consoleView.getStatus() == ACTIVE) {
consoleView.shutdown();
} else {
AzureMessager.getMessager().error("Log is not started.", "Failed to close streaming log");
}
}));
}
Aggregations