public void Initialize_PrimitiveCriteria_NoExceptionRaised() { // Arrange bool executed = false; PrimitiveCriteria criteria = new PrimitiveCriteria(1); ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext(); RevalidatingInterceptor sut = new RevalidatingInterceptor(applicationContext); InterceptArgs args = new InterceptArgs() { ObjectType = typeof(Root), Operation = DataPortalOperations.Update, Parameter = criteria, IsSync = true }; applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server); applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server; // Act sut.Initialize(args); executed = true; // Assert Assert.IsTrue(executed); }
public void Initialize(InterceptArgs e) { // put any logic that is needed in the first step of a DP lifecycle (not instantiated yet) #if DEBUG Debug.WriteLine(string.Format("{0} has started the DataPortal lifecycle.", e.ObjectType.ToString())); #endif }
/// <summary> /// Creates an instance of the type. /// </summary> /// <param name="result">InterceptArgs object from the data portal</param> public Activity(InterceptArgs result) { ObjectType = result.ObjectType; Operation = result.Operation; Runtime = result.Runtime; Exception = result.Exception; }
public void Initialize_InvalidGrandChildObject_ExceptionRaised() { // Arrange IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>(); Root rootObject = dataPortal.Create(new Root.Criteria("Test Data")); Child childObject = rootObject.Children.AddNew(); childObject.Data = "Test child data"; GrandChild grandChildObject = childObject.GrandChildren.AddNew(); ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext(); RevalidatingInterceptor sut = new RevalidatingInterceptor(applicationContext); InterceptArgs args = new InterceptArgs() { ObjectType = typeof(Root), Operation = DataPortalOperations.Update, Parameter = rootObject, IsSync = true }; applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server); applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server; // Act and Assert Assert.ThrowsException <Rules.ValidationException>(() => sut.Initialize(args)); }
public void Initialize_ValidRootObjectWithChild_NoExceptionRaised() { // Arrange bool executed = false; IDataPortal <Root> dataPortal = _testDIContext.CreateDataPortal <Root>(); Root rootObject = dataPortal.Fetch(new Root.Criteria("Test Data")); Child childObject = rootObject.Children.AddNew(); childObject.Data = "Test child data"; ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext(); RevalidatingInterceptor sut = new RevalidatingInterceptor(applicationContext); InterceptArgs args = new InterceptArgs() { ObjectType = typeof(Root), Operation = DataPortalOperations.Update, Parameter = rootObject, IsSync = true }; applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server); applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server; // Act sut.Initialize(args); executed = true; // Assert Assert.IsTrue(executed); }
private void HandlePossibleAchievement(InterceptArgs e) { Achievement achievement = Achievement.Parse(e.Packet); Achievements?.Update(achievement); OnAchievementUpdated(achievement); }
public override void Invoke(InterceptArgs e) { if (Target is null) { throw new NullReferenceException("Open intercept callback target is null."); } _callback(Target, e); }
// @Update [InterceptIn(nameof(Incoming.RemoveHabboItem))] private void HandleRemoveHabboItem(InterceptArgs e) { int itemId = e.Packet.ReadInt(); if (_inventory.TryRemove(itemId, out IInventoryItem item)) { OnItemRemoved(item); } }
// @Update [InterceptIn(nameof(Incoming.InventoryRefresh))] private void HandleInventoryRefresh(InterceptArgs e) { IsRefreshNeeded = true; if (_loadTask.IsCompleted) { _loadTask = ReceiveInventoryAsync(Manager.DisposeToken); } }
private void HandleActivityPointNotification(InterceptArgs e) { int amount = e.Packet.ReadInt(); int change = e.Packet.ReadInt(); ActivityPointType type = (ActivityPointType)e.Packet.ReadInt(); Points[type] = amount; OnPointsUpdated(type, amount, change); }
private void OnInterceptChat(InterceptArgs e) { // Changes incoming chat messages to upper-case if enabled. if (EnablePacketManipulation) { // Replaces a string after the first int (4 bytes) // in the packet using a transform function. e.Packet.ReplaceAt(4, s => s.ToUpper()); } }
protected void OnUserSearchResult(InterceptArgs e) { try { if (SetResult(UserSearchResults.Parse(e.Packet))) { e.Block(); } } catch (Exception ex) { SetException(ex); } }
protected void HandleUserData(InterceptArgs e) { try { if (SetResult(UserData.Parse(e.Packet))) { e.Block(); } } catch (Exception ex) { SetException(ex); } }
protected void OnAchievementList(InterceptArgs e) { try { if (SetResult(Achievements.Parse(e.Packet))) { e.Block(); } } catch (Exception ex) { SetException(ex); } }
private void HandleUserData(InterceptArgs e) { UserData = UserData.Parse(e.Packet); _tcsUserData?.TrySetResult(UserData); _tcsUserData = null; _taskUserData = Task.FromResult <IUserData>(UserData); OnLoadedUserData(); }
private void HandleWalletBalance(InterceptArgs e) { if (_isLoadingCredits) { _isLoadingCredits = false; e.Block(); } Credits = (int)e.Packet.ReadFloatAsString(); OnCreditsUpdated(); }
private void HandleUpdateFigure(InterceptArgs e) { if (UserData is null) { return; } UserData.Figure = e.Packet.ReadString(); UserData.Gender = H.ToGender(e.Packet.ReadString()); OnUserDataUpdated(); }
private void OnInterceptMove(InterceptArgs e) { if (EnablePacketBlocking) { // Flags the packet to be blocked, this cannot be reversed. e.Block(); int x = e.Packet.ReadInt(), y = e.Packet.ReadInt(); Log($"Blocked move packet to ({x}, {y})."); } }
private void OnIntercept(InterceptArgs e) { try { if (SetResult(e.Packet.Copy())) { if (_block) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void HandleCatalogIndex(InterceptArgs e) { try { var catalog = Catalog.Parse(e.Packet); if (catalog.Mode == mode) { if (SetResult(catalog)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void OnUserProfile(InterceptArgs e) { try { var userProfile = UserProfile.Parse(e.Packet); if (userProfile.Id == _userId) { if (SetResult(userProfile)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void OnRoomData(InterceptArgs e) { try { var roomData = RoomData.Parse(e.Packet); if (roomData.Id == _roomId) { if (SetResult(roomData)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void OnHabboGroupDetails(InterceptArgs e) { try { var groupData = GroupData.Parse(e.Packet); if (groupData.Id == groupId) { if (SetResult(groupData)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected override Task OnExecuteAsync() => throw new NotImplementedException(); // @Update SendAsync(Out.RequestPetInfo); // @Update [InterceptIn(nameof(Incoming.PetInfo))] protected void OnPetInfo(InterceptArgs e) { try { var petInfo = PetInfo.Parse(e.Packet); if (petInfo.Id == petId) { if (SetResult(petInfo)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void OnPostItData(InterceptArgs e) { try { var sticky = Sticky.Parse(e.Packet); if (sticky.Id == _stickyId) { if (SetResult(sticky)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
// @Update [InterceptIn(nameof(Incoming.AddHabboItem))] private void HandleAddHabboItem(InterceptArgs e) { /* * Dictionary<int, List<int>> * * int { * int local_2 * int local_3 { * int * } * } */ // ??? }
// @Update [InterceptIn(nameof(Incoming.InventoryItemUpdate))] private void HandleInventoryItemUpdate(InterceptArgs e) { if (_inventory != null) { var item = InventoryItem.Parse(e.Packet); if (_inventory.AddOrUpdate(item)) { OnItemAdded(item); } else { OnItemUpdated(item); } } }
protected void OnNavigatorSearchResults(InterceptArgs e) { try { var results = NavigatorSearchResults.Parse(e.Packet); if (results.Category == category && results.Filter == filter) { if (SetResult(results)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
protected void HandleCatalogPage(InterceptArgs e) { try { var catalogPage = CatalogPage.Parse(e.Packet); if (catalogPage.Id == _pageId && catalogPage.Mode == _mode) { if (SetResult(catalogPage)) { e.Block(); } } } catch (Exception ex) { SetException(ex); } }
private async void HandleLatencyResponse(InterceptArgs e) { if (UserData is null) { await SendAsync(Out.InfoRetrieve); } if (Achievements is null) { await SendAsync(Out.GetUserAchievements); } if (Credits is null && !_isLoadingCredits) { _isLoadingCredits = true; await SendAsync(Out.GetCredits); } }