private async Task <IEnumerable <string> > GetContainersAsync(AccountNode accountNode) { if (!accountNode.HasChildren()) { await LoadContainersAsync(accountNode); } return(accountNode.Nodes.OfType <ContainerNode>().Select(node => node.Name)); }
// Calculates the repulsion force between any two nodes in the diagram space. private Vector CalcRepulsionForce(AccountNode x, AccountNode y) { int proximity = Math.Max(CalcDistance(x.Location, y.Location), 1); // Coulomb's Law: F = k(Qq/r^2) double force = -(REPULSION_CONSTANT / Math.Pow(proximity, 2)); double angle = GetBearingAngle(x.Location, y.Location); return(new Vector(force, angle)); }
// Calculates the attraction force between two connected nodes, using the specified spring length. private Vector CalcAttractionForce(AccountNode x, AccountNode y, double springLength) { int proximity = Math.Max(CalcDistance(x.Location, y.Location), 1); // Hooke's Law: F = -kx double force = ATTRACTION_CONSTANT * Math.Max(proximity - springLength, 0); double angle = GetBearingAngle(x.Location, y.Location); return(new Vector(force, angle)); }
private async Task LoadContainersAsync(AccountNode accountNode) { await DoActionAsync(tslAccountStatus, "Loading containers...", async() => { var service = new BlobService(accountNode.Account.Name, accountNode.Account.Key); var containers = await service.ListContainersAsync(); tvwObjects.BeginUpdate(); accountNode.LoadChildren(containers); tvwObjects.EndUpdate(); }); }
private async void TbSearchContainers_KeyDown(object sender, KeyEventArgs e) { try { string searchText = tbSearchContainers.Text; if (e.KeyCode == Keys.Enter) { if (!string.IsNullOrEmpty(searchText)) { await DoActionAsync(tslAccountStatus, "Searching containers...", async() => { tvwObjects.Nodes.Clear(); var root = AddRootNode(); foreach (var acc in _options.Accounts) { var service = new BlobService(acc.Name, acc.Key); var containers = await service.ListContainersAsync(searchText); if (containers.Any()) { var accountNode = new AccountNode(acc); root.Nodes.Add(accountNode); tvwObjects.BeginUpdate(); accountNode.LoadChildren(containers); tvwObjects.EndUpdate(); accountNode.Expand(); } } root.Expand(); }); } else { FillAccounts(); } } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void btnNetIncome_Click(object sender, RoutedEventArgs e) { dpBalanceDate.Visibility = Visibility.Collapsed; gridFilters.Visibility = Visibility.Collapsed; tpTransactionPeriod.Visibility = Visibility.Visible; cbGroupBy.Visibility = Visibility.Visible; TreeList treeList = new TreeList(); AccountNode incomes = Accounts.ProfitLossReport("/2/", tpTransactionPeriod.StartDate, tpTransactionPeriod.EndDate); AccountNode expenses = Accounts.ProfitLossReport("/3/", tpTransactionPeriod.StartDate, tpTransactionPeriod.EndDate); AccountNode netIncome = new AccountNode(); netIncome.RootAccount = new AccountInfo(SqlHierarchyId.Parse("/4/"), "Net income", incomes.RootAccount.Balance + expenses.RootAccount.Balance); treeList.Tree.Items.Add(incomes); treeList.Tree.Items.Add(expenses); treeList.Tree.Items.Add(netIncome); bookkeeperPanel.Children.Clear(); bookkeeperPanel.Children.Add(treeList); bookkeeperPanel.Tag = AccWindows.NetIncomeReport; BuildChart(); }
public static void ExpandConnectionProperties(ConnectionNode connectionNode) { var accounts = BlockStudioProjectService.BlockStudioProject.Accounts; connectionNode.Nodes[0].Nodes.Clear(); foreach (var account in accounts) { var accountNode = new AccountNode(); accountNode.Text = account.Label; if (account.LockState == LockedState.Locked) { accountNode.ImageIndex = 3; accountNode.SelectedImageIndex = 3; } else if (account.LockState == LockedState.Unlocked) { accountNode.ImageIndex = 4; accountNode.SelectedImageIndex = 4; } else if (account.LockState == LockedState.WrongPassword) { accountNode.ImageIndex = 6; accountNode.SelectedImageIndex = 6; } accountNode.Account = account; accountNode.Name = NodeType.Account.ToString(); var addressNode = new AddressNode(account.Address); var balanceNode = new BalanceNode(string.Format("Balance: {0} Eth", account.BalanceEther)); accountNode.Nodes.Add(addressNode); accountNode.Nodes.Add(balanceNode); connectionNode.Nodes[0].Nodes.Add(accountNode); } }
public abstract string GetEquation(AccountNode _node);
public ReputationFunction(Network _network) { this.network = _network; this.observerNode = _network.observerNode; this.allNodes = _network.allNodes; }
//This methods returns the equation to be solved to determine each node reputation score in string format. //This equation will be solved by linear algebra library. public override string GetEquation(AccountNode _node) { //Sets the self reputation value to the network's default. float selfRep = network.defaultNodeReputation; //If the observer node vouches for this node, then set it to 0 or 1 accordingly. if (observerNode.vouches.ContainsKey(_node)) { selfRep = observerNode.vouches[_node] ? 1 : 0; } string numerator = selfRep + "+"; //The first term of the denominator should be it's w string denominator = "1+"; foreach (AccountNode _neighbour in _node.neighbours.Keys) { if (_neighbour.Equals(observerNode)) { continue; } //If the neighbour has no path for or against to the observer, then dont take it into consideration. if (!_neighbour.hasVouchForPath && !_neighbour.hasVouchAgainstPath) { continue; } float term = (_node.neighbours[_neighbour] ? 1 : 0); //Invert it if arawahawhawanbz if (!_neighbour.hasVouchForPath || !_neighbour.hasVouchForPath) { if (term == 1 && _neighbour.hasVouchForPath && !_neighbour.hasVouchForPath) { term = 0; } if (term == 0 && !_neighbour.hasVouchForPath && _neighbour.hasVouchForPath) { term = 1; } } //The distance weight is calculated as 1/2^n, where n is the node's distance to the observer. float distanceWeight = (float)(1 / Math.Pow(2, _neighbour.distanceFromObserver)); string weight = _neighbour.name + "*" + distanceWeight; if (term > 0 && distanceWeight > 0) { numerator += weight + "+"; } denominator += weight + "+"; } numerator = numerator.TrimEnd('+'); denominator = denominator.TrimEnd('+'); string formula = "(" + numerator + ")/(" + denominator + ")"; return(formula + "-" + _node.name); }
public Point NextPosition; // the node's position after the next iteration /// Initialises a new instance of the Diagram.NodeLayoutInfo class, using the specified parameters. public NodeLayoutInfo(AccountNode node, Vector velocity, Point nextPosition) { Node = node; Velocity = velocity; NextPosition = nextPosition; }
public Diagram(List <AccountNode> _nodes, AccountNode _observer) { nodes = _nodes; observer = _observer; Arrange(); }
private Node TryParseEPasaInternal(TokenType expectedToken, TextReader reader, ref EPasaErrorCode error, string prefix = null, string postFix = null) { Node result = null; if (error != EPasaErrorCode.Success) { return(null); } if (prefix != null) { foreach (var prefixChar in prefix) { if (!reader.MatchChar(prefixChar)) { error = EPasaErrorCode.BadFormat; return(null); } } } switch (expectedToken) { case TokenType.EPASA: result = new EPasaNode { Type = TokenType.EPASA, Account = TryParseEPasaInternal(TokenType.PASA, reader, ref error) as AccountNode, Payload = TryParseEPasaInternal(TokenType.Payload, reader, ref error) as PayloadNode, ExtendedChecksum = TryParseEPasaInternal(TokenType.ExtendedChecksum, reader, ref error) as ValueNode }; if (!reader.MatchChar(null as char?)) { // match end-of-string error = EPasaErrorCode.BadFormat; return(null); } break; case TokenType.PASA: if (IsStartChar(TokenType.AccountNumber, reader.PeekChar())) { result = TryParseEPasaInternal(TokenType.AccountNumber, reader, ref error); } else if (IsStartChar(TokenType.AccountName, reader.PeekChar())) { result = TryParseEPasaInternal(TokenType.AccountName, reader, ref error); } else { error = EPasaErrorCode.InvalidAccountNumber; } break; case TokenType.AccountName: result = new AccountNode { Type = TokenType.AccountName, Name = TryParseEPasaInternal(TokenType.Pascal64String, reader, ref error) as ValueNode }; break; case TokenType.AccountNumber: result = new AccountNode { Type = TokenType.AccountNumber, AccountNo = TryParseEPasaInternal(TokenType.Number, reader, ref error) as ValueNode, Checksum = TryParseEPasaInternal(TokenType.Checksum, reader, ref error) as ValueNode }; break; case TokenType.Checksum: if (IsStartChar(TokenType.Checksum, reader.PeekChar())) { result = TryParseEPasaInternal(TokenType.Number, reader, ref error, prefix: "-") as ValueNode; } break; case TokenType.Payload: if (IsStartChar(TokenType.Payload, reader.PeekChar())) { result = new PayloadNode { Type = TokenType.Payload }; var payloadOpenChar = reader.ReadChar(); ((PayloadNode)result).Content = TryParseEPasaInternal(TokenType.PayloadContent, reader, ref error) as ValueNode; if (reader.PeekChar() == ':') { if (payloadOpenChar != '{') { error = EPasaErrorCode.UnusedPassword; return(result); } ((PayloadNode)result).Password = TryParseEPasaInternal(TokenType.PascalAsciiString, reader, ref error, prefix: ":") as ValueNode; } else if (payloadOpenChar == '{') { error = EPasaErrorCode.MissingPassword; return(null); } var payloadEndChar = reader.PeekChar(); if (!payloadEndChar.IsIn(']', ')', '>', '}')) { error = EPasaErrorCode.BadFormat; return(null); } char?expectedEndChar = null; switch (payloadOpenChar) { case '[': ((PayloadNode)result).Encryption = PayloadType.Public; expectedEndChar = ']'; break; case '(': ((PayloadNode)result).Encryption = PayloadType.RecipientKeyEncrypted; expectedEndChar = ')'; break; case '<': ((PayloadNode)result).Encryption = PayloadType.SenderKeyEncrypted; expectedEndChar = '>'; break; case '{': ((PayloadNode)result).Encryption = PayloadType.PasswordEncrypted; expectedEndChar = '}'; break; default: throw new InternalErrorException("Implementation Error"); } if (reader.PeekChar() != expectedEndChar) { error = EPasaErrorCode.MismatchedPayloadEncoding; return(null); } if (!reader.MatchChar(']', ')', '>', '}')) { error = EPasaErrorCode.BadFormat; return(null); } } break; case TokenType.PayloadContent: var contentStartChar = reader.PeekChar(); if (contentStartChar == '"') { result = TryParseEPasaInternal(TokenType.PascalAsciiString, reader, ref error, prefix: "\"", postFix: "\"") as ValueNode; } else if (IsStartChar(TokenType.HexString, contentStartChar)) { result = TryParseEPasaInternal(TokenType.HexString, reader, ref error, prefix: "0x") as ValueNode; } else if (IsStartChar(TokenType.Base58String, contentStartChar)) { result = TryParseEPasaInternal(TokenType.Base58String, reader, ref error) as ValueNode; } else { // unrecognized content, assume empty } break; case TokenType.ExtendedChecksum: if (reader.PeekChar() == ':') { result = TryParseEPasaInternal(TokenType.HexString, reader, ref error, prefix: ":") as ValueNode; } break; case TokenType.PascalAsciiString: case TokenType.Pascal64String: result = new ValueNode { Type = expectedToken, Value = string.Empty }; if (!IsStartChar(expectedToken, reader.PeekChar())) { // first character is a non-character, assume empty string return(result); } var escapedValue = string.Empty; do { if (reader.PeekChar() == GetEscapeChar(expectedToken)) { escapedValue += reader.ReadChar(); if (!IsEscapedChar(expectedToken, reader.PeekChar())) { error = EPasaErrorCode.BadFormat; // illegal escape sequence return(result); } } else if (IsEscapedChar(expectedToken, reader.PeekChar())) { // encountered a character that needs escaping // assume end of token break; } escapedValue += reader.ReadChar(); } while (IsValidValueChar(expectedToken, reader.PeekChar())); ((ValueNode)result).Value = escapedValue; break; case TokenType.HexString: case TokenType.Base58String: case TokenType.Number: result = new ValueNode { Type = expectedToken, Value = string.Empty }; while (IsValidValueChar(expectedToken, reader.PeekChar())) { ((ValueNode)result).Value = ((ValueNode)result).Value + reader.ReadChar(); } break; default: throw new ArgumentOutOfRangeException(nameof(expectedToken), expectedToken, null); } if (error == EPasaErrorCode.Success && postFix != null) { foreach (var postfixChar in postFix) { if (!reader.MatchChar(postfixChar)) { error = EPasaErrorCode.BadFormat; return(null); } } } return(result); }