public void CreateTransactions(ref TransactionChain chain) { foreach (DelayedMetadataAction action in QueuedActions) { switch (action.Action) { case TransactionActionType.Deleted: // As this is metadata that hasn't yet been created, we don't need to delete it, we just do nothing with it. return; case TransactionActionType.Updated: { UpdateMetadataTransactionLink updateMetadataTransaction = CreateMetadataUpdateTransaction(action); if (updateMetadataTransaction != null) { chain.AddTransaction(updateMetadataTransaction); } break; } default: break; } } }
public void CreateTransactions(ref TransactionChain chain) { DeleteNodeTransactionLink deleteTransaction = null; UpdateNodeTransactionLink updateTransaction = null; foreach (DelayedNodeAction action in QueuedActions) { switch (action.Action) { case TransactionActionType.Deleted: deleteTransaction = CreateNodeDeletionTransaction(action); if (deleteTransaction != null) { chain.AddTransaction(deleteTransaction); } return; case TransactionActionType.TypeUpdated: updateTransaction = CreateNodeUpdatedTransaction(action); break; default: break; } } if (updateTransaction != null) { chain.AddTransaction(updateTransaction); } }
public void AddTransactionChain(TransactionChain transactionChain) { TransactionChains.Enqueue(transactionChain); _hasChanged = true; //Save(); }
public void Delete() { var chain = new TransactionChain(); MetadataSet.Delete(ref chain); MapManager.ExecuteTransaction(chain); }
public void ExecuteOperation() { var chain = new TransactionChain(); chain.TransactionCompleted += ChainOnTransactionCompleted; INode newNode = MapManager.CreateNode(Map.DomainId, Map.RootMapId.Value, Node.Proxy.NodeType, string.Empty, ref chain); IRelationship newMapContainerRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, MapContainerRelationshipType, string.Empty, ref chain); newMapContainerRelationship.ConnectNode(FromConnectionType, newNode, ref chain); newMapContainerRelationship.ConnectNode(ToConnectionType, Map, ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "XPosition", (Node.Location.X + 100).ToString(), ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "YPosition", (Node.Location.Y + 100).ToString(), ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "CollapseState", "None", ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "Visibility", "Visible", ref chain); foreach (var metadata in Node.Metadata) { if (!string.IsNullOrEmpty(metadata.Value.Value)) { newNode.Metadata.Add(null, null, metadata.Key, metadata.Value.Value, ref chain); } } Response = new InProcessTransactionResponse(); Response.Nodes.Add(newNode); Response.Relationships.Add(newMapContainerRelationship); MapManager.ExecuteTransaction(chain); }
public void TestRemoveTransactionExceptions() { var c1 = Money.Currencies.UAH; var c2 = Money.Currencies.UAH; TransactionChain tc1 = new TransactionChain(c1); TransactionChain tc2 = new TransactionChain(c2); var money1 = new Money(-2000.17m, c1); var money2 = new Money(-2000.17m, c2); var category = new Category("Развлєкуха", "icon1448.png", Category.Colors.MAGENTA); DateTime date = DateTime.Now; User user = new User(new PersonName("a", "b"), new Email("mail", "mail.com")); Transaction t1 = new Transaction(user.Guid, money1, "thug life", category, date); Transaction t2 = new Transaction(user.Guid, money2, "salary..", category, date); tc1.AddTransaction(t1); tc2.AddTransaction(t2); Assert.Throws <MissingMemberException>(() => tc1.RemoveTransaction(t2)); Assert.Throws <MissingMemberException>(() => tc2.RemoveTransaction(t1)); }
public void TestMonthIncomeAndExpenses() { //Arrange decimal incomeAmount = 10.0m; decimal expencesAmount = -7.6m; decimal expected1 = (DateTime.Today - DateTime.Today.AddMonths(-1)).Days * 2 * incomeAmount; decimal expected2 = -(DateTime.Today - DateTime.Today.AddMonths(-1)).Days * expencesAmount; var currency = Money.Currencies.EUR; var incomeMoney = new Money(incomeAmount, currency); var expencesMoney = new Money(expencesAmount, currency); var category1 = new Category("Some category", "icon1448.png", Category.Colors.MAGENTA); User user = new User(new PersonName("a", "b"), new Email("mail", "mail.com")); //Act TransactionChain actual1 = new TransactionChain(currency); for (int i = 0; i < 100; ++i) { actual1.AddTransaction(new Transaction(user.Guid, incomeMoney, "thug life", category1, DateTime.Today.AddDays(-i))); actual1.AddTransaction(new Transaction(user.Guid, expencesMoney, "thug life", category1, DateTime.Today.AddDays(-i))); actual1.AddTransaction(new Transaction(user.Guid, incomeMoney, "thug life", category1, DateTime.Today.AddDays(-i))); } //Assert Assert.Equal(expected1, actual1.MonthIncome.Amount); Assert.Equal(expected2, actual1.MonthExpences.Amount); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTerminateOutdatedTransactions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTerminateOutdatedTransactions() { // given long safeZone = 10; int txCount = 3; long firstCommitTimestamp = 10; long commitTimestampInterval = 2; TransactionBatchCommitter committer = NewBatchCommitter(safeZone); TransactionChain chain = CreateTxChain(txCount, firstCommitTimestamp, commitTimestampInterval); long timestampOutsideSafeZone = chain.Last.transactionRepresentation().LatestCommittedTxWhenStarted - safeZone - 1; KernelTransaction txToTerminate = NewKernelTransaction(timestampOutsideSafeZone); KernelTransaction tx = NewKernelTransaction(firstCommitTimestamp - 1); when(_kernelTransactions.activeTransactions()).thenReturn(Iterators.asSet(NewHandle(txToTerminate), NewHandle(tx))); // when committer.Apply(chain.First, chain.Last); // then verify(txToTerminate).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Outdated); verify(tx, never()).markForTermination(any()); _logProvider.formattedMessageMatcher().assertContains("Marking transaction for termination"); _logProvider.formattedMessageMatcher().assertContains("lastCommittedTxId:" + (BASE_TX_ID + txCount - 1)); }
void IEditableObject.EndEdit() { if (Updates.Count > 0) { //removes any operations that act on the same metadata key, only the last update is added to the chain CompactUpdates(); var chain = new TransactionChain(); foreach (var detail in Updates) { switch (detail.Type) { case UpdateMetadataType.AddOrUpdateValue: Metadata.Add(detail.NewKey, detail.NewValue, ref chain); if (UIMetadata.ContainsKey(detail.NewKey)) { UIMetadata[detail.NewKey] = detail.NewValue; } else { UIMetadata.Add(detail.NewKey, detail.NewValue); } OnNotifyPropertyChanged(detail.NewKey); break; case UpdateMetadataType.Delete: if (Metadata.ContainsKey(detail.NewKey)) { Metadata[detail.NewKey].MetadataSet.Delete(ref chain); Metadata.Remove(detail.NewKey); } if (UIMetadata.ContainsKey(detail.NewKey)) { UIMetadata.Remove(detail.NewKey); } break; case UpdateMetadataType.UpdateKey: if (Metadata.ContainsKey(detail.Key)) { var metadataSet = Metadata[detail.Key]; metadataSet.SetName(detail.NewKey, ref chain); if (!metadataSet.Value.Equals(detail.NewValue)) { metadataSet.SetValue(detail.NewValue, ref chain); } Metadata.Remove(detail.Key); Metadata.Add(detail.NewKey, metadataSet); UIMetadata.Remove(detail.Key); UIMetadata.Add(detail.NewKey, detail.NewValue); } break; } } MapManager.ExecuteTransaction(chain); Updates = new List <UpdateMetadataDetail>(); } }
public TransactionChain MoveToNextChain() { CurrentChain = TransactionChains.Dequeue(); _hasChanged = true; //Save(); return(CurrentChain); }
private void OnPlaceholderPropertyChanged(object sender, PropertyChangedEventArgs e) { var propertyPlaceholder = sender as NewDataGridPropertyPlaceholder; if (propertyPlaceholder == null) { return; } if (string.IsNullOrEmpty(propertyPlaceholder.Name.Trim())) { return; } if (propertyPlaceholder.IsNew && MetadataCollection.ContainsKey(propertyPlaceholder.Name)) { throw new Exception("Duplicate Name Inserted"); } if (MetadataUpdating != null) { MetadataUpdating(this, null); } var chain = new TransactionChain(); chain.TransactionCompleted += OnTransactionCompleted; string propertyValue = ""; if (!string.IsNullOrEmpty(propertyPlaceholder.Value)) { propertyValue = propertyPlaceholder.Value; } var multipleNodeMetadata = MetadataCollection["Name"] as MultipleNodeMetadata; if (multipleNodeMetadata != null) { foreach (var node in multipleNodeMetadata.NodeContainer.NodeProperties) { node.Metadata.Add(propertyPlaceholder.Name, propertyValue, ref chain); } } else { propertyPlaceholder.MetadataSet = MetadataCollection.Add(propertyPlaceholder.Name, propertyValue, ref chain); } MapManager.ExecuteTransaction(chain); if (propertyPlaceholder.IsNew) { propertyPlaceholder.IsNew = false; AddNewLine(); } }
public override void Delete(ref TransactionChain chain) { base.Delete(ref chain); DelayedMetadataAction delayedAction = new DelayedMetadataAction(); delayedAction.Action = TransactionActionType.Deleted; DelayedActions.Enqueue(delayedAction); }
public virtual void Delete(ref TransactionChain chain) { IMetadataSetManager metadataSetManager = this; metadataSetManager.Container.Remove(this); /// TODO: Need to consider whether the following should be done here. //MetadataSetFactory.GetInstance(MapManager).Remove(this); }
public bool SetName(string name, ref TransactionChain chain) { if (MetadataSet.Name != name) { MetadataSet.Update(name, null, null, null, null, ref chain); OnNotifyPropertyChanged("Name"); return(true); } return(false); }
public bool SetValue(string value, ref TransactionChain chain) { if (MetadataSet.Value != value) { MetadataSet.Update(null, value, null, null, null, ref chain); OnNotifyPropertyChanged("Value"); return(true); } return(false); }
private void BuildTransactionForRelationship(Relationship relationship, ref TransactionChain chain) { var inProcessRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, FromToRelationshipType, string.Empty, ref chain); var from = Nodes.FirstOrDefault(q => q.Id == relationship.From); var to = Nodes.FirstOrDefault(q => q.Id == relationship.To); if (from != null && to != null && CloneMap.ContainsKey(from) && CloneMap.ContainsKey(to)) { inProcessRelationship.ConnectNode(FromConnectionType, CloneMap[from], ref chain); inProcessRelationship.ConnectNode(ToConnectionType, CloneMap[to], ref chain); } Response.Relationships.Add(inProcessRelationship); }
public override void Update(string name, string value, INode node, IRelationship relationship, ConnectionType connectionType, ref TransactionChain chain) { base.Update(name, value, node, relationship, connectionType, ref chain); DelayedMetadataAction delayedAction = new DelayedMetadataAction(); delayedAction.Action = TransactionActionType.Updated; delayedAction.Name = name; delayedAction.Value = value; delayedAction.Node = node; delayedAction.Relationship = relationship; delayedAction.ConnectionType = connectionType; DelayedActions.Enqueue(delayedAction); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCommitLargeBatch() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCommitLargeBatch() { // given long safeZone = 10; TransactionBatchCommitter committer = NewBatchCommitter(safeZone); TransactionChain chain = CreateTxChain(100, 1, 10); // when committer.Apply(chain.First, chain.Last); // then verify(_commitProcess).commit(eq(chain.First), any(), eq(EXTERNAL)); }
public void Delete() { var metadataCollection = NodeContainer.NodeProperties.Where(node => node.Metadata.ContainsKey(Name)).Select(node => node.Metadata[Name].MetadataSet).ToList(); if (metadataCollection.Count > 0) { var chain = new TransactionChain(); chain.TransactionCompleted += OnTransactionCompleted; foreach (var metadataSet in metadataCollection) { metadataSet.Delete(ref chain); } MapManager.ExecuteTransaction(chain); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotBlockTransactionsForSmallBatch() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotBlockTransactionsForSmallBatch() { // given long safeZone = 10; TransactionBatchCommitter committer = NewBatchCommitter(safeZone); TransactionChain chain = CreateTxChain(3, 1, 1); // when committer.Apply(chain.First, chain.Last); // then verify(_kernelTransactions, never()).blockNewTransactions(); verify(_kernelTransactions, never()).unblockNewTransactions(); }
public bool SetValue(string value, ref TransactionChain chain) { if (_value != value) { _value = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Value")); } return(true); } return(false); }
public bool SetName(string name, ref TransactionChain chain) { if (_name != name) { _name = name; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Name")); } return(true); } return(false); }
public override void Withdraw(Decimal sum) { if (SourceAccount is CreditAccount creditAccount) { if (creditAccount.Balance - sum < -creditAccount.Limit) { throw new CreditLimitExceededException(); } SourceAccount.CareTracker.Backup(); SourceAccount.Balance -= sum; } else { TransactionChain?.Withdraw(sum); } }
public override void Withdraw(Decimal sum) { if (SourceAccount is DebitAccount debitAccount) { if (sum > debitAccount.Balance) { throw new InsufficientFundsException(); } SourceAccount.CareTracker.Backup(); SourceAccount.Balance -= sum; } else { TransactionChain?.Withdraw(sum); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBlockTransactionsForLargeBatch() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBlockTransactionsForLargeBatch() { // given long safeZone = 10; TransactionBatchCommitter committer = NewBatchCommitter(safeZone); TransactionChain chain = CreateTxChain(100, 1, 10); // when committer.Apply(chain.First, chain.Last); // then InOrder inOrder = inOrder(_kernelTransactions); inOrder.verify(_kernelTransactions).blockNewTransactions(); inOrder.verify(_kernelTransactions).unblockNewTransactions(); }
private void ApplyChanges() { foreach (var metadataUpdate in MetadataUpdates) { var chain = new TransactionChain(); foreach (var updatePair in metadataUpdate.Value) { metadataUpdate.Key.Node.Metadata.Add(null, null, updatePair.Key, updatePair.Value, ref chain); if (updatePair.Key == "Name") { metadataUpdate.Key.Name = updatePair.Value; } } metadataUpdate.Key.Node.MapManager.ExecuteTransaction(chain); } if (Updates.Count > 0) { var updateQueries = new ObservableCollection <GlymaSecurityAssociation>(); foreach (var update in Updates) { foreach (var updatePair in update.Value) { if (updatePair.Value.IsUpdatable) { updateQueries.Add(update.Key.CommitChange(updatePair.Key, updatePair.Value.IsChecked)); } else { update.Key.CommitChange(updatePair.Key, updatePair.Value.IsChecked); } } } if (updateQueries.Count > 0) { _securityManager.UpdateSecurityAssociationsAsync("UpdateSecurityAssociations", UpdateCompleted, updateQueries); } } else { UpdateSuccessful(); } }
public void ExecuteOperation() { CloneMap = new Dictionary <Node, INode>(); var chain = new TransactionChain(); chain.TransactionCompleted += ChainOnTransactionCompleted; Response = new InProcessTransactionResponse(); foreach (var node in Nodes) { CloneMap.Add(node, BuildTransactionForNode(node, ref chain)); } foreach (var relationship in Relationships) { BuildTransactionForRelationship(relationship, ref chain); } MapManager.ExecuteTransaction(chain); }
public void TestCurrentAmount() { //Arrange var expected1 = new Money(-1856.4m, Money.Currencies.EUR); var expected2 = new Money(-2000.17m, Money.Currencies.EUR); var expected3 = new Money(287.54m, Money.Currencies.EUR); var currency = Money.Currencies.EUR; var money1 = new Money(-2000.17m, Money.Currencies.EUR); var money2 = new Money(143.77m, Money.Currencies.EUR); var category1 = new Category("Развлєкуха", "icon1448.png", Category.Colors.MAGENTA); var category2 = new Category("Зпшка", "icon0.png", Category.Colors.BLACK); DateTime date1 = DateTime.Today.AddDays(-1); DateTime date2 = DateTime.Today; DateTime date3 = DateTime.Now; User user = new User(new PersonName("a", "b"), new Email("mail", "mail.com")); Transaction t1 = new Transaction(user.Guid, money1, "thug life", category1, date1); Transaction t2 = new Transaction(user.Guid, money2, "salary..", category2, date2); Transaction t3 = new Transaction(user.Guid, money2, "I'm miserable", category2, date3); //Act TransactionChain actual1 = new TransactionChain(currency); actual1.AddTransaction(t1); actual1.AddTransaction(t2); TransactionChain actual2 = new TransactionChain(currency); actual2.AddTransaction(t1); TransactionChain actual3 = new TransactionChain(currency); actual3.AddTransaction(t2); actual3.AddTransaction(t3); //Assert Assert.Equal(expected1, actual1.CurrentAmount); Assert.Equal(expected2, actual2.CurrentAmount); Assert.Equal(expected3, actual3.CurrentAmount); }
public void CreateTransactions(ref TransactionChain chain) { DeleteRelationshipTransactionLink deleteTransaction = null; UpdateRelationshipTransactionLink updateTransaction = null; foreach (DelayedRelationshipAction action in QueuedActions) { switch (action.Action) { case TransactionActionType.Deleted: deleteTransaction = CreateRelationshipDeletionTransaction(action); if (deleteTransaction != null) { chain.AddTransaction(deleteTransaction); } return; case TransactionActionType.Updated: updateTransaction = updateTransaction ?? CreateRelationshipUpdatedTransaction(action); updateTransaction.AddNode(action.ConnectionType, action.Node); break; case TransactionActionType.TypeUpdated: updateTransaction = updateTransaction ?? CreateRelationshipUpdatedTransaction(action); updateTransaction.RelationshipType = action.RelationshipType; break; default: break; } } if (updateTransaction != null) { chain.AddTransaction(updateTransaction); } }
public override void Withdraw(Decimal sum) { if (SourceAccount is DepositAccount depositAccount) { if (depositAccount.Term > TimeSpan.Zero) { throw new DepositTermNotExpiredException(); } if (sum > depositAccount.Balance) { throw new InsufficientFundsException(); } SourceAccount.CareTracker.Backup(); SourceAccount.Balance -= sum; } else { TransactionChain?.Withdraw(sum); } }
public void ExecuteOperation() { var chain = new TransactionChain(); chain.TransactionCompleted += ChainOnTransactionCompleted; INode newNode = MapManager.CreateNode(Map.DomainId, Map.RootMapId.Value, NodeType, string.Empty, ref chain); IRelationship newMapContainerRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, MapContainerRelationshipType, string.Empty, ref chain); newMapContainerRelationship.ConnectNode(FromConnectionType, newNode, ref chain); newMapContainerRelationship.ConnectNode(ToConnectionType, Map, ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "XPosition", X.ToString(), ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "YPosition", Y.ToString(), ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "CollapseState", "None", ref chain); newNode.Metadata.Add(newMapContainerRelationship, FromConnectionType, "Visibility", "Visible", ref chain); if (DefaultMetadata != null) { if (!DefaultMetadata.ContainsKey("Name")) { newNode.Metadata.Add(null, null, "Name", string.Empty, ref chain); } foreach (var valuePair in DefaultMetadata) { newNode.Metadata.Add(null, null, valuePair.Key, valuePair.Value, ref chain); } } else { newNode.Metadata.Add(null, null, "Name", string.Empty, ref chain); } Response = new InProcessTransactionResponse(); Response.Nodes.Add(newNode); Response.Relationships.Add(newMapContainerRelationship); MapManager.ExecuteTransaction(chain); }
public TransactionChain MoveToNextChain() { CurrentChain = TransactionChains.Dequeue(); _hasChanged = true; //Save(); return CurrentChain; }
public virtual void Update(string name, string value, INode node, IRelationship relationship, ConnectionType connectionType, ref TransactionChain chain) { if (name != null) { Name = name; } if (value != null) { Value = value; } if (node != null) { Node = node; } if (relationship != null) { Relationship = relationship; } if (connectionType != null) { ConnectionType = connectionType; } }
public void Update(NodeType nodeType, ref TransactionChain chain) { }
public void Delete(ref TransactionChain chain) { }
public IMetadataSet Add(IRelationship relationship, ConnectionType connectionType, string name, string value, ref TransactionChain chain) { IMetadataSet metadataSet = null; if (connectionType != null && relationship != null) { foreach (IMetadataSet metadata in Metadata) { if (metadata.Name == name && metadata.Relationship.Id == relationship.Id && metadata.ConnectionType.Id == connectionType.Id) { metadataSet = metadata; break; } } } else if (connectionType == null && relationship != null) { foreach (IMetadataSet metadata in Metadata) { if (metadata.Name == name && metadata.Relationship.Id == relationship.Id) { metadataSet = metadata; break; } } } else { foreach (IMetadataSet metadata in Metadata) { if (metadata.Name == name) { metadataSet = metadata; break; } } } if (metadataSet != null) { //TransactionFramework.UpdateMetadataTransactionLink updateMetadataTransaction = UpdateMetadataTransaction(metadataSet, Parent, name, value); metadataSet.Update(null, value, null, null, null, ref chain); } else { AddMetadataTransactionLink addMetadataTransaction = AddMetadataTransaction(metadataSet, Parent, relationship, connectionType, name, value); metadataSet = MetadataSetFactory.GetInstance(MapManager).GetMetadata(addMetadataTransaction, addMetadataTransaction.DomainId, addMetadataTransaction.RootMapId.Value, name, value, Parent, relationship, connectionType); chain.AddTransaction(addMetadataTransaction); Metadata.Add(metadataSet); IMetadataSetManager metadataSetManager = metadataSet as IMetadataSetManager; if (metadataSetManager != null) { metadataSetManager.Container = this; } } return metadataSet; }