public async void AddExistingRamlFromDisk() { SelectExistingRamlOption(); FileDialog fd = new OpenFileDialog(); fd.DefaultExt = ".raml;*.rml;*.yaml;*.json"; fd.Filter = "RAML/OAS files |*.raml;*.rml;*.yaml;*.json"; var opened = fd.ShowDialog(); if (opened != true) { return; } RamlTempFilePath = fd.FileName; RamlOriginalSource = fd.FileName; var previewViewModel = new RamlPreviewViewModel(ServiceProvider, action, RamlTempFilePath, RamlOriginalSource, Path.GetFileName(fd.FileName), isContractUseCase, useBasicAuth: false, username: string.Empty, password: string.Empty); try { StartProgress(); await previewViewModel.FromFile(); } finally { StopProgress(); } ShowPreviewViewAndClose(previewViewModel); }
public async void AddExistingRamlFromExchange() { var exchangeBrowseViewModel = new ExchangeBrowserViewModel(); WindowManager.ShowDialog(exchangeBrowseViewModel); var selectedAsset = exchangeBrowseViewModel.SelectedAsset; if (selectedAsset != null) { var file = selectedAsset.Files.FirstOrDefault(f => f.Classifier == "fat-raml"); if (file == null) { file = selectedAsset.Files.FirstOrDefault(f => f.Classifier == "raml"); } if (file == null) { MessageBox.Show("The selected REST API does not seem to have any RAML file associated"); return; } var uri = file.ExternalLink; var client = new HttpClient(); var byteArray = await client.GetByteArrayAsync(uri); var assetName = NetNamingMapper.GetObjectName(selectedAsset.Name); var zipPath = Path.Combine(Path.GetTempPath(), assetName + ".zip"); File.WriteAllBytes(zipPath, byteArray); var randInt = new Random().Next(short.MaxValue); var destinationFolder = Path.Combine(Path.GetTempPath(), assetName + randInt); ZipFile.ExtractToDirectory(zipPath, destinationFolder); RamlTempFilePath = GetRamlPath(destinationFolder, file.MainFile, uri); if (RamlTempFilePath == null) { MessageBox.Show("Unable to determine main RAML file, please use the 'Upload' option to choose the right file from folder " + destinationFolder); return; } var previewViewModel = new RamlPreviewViewModel(ServiceProvider, action, RamlTempFilePath, RamlTempFilePath, Path.GetFileName(RamlTempFilePath), isContractUseCase, useBasicAuth: false, username: string.Empty, password: string.Empty); try { StartProgress(); await previewViewModel.FromFile(); } finally { StopProgress(); } ShowPreviewViewAndClose(previewViewModel); } }
public void AddNewContract() { var previewViewModel = new RamlPreviewViewModel(ServiceProvider, action, Title, useBasicAuth: false, username: string.Empty, password: string.Empty); previewViewModel.NewContract(); dynamic settings = new ExpandoObject(); settings.Height = 420; WindowManager.ShowDialog(previewViewModel, null, settings); TryClose(); }
private void ShowPreviewViewAndClose(RamlPreviewViewModel previewViewModel) { dynamic settings = new ExpandoObject(); settings.Height = isContractUseCase ? 680 : 520; WindowManager.ShowDialog(previewViewModel, null, settings); if (previewViewModel.WasImported) { TryClose(); } }
public async void AddExistingRamlFromUrl(object parameter) { SelectExistingRamlOption(); var password = string.Empty; if (EnableBasicAuth) { if (string.IsNullOrWhiteSpace(Username)) { MessageBox.Show("Please type your username."); return; } if (parameter is IHavePassword passwordContainer) { var secureString = passwordContainer.Password; password = ConvertToUnsecureString(secureString); } if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show("Please type your password."); return; } } var previewViewModel = new RamlPreviewViewModel(ServiceProvider, action, RamlTempFilePath, Url, "title", isContractUseCase, EnableBasicAuth, Username, password); try { StartProgress(); await previewViewModel.FromUrl(); } finally { StopProgress(); } ShowPreviewViewAndClose(previewViewModel); }