Beispiel #1
0
            public void CreateTheCorrectRepositoryType(ChangeSource source)
            {
                var stamp  = new DateTime(2012, 10, 15, 15, 15, 15);
                var change = new CustomerAudit
                {
                    Email    = "*****@*****.**",
                    IsSynced = false,
                    Type     = "insert",
                    Added    = stamp,
                    Source   = source
                };

                IDictionary <string, object> inputs = new Dictionary <string, object>
                {
                    { "Container", _container },
                    { "Change", change }
                };

                var result = WorkflowInvoker.Invoke(new SyncComplete(), inputs);

                if (source == ChangeSource.MSSQL)
                {
                    _nhRepo.Verify(r => r.Create());
                }
                else
                {
                    _efRepo.Verify(r => r.Create());
                }
            }
Beispiel #2
0
 /// <summary>
 /// Raises event 'ChangeSource'
 /// </summary>
 protected virtual void OnChangeSource()
 {
     if (ChangeSource != null)
     {
         ChangeSource.Invoke(this, System.EventArgs.Empty);
     }
 }
Beispiel #3
0
 static void DefaultUpdateTarget(IPropertyBinding binding, ChangeSource change)
 {
     if (!binding.Target.IsReadOnly)
     {
         binding.Target.Value = binding.Source.Value;
     }
 }
Beispiel #4
0
            public void SetBothSidesAsSynced(ChangeSource source)
            {
                _change.Source = source;
                var change2 = new CustomerAudit
                {
                    Email    = "*****@*****.**",
                    IsSynced = false,
                    Type     = "insert",
                    Added    = _stamp.AddSeconds(5),
                    Source   = ChangeSource.Oracle
                };

                _changesNH.Add(change2);
                var change3 = new CustomerAudit
                {
                    Email    = "*****@*****.**",
                    IsSynced = false,
                    Type     = "insert",
                    Added    = _stamp.AddSeconds(7),
                    Source   = ChangeSource.Oracle
                };

                _changesEF.Add(change3);

                WorkflowInvoker.Invoke(new MarkSynced(), _inputs);

                _mockRepoEF.Verify(r => r.Update(It.Is((CustomerAudit ca) => ca.IsSynced)));
                _mockRepoNH.Verify(r => r.Update(It.Is((CustomerAudit ca) => ca.IsSynced)));

                Assert.IsTrue(change2.IsSynced || change3.IsSynced);
                Assert.IsTrue(_change.IsSynced);

                _mockRepoEF.Verify(r => r.Save());
                _mockRepoNH.Verify(r => r.Save());
            }
Beispiel #5
0
        /// <summary>
        /// Constructs an unsigned transaction by referencing previous unspent outputs.
        /// A change output is added when necessary to return extra value back to the wallet.
        /// </summary>
        /// <param name="outputs">Transaction output array without change.</param>
        /// <param name="changeScript">Output script to pay change to.</param>
        /// <param name="fetchInputsAsync">Input selection source.</param>
        /// <returns>Unsigned transaction and total input amount.</returns>
        /// <exception cref="InsufficientFundsException">Input source was unable to provide enough input value.</exception>
        public static async Task<Tuple<Transaction, Amount>> BuildUnsignedTransaction(Transaction.Output[] outputs,
                                                                                      Amount feePerKb,
                                                                                      InputSource fetchInputsAsync,
                                                                                      ChangeSource fetchChangeAsync)
        {
            if (outputs == null)
                throw new ArgumentNullException(nameof(outputs));
            if (fetchInputsAsync == null)
                throw new ArgumentNullException(nameof(fetchInputsAsync));
            if (fetchChangeAsync == null)
                throw new ArgumentNullException(nameof(fetchChangeAsync));

            var targetAmount = outputs.Sum(o => o.Amount);
            var estimatedSize = Transaction.EstimateSerializeSize(1, outputs, true);
            var targetFee = TransactionFees.FeeForSerializeSize(feePerKb, estimatedSize);

            while (true)
            {
                var funding = await fetchInputsAsync(targetAmount + targetFee);
                var inputAmount = funding.Item1;
                var inputs = funding.Item2;
                if (inputAmount < targetAmount + targetFee)
                {
                    throw new InsufficientFundsException();
                }

                var maxSignedSize = Transaction.EstimateSerializeSize(inputs.Length, outputs, true);
                var maxRequiredFee = TransactionFees.FeeForSerializeSize(feePerKb, maxSignedSize);
                var remainingAmount = inputAmount - targetAmount;
                if (remainingAmount < maxRequiredFee)
                {
                    targetFee = maxRequiredFee;
                    continue;
                }

                var unsignedTransaction = new Transaction(Transaction.SupportedVersion, inputs, outputs, 0, 0);
                var changeAmount = inputAmount - targetAmount - maxRequiredFee;
                if (changeAmount != 0 && !TransactionRules.IsDustAmount(changeAmount, Transaction.PayToPubKeyHashPkScriptSize, feePerKb))
                {
                    var changeScript = await fetchChangeAsync();
                    if (changeScript.Script.Length > Transaction.PayToPubKeyHashPkScriptSize)
                    {
                        throw new Exception("Fee estimation requires change scripts no larger than P2PKH output scripts");
                    }
                    var changeOutput = new Transaction.Output(changeAmount, Transaction.Output.LatestPkScriptVersion, changeScript.Script);

                    var outputList = unsignedTransaction.Outputs.ToList();
                    outputList.Add(changeOutput);
                    var outputsWithChange = outputList.ToArray();

                    unsignedTransaction = new Transaction(unsignedTransaction.Version, unsignedTransaction.Inputs, outputsWithChange,
                        unsignedTransaction.LockTime, unsignedTransaction.Expiry);
                }

                return Tuple.Create(unsignedTransaction, inputAmount);
            }
        }
