public async Task <byte[]> GetPhotoAsync(string userId) { var allUsers = await usersDb.Value; var user = allUsers.FirstOrDefault(u => string.Equals(u.Id.ToString(), userId, StringComparison.OrdinalIgnoreCase)); if (user != null) { var absolutePath = DeloitteHostingEnvironment.Get(string.Format(photoFileTemplate, user.PhotoName)); var imageBytes = File.ReadAllBytes(absolutePath); return(imageBytes); } return(new byte[0]); }
private Task WriteFormattedMessageAsync(string message) { var logsAbsolutePath = DeloitteHostingEnvironment.Get(logsFilePath); lock (_locker) { if (!File.Exists(logsAbsolutePath)) { File.Create(logsAbsolutePath); } File.AppendAllText(logsFilePath, message, System.Text.Encoding.UTF8); } return(Task.CompletedTask); }
private static async Task <IList <User> > ReadUsersFromFile() { try { var absolutePath = DeloitteHostingEnvironment.Get(usersFilePath); var text = File.ReadAllText(absolutePath); var parsed = JsonConvert.DeserializeObject <IEnumerable <User> >(text); return(parsed.ToList()); } catch (Exception e) { await Logger.Instance.LogAsync(e); } return(new List <User>(0)); }
private static async Task<IDictionary<string, Account>> ReadAccountsFromFile() { try { var absolutePath = DeloitteHostingEnvironment.Get(accountsFilePath); var text = File.ReadAllText(absolutePath); var parsed = JsonConvert.DeserializeObject<IEnumerable<Account>>(text); return parsed.ToDictionary(x => x.Login, x => x, StringComparer.OrdinalIgnoreCase); } catch (Exception e) { await Logger.Instance.LogAsync(e); } return new Dictionary<string, Account>(0); }