예제 #1
0
        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);
        }
예제 #2
0
        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);
            }
        }