public Task EventHandle(TopupEvent evt, EventMeta eventBase) { Interlocked.Increment(ref this.executedTimes); // Update database here return(Task.CompletedTask); }
public static SharedArray ConvertToBytes(this EventMeta metaInfo) { var buffer = SharedArray.Rent(); buffer.Write(metaInfo.Version); buffer.Write(metaInfo.Timestamp); buffer.WriteUtf8String(metaInfo.FlowId); return(buffer); }
public async Task EventHandle(TransferRefundsEvent evt, EventMeta eventBase) { using (var db = this.ServiceProvider.GetService <TransferDbContext>()) { var entity = await db.Accounts.FirstOrDefaultAsync(x => x.Id == this.ActorId); this.accountSnapshotHandler.EntityHandle(entity, evt); await db.SaveChangesAsync(); } }
public async Task <IActionResult> Update(string id, [FromBody] EventMeta eventMeta) { var result = await _eventService.Update(CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, CurrentUser.Avatar, id, eventMeta); if (result.Code <= 0) { return(BadRequest(result)); } return(Ok(result)); }
private byte[] ConvertToBytes(EventDocumentDto document, long id) { var meta = new EventMeta { Version = document.Version, Timestamp = document.Timestamp, FlowId = document.FlowId }; using var baseBytes = EventExtensions.ConvertToBytes(meta); var transUnit = new EventTransUnit(document.Name, id, baseBytes.AsSpan(), Encoding.UTF8.GetBytes(document.Data)); using var buffer = EventConverter.ConvertToBytes(transUnit); return(buffer.ToArray()); }
public EventData Convert(DomainEvent @event) { var json = JsonSerializer.Serialize(@event, @event.GetType(), _opt); var data = Encoding.UTF8.GetBytes(json); var evnType = @event.GetType(); var meta = new EventMeta() { EventType = evnType.AssemblyQualifiedName }; var metaJson = JsonSerializer.Serialize(meta); var metaData = Encoding.UTF8.GetBytes(metaJson); return(new EventData(Guid.Parse(@event.Id), evnType.Name, true, data, metaData)); }
private static EventData Map(IDomainEvent<TKey> @event) { var json = System.Text.Json.JsonSerializer.Serialize((dynamic) @event); var data = Encoding.UTF8.GetBytes(json); var eventType = @event.GetType(); var meta = new EventMeta() { EventType = eventType.AssemblyQualifiedName }; var metaJson = System.Text.Json.JsonSerializer.Serialize(meta); var metadata = Encoding.UTF8.GetBytes(metaJson); var eventPayload = new EventData(Guid.NewGuid(), eventType.Name, true, data, metadata); return eventPayload; }
private static EventData Map(IDomainEvent <TKey> @event) { string json = JsonSerializer.Serialize((dynamic)@event); byte[] data = Encoding.UTF8.GetBytes(json); Type eventType = @event.GetType(); EventMeta meta = new EventMeta() { EventType = eventType.AssemblyQualifiedName }; string metaJson = JsonSerializer.Serialize(meta); byte[] metadata = Encoding.UTF8.GetBytes(metaJson); return(new EventData(Guid.NewGuid(), eventType.Name, true, data, metadata)); }
private void EventMeta(EventMeta e, List <MarketMeta> markets, dbEntities cnn) { var spParams = "EXECUTE PROCEDURE BET_EVENTS_UI("; spParams += SourceId + ","; spParams += e.EventId + ","; spParams += e.SportId + ","; spParams += e.CategoryId + ","; spParams += e.TournamentId + ","; spParams += e.HomeTeam + ","; spParams += e.AwayTeam + ","; spParams += "'" + e.EventDate + "',"; spParams += (e.IsLive ? 1 : 0) + ","; spParams += e.Status + ","; spParams += 0 + ")"; cnn.Database.ExecuteSqlCommand(spParams.Trim()); SerilogHelper.Debug(string.Format("META event eventid:{0}", e.EventId)); }
public async Task <IEnumerable <DomainEvent> > GetEvents <T>(Guid id, Int32 eventsPerRequest = 100) where T : AggregateRootWithEvents { String streamName = GetStreamId <T>(id); var encoding = new UTF8Encoding(); var firstEvent = _client.ReadStreamAsync(Direction.Forwards, streamName, StreamPosition.Start, 1); var state = await firstEvent.ReadState; if (state == ReadState.StreamNotFound) { return(Array.Empty <DomainEvent>()); } List <DomainEvent> domainEvents = new(); Int32 streamPosition = 0; while (true) { var partialEvents = _client.ReadStreamAsync(Direction.Forwards, streamName, StreamPosition.FromInt64(streamPosition), eventsPerRequest); var items = await partialEvents.ToListAsync(); if (items.Count == 0) { break; } foreach (var item in items) { EventMeta meta = System.Text.Json.JsonSerializer.Deserialize <EventMeta>(new ReadOnlySpan <Byte>(item.Event.Metadata.ToArray())); String content = encoding.GetString(item.Event.Data.ToArray()); var domainEvent = (DomainEvent)JsonConvert.DeserializeObject(content, Type.GetType(meta.BodyType), _jsonSerializerSettings); domainEvents.Add(domainEvent); } streamPosition += eventsPerRequest; } return(domainEvents); }
/// <summary>Ctor. </summary> public ConfigurationEngineDefaults() { ThreadingConfig = new Threading(); ViewResourcesConfig = new ViewResources(); EventMetaConfig = new EventMeta(); LoggingConfig = new Logging(); VariablesConfig = new Variables(); StreamSelectionConfig = new StreamSelection(); TimeSourceConfig = new TimeSource(); MetricsReportingConfig = new ConfigurationMetricsReporting(); LanguageConfig = new Language(); ExpressionConfig = new Expression(); ExecutionConfig = new Execution(); ExceptionHandlingConfig = new ExceptionHandling(); ConditionHandlingConfig = new ConditionHandling(); AlternativeContextConfig = new AlternativeContext(); ClusterConfig = new Cluster(); PatternsConfig = new Patterns(); MatchRecognizeConfig = new MatchRecognize(); ScriptsConfig = new Scripts(); }
public async Task EventHandle(CreateEvent evt, EventMeta eventBase) { using (var db = this.ServiceProvider.GetService <TransferDbContext>()) { try { var entity = new Repository.Entities.Account() { Id = this.ActorId }; this.accountSnapshotHandler.EntityHandle(entity, evt); db.Accounts.Add(entity); await db.SaveChangesAsync(); } catch (System.Exception e) { e.PGExceptionHandler <AccountDb>(); } } }
public static void UnsafeUpdateVersion <TPrimaryKey>(this SubSnapshot <TPrimaryKey> snapshot, EventMeta eventBase) { snapshot.DoingVersion = eventBase.Version; snapshot.Version = eventBase.Version; }
public static void FullUpdateVersion <TPrimaryKey>(this SubSnapshot <TPrimaryKey> snapshot, EventMeta eventBase, Type grainType) { if (snapshot.Version > 0 && snapshot.Version + 1 != eventBase.Version) { throw new EventVersionException(snapshot.ActorId.ToString(), grainType, eventBase.Version, snapshot.Version); } snapshot.DoingVersion = eventBase.Version; snapshot.Version = eventBase.Version; }
public async Task <ActionResultResponse <string> > Update(string tenantId, string lastUpdateUserId, string lastUpdateFullName, string lastUpdateAvatar, string eventId, EventMeta eventMeta) { var apiUrls = _configuration.GetApiUrl(); if (apiUrls == null) { return(new ActionResultResponse <string>(-5, _sharedResourceService.GetString( "Missing some configuration. Please contact with administrator."))); } var eventTags = new List <TagSubjectViewModel>(); if (eventMeta.StartDate.HasValue && eventMeta.EndDate.HasValue) { if (DateTime.Compare(eventMeta.StartDate.Value, eventMeta.EndDate.Value) > 0) { return(new ActionResultResponse <string>(-1, _websiteEventResourceService.GetString("Start time greater than end time."))); } } var info = await _eventRepository.GetInfo(eventId); if (info == null) { return(new ActionResultResponse <string>(-1, _websiteEventResourceService.GetString("Event does not exists."))); } if (info.TenantId != tenantId) { return(new ActionResultResponse <string>(-2, _websiteEventResourceService.GetString(ErrorMessage.NotHavePermission))); } if (info.ConcurrencyStamp != eventMeta.ConcurrencyStamp) { return(new ActionResultResponse <string>(-3, _websiteEventResourceService.GetString( "The event already updated by other people. you are not allowed to edit the event information."))); } info.IsActive = eventMeta.IsActive; info.Thumbnail = eventMeta.Thumbnail; info.StartDate = eventMeta.StartDate; info.EndDate = eventMeta.EndDate; info.LimitedUsers = eventMeta.LimitedUsers; info.IsAllowRegisterWhenOverload = eventMeta.IsAllowRegisterWhenOverload; info.LimitedAccompanyPersons = eventMeta.LimitedAccompanyPersons; info.StaffOnly = eventMeta.StaffOnly; info.IsAllowRegister = eventMeta.IsAllowRegister; info.IsAllowAccompanyPerson = eventMeta.IsAllowAccompanyPerson; info.ConcurrencyStamp = Guid.NewGuid().ToString(); info.LastUpdate = DateTime.Now; info.LastUpdateUserId = lastUpdateUserId; info.LastUpdateFullName = lastUpdateFullName; info.LastUpdateAvatar = lastUpdateAvatar; await _eventRepository.Update(info); #region translation. if (eventMeta.EventTranslations.Count > 0) { var resultUpdateTranslation = await UpdateEventTranslation(); if (resultUpdateTranslation.Code <= 0) { return(resultUpdateTranslation); } } #endregion return(new ActionResultResponse <string>(1, _websiteEventResourceService.GetString("Update event successful."), string.Empty, info.ConcurrencyStamp)); async Task <ActionResultResponse <string> > UpdateEventTranslation() { foreach (var eventTranslation in eventMeta.EventTranslations) { //var isNameExists = await _eventTranslationRepository.CheckExists( info.Id, // eventTranslation.LanguageId, eventTranslation.Name); //if (isNameExists) // return new ActionResultResponse(-4, _websiteEventResourceService.GetString("Event name: \"{0}\" already exists.")); var eventTranslationInfo = await _eventTranslationRepository.GetInfo(info.Id, eventTranslation.LanguageId); if (eventTranslationInfo != null) { eventTranslationInfo.Name = eventTranslation.Name.Trim(); eventTranslationInfo.MetaTitle = eventTranslation.MetaTitle?.Trim(); eventTranslationInfo.Description = eventTranslation.Description?.Trim(); eventTranslationInfo.MetaDescription = eventTranslation.MetaDescription?.Trim(); eventTranslationInfo.Content = eventTranslation.Content?.Trim(); eventTranslationInfo.UnsignName = eventTranslation.Name?.StripVietnameseChars().ToUpper(); eventTranslationInfo.Address = eventTranslation.Address?.Trim(); if (!string.IsNullOrEmpty(eventTranslation.SeoLink)) { eventTranslationInfo.SeoLink = eventTranslation.SeoLink.ToUrlString(); } else { eventTranslationInfo.SeoLink = eventTranslation.Name.ToUrlString(); } // Check Seolink exists. var isSeolinkExists = await _eventTranslationRepository.CheckSeoLinkExists(eventId, eventTranslation.LanguageId, eventTranslationInfo.SeoLink); if (isSeolinkExists) { return(new ActionResultResponse <string>(-5, _websiteEventResourceService.GetString("Seo link: \"{0}\" already exists.", eventTranslationInfo.SeoLink))); } await _eventTranslationRepository.Update(eventTranslationInfo); } else { var eventTranslationInsert = new EventTranslation { EventId = eventId, LanguageId = eventTranslation.LanguageId.Trim(), Name = eventTranslation.Name.Trim(), MetaTitle = eventTranslation.MetaTitle?.Trim(), Description = eventTranslation.Description?.Trim(), MetaDescription = eventTranslation.MetaDescription?.Trim(), Content = eventTranslation.Content?.Trim(), Address = eventTranslation.Address?.Trim(), UnsignName = eventTranslation.Name.StripVietnameseChars().ToUpper() }; if (!string.IsNullOrEmpty(eventTranslation.SeoLink)) { eventTranslationInsert.SeoLink = eventTranslation.SeoLink.ToUrlString(); } else { eventTranslationInsert.SeoLink = eventTranslation.Name.ToUrlString(); } // Check Seolink exists. var isSeolinkExists = await _eventTranslationRepository.CheckSeoLinkExists(eventId, eventTranslation.LanguageId, eventTranslationInsert.SeoLink); if (isSeolinkExists) { return(new ActionResultResponse <string>(-6, _websiteEventResourceService.GetString("Seo link: \"{0}\" already exists.", eventTranslationInsert.SeoLink))); } await _eventTranslationRepository.Insert(eventTranslationInsert); } var eventTagInsert = new TagSubjectViewModel { TenantId = tenantId, CreatorId = lastUpdateUserId, CreatorFullName = lastUpdateFullName, CreatorAvata = lastUpdateAvatar, Type = TagType.Event, SubjectId = eventId, LanguageId = eventTranslation.LanguageId.Trim(), Tags = eventTranslation.Tags }; eventTags.Add(eventTagInsert); } var resultTag = await new HttpClientService() .PostAsync <ActionResultResponse>($"{apiUrls.CoreApiUrl}/tags", eventTags); return(new ActionResultResponse <string>(1, _websiteEventResourceService.GetString("Update event translation successful."), string.Empty, info.ConcurrencyStamp)); } }
public static void ForceUpdateVersion <TPrimaryKey>(this SnapshotMeta <TPrimaryKey> snapshotMeta, EventMeta eventMeta, Type grainType) { if (snapshotMeta.Version + 1 != eventMeta.Version) { throw new EventVersionException(snapshotMeta.ActorId.ToString(), grainType, eventMeta.Version, snapshotMeta.Version); } snapshotMeta.DoingVersion = eventMeta.Version; snapshotMeta.Version = eventMeta.Version; }
public Task EventHandle(TransferRefundsEvent evt, EventMeta eventBase) { // Update database here return(Task.CompletedTask); }
public async Task <ActionResultResponse <string> > Insert(string tenantId, string creatorId, string creatorFullName, string creatorAvatar, EventMeta eventMeta) { if (eventMeta.StartDate.HasValue && eventMeta.EndDate.HasValue) { if (DateTime.Compare(eventMeta.StartDate.Value, eventMeta.EndDate.Value) > 0) { return(new ActionResultResponse <string>(-1, _websiteEventResourceService.GetString("Start time greater than end time."))); } } var eventId = Guid.NewGuid().ToString(); var events = new Domain.Models.Event { Id = eventId, ConcurrencyStamp = eventId, IsActive = eventMeta.IsActive, StartDate = eventMeta.StartDate, EndDate = eventMeta.EndDate, LimitedUsers = eventMeta.LimitedUsers, IsAllowRegisterWhenOverload = eventMeta.IsAllowRegisterWhenOverload, LimitedAccompanyPersons = eventMeta.LimitedAccompanyPersons, StaffOnly = eventMeta.StaffOnly, IsAllowRegister = eventMeta.IsAllowRegister, IsAllowAccompanyPerson = eventMeta.IsAllowAccompanyPerson, Thumbnail = eventMeta.Thumbnail, Status = ApproverStatus.Draft, TenantId = tenantId, CreatorId = creatorId, CreatorFullName = creatorFullName, CreatorAvatar = creatorAvatar }; var result = await _eventRepository.Insert(events); if (result <= 0) { return(new ActionResultResponse <string>(result, _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong))); } #region insert Translation. if (eventMeta.EventTranslations.Count > 0) { var resultInsertTranslation = await InsertEventTranslation(); if (resultInsertTranslation.Code <= 0) { return(resultInsertTranslation); } } #endregion await SendNotificationToApprover(tenantId, creatorId, creatorFullName, creatorAvatar, eventId); return(new ActionResultResponse <string>(1, _websiteEventResourceService.GetString("Add new event successful."), string.Empty, eventId)); #region Local functions async Task <ActionResultResponse <string> > InsertEventTranslation() { var apiUrls = _configuration.GetApiUrl(); if (apiUrls == null) { return(new ActionResultResponse <string>(-5, _sharedResourceService.GetString( "Missing some configuration. Please contact with administrator."))); } var eventTags = new List <TagSubjectViewModel>(); var eventTranslations = new List <EventTranslation>(); foreach (var eventTranslation in eventMeta.EventTranslations) { // Check name exists. //var isNameExists = await _eventTranslationRepository.CheckExists( eventId, // eventTranslation.LanguageId, eventTranslation.Name); //if (isNameExists) //{ // await RollbackInsertEvent(); // return new ActionResultResponse<string>(-1, // _websiteEventResourceService.GetString("Event name: \"{0}\" already exists.", // eventTranslation.Name)); //} var eventTranslationInsert = new EventTranslation { EventId = eventId, LanguageId = eventTranslation.LanguageId.Trim(), Name = eventTranslation.Name.Trim(), MetaTitle = eventTranslation.MetaTitle?.Trim(), Description = eventTranslation.Description?.Trim(), MetaDescription = eventTranslation.MetaDescription?.Trim(), Content = eventTranslation.Content?.Trim(), UnsignName = eventTranslation.Name?.StripVietnameseChars().ToUpper(), Address = eventTranslation?.Address?.Trim() }; eventTranslationInsert.SeoLink = !string.IsNullOrEmpty(eventTranslation.SeoLink) ? eventTranslation.SeoLink.ToUrlString() : eventTranslation.Name.ToUrlString(); // Check Seolink exists. var isSeolinkExists = await _eventTranslationRepository.CheckSeoLinkExists(eventId, eventTranslation.LanguageId, eventTranslationInsert.SeoLink); if (isSeolinkExists) { await RollbackInsertEvent(); return(new ActionResultResponse <string>(-2, _websiteEventResourceService.GetString("Seo link: \"{0}\" already exists.", eventTranslationInsert.SeoLink))); } eventTranslations.Add(eventTranslationInsert); var eventTagInsert = new TagSubjectViewModel { TenantId = tenantId, CreatorId = creatorId, CreatorFullName = creatorFullName, CreatorAvata = creatorAvatar, Type = TagType.Event, SubjectId = eventId, LanguageId = eventTranslation.LanguageId.Trim(), Tags = eventTranslation.Tags }; eventTags.Add(eventTagInsert); } var resultTag = await new HttpClientService() .PostAsync <ActionResultResponse>($"{apiUrls.CoreApiUrl}/tags", eventTags); var resultTranslation = await _eventTranslationRepository.Inserts(eventTranslations); if (resultTranslation > 0) { return(new ActionResultResponse <string>(resultTranslation, _websiteEventResourceService.GetString("Add new event translation successful."))); } await RollbackInsertEventTranslation(); await RollbackInsertEvent(); return(new ActionResultResponse <string>(-3, _websiteEventResourceService.GetString("Can not insert event translation. Please contact with administrator."))); } async Task RollbackInsertEvent() { await _eventRepository.ForceDelete(eventId); } async Task RollbackInsertEventTranslation() { await _eventTranslationRepository.Delete(eventId); } #endregion Local functions }
private IDomainEvent <TKey> Map(ResolvedEvent resolvedEvent) { EventMeta meta = JsonSerializer.Deserialize <EventMeta>(resolvedEvent.Event.Metadata); return(_eventDeserializer.Deserialize <TKey>(meta.EventType, resolvedEvent.Event.Data)); }
public void LoadEvent(EventMeta meta) { async UniTask LoadCover(CancellationToken token) { Assert.IsNotNull(meta.cover); var tasks = new List <UniTask>(); if (coverImage.sprite != null) { coverImage.DOKill(); coverImage.DOColor(Color.black, 0.4f); tasks.Add(UniTask.Delay(TimeSpan.FromSeconds(0.4f), cancellationToken: token)); } Sprite sprite = null; tasks.Add(Context.AssetMemory.LoadAsset <Sprite>(meta.cover.OriginalUrl, AssetTag.EventCover, cancellationToken: token).ContinueWith(result => sprite = result)); try { await tasks; } catch (OperationCanceledException) { return; } coverImage.sprite = sprite; coverImage.FitSpriteAspectRatio(); coverImage.DOColor(Color.white, 2f).SetDelay(0.8f); } async UniTask LoadLogo(CancellationToken token) { Assert.IsNotNull(meta.logo); var tasks = new List <UniTask>(); if (logoImage.sprite != null) { logoImage.DOKill(); logoImage.DOFade(0, 0.4f); tasks.Add(UniTask.Delay(TimeSpan.FromSeconds(0.4f), cancellationToken: token)); } Sprite sprite = null; tasks.Add(Context.AssetMemory.LoadAsset <Sprite>(meta.logo.OriginalUrl, AssetTag.EventLogo, cancellationToken: token).ContinueWith(result => sprite = result)); try { await tasks; } catch (OperationCanceledException) { return; } logoImage.sprite = sprite; logoImage.DOFade(1, 0.8f).SetDelay(0.4f); } AddTask(LoadCover); AddTask(LoadLogo); Context.Player.Settings.SeenEvents.Add(meta.uid); Context.Player.SaveSettings(); infoBanner.Leave(onComplete: () => { if (!Context.Player.Settings.ReadEventDetails.Contains(meta.uid)) { viewDetailsNotification.Show(); } viewDetailsButton.onPointerClick.SetListener(_ => { Context.Player.Settings.ReadEventDetails.Add(meta.uid); Context.Player.SaveSettings(); viewDetailsNotification.Hide(); if (meta.url.IsNullOrEmptyTrimmed()) { Application.OpenURL($"{Context.WebsiteUrl}/posts/{meta.uid}"); } else { WebViewOverlay.Show(meta.url, onFullyShown: () => { LoopAudioPlayer.Instance.FadeOutLoopPlayer(); }, onFullyHidden: async() => { AudioSettings.Reset(AudioSettings.GetConfiguration()); Context.AudioManager.Dispose(); Context.AudioManager.Initialize(); await UniTask.DelayFrame(5); LoopAudioPlayer.Instance.Apply(it => { it.FadeInLoopPlayer(); it.PlayAudio(it.PlayingAudio, forceReplay: true); }); }); } }); const string dateFormat = "yyyy/MM/dd HH:mm"; durationText.text = (meta.startDate.HasValue ? meta.startDate.Value.LocalDateTime.ToString(dateFormat) : "") + "~" + (meta.endDate.HasValue ? meta.endDate.Value.LocalDateTime.ToString(dateFormat) : ""); enterButton.onPointerClick.SetListener(_ => { if (meta.locked) { Context.Haptic(HapticTypes.Failure, true); // TODO return; } Context.Haptic(HapticTypes.SoftImpact, true); if (meta.levelId != null) { SpinnerOverlay.Show(); RestClient.Get <OnlineLevel>(new RequestHelper { Uri = $"{Context.ApiUrl}/levels/{meta.levelId}" }).Then(level => { Context.ScreenManager.ChangeScreen( GamePreparationScreen.Id, ScreenTransition.In, 0.4f, transitionFocus: GetComponent <RectTransform>().GetScreenSpaceCenter(), payload: new GamePreparationScreen.Payload { Level = level.ToLevel(LevelType.User) } ); }).CatchRequestError(error => { Debug.LogError(error); Dialog.PromptAlert("DIALOG_COULD_NOT_CONNECT_TO_SERVER".Get()); }).Finally(() => SpinnerOverlay.Hide()); } else if (meta.collectionId != null) { Context.ScreenManager.ChangeScreen( CollectionDetailsScreen.Id, ScreenTransition.In, 0.4f, transitionFocus: GetComponent <RectTransform>().GetScreenSpaceCenter(), payload: new CollectionDetailsScreen.Payload { CollectionId = meta.collectionId, Type = LevelType.User } ); } }); infoBanner.transform.RebuildLayout(); infoBanner.Enter(); }); }
public Task EventHandle(TopupEvent evt, EventMeta eventBase) { // Update database here return(Task.CompletedTask); }