Beispiel #6
0
        private static void HandleDataModelChange(ChangeSource source, object originator)
        {
            EntityGroupManager?.RecreateEntityGroupGraphs();

            foreach (var window in s_ActiveWindows)
            {
                window.m_TreeView.Invalidate();
            }
        }
Beispiel #7
0
 public void CreateTheCorrectRepositoryType(ChangeSource source)
 {
     _change.Source = source;
     WorkflowInvoker.Invoke(new SyncChange(), _inputs);
     if (source == ChangeSource.MSSQL)
     {
         _nhRepo.Verify(r => r.Create());
     }
     else
     {
         _efRepo.Verify(r => r.Create());
     }
 }
Beispiel #8
0
            public void SetTheCorrectChangeSource(ChangeSource source)
            {
                IDictionary <string, object> inputs = new Dictionary <string, object>
                {
                    { "Container", _container },
                    { "Source", source }
                };

                WorkflowInvoker.Invoke(new GetChanges(), inputs);
                _mockRepo.Verify(r => r.All <CustomerAudit>());
                Assert.AreEqual(source, _changes[0].Source);
                Assert.AreEqual(source, _changes[1].Source);
            }
Beispiel #9
0
        private static void HandleSceneGraphChange(ChangeSource source, object originator)
        {
            foreach (var entityGroup in LoadedEntityGroups)
            {
                var graph = EntityGroupManager.GetSceneGraph(entityGroup);
                graph.CommitChanges();
            }

            foreach (var window in s_ActiveWindows)
            {
                window.m_TreeView.Invalidate();
            }
        }
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Sends a StoreItemChanged event out to all listeners.
        /// </summary>
        //------------------------------------------------------------------------------------
        private void SendItemChangedEvent(StoreItem item, ChangeType changeType, ItemProperty itemProperty)
        {
            if (Planner.Instance.IsStartupComplete)
            {
                if (StoreItemChanged != null)
                {
                    StoreItemChange change = null;
                    ChangeSource    source = ChangeSource.Default;
                    if (UndoInProgress)
                    {
                        source = ChangeSource.Undo;
                    }
                    else if (RefreshInProgress)
                    {
                        source = ChangeSource.Refresh;
                    }

                    switch (changeType)
                    {
                    case ChangeType.Added:
                        change = new StoreItemChange()
                        {
                            Item = item, ChangeType = changeType, PublicPropName = null, ChangeSource = source
                        };
                        break;

                    case ChangeType.Removed:
                        change = new StoreItemChange()
                        {
                            Item = item, ChangeType = ChangeType.Removed, PublicPropName = null, ChangeSource = source
                        };
                        break;

                    case ChangeType.Updated:
                        change = new StoreItemChange()
                        {
                            Item = item, ChangeType = ChangeType.Updated, PublicPropName = itemProperty.PublicPropName, OldValue = itemProperty.PreviousValue, NewValue = itemProperty.CurrentValue, ChangeSource = source
                        };
                        break;
                    }

                    if (change != null)
                    {
                        StoreItemChanged(this, new StoreItemChangedEventArgs(change));
                    }
                }
            }
        }
Beispiel #11
0
            public void CreateTheCorrectRepositoryType(ChangeSource source)
            {
                IDictionary <string, object> inputs = new Dictionary <string, object>
                {
                    { "Container", _container },
                    { "Source", source }
                };

                WorkflowInvoker.Invoke(new GetChanges(), inputs);
                if (source == ChangeSource.MSSQL)
                {
                    _efRepo.Verify(f => f.Create());
                }
                else
                {
                    _nhRepo.Verify(f => f.Create());
                }
            }
