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, ramlSource); task.WaitWithPumping(); info.RamlDocument = task.Result; return(info); }
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; }
private Result GenerateCodeUsingTemplate(string wszInputFilePath, RamlInfo ramlInfo, System.IServiceProvider globalProvider, string refFilePath) { var model = GetGeneratorModel(wszInputFilePath, ramlInfo); var templateFolder = GetTemplateFolder(wszInputFilePath); var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName); var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; var t4Service = new T4Service(globalProvider); var targetNamespace = RamlReferenceReader.GetRamlNamespace(refFilePath); var res = t4Service.TransformText(templateFilePath, model, extensionPath, wszInputFilePath, targetNamespace); return res; }
private static ClientGeneratorModel GetGeneratorModel(string wszInputFilePath, RamlInfo ramlInfo) { var rootName = NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(wszInputFilePath)); if (!rootName.ToLower().Contains("client")) rootName += "Client"; var model = new ClientGeneratorService(ramlInfo.RamlDocument, rootName).BuildModel(); return model; }
private static ClientGeneratorModel GetGeneratorModel(string clientRootClassName, RamlInfo ramlInfo, string targetNamespace) { var model = new ClientGeneratorService(ramlInfo.RamlDocument, clientRootClassName, targetNamespace).BuildModel(); return model; }