コード例 #1
0
 public void Setup()
 {
     var raml = new RamlParser().Load("files/box.raml");
     var raml2 = new RamlParser().Load("files/congo-drones-5-f.raml");
     deliveriesResource = raml2.Resources.First(r => r.RelativeUri == "/deliveries");
     searchResource = raml.Resources.First(r => r.RelativeUri == "/search");
     foldersResource = raml.Resources.First(r => r.RelativeUri == "/folders");
 }
コード例 #2
0
 public RamlDocWrapper(string ramlFilePath)
 {
     //MuleSoft Raml parser
     var parser = new RamlParser();
     try
     {
         ramlDocument = parser.LoadAsync(ramlFilePath).Result;
     }
     catch (AggregateException ae)            //Exceptions received from assync RamlParser
     {
         throw ae.Flatten();
     }
 }
コード例 #3
0
        public Program()
        {
            var parser = new RamlParser();
            var raml = parser.LoadAsync(@"c:\temp\test.raml").Result;

            var apiName = Helpers.GetMethodOrClassName(raml.Title);
            var apiBaseUrl = new Uri(raml.BaseUri);
            var api = new Api(apiName, apiBaseUrl);

            foreach (var resource in raml.Resources)
            {
                foreach (var method in resource.Methods)
                {
                    if (string.IsNullOrEmpty(method.Description))
                    {
                        throw new Exception(string.Format("{0} method on {1} has no description", method, resource.RelativeUri));
                    }

                    var apiMethodName = Helpers.GetMethodOrClassName(method.Description);
                    var apiMethodHasBody = (method.Verb == "post" || method.Verb == "put" || method.Verb == "patch") && method.Body != null && method.Body.Any();
                    var apiMethod = new Method(apiMethodName, method.Verb, resource.RelativeUri, apiMethodHasBody);

                    if (method.QueryParameters != null)
                    {
                        foreach (var parameter in method.QueryParameters)
                        {
                            var apiMethodQueryParameterName = Helpers.ToCamelCase(parameter.Key);
                            var apiMethodQueryParameter = new QueryParameter(apiMethodQueryParameterName, parameter.Value.Required);
                            apiMethod.AddQueryParameter(apiMethodQueryParameter);
                        }
                    }

                    api.AddMethod(apiMethod);
                }
            }

            var ts = api.ToTypescript();
            ts += "";
        }
コード例 #4
0
        public static RamlInfo GetRamlInfo(string ramlSource)
        {
            var info = new RamlInfo();

            if (ramlSource.StartsWith("http"))
            {
                Uri uri;
                if (!Uri.TryCreate(ramlSource, UriKind.Absolute, out uri))
                {
                    info.ErrorMessage = "Invalid Url specified: " + uri.AbsoluteUri;
                    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, info.ErrorMessage);
                    return info;
                }

                var absolutePath = uri.AbsoluteUri;
                if (absolutePath.Contains("/"))
                    absolutePath = absolutePath.Substring(0, absolutePath.LastIndexOf("/", StringComparison.InvariantCulture) + 1);

                info.AbsolutePath = absolutePath;

                try
                {
                    info.RamlContents = Downloader.GetContents(uri);
                }
                catch (HttpRequestException rex)
                {
                    var errorMessage = rex.Message;
                    if (rex.InnerException != null)
                        errorMessage += " - " + rex.InnerException.Message;

                    if (errorMessage.Contains("404"))
                        errorMessage = "Url not found, could not load the specified url: " + uri.AbsoluteUri;

                    info.ErrorMessage = errorMessage;

                    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                        VisualStudioAutomationHelper.GetExceptionInfo(rex));

                    return info;
                }
                catch (Exception ex)
                {
                    var errorMessage = ex.Message;
                    if (ex.InnerException != null)
                        errorMessage += " - " + ex.InnerException.Message;

                    info.ErrorMessage = "Error when trying to load specified url " + uri.AbsoluteUri + ". " + errorMessage;

                    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                        VisualStudioAutomationHelper.GetExceptionInfo(ex));

                    return info;
                }
            }
            else
            {
                if (!File.Exists(ramlSource))
                {
                    info.ErrorMessage = "Error. File " + ramlSource + " does not exist.";
                    return info;
                }

                info.AbsolutePath = Path.GetDirectoryName(ramlSource) + "\\";

                try
                {
                    info.RamlContents = File.ReadAllText(ramlSource);
                }
                catch (Exception ex)
                {
                    var errorMessage = ex.Message;
                    if (ex.InnerException != null)
                        errorMessage += " - " + ex.InnerException.Message;

                    info.ErrorMessage = "Error when trying to read file " + ramlSource + ". " + errorMessage;

                    ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                        VisualStudioAutomationHelper.GetExceptionInfo(ex));

                    return info;
                }
            }

            var task = new RamlParser().LoadRamlAsync(info.RamlContents);
            task.WaitWithPumping();
            info.RamlDocument = task.Result;

            return info;
        }
コード例 #5
0
 private async Task<ClientGeneratorModel> GetContactsGeneratedModel()
 {
     var parser = new RamlParser();
     var raml = await parser.LoadAsync("files/contacts.raml");
     return new ClientGeneratorService(raml, "test").BuildModel();
 }
