/// <summary> /// 回答被赞同的相关事件处理 /// </summary> private void AskAnswerSupportEventModule_After(long objectId, SupportOpposeEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().AskAnswer()) { //如果不是第一次顶踩,则不处理 if (!eventArgs.FirstTime) { return; } if (eventArgs.EventOperationType == EventOperationType.Instance().Support()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //创建顶回答的动态[关注回答者的粉丝可以看到该顶信息] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.SourceId = answer.AnswerId; activityOfFollower.UserId = eventArgs.UserId; activityOfFollower.ReferenceId = answer.AnswerId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.OwnerId = eventArgs.UserId; activityOfFollower.OwnerName = userService.GetFullUser(eventArgs.UserId).DisplayName; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建顶回答的动态[关注该问题的用户可以看到该顶信息] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.SourceId = answer.AnswerId; activityOfQuestionSubscriber.UserId = eventArgs.UserId; activityOfQuestionSubscriber.ReferenceId = answer.AnswerId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeSupported(); //回答收到赞同时产生积分 string eventOperationType = EventOperationType.Instance().Support(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //赞同者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(question.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加赞同的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerSupportCount(), 1); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Oppose()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeOpposed(); //回答收到反对时产生积分 string eventOperationType = EventOperationType.Instance().Oppose(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //反对者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(answer.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加反对的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerOpposeCount(), 1); } } }
protected override void OnApplyTemplate() { var popupRadius = (CornerRadius)ResourceAccessor.ResourceLookup(this, c_overlayCornerRadiusKey); m_headerContentPresenter = GetTemplateChild <ContentPresenter>("ContentPresenter"); var tabView = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this)); var internalTabView = tabView ?? null; Button GetCloseButton(TabView internalTabView) { var closeButton = (Button)GetTemplateChild("CloseButton"); if (closeButton != null) { // Do localization for the close button automation name if (string.IsNullOrEmpty(AutomationProperties.GetName(closeButton))) { var closeButtonName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_TabViewCloseButtonName); AutomationProperties.SetName(closeButton, closeButtonName); } if (internalTabView != null) { // Setup the tooltip for the close button var tooltip = new ToolTip(); tooltip.Content = internalTabView.GetTabCloseButtonTooltipText(); ToolTipService.SetToolTip(closeButton, tooltip); } closeButton.Click += OnCloseButtonClick; } return(closeButton); } m_closeButton = GetCloseButton(internalTabView); OnHeaderChanged(); OnIconSourceChanged(); if (tabView != null) { if (SharedHelpers.IsThemeShadowAvailable()) { if (internalTabView != null) { var shadow = new ThemeShadow(); if (!SharedHelpers.Is21H1OrHigher()) { if (internalTabView.GetShadowReceiver() is { } shadowReceiver) { shadow.Receivers.Add(shadowReceiver); } } m_shadow = shadow; double shadowDepth = (double)SharedHelpers.FindInApplicationResources(TabView.c_tabViewShadowDepthName, TabView.c_tabShadowDepth); var currentTranslation = Translation; var translation = new Vector3(currentTranslation.X, currentTranslation.Y, (float)shadowDepth); Translation = translation; UpdateShadow(); } } tabView.TabDragStarting += OnTabDragStarting; tabView.TabDragCompleted += OnTabDragCompleted; } UpdateCloseButton(); UpdateForeground(); UpdateWidthModeVisualState(); }
/// <summary> /// 问题增删改等触发的事件 /// </summary> private void AskQuestionEventModule_After(AskQuestion question, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { //冻结用户的积分 if (question.AddedReward > 0) { userService.FreezeTradePoints(question.UserId, question.AddedReward); } //向定向提问的目标用户发送通知 if (question.AskUserId > 0) { Notice notice = Notice.New(); notice.UserId = question.AskUserId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = question.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().AskUser(); noticeService.Create(notice); } //自动关注(提问者自动关注[订阅]该问题) if (!subscribeService.IsSubscribed(question.QuestionId, question.UserId)) { subscribeService.Subscribe(question.QuestionId, question.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { //已解决问题的积分不返还,未解决/已取消的问题应该解除冻结积分 if (question.Reward > 0 && question.Status != QuestionStatus.Resolved) { userService.UnfreezeTradePoints(question.UserId, question.Reward); } //删除所有用户对该问题的关注(订阅) IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(question.QuestionId); foreach (var userId in userIds) { subscribeService.CancelSubscribe(question.QuestionId, userId); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { //冻结用户的积分 if (question.AddedReward != 0) { userService.FreezeTradePoints(question.UserId, question.AddedReward); } if (question.Status == QuestionStatus.Canceled) { subscribeService.CancelSubscribe(question.QuestionId, question.UserId); int pageSize = 100; for (int i = 1; i <= question.AnswerCount; i = i + pageSize) { PagingDataSet <AskAnswer> answers = askService.GetAnswersByQuestionId(question.QuestionId, SortBy_AskAnswer.DateCreated_Desc, pageSize, i); foreach (AskAnswer answer in answers) { subscribeService.CancelSubscribe(question.QuestionId, answer.UserId); } } } } //加精时处理积分和威望并产生通知 else if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { string pointItemKey = PointItemKeys.Instance().EssentialContent(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "问题", question.Subject); pointService.GenerateByRole(question.UserId, pointItemKey, description); if (question.UserId > 0) { Notice notice = Notice.New(); notice.UserId = question.UserId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = question.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); } }
/// <summary> /// 回答审核状态变更事件 /// </summary> private void AskAnswerAuditEventModule_After(AskAnswer answer, AuditEventArgs eventArgs) { bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); //审核状态发生变化时处理积分 string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Ask_CreateAnswer(); if (eventArgs.OldAuditStatus == null) { eventOperationType = EventOperationType.Instance().Create(); } else { eventOperationType = EventOperationType.Instance().Approved(); } } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Ask_DeleteAnswer(); if (eventArgs.NewAuditStatus == null) { eventOperationType = EventOperationType.Instance().Delete(); } else { eventOperationType = EventOperationType.Instance().Disapproved(); } } if (!string.IsNullOrEmpty(pointItemKey)) { AskQuestion question = answer.Question; string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", HtmlUtility.TrimHtml(answer.Body, 10)); pointService.GenerateByRole(answer.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete()); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); } //审核状态发生变化时生成动态 if (auditDirection == true) { AskQuestion question = answer.Question; //创建回答的动态[关注回答者的粉丝可以看到该回答] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().CreateAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; //判断是否有图片、音频、视频 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskAnswer()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(answer.AnswerId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { activityOfFollower.HasImage = true; } activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.SourceId = answer.AnswerId; activityOfFollower.UserId = answer.UserId; activityOfFollower.ReferenceId = answer.QuestionId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfFollower.OwnerId = answer.UserId; activityOfFollower.OwnerName = answer.Author; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建回答的动态[关注该问题的用户可以看到该回答] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().CreateAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.HasImage = activityOfFollower.HasImage; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.SourceId = answer.AnswerId; activityOfQuestionSubscriber.UserId = answer.UserId; activityOfQuestionSubscriber.ReferenceId = answer.QuestionId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); } else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().AskAnswer(), answer.AnswerId); } }
protected override void OnApplyTemplate() { if (string.IsNullOrEmpty(PrefixText)) { PrefixText = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPrefixTextName); } if (string.IsNullOrEmpty(SuffixText)) { SuffixText = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlSuffixTextName); } var rootGrid = GetTemplateChild <FrameworkElement>(c_rootGridName); if (rootGrid != null) { rootGrid.KeyDown += OnRootGridKeyDown; m_rootGridKeyDownRevoker.Disposable = Disposable.Create(() => rootGrid.KeyDown -= OnRootGridKeyDown); } var firstPageButton = GetTemplateChild <Button>(c_firstPageButtonName); if (firstPageButton != null) { AutomationProperties.SetName(firstPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlFirstPageButtonTextName)); firstPageButton.Click += FirstButtonClicked; m_firstPageButtonClickRevoker.Disposable = Disposable.Create(() => firstPageButton.Click -= FirstButtonClicked); } var previousPageButton = GetTemplateChild <Button>(c_previousPageButtonName); if (previousPageButton != null) { AutomationProperties.SetName(previousPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPreviousPageButtonTextName)); previousPageButton.Click += PreviousButtonClicked; m_previousPageButtonClickRevoker.Disposable = Disposable.Create(() => previousPageButton.Click -= PreviousButtonClicked); } var nextPageButton = GetTemplateChild <Button>(c_nextPageButtonName); if (nextPageButton != null) { AutomationProperties.SetName(nextPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlNextPageButtonTextName)); nextPageButton.Click += NextButtonClicked; m_nextPageButtonClickRevoker.Disposable = Disposable.Create(() => nextPageButton.Click -= NextButtonClicked); } var lastPageButton = GetTemplateChild <Button>(c_lastPageButtonName); if (lastPageButton != null) { AutomationProperties.SetName(lastPageButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlLastPageButtonTextName)); lastPageButton.Click += LastButtonClicked; m_lastPageButtonClickRevoker.Disposable = Disposable.Create(() => lastPageButton.Click -= LastButtonClicked); } m_comboBoxSelectionChangedRevoker.Disposable = null; void InitComboBox(ComboBox comboBox) { m_comboBox = comboBox; if (comboBox != null) { FillComboBoxCollectionToSize(NumberOfPages); comboBox.SelectedIndex = SelectedPageIndex - 1; AutomationProperties.SetName(comboBox, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPageTextName)); comboBox.SelectionChanged += ComboBoxSelectionChanged; m_comboBoxSelectionChangedRevoker.Disposable = Disposable.Create(() => comboBox.SelectionChanged -= ComboBoxSelectionChanged); } } InitComboBox((ComboBox)GetTemplateChild(c_comboBoxName)); m_numberBoxValueChangedRevoker.Disposable = null; void InitNumberBox(NumberBox numberBox) { m_numberBox = numberBox; if (numberBox != null) { numberBox.Value = SelectedPageIndex + 1; AutomationProperties.SetName(numberBox, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PagerControlPageTextName)); numberBox.ValueChanged += NumberBoxValueChanged; m_numberBoxValueChangedRevoker.Disposable = Disposable.Create(() => numberBox.ValueChanged -= NumberBoxValueChanged); } } InitNumberBox((NumberBox)GetTemplateChild(c_numberBoxName)); m_numberPanelRepeater = (ItemsRepeater)GetTemplateChild(c_numberPanelRepeaterName); m_selectedPageIndicator = (FrameworkElement)GetTemplateChild(c_numberPanelIndicatorName); // This is for the initial loading of the control OnDisplayModeChanged(); UpdateOnEdgeButtonVisualStates(); OnNumberOfPagesChanged(0); // Update button visibilities OnButtonVisibilityChanged(FirstButtonVisibility, c_firstPageButtonVisibleVisualState, c_firstPageButtonNotVisibleVisualState, c_firstPageButtonHiddenVisualState, 0); OnButtonVisibilityChanged(PreviousButtonVisibility, c_previousPageButtonVisibleVisualState, c_previousPageButtonNotVisibleVisualState, c_previousPageButtonHiddenVisualState, 0); OnButtonVisibilityChanged(NextButtonVisibility, c_nextPageButtonVisibleVisualState, c_nextPageButtonNotVisibleVisualState, c_nextPageButtonHiddenVisualState, NumberOfPages - 1); OnButtonVisibilityChanged(LastButtonVisibility, c_lastPageButtonVisibleVisualState, c_lastPageButtonNotVisibleVisualState, c_lastPageButtonHiddenVisualState, NumberOfPages - 1); OnSelectedPageIndexChange(-1); }
/// <summary> /// 问题审核状态变更事件 /// </summary> private void AskQuestionAuditEventModule_After(AskQuestion question, AuditEventArgs eventArgs) { bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); //审核状态发生变化时处理积分 string pointItemKey = string.Empty; string eventOperationType = string.Empty; if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Ask_CreateQuestion(); if (eventArgs.OldAuditStatus == null) { eventOperationType = EventOperationType.Instance().Create(); } else { eventOperationType = EventOperationType.Instance().Approved(); } } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Ask_DeleteQuestion(); if (eventArgs.NewAuditStatus == null) { eventOperationType = EventOperationType.Instance().Delete(); } else { eventOperationType = EventOperationType.Instance().Disapproved(); } } if (!string.IsNullOrEmpty(pointItemKey)) { string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "问题", question.Subject); pointService.GenerateByRole(question.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == question.UserId); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); } //审核状态发生变化时生成动态 if (auditDirection == true) { //1.创建发布问题的动态[关注发布者的粉丝可以看到该动态] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().CreateAskQuestion(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; //判断是否有图片、音频、视频 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskQuestion()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(question.QuestionId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { activityOfFollower.HasImage = true; } activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfFollower.SourceId = question.QuestionId; activityOfFollower.UserId = question.UserId; activityOfFollower.ReferenceId = 0; activityOfFollower.ReferenceTenantTypeId = string.Empty; activityOfFollower.OwnerId = question.UserId; activityOfFollower.OwnerName = question.Author; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //2.创建发布问题的动态[关注问题所属标签的用户可以看到该动态] Activity activityOfTagSubscriber = Activity.New(); activityOfTagSubscriber.ActivityItemKey = ActivityItemKeys.Instance().CreateAskQuestion(); activityOfTagSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfTagSubscriber.HasImage = activityOfFollower.HasImage; activityOfTagSubscriber.IsOriginalThread = true; activityOfTagSubscriber.IsPrivate = false; activityOfTagSubscriber.TenantTypeId = TenantTypeIds.Instance().AskQuestion(); activityOfTagSubscriber.SourceId = question.QuestionId; activityOfTagSubscriber.UserId = question.UserId; activityOfTagSubscriber.ReferenceId = 0; activityOfTagSubscriber.ReferenceTenantTypeId = string.Empty; IEnumerable <Tag> tags = tagService.GetTopTagsOfItem(question.QuestionId, 100); foreach (var tag in tags) { activityOfTagSubscriber.OwnerId = tag.TagId; activityOfTagSubscriber.OwnerName = tag.TagName; activityOfTagSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskTag(); activityService.Generate(activityOfTagSubscriber, false); } } //删除动态 else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().AskQuestion(), question.QuestionId); } }
/// <summary> /// 积分交易 /// </summary> /// <param name="payerUserId">支付积分人UserId</param> /// <param name="payeeUserId">接收积分人UserId</param> /// <param name="points">交易积分额</param> /// <param name="description">交易描述</param> /// <param name="isImmediate">是否即时交易</param> /// <param name="needPointMessage">是否需要积分提醒</param> public void Trade(long payerUserId, long payeeUserId, int points, string description, bool isImmediate) { //如果是即时交易,从支付方从交易积分扣除,否则从冻结的交易积分扣除(不足时抛出异常) if (points <= 0) { return; } //1、首先检查payerUserId是否可以支付积分交易额,如果余额不足抛出异常 IUserService userService = DIContainer.Resolve <IUserService>(); IUser payer = userService.GetUser(payerUserId); if (payer == null) { throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", payerUserId)); } PointCategory pointCategory = GetPointCategory(PointCategoryKeys.Instance().TradePoints()); if (pointCategory == null) { return; } if (isImmediate && payer.TradePoints < points) { throw new ExceptionFacade(string.Format("积分余额不足,仅有{0}{2}{3},不够支付{1}{2}{3}", payer.TradePoints, points, pointCategory.Unit, pointCategory.CategoryName)); } if (!isImmediate && payer.FrozenTradePoints < points) { throw new ExceptionFacade(string.Format("冻结积分余额不足,仅有{0}{2}{3},不够支付{1}{2}{3}", payer.FrozenTradePoints, points, pointCategory.Unit, pointCategory.CategoryName)); } IUser payee = userService.GetUser(payeeUserId); if (payee == null) { throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", payeeUserId)); } //2、检查是否需要缴纳交易税,如果需要,则创建系统积分记录,变更系统积分总额 PointSettings pointSettings = pointSettingsManager.Get(); int realPoints = points; if (pointSettings.TransactionTax > 0 && pointSettings.TransactionTax < 100) { realPoints = points * (100 - pointSettings.TransactionTax) / 100; int taxPoints = points - realPoints; if (taxPoints > 0) { PointRecord pointRecord = new PointRecord(0, ResourceAccessor.GetString("Common_TransactionTax"), description, 0, 0, taxPoints); pointRecordRepository.Insert(pointRecord); ChangeSystemTradePoints(taxPoints); } } //3、points去除交易税,分别变更交易双方的积分值,并生成积分记录 PointRecord payerPointRecord = new PointRecord(payerUserId, ResourceAccessor.GetString("Common_PointTrade"), description, 0, 0, -points); pointRecordRepository.Insert(payerPointRecord); if (isImmediate) { userService.ChangePoints(payerUserId, 0, 0, -points); } else { userService.ReduceFrozenTradePoints(payerUserId, points); } //用于积分提醒 TrackPointRecord(payerUserId, payerPointRecord); PointRecord payeePointRecord = new PointRecord(payeeUserId, ResourceAccessor.GetString("Common_PointTrade"), description, 0, 0, realPoints); pointRecordRepository.Insert(payeePointRecord); userService.ChangePoints(payeeUserId, 0, 0, realPoints); }
/// <summary> /// 奖惩用户 /// </summary> /// <param name="userId">被奖惩用户</param> /// <param name="experiencePoints">经验</param> /// <param name="reputationPoints">威望</param> /// <param name="tradePoints">金币</param> /// <param name="description">奖惩理由</param> public void Reward(long userId, int experiencePoints, int reputationPoints, int tradePoints, string description) { if (experiencePoints == 0 && reputationPoints == 0 && tradePoints == 0) { return; } IUserService userService = DIContainer.Resolve <IUserService>(); IUser user = userService.GetUser(userId); if (user == null) { throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", userId)); } //1、增减用户积分额并生成用户积分记录; bool isIncome = experiencePoints > 0 || reputationPoints > 0 || tradePoints > 0; PointRecord pointRecord = new PointRecord(userId, isIncome ? ResourceAccessor.GetString("Common_AdminReward") : ResourceAccessor.GetString("Common_AdminPunish"), description, experiencePoints, reputationPoints, tradePoints); pointRecordRepository.Insert(pointRecord); userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints); //2、增减系统积分额并生成系统积分记录; PointRecord systemPointRecord = new PointRecord(0, isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), description, -experiencePoints, -reputationPoints, -tradePoints); pointRecordRepository.Insert(systemPointRecord); ChangeSystemTradePoints(-tradePoints); //3、生成操作文章 OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>(); IOperatorInfoGetter operatorInfoGetter = DIContainer.Resolve <IOperatorInfoGetter>(); if (operatorInfoGetter == null) { return; } OperationLogEntry logEntry = new OperationLogEntry(operatorInfoGetter.GetOperatorInfo()); logEntry.ApplicationId = 0; logEntry.Source = string.Empty; logEntry.OperationType = EventOperationType.Instance().Update(); logEntry.OperationObjectName = user.UserName; logEntry.OperationObjectId = userId; PointCategory experiencePointCategory = GetPointCategory(PointCategoryKeys.Instance().ExperiencePoints()); if (experiencePointCategory == null) { return; } PointCategory reputationPointCategory = GetPointCategory(PointCategoryKeys.Instance().ReputationPoints()); if (reputationPointCategory == null) { return; } PointCategory tradePointCategory = GetPointCategory(PointCategoryKeys.Instance().TradePoints()); if (tradePointCategory == null) { return; } logEntry.Description = string.Format("{0}“{1}”:{2}{3}{4},{5}{6}{7},{8}{9}{10}", isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), user.UserName, experiencePoints, experiencePointCategory.Unit, experiencePointCategory.CategoryName, reputationPoints, reputationPointCategory.Unit, reputationPointCategory.CategoryName, tradePoints, tradePointCategory.Unit, tradePointCategory.CategoryName); logService.Create(logEntry); }
public AppLogic() { mLogger = new Logger(); mAccessor = new ResourceAccessor(mLogger); }
private void InitializeTemplate() { _eventSubscriptions.Disposable = null; var registrations = new CompositeDisposable(); var spinDownName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NumberBoxDownSpinButtonName); var spinUpName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NumberBoxUpSpinButtonName); if (this.GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown) { spinDown.Click += OnSpinDownClick; registrations.Add(() => spinDown.Click -= OnSpinDownClick); // Do localization for the down button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinDown))) { AutomationProperties.SetName(spinDown, spinDownName); } } if (GetTemplateChild(c_numberBoxUpButtonName) is RepeatButton spinUp) { spinUp.Click += OnSpinUpClick; registrations.Add(() => spinUp.Click -= OnSpinUpClick); // Do localization for the up button if (string.IsNullOrEmpty(AutomationProperties.GetName(spinUp))) { AutomationProperties.SetName(spinUp, spinUpName); } } if (GetTemplateChild(c_numberBoxTextBoxName) is TextBox textBox) { textBox.KeyDown += OnNumberBoxKeyDown; registrations.Add(() => textBox.KeyDown -= OnNumberBoxKeyDown); textBox.KeyUp += OnNumberBoxKeyUp; registrations.Add(() => textBox.KeyUp -= OnNumberBoxKeyUp); m_textBox = textBox; } m_popup = GetTemplateChild(c_numberBoxPopupName) as Windows.UI.Xaml.Controls.Primitives.Popup; if (SharedHelpers.IsThemeShadowAvailable()) { // UNO TODO //if (GetTemplateChildT(c_numberBoxPopupContentRootName) is UIElement popupRoot) //{ // if (!popupRoot.Shadow()) // { // popupRoot.Shadow(ThemeShadow{}); // auto&& translation = popupRoot.Translation(); // const double shadowDepth = unbox_value<double>(SharedHelpers.FindResource(c_numberBoxPopupShadowDepthName, Application.Current().Resources(), box_value(c_popupShadowDepth))); // popupRoot.Translation({ translation.x, translation.y, (float)shadowDepth }); // } //} } if (GetTemplateChild(c_numberBoxPopupDownButtonName) is RepeatButton popupSpinDown) { popupSpinDown.Click += OnSpinDownClick; registrations.Add(() => popupSpinDown.Click -= OnSpinDownClick); } if (GetTemplateChild(c_numberBoxPopupUpButtonName) is RepeatButton popupSpinUp) { popupSpinUp.Click += OnSpinUpClick; registrations.Add(() => popupSpinUp.Click -= OnSpinUpClick); } // .NET rounds to 12 significant digits when displaying doubles, so we will do the same. m_displayRounder.SignificantDigits = 12; UpdateSpinButtonPlacement(); UpdateSpinButtonEnabled(); if (ReadLocalValue(ValueProperty) == DependencyProperty.UnsetValue && ReadLocalValue(TextProperty) != DependencyProperty.UnsetValue) { // If Text has been set, but Value hasn't, update Value based on Text. UpdateValueToText(); } else { UpdateTextToValue(); } _eventSubscriptions.Disposable = registrations; }
private string GetToolTipString() { uint sliderValue = (uint)(Math.Round(this.Value)); if (this.ColorChannel == ColorPickerHsvChannel.Alpha) { return(string.Format( ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringAlphaSlider), sliderValue)); } else { ColorPicker parentColorPicker = GetParentColorPicker(); if (parentColorPicker != null && DownlevelHelper.ToDisplayNameExists()) { Hsv currentHsv = parentColorPicker.GetCurrentHsv(); string localizedString; switch (this.ColorChannel) { case ColorPickerHsvChannel.Hue: currentHsv.H = this.Value; localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithColorName); break; case ColorPickerHsvChannel.Saturation: localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithColorName); currentHsv.S = this.Value / 100; break; case ColorPickerHsvChannel.Value: localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithColorName); currentHsv.V = this.Value / 100; break; default: throw new InvalidOperationException("Invalid ColorPickerHsvChannel."); // Uno Doc: 'throw winrt::hresult_error(E_FAIL);' } return(string.Format( CultureInfo.CurrentUICulture, localizedString, sliderValue, ColorHelper.ToDisplayName(ColorConversion.ColorFromRgba(ColorConversion.HsvToRgb(currentHsv))))); } else { string localizedString; switch (this.ColorChannel) { case ColorPickerHsvChannel.Hue: localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithoutColorName); break; case ColorPickerHsvChannel.Saturation: localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithoutColorName); break; case ColorPickerHsvChannel.Value: localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithoutColorName); break; default: throw new InvalidOperationException("Invalid ColorPickerHsvChannel."); // Uno Doc: 'throw winrt::hresult_error(E_FAIL);' } return(string.Format( CultureInfo.CurrentUICulture, localizedString, sliderValue)); } } }
/// <summary> /// 转换成用户所在时区的时间,并返回站点设置的日期格式 /// </summary> /// <param name="dateTime">原日期(UTC时间)</param> /// <returns> /// <para>返回友好的时间描述,例如:</para> /// <list type="bullet"> /// <item>2分钟以前</item> /// <item>昨天 8:39</item> /// <item>......</item> /// </list> /// </returns> public static string ToFriendlyDate(this DateTime dateTime, bool showTime = true, string dateFormat = "") { if (dateTime == DateTime.MinValue) { return(ResourceAccessor.GetString("Common_DatetimeWhenZero")); } if (string.IsNullOrEmpty(dateFormat)) { dateFormat = ResourceAccessor.GetString("Common_DefaultDateFormat"); } string timeFormat = ResourceAccessor.GetString("Common_DefaultTimeFormat"); DateTime userDate = dateTime.ConvertToUserDate(); DateTime userNow = DateTime.UtcNow.ConvertToUserDate(); if (userDate > userNow) { return(userDate.ToString(dateFormat + (showTime ? " " + timeFormat : ""))); } TimeSpan intervalTime = userNow - userDate; int intervalDays; if (userNow.Year == userDate.Year) { intervalDays = userNow.DayOfYear - userDate.DayOfYear; } else { intervalDays = intervalTime.Days + 1; } string result = "{0}"; if (showTime) { result = "{0}" + " " + userDate.ToString(timeFormat); } if (intervalDays > 7) { if (userDate.Year == userNow.Year) { return(string.Format(ResourceAccessor.GetString("Common_Pattern_CNMonthDay"), userDate.Month, userDate.Day, showTime ? " " + userDate.ToString(timeFormat) : "")); } return(userDate.ToString(dateFormat + (showTime ? " " + timeFormat : ""))); } if (intervalDays >= 3) { string timeScope = string.Format(ResourceAccessor.GetString("Common_Pattern_DayAgo"), intervalDays); return(string.Format(result, timeScope)); } if (intervalDays == 2) { return(string.Format(result, ResourceAccessor.GetString("Common_BeforeYesterday"))); } if (intervalDays == 1) { return(string.Format(result, ResourceAccessor.GetString("Common_YesterdayAt"))); } if (intervalTime.Hours >= 1) { return(string.Format(ResourceAccessor.GetString("Common_Pattern_HoursAgo"), intervalTime.Hours)); } if (intervalTime.Minutes >= 1) { return(string.Format(ResourceAccessor.GetString("Common_Pattern_MinutelAgo"), intervalTime.Minutes)); } if (intervalTime.Seconds >= 1) { return(string.Format(ResourceAccessor.GetString("Common_Pattern_SecondsAgo"), intervalTime.Seconds)); } return(ResourceAccessor.GetString("Common_Now")); }
protected override string GetLocalizedControlTypeCore() { return(ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_RatingLocalizedControlType)); }
private static void Main1(string[] args) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); }
void UpdateAutomationName() { Contact contact = Contact; string automationName; string contactName; // The AutomationName for the control is in the format: PersonName, BadgeInformation. // PersonName is set based on the name / initial properties in the order below. // if none exist, it defaults to "Person" if (IsGroup) { contactName = ResourceAccessor.GetLocalizedStringResource(SR_GroupName); } else if (contact != null && !string.IsNullOrEmpty(contact.DisplayName)) { contactName = contact.DisplayName; } else if (!string.IsNullOrEmpty(DisplayName)) { contactName = DisplayName; } else if (!string.IsNullOrEmpty(Initials)) { contactName = Initials; } else { contactName = ResourceAccessor.GetLocalizedStringResource(SR_PersonName); } // BadgeInformation portion of the AutomationName is set to 'n items' if there is a BadgeNumber, // or 'icon' for BadgeGlyph or BadgeImageSource. If BadgeText is specified, it will override // the string 'items' or 'icon' if (BadgeNumber > 0) { if (!string.IsNullOrEmpty(BadgeText)) { automationName = StringUtil.FormatString( ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemTextOverride), contactName, BadgeNumber, BadgeText); } else { automationName = StringUtil.FormatString( GetLocalizedPluralBadgeItemStringResource(BadgeNumber), contactName, BadgeNumber); } } else if (!string.IsNullOrEmpty(BadgeGlyph) || BadgeImageSource != null) { if (!string.IsNullOrEmpty(BadgeText)) { automationName = StringUtil.FormatString( ResourceAccessor.GetLocalizedStringResource(SR_BadgeIconTextOverride), contactName, BadgeText); } else { automationName = StringUtil.FormatString( ResourceAccessor.GetLocalizedStringResource(SR_BadgeIcon), contactName); } } else { automationName = contactName; } AutomationProperties.SetName(this, automationName); }