public static IServiceCollection AddSwagger(this IServiceCollection services, IConfiguration configuration) { ApiDetails apiDetails = new ApiDetails(); configuration.GetSection("ApiDetails").Bind(apiDetails); services.AddSwaggerGen(options => { var info = new OpenApiInfo { Title = $"{apiDetails.Title} - {apiDetails.Owners}", Version = "v1", Description = $"### {apiDetails.Description}\n" + $"### [{apiDetails.Title} Git Repository]({apiDetails.GitRepoUrl})" }; options.SwaggerDoc("v1", info); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath); }); return(services); }
public List <ApiDetails> GetPublicApiDetails(XmlNodeList publicAssembliesNodeList) { var publicAssembliesDetails = new List <ApiDetails>(); foreach (XmlNode node in publicAssembliesNodeList) { if (node?.Attributes?.Count > 0) { var apiDetails = new ApiDetails(); foreach (XmlAttribute attribute in node.Attributes) { if (attribute != null) { if (attribute.Name.ToLower().Equals("name")) { apiDetails.ApiName = $"{attribute.Value}.dll"; } if (attribute.Name.ToLower().Equals("version")) { apiDetails.Version = attribute.Value; } } } publicAssembliesDetails.Add(apiDetails); } } return(publicAssembliesDetails); }
public static void Main(string[] args) { Console.WriteLine(ApplicationDetails.Header); log.Warn("GHOSTS API coming online..."); ApiDetails.LoadConfiguration(); var host = WebHost.CreateDefaultBuilder(args) .UseStartup <Startup>() .Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var dbInitializerLogger = services.GetRequiredService <ILogger <DbInitializer> >(); DbInitializer.Initialize(context, userManager, roleManager, dbInitializerLogger).Wait(); } catch (Exception ex) { log.Fatal(ex, "An error occurred while seeding the GHOSTS database"); } } host.Run(); }
public static ResultsItem InsertNewAPI(LocalCoins.ExchangeApiInfo exchangeApiDetails, PegaUser user) { try { using (PegasunDBContext db = new PegasunDBContext()) { ApiDetails serviceApi = new ApiDetails { Name = exchangeApiDetails.Name.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }), Exchange = (short)exchangeApiDetails.Exchange, ApiAction = (short)exchangeApiDetails.ApiAction, ApiPublic = Cryptography.Encrypt(exchangeApiDetails.ApiPublic, Types.EncryptionType.ApiKey_Public, user), ApiPrivate = Cryptography.Encrypt(exchangeApiDetails.ApiPrivate, Types.EncryptionType.ApiKey_Private, user), ApiThirdKey = exchangeApiDetails.ApiThirdKey.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM }), DateAdded = DateTime.Now, UserId = user.UserId, }; db.ApiDetails.Add(serviceApi); db.SaveChanges(); } return(ResultsItem.Success("Successfully created a new API.")); } catch (Exception ex) { return(ResultsItem.Error($"Unable to create a new API. {ex.Message}")); } }
void GetSubTabPreferenceDetail(XNode selectedNode, WorkbookSubTab tab) { IEnumerable <XElement> elements = from p in ((XElement)selectedNode).Descendants("Widget") select p; foreach (XElement element in elements) { string apiCalls = element.Attribute("LayoutDataIDs").Value; if (string.IsNullOrEmpty(apiCalls)) { continue; } string preferenceName = element.Attribute("PrefName").Value; List <string> apiList = new List <string>(apiCalls.Split('`')); var apicalls = new List <Api>(); foreach (string apiNumber in apiList) { Api details = ApiDetails.Get(apiNumber); apicalls.Add(new Api { ApiNumber = apiNumber, ApiDescription = details != null ? details.ApiDescription : string.Empty }); } Preference pref = new Preference { ApiDetails = apicalls, PreferenceName = preferenceName }; tab.PreferenceDetails.Add(pref); } }
private static IEnumerable <string> GetCompatiblePackageVersionsForTarget( ApiDetails apiDetails, PackageDetailsWithApiIndices package, string target, bool checkLesserPackage) { // If ApiDetails found, use them to get compatible versions if (apiDetails == null) { if (!checkLesserPackage || package.PackageDetails.Targets == null || !package.PackageDetails.Targets.TryGetValue(target, out var compatiblePackageVersionsForTarget)) { return(new List <string>()); } return(compatiblePackageVersionsForTarget.ToList()); } // If ApiDetails not found, fallback to using PackageDetails to get compatible versions else if (apiDetails.Targets.TryGetValue(target, out var compatiblePackageVersionsForTarget)) { return(compatiblePackageVersionsForTarget.ToList()); } return(new List <string>()); }
public ReservationsDetail GetReservations(ReservationParam reservationParam, ApiDetails apiDetails) { //dodo: add more remaining fields string uri = "reservations?limit=" + reservationParam.limit + "&skip=" + reservationParam.skip; ApiHttpClient.ApiDetails = apiDetails; var jsonString = ApiHttpClient.Get(uri).Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <ReservationsDetail>(jsonString)); }
/// <summary> /// Method returns address corrections and details based on street number, street address and borough for NYC properties /// </summary> public static void PostCallBack(Common.Context appContext, BAL.Results result) { string username = appContext.getUserName().ToLower(); ApiDetails apiDetails = GetApiDetails(username); if (apiDetails == null) { return; } PostCallBack(apiDetails.baseURL, apiDetails.callbackapi, apiDetails.apiKey, username, result); }
private static ApiDetails GetApiDetails(string username) { if (username != "portal") { return(null); } ApiDetails apiDetails = new ApiDetails(); apiDetails.baseURL = AppSettings.Get(AppSettings.PORTAL_BASE_URL); apiDetails.apiKey = AppSettings.Get(AppSettings.PORTAL_API_KEY); apiDetails.callbackapi = AppSettings.Get(AppSettings.PORTAL_CALLBACK_API); return(apiDetails); }
public static ResultsItem DeleteAPI(int apiId) { try { using (PegasunDBContext db = new PegasunDBContext()) { ApiDetails apiDetail = db.ApiDetails.FirstOrDefault(x => x.Id == apiId); if (apiDetail != null) { db.ApiDetails.Remove(apiDetail); db.SaveChanges(); } } return(ResultsItem.Success("Successfully updated deleted API.")); } catch (Exception ex) { return(ResultsItem.Error($"Unable to delete API. {ex.Message}")); } }
private static string GetExtensionSignature(ApiDetails api) { try { if (api == null || api.MethodParameters == null || api.MethodParameters.Count() == 0) { return(null); } var possibleExtension = api.MethodParameters[0]; var methodSignatureIndex = api.MethodSignature.IndexOf("(") >= 0 ? api.MethodSignature.IndexOf("(") : api.MethodSignature.Length; var sliceMethodSignature = api.MethodSignature.Substring(0, methodSignatureIndex); var methondNameIndex = sliceMethodSignature.LastIndexOf(api.MethodName); var methodName = sliceMethodSignature.Substring(methondNameIndex >= 0 ? methondNameIndex : sliceMethodSignature.Length); var methodSignature = $"{possibleExtension}.{methodName}({String.Join(", ", api.MethodParameters.Skip(1))})"; return(methodSignature); } catch { return(null); } }
private static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description, ApiDetails apiDetails) { var info = new OpenApiInfo() { Title = $"{apiDetails.Title} {description.ApiVersion} - {apiDetails.Owners}", Version = description.ApiVersion.ToString(), Description = $"### {apiDetails.Description}\n" + $"### [{apiDetails.Title} - Git Repository]({apiDetails.GitRepoUrl})" }; if (description.IsDeprecated) { info.Description = $"## Warning: This API version has been deprecated.\r\n{info.Description}"; } return(info); }
public static IServiceCollection AddSwagger(this IServiceCollection services, ApiDetails apiDetails) { services.AddSwaggerGen(options => { // resolve the IApiVersionDescriptionProvider service // note: that we have to build a temporary service provider here because one has not been created yet var provider = services.BuildServiceProvider().GetRequiredService <IApiVersionDescriptionProvider>(); foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description, apiDetails)); } var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath); options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme() { Description = "Authorization header using Bearer scheme", Name = "Authorization", In = ParameterLocation.Header }); options.DocumentFilter <SwaggerSecurityRequirementsDocumentFilter>(); }); return(services); }