コード例 #6
0
        public async Task FromFile()
        {
            //TODO: check
            try
            {
                txtFileName.Text = Path.GetFileName(RamlTempFilePath);

                SetDefaultClientRootClassName();

                var result = includesManager.Manage(RamlTempFilePath, Path.GetTempPath(), Path.GetTempPath());
                var parser = new RamlParser();
                var document = await parser.LoadRamlAsync(result.ModifiedContents, Path.GetTempPath());

                SetPreview(document);
            }
            catch (Exception ex)
            {
                ShowErrorStopProgressAndDisableOk("Error while parsing raml file. " + ex.Message);
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                    VisualStudioAutomationHelper.GetExceptionInfo(ex));
            }
        }
コード例 #7
0
        private async Task GetRamlFromURL()
        {
            //StartProgress();
            //DoEvents();

            try
            {
                var url = RamlOriginalSource;
                var result = includesManager.Manage(url, Path.GetTempPath(), Path.GetTempPath());

                var raml = result.ModifiedContents;
                var parser = new RamlParser();

                var ramlDocument = await parser.LoadRamlAsync(raml, Path.GetTempPath());

                var filename = SetFilename(url);

                var path = Path.Combine(Path.GetTempPath(), filename);
                File.WriteAllText(path, raml);
                RamlTempFilePath = path;
                RamlOriginalSource = url;

                SetPreview(ramlDocument);

                btnOk.IsEnabled = true;
                //StopProgress();
            }
            catch (UriFormatException uex)
            {
                ShowErrorAndDisableOk(uex.Message);
            }
            catch (HttpRequestException rex)
            {
                ShowErrorAndDisableOk(GetFriendlyMessage(rex));
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                    VisualStudioAutomationHelper.GetExceptionInfo(rex));
            }
            catch (Exception ex)
            {
                ShowErrorAndDisableOk(ex.Message);
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                    VisualStudioAutomationHelper.GetExceptionInfo(ex));
            }
        }
コード例 #8
0
		private async Task<WebApiGeneratorModel> GetGitHubGeneratedModel()
		{
			var parser = new RamlParser();
			var raml = await parser.LoadAsync("files/github.raml");
            return new WebApiGeneratorService(raml, "TestNs").BuildModel();
		}
コード例 #9
0
		private async Task<WebApiGeneratorModel> GetCongoGeneratedModel()
		{
			var parser = new RamlParser();
			var raml = await parser.LoadAsync("files/congo-drones-5-f.raml");
            return new WebApiGeneratorService(raml, "TestNs").BuildModel();
		}
コード例 #10
0
		private async Task<WebApiGeneratorModel> GetTwitterGeneratedModel()
		{
			var parser = new RamlParser();
			var raml = await parser.LoadAsync("files/twitter.raml");
			return new WebApiGeneratorService(raml).BuildModel();
		}
コード例 #11
0
 private async Task<ClientGeneratorModel> GetGitHubGeneratedModel()
 {
     var parser = new RamlParser();
     var raml = await parser.LoadAsync("files/github.raml");
     return new ClientGeneratorService(raml, "test", "TargetNamespace").BuildModel();
 }
コード例 #12
0
 private async Task<ClientGeneratorModel> GetCongoGeneratedModel()
 {
     var parser = new RamlParser();
     var raml = await parser.LoadAsync("files/congo-drones-5-f.raml");
     return new ClientGeneratorService(raml, "test", "TargetNamespace").BuildModel();
 }
コード例 #13
0
        private async Task GetRamlFromURL()
        {
            //StartProgress();
            //DoEvents();

            try
            {
                var url = RamlOriginalSource;
                var result = includesManager.Manage(url, Path.GetTempPath());

                var raml = result.ModifiedContents;
                var parser = new RamlParser();

                var ramlDocument = await parser.LoadRamlAsync(raml);

                var filename = Path.GetFileName(url);

                if (string.IsNullOrEmpty(filename))
                    filename = "reference.raml";

                if (!filename.ToLowerInvariant().EndsWith(RamlFileExtension))
                    filename += RamlFileExtension;

                filename = NetNamingMapper.RemoveIndalidChars(Path.GetFileNameWithoutExtension(filename)) +
                                   RamlFileExtension;

                txtFileName.Text = filename;

                var path = Path.Combine(Path.GetTempPath(), filename);
                File.WriteAllText(path, raml);
                RamlTempFilePath = path;
                RamlOriginalSource = url;

                SetPreview(ramlDocument);

                btnOk.IsEnabled = true;
                //StopProgress();
            }
            catch (UriFormatException uex)
            {
                ShowErrorAndDisableOk(uex.Message);
            }
            catch (HttpRequestException rex)
            {
                ShowErrorAndDisableOk(GetFriendlyMessage(rex));
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                    VisualStudioAutomationHelper.GetExceptionInfo(rex));
            }
            catch (Exception ex)
            {
                ShowErrorAndDisableOk(ex.Message);
                ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                    VisualStudioAutomationHelper.GetExceptionInfo(ex));
            }
        }