public Application(IConfiguration config, ICallData callData) { _callData = callData; _twilioApi = config["TwilioApi"]; _credentials = config["Credentials"]; _twilioEndpoint = config["TwilioApiEndpoint"]; }
public TimeTaskExecutor(Uri endpointUri, ICallData callData, ILogger logger, ApiKeysStrings apiKeys) { _endpointUri = endpointUri; _callData = callData; _logger = logger; _clientPolicy = Policy.Handle <HttpRequestException>() .WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2) }, (exception, span) => { _logger.LogDebug($"Retrying after exception: {exception} {exception.Message}"); }); _httpClient.DefaultRequestHeaders.Add("X-API-Key", apiKeys.ClientKey); }
public byte[] Call(ICallData data) { var result = _serverApiService.InvokeServerCommand(_commandName, data.GetBytes()) .GetAwaiter() .GetResult(); switch (result.Result) { case ServerCommandResult.Success: return(result.Data); case ServerCommandResult.Error: throw TransportClient.ReadException(result.Data); default: throw new InvalidOperationException("Unable to deserialize server command response"); } }
//method to populate the data grid with call records private void PopulateGrid(ICallData callData) { //create a list of the call records _callRecords = callData.GetCalls().ToList(); //remove any invalid records when the page loads _callRecords = RemoveInvalidRecords(_callRecords); //create a new binding source and set the data source to _callRecords BindingSource bs = new BindingSource(); bs.DataSource = _callRecords; //attach the binding source info to the data grid dataGridViewRecords.DataSource = bs; //hide the column with the Rate object dataGridViewRecords.Columns[7].Visible = false; //show the count in the label (number of entries) labelCount.Text = _callRecords.Count.ToString(); Validate(); }
//method to populate the data grid by the from phone number private void PopulateGridByPhoneNumber(ICallData callData) { //get the records _callRecords = callData.GetCalls().ToList(); //remove any invalid records _callRecords = RemoveInvalidRecords(_callRecords); //create a new binding source and set the data source to _callRecords BindingSource bs = new BindingSource(); bs.DataSource = from record in _callRecords select record; //create a binding list using _callRecords BindingList <CallRecord> list = new BindingList <CallRecord>(_callRecords); //filter the list by the fromPhoneNumber combo box var filter = list.Where(rec => rec.CallFromNumber == comboBoxFromPhoneNumber.SelectedItem.ToString()).ToList(); //if the "answered only" box isn't selected, show all the records from the phone number if (!checkBoxAnsweredCalls.Checked) { dataGridViewRecords.DataSource = filter; labelCount.Text = filter.Count.ToString(); //update the count //hide the column with the Rate object dataGridViewRecords.Columns[7].Visible = false; } //otherwise only show records from the phone number that have "Y" for callCompletedStatus else { ShowAnsweredOnly(filter); } //set the list to contain only the filtered records _callRecords = filter; }
/// <summary> /// Invokes a method on an existing smart contract /// </summary> public VmExecutionResult ExecuteMethod( IGasMeter gasMeter, IContractStateRepository repository, ICallData callData, ITransactionContext transactionContext) { this.logger.LogTrace("(){0}:{1}", nameof(callData.MethodName), callData.MethodName); if (callData.MethodName == null) { this.logger.LogTrace("(-)[CALLCONTRACT_METHODNAME_NOT_GIVEN]"); return(VmExecutionResult.Error(gasMeter.GasConsumed, null)); } byte[] contractExecutionCode = repository.GetCode(callData.ContractAddress); string typeName = repository.GetContractType(callData.ContractAddress); if (contractExecutionCode == null) { return(VmExecutionResult.Error(gasMeter.GasConsumed, new SmartContractDoesNotExistException(callData.MethodName))); } byte[] gasInjectedCode = SmartContractGasInjector.AddGasCalculationToContractMethod(contractExecutionCode, typeName, callData.MethodName); Type contractType = Load(gasInjectedCode, typeName); if (contractType == null) { this.logger.LogTrace("(-)[CALLCONTRACT_CONTRACTTYPE_NULL]"); return(VmExecutionResult.Error(gasMeter.GasConsumed, null)); } uint160 contractAddress = callData.ContractAddress; IPersistenceStrategy persistenceStrategy = new MeteredPersistenceStrategy(repository, gasMeter, new BasicKeyEncodingStrategy()); IPersistentState persistentState = new PersistentState(persistenceStrategy, contractAddress, this.network); var internalTransferList = new List <TransferInfo>(); IInternalTransactionExecutor internalTransactionExecutor = this.internalTransactionExecutorFactory.Create(this, repository, internalTransferList, transactionContext); var balanceState = new BalanceState(repository, transactionContext.Amount, internalTransferList); var contractState = new SmartContractState( new Block( transactionContext.BlockHeight, transactionContext.Coinbase.ToAddress(this.network) ), new Message( callData.ContractAddress.ToAddress(this.network), transactionContext.From.ToAddress(this.network), transactionContext.Amount ), persistentState, gasMeter, internalTransactionExecutor, new InternalHashHelper(), () => balanceState.GetBalance(callData.ContractAddress)); LogExecutionContext(this.logger, contractState.Block, contractState.Message, contractAddress, callData); LifecycleResult result = SmartContractRestorer.Restore(contractType, contractState); if (!result.Success) { LogException(result.Exception); this.logger.LogTrace("(-)[CALLCONTRACT_INSTANTIATION_FAILED]:{0}={1}", nameof(gasMeter.GasConsumed), gasMeter.GasConsumed); return(VmExecutionResult.Error(gasMeter.GasConsumed, result.Exception.InnerException ?? result.Exception)); } else { this.logger.LogTrace("[CALL_CONTRACT_INSTANTIATION_SUCCEEDED]"); } object methodResult = null; try { MethodInfo methodToInvoke = contractType.GetMethod(callData.MethodName); if (methodToInvoke == null) { throw new ArgumentException(string.Format("[CALLCONTRACT_METHODTOINVOKE_NULL_DOESNOT_EXIST]:{0}={1}", nameof(callData.MethodName), callData.MethodName)); } if (methodToInvoke.IsConstructor) { throw new ConstructorInvocationException("[CALLCONTRACT_CANNOT_INVOKE_CTOR]"); } SmartContract smartContract = result.Object; methodResult = methodToInvoke.Invoke(smartContract, callData.MethodParameters); } catch (ArgumentException argumentException) { LogException(argumentException); return(VmExecutionResult.Error(gasMeter.GasConsumed, argumentException)); } catch (TargetInvocationException targetException) { LogException(targetException); return(VmExecutionResult.Error(gasMeter.GasConsumed, targetException.InnerException ?? targetException)); } catch (TargetParameterCountException parameterException) { LogException(parameterException); } catch (ConstructorInvocationException constructorInvocationException) { LogException(constructorInvocationException); return(VmExecutionResult.Error(gasMeter.GasConsumed, constructorInvocationException)); } this.logger.LogTrace("(-):{0}={1}", nameof(gasMeter.GasConsumed), gasMeter.GasConsumed); return(VmExecutionResult.Success(internalTransferList, gasMeter.GasConsumed, methodResult)); }
/// <summary> /// Invokes a method on an existing smart contract /// </summary> public VmExecutionResult ExecuteMethod( IGasMeter gasMeter, IContractState repository, ICallData callData, ITransactionContext transactionContext) { this.logger.LogTrace("(){0}:{1}", nameof(callData.MethodName), callData.MethodName); if (callData.MethodName == null) { this.logger.LogTrace("(-)[CALLCONTRACT_METHODNAME_NOT_GIVEN]"); return(VmExecutionResult.Error(gasMeter.GasConsumed, null)); } byte[] contractExecutionCode = repository.GetCode(callData.ContractAddress); string typeName = repository.GetContractType(callData.ContractAddress); if (contractExecutionCode == null) { return(VmExecutionResult.Error(gasMeter.GasConsumed, new SmartContractDoesNotExistException(callData.MethodName))); } // TODO consolidate this with CallData. MethodCall methodCall = new MethodCall(callData.MethodName, callData.MethodParameters); ContractByteCode code; using (IContractModuleDefinition moduleDefinition = this.moduleDefinitionReader.Read(contractExecutionCode)) { moduleDefinition.InjectMethodGas(typeName, methodCall); code = moduleDefinition.ToByteCode(); } var internalTransferList = new List <TransferInfo>(); var contractLogger = new ContractLogHolder(this.network); ISmartContractState contractState = this.SetupState(contractLogger, internalTransferList, gasMeter, repository, transactionContext, callData.ContractAddress); Result <IContract> contractLoadResult = this.Load( code, typeName, callData.ContractAddress, contractState); if (!contractLoadResult.IsSuccess) { // TODO this is temporary until we improve error handling overloads var exception = new Exception(contractLoadResult.Error); LogException(exception); this.logger.LogTrace("(-)[LOAD_CONTRACT_FAILED]:{0}={1}", nameof(gasMeter.GasConsumed), gasMeter.GasConsumed); return(VmExecutionResult.Error(gasMeter.GasConsumed, exception)); } IContract contract = contractLoadResult.Value; LogExecutionContext(this.logger, contract.State.Block, contract.State.Message, contract.Address, callData); IContractInvocationResult invocationResult = contract.Invoke(methodCall); if (!invocationResult.IsSuccess) { this.logger.LogTrace("(-)[CALLCONTRACT_INSTANTIATION_FAILED]:{0}={1}", nameof(gasMeter.GasConsumed), gasMeter.GasConsumed); return(VmExecutionResult.Error(gasMeter.GasConsumed, new Exception("Method invocation failed!"))); } this.logger.LogTrace("[CALL_CONTRACT_INSTANTIATION_SUCCEEDED]"); this.logger.LogTrace("(-):{0}={1}", nameof(gasMeter.GasConsumed), gasMeter.GasConsumed); return(VmExecutionResult.Success(internalTransferList, gasMeter.GasConsumed, invocationResult.Return, contractLogger.GetRawLogs())); }
public void SetEndedCall(ICallData call) { EndedCall = call; }