public IActionResult Extend([FromBody] Int32 _1) { try { // ここに到達できているということはトークン自体は正規のものである // しかし有効かどうかはまた別問題のため、有効性を確認する using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } // 新しい有効期限のトークン String idAndToken = GenerateIdAndTokenString(loginUser.Id); // ID とログイン用トークンを返す return(Ok(idAndToken)); } catch (Exception excep) { Debug.WriteLine("延長サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult DeleteHistoriesAll() { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out DbSet <HistorySong> historySongs); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } IQueryable <HistorySong> histories = historySongs.Where(x => x.UserId == loginUser.Id); if (!histories.Any()) { return(NotAcceptable()); } // マイ履歴を削除 historySongs.RemoveRange(histories); userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("マイ履歴すべて削除サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public override String ControllerStatus() { String status; try { if (DefaultGuestUserThumbnail == null) { throw new Exception("デフォルトゲストプロフィール画像が作成できませんでした。" + ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + " フォルダーがあるか確認してください。"); } if (DefaultRegisteredUserThumbnail == null) { throw new Exception("デフォルト登録ユーザープロフィール画像が作成できませんでした。" + ServerConstants.FOLDER_NAME_SAMPLE_DATA_IMAGES + " フォルダーがあるか確認してください。"); } if (!ServerCommon.IsTokenSecretKeyValid()) { throw new Exception("トークン生成用の秘密鍵の長さが足りません。" + ServerConstants.TOKEN_SECRET_KEY_LENGTH_MIN + " 文字以上にしてください。"); } using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); // FirstOrDefault を使用すると列の不足を検出できる registeredUsers.FirstOrDefault(x => x.Id == String.Empty); status = "正常 / ユーザー数:" + registeredUsers.Count(); } catch (Exception excep) { status = "エラー / " + excep.Message; Debug.WriteLine("認証 API 状態取得サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); } return(status); }
public IActionResult GetStocks() { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out DbSet <StockSong> stockSongs, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } // キャッシュチェック DateTime lastModified = ServerCommon.LastModified(ServerConstants.FILE_NAME_USER_PROFILES); if (IsEntityTagValid(YbdCommon.DateTimeToModifiedJulianDate(lastModified))) { Debug.WriteLine("GetStocks() キャッシュ有効: "); return(NotModified()); } StockSong[] results = stockSongs.Where(x => x.UserId == loginUser.Id).OrderByDescending(x => x.RequestTime).ToArray(); EntityTagHeaderValue eTag = GenerateEntityTag(YbdCommon.DateTimeToModifiedJulianDate(lastModified)); return(File(JsonSerializer.SerializeToUtf8Bytes(results), ServerConstants.MIME_TYPE_JSON, lastModified, eTag)); } catch (Exception excep) { Debug.WriteLine("後で歌う予定リスト取得サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public UserProfileOptionsControl(Lifetime lifetime, OptionsSettingsSmartContext ctx, KaVEISettingsStore settingsStore, IActionExecutor actionExecutor, DataContexts dataContexts, IMessageBoxCreator messageBoxCreator, IUserProfileSettingsUtils userProfileUtils) { _messageBoxCreator = messageBoxCreator; _userProfileUtils = userProfileUtils; _lifetime = lifetime; _ctx = ctx; _settingsStore = settingsStore; _actionExecutor = actionExecutor; _dataContexts = dataContexts; InitializeComponent(); userProfileUtils.EnsureProfileId(); _userProfileSettings = userProfileUtils.GetSettings(); _userProfileContext = new UserProfileContext(_userProfileSettings, userProfileUtils); _userProfileContext.PropertyChanged += UserProfileContextOnPropertyChanged; DataContext = _userProfileContext; if (_ctx != null) { BindToUserProfileChanges(); } }
public IActionResult SetThumbnail([FromBody] TransferFile?transferFile) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } if (transferFile == null) { return(BadRequest()); } // 設定 using MemoryStream memoryStream = new MemoryStream(transferFile.Content); loginUser.Bitmap = ServerCommon.CreateThumbnail(memoryStream, transferFile.Mime, YbdConstants.USER_THUMBNAIL_WIDTH_MAX, YbdConstants.USER_THUMBNAIL_HEIGHT_MAX, true); loginUser.Mime = transferFile.Mime; loginUser.LastModified = YbdCommon.UtcNowModifiedJulianDate(); userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("プロフィール画像設定サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult DeleteRequestAll() { try { // 管理者権限が必要 using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser) || !loginUser.IsAdmin) { return(Unauthorized()); } using RequestSongContext requestSongContext = CreateRequestSongContext(out DbSet <RequestSong> requestSongs); if (!requestSongs.Any()) { return(NotAcceptable()); } requestSongContext.Database.EnsureDeleted(); requestSongContext.Database.EnsureCreated(); SendSse(YbdConstants.SSE_DATA_REQUEST_CHANGED); return(Ok()); } catch (Exception excep) { Debug.WriteLine("予約一括削除サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new UserProfileContext( serviceProvider.GetRequiredService < DbContextOptions <UserProfileContext> >())) { // Look for any movies. if (context.UserDetails.Any()) { return; // DB has been seeded } context.UserDetails.AddRange( new UserDetails { userName = "******", alias = "tomAlias", website = "tom.ca", socialUrl = "friends.com/tom", email = "*****@*****.**", dob = DateTime.Parse("1989-2-12"), }, new UserDetails { userName = "******", alias = "jerryAlias", website = "jerry.ca", socialUrl = "friends.com/jerry", email = "*****@*****.**", dob = DateTime.Parse("1989-2-24"), }, new UserDetails { userName = "******", alias = "pickachuAlias", website = "pickachu.ca", socialUrl = "friends.com/pickachu", email = "*****@*****.**", dob = DateTime.Parse("1989-3-12"), }, new UserDetails { userName = "******", alias = "tweetyAlias", website = "tweety.ca", socialUrl = "friends.com/tweety", email = "*****@*****.**", dob = DateTime.Parse("1989-4-12"), } ); context.SaveChanges(); } }
public void SetUp() { _rndGuid = "xyz"; _userProfileSettings = new UserProfileSettings(); _userProfileSettingsUtil = Mock.Of <IUserProfileSettingsUtils>(); Mock.Get(_userProfileSettingsUtil).Setup(u => u.CreateNewProfileId()).Returns(_rndGuid); _dataContext = new UserProfileContext(_userProfileSettings, _userProfileSettingsUtil); }
public UserApi(UserProfileContext context) { _context = context; if (_context.Users.Count() == 0) { Add(new User { FirstMidName = "Name", LastName = "Last name", Email = "*****@*****.**" }); } }
public ActionResult Login() { UserProfileContext userprofile_db = new UserProfileContext(); UserProfile user = userprofile_db.UserProfiles_DbSet.FirstOrDefault(a => a.UserName == DrilledHoleSurveyClass.AdministratorName); if (user == null) { WebSecurity.CreateUserAndAccount(DrilledHoleSurveyClass.AdministratorName, "111111"); } var model = new LoginModel(); return(View(model)); }
public IActionResult AddUser([FromBody] LoginInfo registerInfo) { try { if (!registerInfo.IsValid()) { return(BadRequest()); } using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); RegisteredUser newUser = new(); newUser.Name = registerInfo.Name; newUser.Password = registerInfo.Password; newUser.LastModified = newUser.LastLogin = YbdCommon.UtcNowModifiedJulianDate(); if (!IsAdminRegistered(registeredUsers)) { // 管理者未登録の場合は管理者登録でなければならない if (newUser.Name != YbdConstants.ADMIN_NAME) { return(BadRequest()); } newUser.IsAdmin = true; } // 同じ名前のユーザーが既に存在している場合は登録できない if (registeredUsers.FirstOrDefault(x => x.Name == newUser.Name) != null) { return(Conflict()); } // 登録 HashPassword(newUser); registeredUsers.Add(newUser); userProfileContext.SaveChanges(); String idAndToken = GenerateIdAndTokenString(newUser.Id); Debug.WriteLine("AddUser() " + idAndToken); // 登録と同時にログインできるように ID とログイン用トークンを返す return(Ok(idAndToken)); } catch (Exception excep) { Debug.WriteLine("ユーザー登録サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult IsAdminRegistered() { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); Boolean registered = IsAdminRegistered(registeredUsers); return(File(JsonSerializer.SerializeToUtf8Bytes(registered), ServerConstants.MIME_TYPE_JSON)); } catch (Exception excep) { Debug.WriteLine("認証 API 管理者登録確認サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public static Task SetProfileAsync( this IDistributedCache cache, UserChat userchat, UserProfileContext context, CancellationToken cancellationToken = default ) => cache.SetStringAsync( GetKey(userchat, "profile"), JsonConvert.SerializeObject(context), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromHours(1) }, cancellationToken );
public UserProfileDialog(IActionExecutor actionExec, UploadWizardPolicy policy, IUserProfileSettingsUtils userProfileUtils) { _actionExec = actionExec; _policy = policy; InitializeComponent(); _userProfileSettingsUtils = userProfileUtils; _userProfileSettings = _userProfileSettingsUtils.GetSettings(); var userProfileContext = new UserProfileContext(_userProfileSettings, _userProfileSettingsUtils); DataContext = userProfileContext; }
public IActionResult DeleteUser(String?id) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out DbSet <StockSong> stockSongs, out DbSet <HistorySong> historySongs); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser) || !loginUser.IsAdmin) { return(Unauthorized()); } if (String.IsNullOrEmpty(id)) { return(BadRequest()); } RegisteredUser?deleteUser = registeredUsers.SingleOrDefault(x => x.Id == id); if (deleteUser == null) { return(NotAcceptable()); } if (deleteUser.IsAdmin) { // 管理者は削除できない return(NotAcceptable()); } // 後で歌う予定リストを削除 stockSongs.RemoveRange(stockSongs.Where(x => x.UserId == deleteUser.Id)); // マイ履歴を削除 historySongs.RemoveRange(historySongs.Where(x => x.UserId == deleteUser.Id)); // 本体を削除 registeredUsers.Remove(deleteUser); #if DEBUG Thread.Sleep(1000); #endif userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("ユーザー削除サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserProfileContext profileContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } profileContext.Database.Migrate(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); app.UseAuthentication(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ProfileService.API v1")); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public IActionResult Login([FromBody] LoginInfo loginInfo) { try { if (!loginInfo.IsValid()) { return(BadRequest()); } #if DEBUG Thread.Sleep(1000); #endif // ユーザーを検索 using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); RegisteredUser?loginUser = registeredUsers.SingleOrDefault(x => x.Name == loginInfo.Name); if (loginUser == null) { return(NotAcceptable()); } // パスワードハッシュの一致を確認 if (loginUser.Password != HashPassword(loginInfo.Password, loginUser.Salt)) { return(NotAcceptable()); } String idAndToken = GenerateIdAndTokenString(loginUser.Id); Debug.WriteLine("Login() " + idAndToken); loginUser.LastLogin = YbdCommon.UtcNowModifiedJulianDate(); userProfileContext.SaveChanges(); // ID とログイン用トークンを返す return(Ok(idAndToken)); } catch (Exception excep) { Debug.WriteLine("ログインサーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult SetPassword([FromBody] String?[] passwords) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } if (passwords.Length < 2) { return(BadRequest()); } String?currentPassword = passwords[0]; String?newPassword = passwords[1]; if (String.IsNullOrEmpty(currentPassword) || String.IsNullOrEmpty(newPassword)) { return(BadRequest()); } // 現在のパスワードハッシュの一致を確認 if (loginUser.Password != HashPassword(currentPassword, loginUser.Salt)) { return(NotAcceptable()); } // 設定 loginUser.Password = newPassword; loginUser.LastModified = YbdCommon.UtcNowModifiedJulianDate(); HashPassword(loginUser); userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("パスワード設定サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult SetName([FromBody] String?newName) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } if (String.IsNullOrEmpty(newName)) { return(BadRequest()); } // 管理者の名前は変更できない if (loginUser.IsAdmin) { return(BadRequest()); } // 同じ名前のユーザーが既に存在している場合は登録できない if (registeredUsers.FirstOrDefault(x => x.Name == newName) != null) { return(Conflict()); } // 設定 loginUser.Name = newName; loginUser.LastModified = YbdCommon.UtcNowModifiedJulianDate(); userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("名前設定サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public SimpleMembershipInitializer() { Database.SetInitializer <UserProfileContext>(null); try { using (var context = new UserProfileContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("SurveyUserProfileConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
public IActionResult DeleteStock(String?stockSongId) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out DbSet <StockSong> stockSongs, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } if (String.IsNullOrEmpty(stockSongId)) { return(BadRequest()); } if (!Int32.TryParse(stockSongId, out Int32 stockSongIdNum)) { return(BadRequest()); } StockSong?stockSong = stockSongs.SingleOrDefault(x => x.StockSongId == stockSongIdNum); if (stockSong == null) { return(NotAcceptable()); } if (stockSong.UserId != loginUser.Id) { return(Unauthorized()); } // 後で歌う予定リストから削除 stockSongs.Remove(stockSong); userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("後で歌う予定リスト削除サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public void SetUp() { _userSettings = new UserProfileSettings { ProfileId = "" }; _updatedProperties = new List <string>(); var newGuid = Guid.NewGuid(); _someGuid = newGuid.ToString(); var rnd = Mock.Of <IRandomizationUtils>(); Mock.Get(rnd).Setup(r => r.GetRandomGuid()).Returns(newGuid); _userSettingsUtil = Mock.Of <IUserProfileSettingsUtils>(); Mock.Get(_userSettingsUtil).Setup(u => u.CreateNewProfileId()).Returns(_someGuid); _sut = new UserProfileContext(_userSettings, _userSettingsUtil); _sut.PropertyChanged += (sender, args) => { _updatedProperties.Add(args.PropertyName); }; }
public IActionResult AddStock([FromBody] AvailableSong availableSong) { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out DbSet <StockSong> stockSongs, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser)) { return(Unauthorized()); } StockSong?stockSong = stockSongs.SingleOrDefault(x => x.UserId == loginUser.Id && x.AvailableSongId == availableSong.Id); if (stockSong == null) { // 新規追加 stockSong = new(); YbdCommon.CopySongProperty(availableSong, stockSong); stockSong.AvailableSongId = availableSong.Id; stockSong.UserId = loginUser.Id; stockSong.RequestTime = YbdCommon.UtcNowModifiedJulianDate(); stockSongs.Add(stockSong); } else { // 登録日時更新 stockSong.RequestTime = YbdCommon.UtcNowModifiedJulianDate(); } userProfileContext.SaveChanges(); return(Ok()); } catch (Exception excep) { Debug.WriteLine("後で歌う予定追加サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult GetPublicUserInfo(String?id) { try { // キャッシュチェック DateTime lastModified = ServerCommon.LastModified(ServerConstants.FILE_NAME_USER_PROFILES); if (IsEntityTagValid(YbdCommon.DateTimeToModifiedJulianDate(lastModified))) { Debug.WriteLine("GetPublicUserInfo() キャッシュ有効: " + id); return(NotModified()); } if (String.IsNullOrEmpty(id)) { return(BadRequest()); } using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); RegisteredUser?registeredUser = registeredUsers.SingleOrDefault(x => x.Id == id); if (registeredUser == null) { return(NotAcceptable()); } PublicUserInfo userInfo = new PublicUserInfo(); registeredUser.CopyPublicInfo(userInfo, false); EntityTagHeaderValue eTag = GenerateEntityTag(YbdCommon.DateTimeToModifiedJulianDate(lastModified)); return(File(JsonSerializer.SerializeToUtf8Bytes(userInfo), ServerConstants.MIME_TYPE_JSON, lastModified, eTag)); } catch (Exception excep) { Debug.WriteLine("公開ユーザー情報取得サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public IActionResult GetUsers() { try { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); if (!IsTokenValid(registeredUsers, out RegisteredUser? loginUser) || !loginUser.IsAdmin) { return(Unauthorized()); } // キャッシュチェック DateTime lastModified = ServerCommon.LastModified(ServerConstants.FILE_NAME_USER_PROFILES); if (IsEntityTagValid(YbdCommon.DateTimeToModifiedJulianDate(lastModified))) { Debug.WriteLine("GetUsers() キャッシュ有効: "); return(NotModified()); } RegisteredUser[] registeredUsersArray = registeredUsers.Where(x => !x.IsAdmin).OrderBy(x => x.Name).ToArray(); PublicUserInfo[] results = new PublicUserInfo[registeredUsersArray.Length]; for (Int32 i = 0; i < registeredUsersArray.Length; i++) { PublicUserInfo publicUserInfo = new(); registeredUsersArray[i].CopyPublicInfo(publicUserInfo, true); results[i] = publicUserInfo; } EntityTagHeaderValue eTag = GenerateEntityTag(YbdCommon.DateTimeToModifiedJulianDate(lastModified)); return(File(JsonSerializer.SerializeToUtf8Bytes(results), ServerConstants.MIME_TYPE_JSON, lastModified, eTag)); } catch (Exception excep) { Debug.WriteLine("ユーザー一覧取得サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }
public UsersController(UserProfileContext context) { _context = context; }
public String Test() { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); return("Test isTokenValid: " + IsTokenValid(registeredUsers, out RegisteredUser? registeredUser) + " / " + Environment.TickCount.ToString("#,0")); }
public UserProfileService(UserProfileContext userProfileContext) { _context = userProfileContext; }
public IActionResult GetThumbnail(String?id) { try { RegisteredUser?registeredUser = null; if (String.IsNullOrEmpty(id)) { // 引数が空の場合は、ゲストのプロフィール画像を返す if (DefaultGuestUserThumbnail == null) { throw new Exception(); } registeredUser = new() { Bitmap = DefaultGuestUserThumbnail.Bitmap, Mime = DefaultGuestUserThumbnail.Mime, LastModified = YbdConstants.INVALID_MJD, }; } else { using UserProfileContext userProfileContext = CreateUserProfileContext(out DbSet <RegisteredUser> registeredUsers, out _, out _); registeredUser = registeredUsers.SingleOrDefault(x => x.Id == id); if (registeredUser == null) { return(NotAcceptable()); } // 指定されたユーザーにプロフィール画像が設定されていない場合 if (registeredUser.Bitmap.Length == 0) { Thumbnail?defaultThumbnail; if (registeredUser.IsAdmin) { defaultThumbnail = DefaultAdminUserThumbnail; } else { defaultThumbnail = DefaultRegisteredUserThumbnail; } if (defaultThumbnail == null) { throw new Exception(); } registeredUser = new() { Bitmap = defaultThumbnail.Bitmap, Mime = defaultThumbnail.Mime, LastModified = YbdConstants.INVALID_MJD, }; } } // キャッシュチェック DateTime lastModified = YbdCommon.ModifiedJulianDateToDateTime(registeredUser.LastModified); if (IsEntityTagValid(YbdCommon.DateTimeToModifiedJulianDate(lastModified))) { Debug.WriteLine("GetThumbnail() プロフィール画像キャッシュ有効: " + id); return(NotModified()); } // プロフィール画像を返す Debug.WriteLine("GetThumbnail() プロフィール画像キャッシュ無効: " + id); EntityTagHeaderValue eTag = GenerateEntityTag(registeredUser.LastModified); return(File(registeredUser.Bitmap, registeredUser.Mime, lastModified, eTag)); } catch (Exception excep) { Debug.WriteLine("プロフィール画像取得サーバーエラー:\n" + excep.Message); Debug.WriteLine(" スタックトレース:\n" + excep.StackTrace); return(InternalServerError()); } }