public UserHelper(IAppConfigHelper appConfigHelper, IAppCache appCache, IPrincipal user, IUserService userService) { _appConfigHelper = appConfigHelper; _appCache = appCache; _user = user; _userService = userService; }
public CRepositoryWrapper(CRepositoryContext repositoryContext, IAppCache cache) { _repoContext = repositoryContext; _cache = cache; }
public OntologyExplorerController(IConfiguration config, ILogger <OntologyExplorerController> logger) { Configuration = config; _logger = logger; _cacheOntologyExplorer = new CachingService(); }
internal static async Task <HttpResponseMessage> PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, int id) { if (request.Content.IsMimeMultipartContent() == false) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var root = IOHelper.MapPath(SystemDirectories.TempFileUploads); //ensure it exists Directory.CreateDirectory(root); var provider = new MultipartFormDataStreamProvider(root); var result = await request.Content.ReadAsMultipartAsync(provider); //must have a file if (result.FileData.Count == 0) { return(request.CreateResponse(HttpStatusCode.NotFound)); } var user = userService.GetUserById(id); if (user == null) { return(request.CreateResponse(HttpStatusCode.NotFound)); } var tempFiles = new PostedFiles(); if (result.FileData.Count > 1) { return(request.CreateValidationErrorResponse("The request was not formatted correctly, only one file can be attached to the request")); } //get the file info var file = result.FileData[0]; var fileName = file.Headers.ContentDisposition.FileName.Trim(new[] { '\"' }).TrimEnd(); var safeFileName = fileName.ToSafeFileName(); var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLower(); if (Current.Configs.Settings().Content.DisallowedUploadFiles.Contains(ext) == false) { //generate a path of known data, we don't want this path to be guessable user.Avatar = "UserAvatars/" + (user.Id + safeFileName).GenerateHash <SHA1>() + "." + ext; using (var fs = System.IO.File.OpenRead(file.LocalFileName)) { Current.MediaFileSystem.AddFile(user.Avatar, fs, true); } userService.Save(user); //track the temp file so the cleanup filter removes it tempFiles.UploadedFiles.Add(new ContentPropertyFile { TempFilePath = file.LocalFileName }); } return(request.CreateResponse(HttpStatusCode.OK, user.GetUserAvatarUrls(cache))); }
public WatchListRepository(IDatabaseFactory databaseFactory, ICachingFactory cacheFactory) : base(databaseFactory.GetContext()) { _cache = cacheFactory.GetCacheService(); }
public MinionsReadService(IAppCache appCache) { _appCache = appCache; }
public CachedCallHistoryRepository(IAppCache cache, ICallHistoryRepository internalRepository) { _lazyCache = cache; _internalRepository = internalRepository; }
public TemplateRenderingConfigurationExpression(IContainAppPath appPathContainer, IAppCache appCache) { _appPathContainer = appPathContainer; _appCache = appCache; }
public static void ClearRegisteredSips(this IAppCache cache) { log.Debug("Removing registered sips from cache"); cache.Remove(RegisteredSipsKey); }
public static void FullReload(this IAppCache cache) { cache.ClearRegisteredSips(); cache.ResetLocationNetworks(); cache.ResetSettings(); }
public static void ResetProfiles(this IAppCache cache) { log.Debug("Removing profiles from cache"); cache.Remove(ProfilesKey); }
public static IList <ProfileNameAndSdp> GetProfiles(this IAppCache cache, Func <IList <ProfileNameAndSdp> > loader) { return(cache.GetOrAdd(ProfilesKey, loader, DateTimeOffset.UtcNow.AddSeconds(CacheTimeProfiles))); }
public static void ResetAvailableFilters(this IAppCache cache) { log.Debug("Removing available filters from cache"); cache.Remove(AvailableFiltersKey); }
public static IList <AvailableFilter> GetAvailableFilters(this IAppCache cache, Func <IList <AvailableFilter> > loader) { var list = cache.GetOrAdd(AvailableFiltersKey, loader, DateTimeOffset.UtcNow.AddSeconds(CacheTimeFilter)); return(list); }
public TemplatesFactory(IAppCache appCache) { }
public YoutubeService(IAppCache appCache) { _converter = new Converter(); _cache = new YoutubeCache(appCache); }
public static List <Setting> GetSettings(this IAppCache cache, Func <List <Setting> > loader) { var list = cache.GetOrAdd(SettingsKey, loader, DateTimeOffset.UtcNow.AddSeconds(CacheTimeSettings)); return(list); }
public static void ResetLocationNetworks(this IAppCache cache) { log.Debug("Removing location networks from cache"); cache.Remove(LocationNetworksKey); }
public static void ResetSettings(this IAppCache cache) { log.Debug("Removing settings from cache"); cache.Remove(SettingsKey); }
protected BaseDocumentRepository(IAppCache cache) : base(cache) { }
public static List <LocationNetwork> GetOrAddLocationNetworks(this IAppCache cache, Func <List <LocationNetwork> > loader) { var list = cache.GetOrAdd(LocationNetworksKey, loader, DateTimeOffset.UtcNow.AddSeconds(CacheTimeSettings)); return(list); }
private const int MaxLength = 20000000; //20mb set in from end public FileController(ApplicationDbContext context, IMapper mapper, ILogger <FileController> logger, IAppCache cache, IConfiguration configuration) { this.context = context; this.mapper = mapper; this.logger = logger; this.cache = cache; this.storageConnectionString = configuration["StorageConnectionString"]; }
/// <summary> /// Tries to lookup the user's Gravatar to see if the endpoint can be reached, if so it returns the valid URL /// </summary> /// <param name="user"></param> /// <param name="cache"></param> /// <param name="mediaFileManager"></param> /// <returns> /// A list of 5 different sized avatar URLs /// </returns> public static string[] GetUserAvatarUrls(this IUser user, IAppCache cache, MediaFileManager mediaFileManager, IImageUrlGenerator imageUrlGenerator) { // If FIPS is required, never check the Gravatar service as it only supports MD5 hashing. // Unfortunately, if the FIPS setting is enabled on Windows, using MD5 will throw an exception // and the website will not run. // Also, check if the user has explicitly removed all avatars including a Gravatar, this will be possible and the value will be "none" if (user.Avatar == "none" || CryptoConfig.AllowOnlyFipsAlgorithms) { return(new string[0]); } if (user.Avatar.IsNullOrWhiteSpace()) { var gravatarHash = user.Email.GenerateHash <MD5>(); var gravatarUrl = "https://www.gravatar.com/avatar/" + gravatarHash + "?d=404"; //try Gravatar var gravatarAccess = cache.GetCacheItem <bool>("UserAvatar" + user.Id, () => { // Test if we can reach this URL, will fail when there's network or firewall errors var request = (HttpWebRequest)WebRequest.Create(gravatarUrl); // Require response within 10 seconds request.Timeout = 10000; try { using ((HttpWebResponse)request.GetResponse()) { } } catch (Exception) { // There was an HTTP or other error, return an null instead return(false); } return(true); }); if (gravatarAccess) { return(new[] { gravatarUrl + "&s=30", gravatarUrl + "&s=60", gravatarUrl + "&s=90", gravatarUrl + "&s=150", gravatarUrl + "&s=300" }); } return(new string[0]); } //use the custom avatar var avatarUrl = mediaFileManager.FileSystem.GetUrl(user.Avatar); return(new[] { imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(avatarUrl) { ImageCropMode = ImageCropMode.Crop, Width = 30, Height = 30 }), imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(avatarUrl) { ImageCropMode = ImageCropMode.Crop, Width = 60, Height = 60 }), imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(avatarUrl) { ImageCropMode = ImageCropMode.Crop, Width = 90, Height = 90 }), imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(avatarUrl) { ImageCropMode = ImageCropMode.Crop, Width = 150, Height = 150 }), imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(avatarUrl) { ImageCropMode = ImageCropMode.Crop, Width = 300, Height = 300 }) }); }
public ExchangeRatesCommand(IOrderCloudIntegrationsBlobService blob, IFlurlClientFactory flurlFactory, IAppCache cache) { _client = new OrderCloudIntegrationsExchangeRatesClient(flurlFactory); _blob = blob; _cache = cache; }
internal static IActionResult PostSetAvatarInternal(IList <IFormFile> files, IUserService userService, IAppCache cache, MediaFileManager mediaFileManager, IShortStringHelper shortStringHelper, ContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id) { if (files is null) { return(new UnsupportedMediaTypeResult()); } var root = hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempFileUploads); //ensure it exists Directory.CreateDirectory(root); //must have a file if (files.Count == 0) { return(new NotFoundResult()); } var user = userService.GetUserById(id); if (user == null) { return(new NotFoundResult()); } if (files.Count > 1) { return(new ValidationErrorResult("The request was not formatted correctly, only one file can be attached to the request")); } //get the file info var file = files.First(); var fileName = file.FileName.Trim(new[] { '\"' }).TrimEnd(); var safeFileName = fileName.ToSafeFileName(shortStringHelper); var ext = safeFileName.Substring(safeFileName.LastIndexOf('.') + 1).ToLower(); if (contentSettings.DisallowedUploadFiles.Contains(ext) == false) { //generate a path of known data, we don't want this path to be guessable user.Avatar = "UserAvatars/" + (user.Id + safeFileName).GenerateHash <SHA1>() + "." + ext; using (var fs = file.OpenReadStream()) { mediaFileManager.FileSystem.AddFile(user.Avatar, fs, true); } userService.Save(user); } return(new OkObjectResult(user.GetUserAvatarUrls(cache, mediaFileManager, imageUrlGenerator))); }
public LocationInfoRepository(IAppCache cache) : base(cache) { }
/// <summary> /// Contructor to create a cache of <see cref="IAzureProxy"/> /// </summary> /// <param name="azureProxy"><see cref="AzureProxy"/></param> /// <param name="cache">Lazy cache using <see cref="IAppCache"/></param> public CachingWithRetriesAzureProxy(IAzureProxy azureProxy, IAppCache cache) { this.azureProxy = azureProxy; this.cache = cache; }
public CachedSipAccountRepository(IAppCache cache, ISipAccountRepository internalRepository) { _lazyCache = cache; _internalRepository = internalRepository; }
public UserController(IMediator mediator, TrainDTrainorContext context, IAppCache cache) : base(mediator, cache) { _context = context; }
/// <summary> /// Default constructor which will use the current thread's culture /// </summary> /// <param name="localizationService"></param> /// <param name="requestCache"></param> public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCache) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); }
protected BaseRepository(IAppCache cache) : base(cache) { }
public OMDBService(IAppCache appCache) { _parser = new ResponseParser(); _client = new OMDBClient(); _appCache = appCache; }
public GetGlobalCommandStats(IAppCache cache, ClemBotContext context) { _cache = cache; _context = context; }
public YoutubeCache(IAppCache appCache) { _appCache = appCache; }
protected CachedObjectAsync(IAppCache lazyCache) : base(lazyCache) { }
public TemplateRenderingConfigurationExpression() { _appPathContainer = new AppPathContainer(); _appCache = new AppCache(); }
public SimpleRegisteredSipRepository(ISettingsManager settingsManager, IAppCache cache) : base(cache) { _settingsManager = settingsManager; }