Beispiel #12
0
            public void CreateTheCorrectRepositoryType(ChangeSource source)
            {
                var change = new CustomerAudit {
                    Id = 3, Source = source
                };

                IDictionary <string, object> inputs = new Dictionary <string, object>
                {
                    { "Container", _container },
                    { "Ignored", change }
                };

                WorkflowInvoker.Invoke(new IgnoreChange(), inputs);
                if (source == ChangeSource.MSSQL)
                {
                    _efRepo.Verify(f => f.Create());
                }
                else
                {
                    _nhRepo.Verify(f => f.Create());
                }
            }
 static void DoNotUpdate(IPropertyBinding binding, ChangeSource source)
 {
 }
        /// <summary>
        /// Constructs an unsigned transaction by referencing previous unspent outputs.
        /// A change output is added when necessary to return extra value back to the wallet.
        /// </summary>
        /// <param name="outputs">Transaction output array without change.</param>
        /// <param name="changeScript">Output script to pay change to.</param>
        /// <param name="fetchInputsAsync">Input selection source.</param>
        /// <returns>Unsigned transaction and total input amount.</returns>
        /// <exception cref="InsufficientFundsException">Input source was unable to provide enough input value.</exception>
        public static async Task <Tuple <Transaction, Amount> > BuildUnsignedTransaction(Transaction.Output[] outputs,
                                                                                         Amount feePerKb,
                                                                                         InputSource fetchInputsAsync,
                                                                                         ChangeSource fetchChangeAsync)
        {
            if (outputs == null)
            {
                throw new ArgumentNullException(nameof(outputs));
            }
            if (fetchInputsAsync == null)
            {
                throw new ArgumentNullException(nameof(fetchInputsAsync));
            }
            if (fetchChangeAsync == null)
            {
                throw new ArgumentNullException(nameof(fetchChangeAsync));
            }

            var targetAmount  = outputs.Sum(o => o.Amount);
            var estimatedSize = Transaction.EstimateSerializeSize(1, outputs, true);
            var targetFee     = TransactionFees.FeeForSerializeSize(feePerKb, estimatedSize);

            while (true)
            {
                var funding = await fetchInputsAsync(targetAmount + targetFee);

                var inputAmount = funding.Item1;
                var inputs      = funding.Item2;
                if (inputAmount < targetAmount + targetFee)
                {
                    throw new InsufficientFundsException();
                }

                var maxSignedSize   = Transaction.EstimateSerializeSize(inputs.Length, outputs, true);
                var maxRequiredFee  = TransactionFees.FeeForSerializeSize(feePerKb, maxSignedSize);
                var remainingAmount = inputAmount - targetAmount;
                if (remainingAmount < maxRequiredFee)
                {
                    targetFee = maxRequiredFee;
                    continue;
                }

                var unsignedTransaction = new Transaction(Transaction.SupportedVersion, inputs, outputs, 0, 0);
                var changeAmount        = inputAmount - targetAmount - maxRequiredFee;
                if (changeAmount != 0 && !TransactionRules.IsDustAmount(changeAmount, Transaction.PayToPubKeyHashPkScriptSize, feePerKb))
                {
                    var changeScript = await fetchChangeAsync();

                    if (changeScript.Script.Length > Transaction.PayToPubKeyHashPkScriptSize)
                    {
                        throw new Exception("Fee estimation requires change scripts no larger than P2PKH output scripts");
                    }
                    var changeOutput = new Transaction.Output(changeAmount, Transaction.Output.LatestPkScriptVersion, changeScript.Script);

                    var outputList = unsignedTransaction.Outputs.ToList();
                    outputList.Add(changeOutput);
                    var outputsWithChange = outputList.ToArray();

                    unsignedTransaction = new Transaction(unsignedTransaction.Version, unsignedTransaction.Inputs, outputsWithChange,
                                                          unsignedTransaction.LockTime, unsignedTransaction.Expiry);
                }

                return(Tuple.Create(unsignedTransaction, inputAmount));
            }
        }
Beispiel #15
0
 public ChangeEventArgs(ChangeInfo info, ChangeSource source, ChangeType type)
 {
     this.Info = info;
     this.Source = source;
     this.Type = type;
 }
Beispiel #16
0
            public object Deserialize(JsonReader reader)
            {
                string property;
                while (reader.ReadProperty(out property))
                {
                    switch (property)
                    {
                        case "source":
                            Source = reader.ReadValue<ChangeSource>();
                            break;
                        case "changes":
                            Changes = reader.ReadValue<List<ModelEvent>>();
                            break;
                        default:
                            throw new ArgumentException("The specified property could not be deserialized.", property);
                    }
                }

                return this;
            }