public bool Execute() { config = Configuration.Load(); config.FilePath = config.FilePath ?? DefaultFilePath; var fileDirectory = new FileInfo(config.FilePath).Directory.FullName; if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } var cacheFilePath = config.FilePath + ".cache"; string source; try { config.Metadata = GetProxy(); var template = new CSharpProxyTemplate(config); source = template.TransformText(); File.WriteAllText(cacheFilePath, source); } catch (InvalidOperationException) { source = File.ReadAllText(cacheFilePath); } File.WriteAllText(config.FilePath, source); this.Filename = config.FilePath; return(true); }
public string Generate() { config.Metadata = GetProxy(); //Append web method as suffix if one web API has more than one web methods. foreach (var controllerDefinition in config.Metadata.Definitions) { var duplicatedList = controllerDefinition.ActionMethods.GroupBy(method => method.Name).Where(group => group.Count() > 1).ToList(); foreach (var duplicatedItem in duplicatedList) { foreach (var method in duplicatedItem) { method.Name = method.Name + method.Type; } } } config.Metadata.HostKey = config.HostKey; config.Namespace = config.ConfigFileName.Replace(".config", ""); if (String.IsNullOrEmpty(config.Metadata.HostKey)) { config.Metadata.HostKey = "WebApiProxyHost"; } var template = new CSharpProxyTemplate(config); var source = template.TransformText(); return(source); }
public bool Execute() { try { config = Configuration.Load(); config.Metadata = GetProxy(); var template = new CSharpProxyTemplate(config); var source = template.TransformText(); File.WriteAllText(Filename, source); File.WriteAllText(Configuration.CacheFile, source); } catch (ConnectionException) { tryReadFromCache(); // throw ex; } catch (Exception ex) { throw ex; } return(true); }
public string Generate() { config.Metadata = GetProxy(); var template = new CSharpProxyTemplate(config); var source = template.TransformText(); return(source); }