use of com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method saveAppServiceFile.
@SneakyThrows
@Override
public void saveAppServiceFile(@NotNull AppServiceFile file, @NotNull Object context, @Nullable File dest) {
final File destFile = Objects.isNull(dest) ? DefaultLoader.getUIHelper().showFileSaver("Download", file.getName()) : dest;
if (Objects.isNull(destFile)) {
return;
}
final OutputStream output = new FileOutputStream(destFile);
final Project project = (Project) context;
final AzureString title = AzureOperationBundle.title("appservice|file.download", file.getName());
final AzureTask<Void> task = new AzureTask<>(project, title, false, () -> {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
file.getApp().getFileContent(file.getPath()).doOnComplete(() -> notifyDownloadSuccess(file.getName(), destFile, ((Project) context))).doOnTerminate(() -> IOUtils.closeQuietly(output, null)).subscribe(bytes -> {
try {
if (bytes != null) {
output.write(bytes.array(), 0, bytes.limit());
}
} catch (final IOException e) {
final String error = "failed to write data into local file";
final String action = "try later";
throw new AzureToolkitRuntimeException(error, e, action);
}
}, IDEHelperImpl::onRxException);
});
AzureTaskManager.getInstance().runInModal(task);
}
use of com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile 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.appservice.model.AppServiceFile in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method openAppServiceFile.
@AzureOperation(name = "appservice|file.open", params = { "target.getName()" }, type = AzureOperation.Type.SERVICE)
@SneakyThrows
public void openAppServiceFile(AppServiceFile target, Object context) {
final IAppService appService = target.getApp();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance((Project) context);
final VirtualFile virtualFile = getOrCreateVirtualFile(target, fileEditorManager);
final OutputStream output = virtualFile.getOutputStream(null);
final AzureString title = AzureOperationBundle.title("appservice|file.open", virtualFile.getName());
final AzureTask<Void> task = new AzureTask<>(null, title, false, () -> {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.setIndeterminate(true);
indicator.setText2("Checking file existence");
final AppServiceFile file = appService.getFileByPath(target.getPath());
if (file == null) {
final String failureFileDeleted = String.format("Target file (%s) has been deleted", target.getName());
UIUtil.invokeLaterIfNeeded(() -> Messages.showWarningDialog(failureFileDeleted, "Open File"));
return;
}
indicator.setText2("Loading file content");
final String failure = String.format("Can not open file (%s). Try downloading it first and open it manually.", virtualFile.getName());
appService.getFileContent(file.getPath()).doOnComplete(() -> AzureTaskManager.getInstance().runLater(() -> {
final Consumer<String> contentSaver = content -> saveFileToAzure(target, content, fileEditorManager.getProject());
if (!openFileInEditor(contentSaver, virtualFile, fileEditorManager)) {
Messages.showWarningDialog(failure, "Open File");
}
}, AzureTask.Modality.NONE)).doAfterTerminate(() -> IOUtils.closeQuietly(output, null)).subscribe(bytes -> {
try {
if (bytes != null) {
output.write(bytes.array(), 0, bytes.limit());
}
} catch (final IOException e) {
final String error = "failed to load data into editor";
final String action = "try later or downloading it first";
throw new AzureToolkitRuntimeException(error, e, action);
}
}, IDEHelperImpl::onRxException);
});
AzureTaskManager.getInstance().runInModal(task);
}
Aggregations