/// <summary> /// Helper to create to get or create the dynamic site - called by the GetSite methods. /// </summary> private T GetSiteWorker <T>(CallSiteBinder action, Func <CallSiteBinder, T> ctor) where T : CallSite { SiteKey sk = new SiteKey(typeof(T), action); lock (_sites) { SiteKey old; if (!_sites.TryGetValue(sk, out old)) { SitesCreated++; if (SitesCreated < 0) { // overflow, just reset back to zero... SitesCreated = 0; LastCleanup = 0; } sk.Site = ctor(sk.Action); _sites[sk] = sk; } else { sk = old; } sk.HitCount++; } Cleanup(); return((T)sk.Site); }
internal TagBuilder GenerateHtml() { if (Generator is null) { throw new ArgumentNullException(nameof(Generator)); } TagBuilder input = null; if (For != null || !string.IsNullOrWhiteSpace(Id)) { // Generate an <input> element using Model or Id property details. input = Generator.GenerateHidden( ViewContext, For?.ModelExplorer, For?.Name ?? Id, null, true, null); } var props = new RecaptchaProps( Type, SiteKey.TrimToNull() ?? Settings?.First(Type)?.SiteKey, callback: Callback, expiredCallback: ExpiredCallback, errorCallback: ErrorCallback, theme: Theme, tabIndex: TabIndex, size: Size, badge: Badge, action: Action); return(props.GenerateHtml(input)); }
/// <summary> /// Helper to create to get or create the dynamic site - called by the GetSite methods. /// </summary> private T GetOrCreateSite <T>(CallSiteBinder siteBinder, Func <CallSiteBinder, T> factory) where T : CallSite { SiteKey sk = new SiteKey(typeof(T), siteBinder); lock (_sites) { if (!_sites.TryGetValue(sk, out SiteKey old)) { SitesCreated++; if (SitesCreated < 0) { // overflow, just reset back to zero... SitesCreated = 0; LastCleanup = 0; } sk.Site = factory(sk.SiteBinder); _sites[sk] = sk; } else { sk = old; } sk.HitCount++; CleanupNoLock(); } return((T)sk.Site); }
/// <summary> /// Displays information about the Server we are connected to. /// </summary> static void DisplayPetraServerInformation() { int TotalConnectedClients; int CurrentlyConnectedClients; Int64 SiteKey; Int64 DBReconnectionAttemptsCounter; Int64 DBConnectionCheckInterval; RetrieveConnectedClients(out TotalConnectedClients, out CurrentlyConnectedClients, out SiteKey, out DBReconnectionAttemptsCounter, out DBConnectionCheckInterval); TLogging.Log(TRemote.GetServerInfoVersion()); TLogging.Log(Catalog.GetString("Configuration file: " + TAppSettingsManager.ConfigFileName)); TLogging.Log(" * " + Catalog.GetString(String.Format("DB Connection State: {0}", ((DBReconnectionAttemptsCounter == -1) ? String.Format("Not yet connected") : ((DBReconnectionAttemptsCounter == 0) ? String.Format("OK") : String.Format("BROKEN / Reconnection Attempt #" + DBReconnectionAttemptsCounter.ToString()))))) + ((DBReconnectionAttemptsCounter == 0) ? (DBConnectionCheckInterval == 0) ? Catalog.GetString(" (at last DB action)") : Catalog.GetString(" (polling enabled)") : "")); TLogging.Log(" * " + String.Format(Catalog.GetString("Client connections since Server start: {0}"), TotalConnectedClients.ToString())); TLogging.Log(" * " + String.Format(Catalog.GetString("Clients currently connected: {0}"), CurrentlyConnectedClients)); TLogging.Log(" * " + String.Format(Catalog.GetString("SiteKey of OpenPetra Installation: {0}{1}"), (SiteKey != -1) ? SiteKey.ToString() : Catalog.GetString("N/A"), (SiteKey == 99000000) ? Catalog.GetString(" (SiteKey not yet set up)") : String.Empty)); TLogging.Log(TRemote.GetServerInfoState()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Kharban_WebAPI", Version = "v1" }); }); // configure strongly typed settings object var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appSettingsSection); var appSettings = appSettingsSection.Get <AppSettings>(); var key = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; }); // configure strongly typed settings object var pushNotificationsOptions = Configuration.GetSection("PushNotifications"); services.Configure <PushNotificationsOptions>(pushNotificationsOptions); SiteKey.ConfigureConnectionString(Configuration.GetSection("ConnectionStrings")); SiteKey.ConfigurePushNotification(Configuration.GetSection("PushNotifications")); SiteKey.ConfigureAppSettings(Configuration.GetSection("AppSettings")); // configure DI for application services services.AddScoped <IUserService, UserService>(); }
/// <summary> /// Displays information about the Server we are connected to. /// </summary> static void DisplayPetraServerInformation() { int TotalConnectedClients; int CurrentlyConnectedClients; Int64 SiteKey; RetrieveConnectedClients(out TotalConnectedClients, out CurrentlyConnectedClients, out SiteKey); TLogging.Log(TRemote.GetServerInfoVersion()); TLogging.Log(Catalog.GetString("Configuration file: " + TAppSettingsManager.ConfigFileName)); TLogging.Log(" * " + String.Format(Catalog.GetString("Client connections since Server start: {0}"), TotalConnectedClients.ToString())); TLogging.Log(" * " + String.Format(Catalog.GetString("Clients currently connected: {0}"), CurrentlyConnectedClients)); TLogging.Log(" * " + String.Format(Catalog.GetString("SiteKey of OpenPetra Installation: {0}{1}"), (SiteKey != -1) ? SiteKey.ToString() : Catalog.GetString("N/A"), (SiteKey == 99000000) ? Catalog.GetString(" (SiteKey not yet set up)") : String.Empty)); TLogging.Log(TRemote.GetServerInfoState()); }
public override string ToString() { return(SiteKey.ToString()); }