public ApiResult <long> Post([FromBody] SdkPackage value) { if (!ModelState.IsValid) { return(new ApiResult <long>(l, BasicControllerEnums.UnprocessableEntity, ModelErrors())); } value.UserID = UserId; sdkDB.Add(value); try { sdkDB.SaveChanges(); } catch (Exception ex) { return(new ApiResult <long>(l, BasicControllerEnums.ExpectationFailed, ex.Message) { data = 0 }); } return(new ApiResult <long>(value.Id)); }
private Dictionary <string, string> BuildPackage(SdkPackage item) { var result = new Dictionary <string, string>(); var swaggerDocument = string.Empty; using (var hc = new HttpClient()) { swaggerDocument = hc.GetStringAsync(item.SwaggerUri).Result; } if (string.IsNullOrWhiteSpace(swaggerDocument)) { return(result); } engine.RemoveVariable("packageObject"); engine.SetVariableValue("packageObject", swaggerDocument); if (item.SdkGenerators != null && item.SdkGenerators.Count > 0) { item.SdkGenerators.ForEach(g => { if (!g.Enable) { return; } try { var templateSource = string.Empty; using (var hc = new HttpClient()) { templateSource = hc.GetStringAsync(g.Uri).Result; } engine.Execute(templateSource); var CompiledCode = engine.CallFunction <string>("codeCompile"); if (!result.ContainsKey(g.Name)) { result.Add(g.Name, CompiledCode); } } catch { } }); } return(result); }
public ApiResult <bool> Put([FromBody] SdkPackage value) { if (!ModelState.IsValid) { return(new ApiResult <bool>(l, BasicControllerEnums.UnprocessableEntity, ModelErrors())); } var Entity = sdkDB.Packages.Where(x => x.Id == value.Id && x.UserID == UserId) .Include(x => x.SdkGenerators) .FirstOrDefault(); if (Entity == null) { return(new ApiResult <bool>(l, BasicControllerEnums.NotFound) { data = false }); } if (!string.IsNullOrWhiteSpace(value.Name) && !value.Name.Equals(Entity.Name)) { Entity.Name = value.Name; } if (!string.IsNullOrWhiteSpace(value.PackageName) && !value.PackageName.Equals(Entity.PackageName)) { Entity.PackageName = value.PackageName; } if (!string.IsNullOrWhiteSpace(value.Description) && !value.Description.Equals(Entity.Description)) { Entity.Description = value.Description; } if (!string.IsNullOrWhiteSpace(value.Summary) && !value.Description.Equals(Entity.Summary)) { Entity.Summary = value.Summary; } if (!string.IsNullOrWhiteSpace(value.WebSite) && !value.WebSite.Equals(Entity.WebSite)) { Entity.WebSite = value.WebSite; } if (!string.IsNullOrWhiteSpace(value.LogoUri) && !value.LogoUri.Equals(Entity.LogoUri)) { Entity.LogoUri = value.LogoUri; } if (!string.IsNullOrWhiteSpace(value.Tags) && !value.Tags.Equals(Entity.Tags)) { Entity.Tags = value.Tags; } Entity.Enable = value.Enable; #region Templates if (Entity.SdkGenerators != null && Entity.SdkGenerators.Count > 0) { Entity.SdkGenerators.Clear(); } if (value.SdkGenerators != null && value.SdkGenerators.Count > 0) { Entity.SdkGenerators = value.SdkGenerators .Where(x => !string.IsNullOrWhiteSpace(x.Name)) .Select(x => new SdkGenerator() { Description = x.Description, Name = x.Name, Uri = x.Uri, CompiledCode = "", Enable = x.Enable, SdkPackageId = value.Id }).ToList(); } #endregion try { sdkDB.SaveChanges(); } catch (Exception ex) { return(new ApiResult <bool>(l, BasicControllerEnums.ExpectationFailed, ex.Message) { data = false }); } return(new ApiResult <bool>(true)); }