private static string ProcessContent(PublicUserInfo userInfo, Note note) { var content = note.Content; var beginMatch = EnNoteBeginTagRegex.Match(content); if (!beginMatch.Success) { throw new EverpageException("Cannot find the begin tag <en-note> in the content."); } var startIndex = beginMatch.Index + beginMatch.Length; var endIndex = content.LastIndexOf("</en-note>", StringComparison.Ordinal); if (endIndex < 0) { throw new EverpageException("Cannot find the end tag </en-note> in the content."); } var body = content.Substring(startIndex, endIndex - startIndex); var resources = note.Resources != null ? note.Resources.ToDictionary(r => ToHex(r.Data.BodyHash)) : new Dictionary <string, Resource>(); return(EnMediaTagRegex.Replace(body, m => EnMediaToImg(m, resources, userInfo.WebApiUrlPrefix))); }
// ==================================================================== // public メンバー関数 // ==================================================================== // -------------------------------------------------------------------- // 公開情報のみをコピー // -------------------------------------------------------------------- public void CopyPublicInfo(PublicUserInfo publicUserInfo, Boolean forAdmin) { // 他人も取得可能な情報 publicUserInfo.Id = Id; publicUserInfo.IsAdmin = IsAdmin; publicUserInfo.Name = Name; // 管理者のみ取得可能な情報 if (forAdmin) { publicUserInfo.LastModified = LastModified; publicUserInfo.LastLogin = LastLogin; } }
/// <summary> /// Generates a list of public userinfos out of the friend list of the current user /// </summary> /// <returns>The list.</returns> public List <PublicUserInfo> FriendList() { CoflnetUser currentUser = UserService.Instance.CurrentUser; return(currentUser.Friends.ConvertAll((Reference <CoflnetUser> input) => { PublicUserInfo userInfo; EntityManager.Instance.TryGetEntity <PublicUserInfo>(input.EntityId, out userInfo); if (userInfo == null) { userInfo = new PublicUserInfo() { Id = input.EntityId, userName = "******" }; } return userInfo; })); }
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 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 IList<Contract> GetContractOfManagerWithUser(PublicUserInfo employee) { EnsureManager(); return ((IManagerPanelDAO)_db).GetContractsOfManager(((IManagerPanelDAO) _db).GetUser(employee.Login)); }
private void PrepareForRemoving(String Login) { PublicUserInfo userInfo = new PublicUserInfo() { Login = "******" }; User user = new User() { PublicUserInfo = userInfo }; Project project = new Project() { Manager = userInfo }; EmployeeDescription employeeDescription = new EmployeeDescription() { Employee = userInfo, Project = project }; Contract contract = new Contract() { Creator = userInfo, Employee = userInfo, Project = project }; WorkRecord record = new WorkRecord { EmployeeDescription = employeeDescription, MinutesWorked = 12 }; Summary summary = new Summary { EmployeeDescription = employeeDescription }; Dao.SetUser(user); Assert.IsFalse(Dao.GetEmployeeDescriptions(user).Count > 0); Assert.IsFalse(Dao.GetRecords(user).Count > 0); Assert.IsFalse(Dao.GetSummaries(user).Count > 0); Assert.IsFalse(Dao.GetContracts(user).Count > 0); Dao.SetProject(project); Dao.SetEmployeeDescription(employeeDescription); Dao.SetRecord(record); Dao.SetSummary(summary); Dao.SetContract(contract); Assert.IsTrue(Dao.GetEmployeeDescriptions(user).Count > 0); Assert.IsTrue(Dao.GetRecords(user).Count > 0); Assert.IsTrue(Dao.GetContracts(user).Count > 0); Assert.IsTrue(Dao.GetSummaries(user).Count > 0); }
public void RemovedRecordIsRemovedPermanently() { PublicUserInfo userInfo = new PublicUserInfo() { Login = "******" }; Project project = new Project() { Manager = userInfo }; EmployeeDescription employeeDescription = new EmployeeDescription() { Employee = userInfo, Project = project }; WorkRecord workRecord = new WorkRecord() { EmployeeDescription = employeeDescription }; User user = new User() { PublicUserInfo = userInfo }; Dao.SetUser(user); Dao.SetProject(project); Dao.SetEmployeeDescription(employeeDescription); Dao.SetRecord(workRecord); Assert.IsTrue(Dao.GetRecordsOfEmployee(employeeDescription).Count > 0); Dao.RemoveRecord(workRecord); Assert.IsFalse(Dao.GetRecordsOfEmployee(employeeDescription).Count > 0); }