public void Clean() { IEnumerable <string> tempFiles = null; Common.Utility.ExceptionablePlaceWrapper(() => { lock (_lock) { var now = DateTime.Now; var life = new TimeSpan(0, 0, 0, 0, this.lifeInterval); cacheContent = cacheContent.Where( x => !x.Value.IsDownloaded || now.Subtract((DateTime)x.Value.GetLastUsingTime()).Ticks < life.Ticks) .ToDictionary(x => x.Key, x => x.Value); //also remove files survived by some reason from previous iteration //By some reason it means locking of file by reading or writing tempFiles = Directory.EnumerateFiles(this.tempFileDirectory) .Where(x => x.EndsWith(".tmp")).Except(cacheContent.Values.Select(x => x.LocalAddress)); } }, "", "", false); ; Parallel.ForEach(tempFiles, (file) => { Common.Utility.ExceptionablePlaceWrapper(() => { //if file is locked, it won't be deleted. File.Delete(file); }, U.Message(InstallationUtility.FILE_NOT_DELETED, U.Arg("FileName", file)), U.Message(InstallationUtility.FILE_DELETED, U.Arg("FileName", file)), false); }); }
public void Get(string key, Action <PackageCacherResponse> response) { lock (_lock) { if (cacheContent.ContainsKey(key)) { var bundle = cacheContent[key]; bundle.UpdateLastAccessTime(); if (bundle.IsDownloaded) { U.LogDebug(U.Message(IU.FILE_FOUND_BY_KEY, U.Arg("Key", key))); response(new PackageCacherResponse(key, bundle.LocalAddress, null, bundle.RevisionNumber)); } else { U.LogDebug(U.Message(IU.FILE_IS_DOWNLOADING, U.Arg("Key", key))); bundle.PackageDownloaded += (sender, args) => { response(new PackageCacherResponse(key, bundle.LocalAddress, null, bundle.RevisionNumber)); }; } return; } } U.LogDebug(U.Message(IU.KEY_NOT_FOUND, U.Arg("Key", key))); response(new PackageCacherResponse(key, null, null, -1)); }
public void Stop() { if (daemonHolder != null) { daemonHolder.Stop(); } daemonHolder = null; U.LogInfo(U.Message(IU.BACKGROUND_TEMP_CLEANER_STOPPED)); }
public void Start() { if (daemonHolder != null) { daemonHolder.Stop(); } daemonHolder = CommonDataTypes.Utility.Utility.CreateAndRunRepeatedProcess(this.clearInterval, false, Clean); U.LogInfo(U.Message(IU.BACKGROUND_TEMP_CLEANER_STARTED)); }
public void Remove(string key) { lock (_lock) { if (cacheContent.ContainsKey(key)) { cacheContent.Remove(key); U.LogDebug(U.Message(IU.ENTRY_REMOVED, U.Arg("Key", key))); } } }
public void RegisterDownloaded(string key, int revisionNumber) { lock (_lock) { cacheContent[key].RevisionNumber = revisionNumber; cacheContent[key].UpdateLastAccessTime(); cacheContent[key].SetDownloaded(); U.LogDebug(U.Message(IU.ADDRESS_CONFIRMED, U.Arg("Key", key), U.Arg("RevNumber", revisionNumber))); } }
public void DobarKonstruktor() { utility = new Common.Utility(); Assert.AreNotEqual(null, utility); utility = new Common.Utility(500); Assert.AreEqual(utility.Price, 500); utility = new Common.Utility(1000, 2000); Assert.AreEqual(utility.Power, 1000); Assert.AreEqual(utility.Price, 2000); }
public void LosKonstruktor() { Assert.Throws <ArgumentOutOfRangeException>( () => { utility = new Common.Utility(-1000); } ); Assert.Throws <ArgumentOutOfRangeException>( () => { utility = new Common.Utility(200, -500); } ); }
/// <summary> /// Creates an access JwtSecurityToken given an <paramref name="account"/> and <paramref name="refreshTokenId"/>. /// </summary> /// <param name="account">The Account from which to retrieve user claims.</param> /// <param name="refreshTokenId">The refresh token id to use for the jti claim.</param> /// <returns>The created JwtSecurityToken.</returns> public JwtSecurityToken GetAccessToken(Account account, Guid refreshTokenId) { var expiry = Utility.GetSetting <int>(Settings.JwtAccessTokenExpiry); var key = Utility.GetSetting <string>(Settings.JwtKey); var claims = new List <Claim>() { new Claim(ClaimTypes.Name, account.Name), new Claim(ClaimTypes.NameIdentifier, account.Id.ToString()), new Claim(ClaimTypes.Role, account.Role.ToString()), new Claim("sub", account.Id.ToString()), new Claim("name", account.Name), new Claim("role", account.Role.ToString()), new Claim("jti", refreshTokenId.ToString()), new Claim("pwd", account.PasswordResetRequired.ToString().ToLower()), }; return(GetJwtSecurityToken(claims, expiry)); }
private JwtSecurityToken GetJwtSecurityToken(List <Claim> claims, DateTime expiresUtc, DateTime issuedUtc) { if (!claims.Any(c => c.Type == "iat")) { claims.Add(new Claim("iat", ((DateTimeOffset)issuedUtc).ToUnixTimeSeconds().ToString())); } var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Utility.GetSetting <string>(Settings.JwtKey))); var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha512); var token = new JwtSecurityToken( issuer: Utility.GetSetting <string>(Settings.JwtIssuer), audience: Utility.GetSetting <string>(Settings.JwtAudience), claims: claims, notBefore: issuedUtc, expires: expiresUtc, signingCredentials: credentials); return(token); }
/// <summary> /// Initializes a new instance of the <see cref="TeamsController"/> class. /// </summary> /// <param name="telemetryClient">ApplicationInsights DI.</param> /// <param name="configurationProvider">ConfigurationProvider DI.</param> /// <param name="openShiftRequestController">OpenShiftRequestController DI.</param> /// <param name="swapShiftController">SwapShiftController DI.</param> /// <param name="utility">The common utility methods DI.</param> /// <param name="userMappingProvider">The user mapping provider DI.</param> /// <param name="shiftMappingEntityProvider">The shift entity mapping provider DI.</param> /// <param name="openShiftRequestMappingEntityProvider">The open shift request mapping entity provider DI.</param> /// <param name="openShiftMappingEntityProvider">The open shift mapping entity provider DI.</param> /// <param name="swapShiftMappingEntityProvider">The swap shift mapping entity provider DI.</param> public TeamsController( TelemetryClient telemetryClient, IConfigurationProvider configurationProvider, OpenShiftRequestController openShiftRequestController, SwapShiftController swapShiftController, Common.Utility utility, IUserMappingProvider userMappingProvider, IShiftMappingEntityProvider shiftMappingEntityProvider, IOpenShiftRequestMappingEntityProvider openShiftRequestMappingEntityProvider, IOpenShiftMappingEntityProvider openShiftMappingEntityProvider, ISwapShiftMappingEntityProvider swapShiftMappingEntityProvider) { this.telemetryClient = telemetryClient; this.configurationProvider = configurationProvider; this.openShiftRequestController = openShiftRequestController; this.swapShiftController = swapShiftController; this.utility = utility; this.userMappingProvider = userMappingProvider; this.shiftMappingEntityProvider = shiftMappingEntityProvider; this.openShiftRequestMappingEntityProvider = openShiftRequestMappingEntityProvider; this.openShiftMappingEntityProvider = openShiftMappingEntityProvider; this.swapShiftMappingEntityProvider = swapShiftMappingEntityProvider; }
public string ReserveAddress(string key) { lock (_lock) { string localAddress = null; if (cacheContent.ContainsKey(key)) { throw new InvalidDataException(U.Message(IU.NOT_ALLOWED_KEYS_DUPLICATION, U.Arg("Key", key))); } localAddress = GetLocalAddress(key); var bundle = new StaffBundle() { LocalAddress = localAddress, }; cacheContent.Add(key, bundle); U.LogDebug(U.Message(IU.LOCAL_ADDRESS_RESERVED, U.Arg("LocalAddress", localAddress))); return(localAddress); } }
/// <summary> /// Creates a refresh JwtSecurityToken with the specified <paramref name="refreshTokenId"/> and default expiry. /// </summary> /// <param name="refreshTokenId">The token id.</param> /// <returns>The created JwtSecurityToken.</returns> public JwtSecurityToken GetRefreshToken(Guid refreshTokenId) { var expiry = Utility.GetSetting <int>(Settings.JwtRefreshTokenExpiry); return(GetRefreshToken(refreshTokenId, DateTime.UtcNow.AddMinutes(expiry), DateTime.UtcNow)); }