/* * actual while implementation */ private static void WhileUnchecked(Node pars, Node ip, Node dp) { // looping as long as statement is true while (StatementHelper.CheckExpressions(ip, dp)) { Node oldIp = ip["code"].Clone(); pars["_ip"].Value = ip["code"]; RaiseActiveEvent( "magix.execute", pars); ip["code"].Clear(); ip["code"].AddRange(oldIp); } }
/* * helper for executing [if]/[else-if] */ private static void IfElseIfImplementation(Node pars, string evt) { Node ip = Ip(pars); Node dp = Dp(pars); // verifying [if] or [else-if] has a [code] block beneath itself if (!ip.Contains("code")) { throw new HyperlispSyntaxErrorException("you must supply a [code] node for your [" + evt + "] expressions"); } // verifying there's at least an [lhs] node beneath [if] or [else-if] if (!ip.Contains("lhs")) { throw new HyperlispSyntaxErrorException("you must supply an [lhs] node for your [" + evt + "] expressions"); } // verifying there's an operator on [if] or [else-if] if (string.IsNullOrEmpty(ip.Get <string>())) { throw new HyperlispSyntaxErrorException("you must supply an operator for your [" + evt + "] expressions as Value of [" + evt + "]"); } // checking statement to see if it's true, before we execute [code] block if (StatementHelper.CheckExpressions(ip, dp)) { // yup, we've got a match, executing [code] block pars["_ip"].Value = ip["code"]; RaiseActiveEvent( "magix.execute", pars); // checking to see if we should add state ("_state_if") to state such that no followup [else] or [else-if] gets executed Node next = ip.Next(); if (next != null && (next.Name == "else-if" || next.Name == "magix.execute.else-if" || next.Name == "else" || next.Name == "magix.execute.else")) { PushState(pars, ip); } } }
public async Task <TransferMoneyResultDto> TransferMoney(TransferMoneyDto dto) { ValidationHelper.Validate(_transferMoneyValidator, dto); Account sender = await _accountRepository.GetByIBanNumber(dto.sender_iban_number); if (sender == null) { throw new AccountNotFoundException("sender was not found"); } Account payee = await _accountRepository.GetByIBanNumber(dto.payee_iban_number); if (payee == null) { throw new AccountNotFoundException("payee was not found"); } var statements = await _statementRepository.GetByAccountId(sender.Id); var totalBalance = statements.Sum(x => StatementHelper.CalculateActualAmount(x.Amount, x.Fee)); if (totalBalance < dto.amount) { throw new MoneyNotEnoughException("not enough money to transfer"); } TransferMoneyFullDto fullDto = new TransferMoneyFullDto { amount = dto.amount, sender = sender, payee = payee, transfer_date = DateTime.Now, transfer_fee = _appSettings.TransferFee }; var dtoResult = await _transactionRepository.SaveTransferringMoney(fullDto); return(dtoResult); }
public async Task <ICrateResponse> BulkInsert <T>(IEnumerable <T> entities) { var statement = StatementHelper.BulkInsertStatement(entities); return(await this.SubmitRequest(new CrateRequest(statement))); }
public async Task <ICrateResponse> Insert <T>(T entity) { var statement = StatementHelper.InsertStatement(entity); return(await this.SubmitRequest(new CrateRequest(statement))); }
public async Task <ICrateResponse> CreateTable <T>(int?shards = null, int?replicas = null) { var statement = StatementHelper.CreateTableStatement(typeof(T), shards, replicas); return(await this.SubmitRequest(new CrateRequest(statement))); }
static public Block ParseBlock(ref List <Token> .Enumerator tokens, Block parent, FunctionType func) { var thisBlock = new Block(parent); thisBlock.Function = func; // Climb the parents to find the function we are in if (func == null) { Block curBlock = thisBlock; do { if (curBlock.Function != null) { func = curBlock.Function; } curBlock = curBlock.Parent; }while (curBlock != null); } if (parent != null) { thisBlock.TempDeclarationNumber = parent.TempDeclarationNumber; } while (tokens.Current != null && tokens.Current.Type != TokenType.CloseBlock) { if (tokens.Current.Text == "typedef") { } else if (tokens.Current.Text == "if") { thisBlock.Statements.Add(If.ParseIf(thisBlock, ref tokens)); } else if (tokens.Current.Text == "do") { thisBlock.Statements.Add(DoWhile.Parse(thisBlock, ref tokens)); } else if (tokens.Current.Text == "while") { thisBlock.Statements.Add(While.Parse(thisBlock, ref tokens)); } else if (tokens.Current.Text == "struct") { tokens.MoveNext(); if (tokens.Current.Type != TokenType.OpenBlock) { throw new System.Exception("That was gay"); } } else if (tokens.Current.Text == "return") { tokens.MoveNext(); if (tokens.Current.Type == TokenType.StatementEnd) { var returnStatement = new Return(null); thisBlock.Statements.Add(returnStatement); tokens.MoveNext(); } else { var returnList = Tokenizer.GetStatement(ref tokens); Declaration decl = thisBlock.CreateTempDeclaration(func.ReturnType); StatementHelper.Parse(thisBlock, decl, returnList); var returnStatement = new Return(decl); thisBlock.Statements.Add(returnStatement); tokens.MoveNext(); } } else { FunctionType.CallConvention specifiedConvention = FunctionType.CallConvention.CalleeSave; bool useStack = false; while (tokens.Current.Text.StartsWith("__")) { switch (tokens.Current) { case "__usestack": useStack = true; break; case "__stdcall": specifiedConvention = FunctionType.CallConvention.CalleeSave; break; case "__cdecl": specifiedConvention = FunctionType.CallConvention.CallerSave; break; } tokens.MoveNext(); } Declaration declForStatement = thisBlock.FindDeclaration(tokens.Current.Text); if (declForStatement != null) { StatementHelper.Parse(thisBlock, Tokenizer.GetStatement(ref tokens)); Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); tokens.MoveNext(); } else { String resultName = String.Empty; Type resultType = TypeHelper.ParseType(ref tokens); if (resultType == null) { StatementHelper.Parse(thisBlock, Tokenizer.GetStatement(ref tokens)); Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); tokens.MoveNext(); } else { // Read the name of the declaration/type if (tokens.Current.Type == TokenType.StringType) { resultName = tokens.Current.Text; tokens.MoveNext(); } // in this case it's either a prototype or a function // Either way it gets added to the types of this module if (tokens.Current.Type == TokenType.OpenParen) { FunctionType function = new FunctionType(ref tokens, resultType) { CallingConvention = specifiedConvention, UseStack = useStack }; resultType = function; thisBlock.Types.Add(function); if (tokens.Current.Type == TokenType.OpenBlock) { var declaration = new Declaration(resultType, resultName); thisBlock.Declarations.Add(declaration); tokens.MoveNext(); var block = Block.ParseBlock(ref tokens, thisBlock, function); Debug.Assert(tokens.Current.Type == TokenType.CloseBlock); tokens.MoveNext(); declaration.Code = block; //STP: Not sure about this //thisBlock.Declarations.Add(declaration); } else { Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); tokens.MoveNext(); } } else if (tokens.Current == "[") { resultType = new WabbitC.Model.Types.Array(resultType, ref tokens); var declaration = new Declaration(resultType, resultName); thisBlock.Declarations.Add(declaration); Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); tokens.MoveNext(); } else { do { var decl = new Declaration(resultType, resultName); thisBlock.Declarations.Add(decl); // Handle declarations with initial values if (tokens.Current.Text == "=") { tokens.MoveNext(); var valueList = Tokenizer.GetStatement(ref tokens); StatementHelper.Parse(thisBlock, decl, valueList); if (tokens.Current.Text != ",") { Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); break; } else { tokens.MoveNext(); Debug.Assert(tokens.Current.Type == TokenType.StringType); resultName = tokens.Current.Text; tokens.MoveNext(); } } else { if (tokens.Current.Text != ",") { Debug.Assert(tokens.Current.Type == TokenType.StatementEnd); break; } else { tokens.MoveNext(); Debug.Assert(tokens.Current.Type == TokenType.StringType); resultName = tokens.Current.Text; tokens.MoveNext(); } } } while (true); tokens.MoveNext(); } } } } } return(thisBlock); }