/// <summary> /// Adds an operation to the list of pending operations /// </summary> /// <returns>The operation clock</returns> /// <param name="op">The operation to add</param> public static long AddOperation(IPendingOperation op) { lock (_pendingOperationsLock) _pendingOperations.Add(op); return(op.Clock); }
public async Task <string> CreateOperation(IPendingOperation operation) { var op = new PendingOperation() { OperationId = operation.OperationId, Amount = operation.Amount, CoinAdapterAddress = operation.CoinAdapterAddress, FromAddress = operation.FromAddress, OperationType = operation.OperationType, SignFrom = operation.SignFrom, SignTo = operation.SignTo, ToAddress = operation.ToAddress, Change = operation.Change }; var match = new OperationToHashMatch() { OperationId = op.OperationId, TransactionHash = "" }; await _operationToHashMatchRepository.InsertOrReplaceAsync(match); await _pendingOperationRepository.InsertOrReplace(op); return(op.OperationId); }
public static void RegisterPendingOperation(object objectWrapped, IPendingOperation pendingOperation) { if (objectWrapped == null) { throw new ArgumentNullException(nameof(objectWrapped)); } if (pendingOperation == null) { throw new ArgumentNullException(nameof(pendingOperation)); } ActionQueue actionQueue = null; if (_wrappersCache.TryGetValue(objectWrapped, out var wrapperTypes)) { var firstWrapper = wrapperTypes.First().Value; actionQueue = ((IServiceActorWrapper)firstWrapper).ActionQueue; } if (actionQueue == null) { throw new InvalidOperationException($"Object {objectWrapped} of type '{objectWrapped.GetType()}' is not managed by ServiceActor: call ServiceRef.Create<> to create a service actor for it"); } actionQueue.RegisterPendingOperation(pendingOperation); }
public Task GetOrDownloadAsync(string url) { //simulate image download IPendingOperation pendingOperation = null; Console.WriteLine($"Downloading {url}"); Task.Delay(2000).ContinueWith(_ => { Console.WriteLine($"Downloaded {url}"); pendingOperation.Complete(); }); pendingOperation = ServiceRef.RegisterPendingOperation(this, actionOnCompletion: (res) => { //Accessing _images here would be risky, just wrap the call... ServiceRef.Call(this, () => { Console.WriteLine($"Adding to images {url}"); _images.Add(new ImageStuff() { Url = url, Data = new byte[] { 0x01 } }); Console.WriteLine($"Added to images {url}"); }); }); return(Task.CompletedTask); }
public StoredPendingOperation(IPendingOperation <TId, TData> pendingOperation) { Assert(pendingOperation != null); TransactionId = pendingOperation.TransactionId; OriginalData = AsStoredEntrySnapshot(pendingOperation.OriginalData); OperationTime = pendingOperation.OperationTime; }
public void BeginOperation() { _pendingOperation = ServiceRef.RegisterPendingOperation(this); Task.Factory.StartNew(() => { //simulate some work Task.Delay(1000).Wait(); ServiceRef.Create <IPendingOpsService>(this) .CompleteOperation(); }); }
public async Task <IPendingOperation> GetOperationByHashAsync(string hash) { IOperationToHashMatch match = await _operationToHashMatchRepository.GetByHashAsync(hash); if (match == null) { return(null); } IPendingOperation operation = await _pendingOperationRepository.GetOperation(match.OperationId); return(operation); }
private static StoredPendingOperation AsStoredPendingOperation(IPendingOperation <TId, TData> pendingOperation) { if (pendingOperation == null) { return(null); } if (pendingOperation is StoredPendingOperation storedPendingOperation) { return(storedPendingOperation); } return(new StoredPendingOperation(pendingOperation)); }
public Task <bool> BeginOperationAsync() { _pendingOperation = ServiceRef.RegisterPendingOperation(this, () => OperationCompleted); Task.Run(async() => { //simulate some work await Task.Delay(1000); await ServiceRef.Create <IPendingOpsServiceAsync>(this) .CompleteOperationAsync(); }); return(Task.FromResult(false)); }
private async Task StartProcessing(IPendingOperation operation) { await CreateOperation(operation); await _queue.PutRawMessageAsync(JsonConvert.SerializeObject(new OperationHashMatchMessage() { OperationId = operation.OperationId })); await _eventTraceRepository.InsertAsync(new EventTrace() { Note = $"First appearance for the operation. Put it in{Constants.PendingOperationsQueue}", OperationId = operation.OperationId, TraceDate = DateTime.UtcNow }); }
public static PendingOperationEntity Create(IPendingOperation match) { return(new PendingOperationEntity { PartitionKey = GetPartitionKey(), OperationId = match.OperationId, Amount = match.Amount, CoinAdapterAddress = match.CoinAdapterAddress, SignFrom = match.SignFrom, SignTo = match.SignTo, ToAddress = match.ToAddress, FromAddress = match.FromAddress, OperationType = match.OperationType, Change = match.Change }); }
public async Task RefreshOperationAsync(string trHash) { IOperationToHashMatch match = await _operationToHashMatchRepository.GetByHashAsync(trHash); if (match == null) { return; } IPendingOperation operation = await _pendingOperationRepository.GetOperation(match.OperationId); match.TransactionHash = ""; await _operationToHashMatchRepository.InsertOrReplaceAsync(match); await _queue.PutRawMessageAsync(JsonConvert.SerializeObject(new OperationHashMatchMessage() { OperationId = match.OperationId })); }
public async Task InsertOrReplace(IPendingOperation pendingOp) { var entity = PendingOperationEntity.Create(pendingOp); await _table.InsertOrReplaceAsync(entity); }
public void EnqueuePendingOperation(IPendingOperation pendingOperation) => _pendingOperations.Enqueue(pendingOperation);