use of com.microsoft.azure.toolkit.lib.appservice.service.IAppService 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.service.IAppService in project azure-tools-for-java by Microsoft.
the class WebAppBasePropertyViewPresenter method getPublishingProfile.
protected boolean getPublishingProfile(@Nonnull String sid, @Nonnull String webAppId, @Nullable String name, @Nonnull String filePath) throws Exception {
final ResourceId resourceId = ResourceId.fromString(webAppId);
final File file = new File(Paths.get(filePath, String.format("%s_%s.PublishSettings", resourceId.name(), System.currentTimeMillis())).toString());
try {
file.createNewFile();
} catch (final IOException e) {
AzureMessager.getMessager().warning("failed to create publishing profile xml file");
return false;
}
final IAppService resource = getWebAppBase(sid, webAppId, name);
try (final InputStream inputStream = resource.listPublishingProfileXmlWithSecrets();
final OutputStream outputStream = new FileOutputStream(file)) {
IOUtils.copy(inputStream, outputStream);
return true;
} catch (final IOException e) {
AzureMessager.getMessager().warning("failed to get publishing profile xml");
return false;
}
}
use of com.microsoft.azure.toolkit.lib.appservice.service.IAppService 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