public async Task CreateOrUpdateSynthesisActivity(SynthesisActivityItemViewModel item) { OligoSynthesisActivity entity; OligoSynthesisProcess currentOligoSynthesisProcess = await GetCurrentOligoSynthesisProcess(); if (string.IsNullOrWhiteSpace(item.Id)) { entity = new OligoSynthesisActivity(); entity.OligoSynthesisProcess = currentOligoSynthesisProcess; } else { entity = currentOligoSynthesisProcess.OligoSynthesisActivities.Single(x => x.Id == item.Id); } entity.DNASequence = !string.IsNullOrWhiteSpace(item.DNASequence) ? item.DNASequence.ToUpper() : "A"; if (item.SynthesisCycle != null && !string.IsNullOrWhiteSpace(item.SynthesisCycle.Id)) { entity.SynthesisCycle = unitOfWork.GetById <SynthesisCycle>(item.SynthesisCycle.Id); } else { SynthesisCycle defaultSynthesisCycle = await unitOfWork.GetAll <SynthesisCycle>() .Include(x => x.CycleSteps) .SingleAsync(x => x.UserId == null); entity.SynthesisCycle = defaultSynthesisCycle; } await AssignToChannel(entity, currentOligoSynthesisProcess.OligoSynthesisActivities); CalcOligoSynthesisActivityTotalTime(entity); unitOfWork.InsertOrUpdate(entity); unitOfWork.Commit(); currentOligoSynthesisProcess = await GetCurrentOligoSynthesisProcess(); currentOligoSynthesisProcess.TotalTime = currentOligoSynthesisProcess.OligoSynthesisActivities.Sum(x => x.TotalTime); unitOfWork.Commit(); }
public async Task <SynthesisProcessViewModel> GetCurrentSynthesisProcess() { OligoSynthesisProcess currentOligoSynthesisProcess = await GetCurrentOligoSynthesisProcess(); if (currentOligoSynthesisProcess == null) { currentOligoSynthesisProcess = new OligoSynthesisProcess { Status = SynthesisProcessStatus.NotStarted, User = GetCurrentUser() }; unitOfWork.InsertOrUpdate(currentOligoSynthesisProcess); unitOfWork.Commit(); } return(new SynthesisProcessViewModel() { Id = currentOligoSynthesisProcess.Id, Status = currentOligoSynthesisProcess.Status }); }
private async Task StartOligoSynthesisProcess() { //try //{ // var oligoSynthesizerBackgroundService = DependencyService.Get<IOligoSynthesizerBackgroundService>(); // oligoSynthesizerBackgroundService.Start(); //} //catch (Exception ex) //{ // LogAction($"Oligo synthesis process failed: {ex.Message}"); //} ICloudTable <OligoSynthesisProcess> oligoSynthesisProcessTable = null; OligoSynthesisProcess currentOligoSynthesisProcess = null; try { await AwaitPreviousSynthesisProcess(); LogAction("Syncing oligo synthesis process..."); var currentUserId = GetCurrentUserId(); LogAction("Syncing oligo synthesis process."); await CloudService.SyncOfflineCacheAsync(); LogAction("Sync completed."); oligoSynthesisProcessTable = await CloudService.GetTableAsync <OligoSynthesisProcess>(); var allOligoSynthesisProcesses = await oligoSynthesisProcessTable.ReadAllItemsAsync(); currentOligoSynthesisProcess = allOligoSynthesisProcesses.Where(x => x.UserId == currentUserId) .OrderByDescending(x => x.CreatedAt) .FirstOrDefault(); if (currentOligoSynthesisProcess == null) { LogAction("Oligo synthesis process not found."); } var hardwareFunctionTable = await CloudService.GetTableAsync <HardwareFunction>(); var allHardwareFunctions = await hardwareFunctionTable.ReadAllItemsAsync(); IEnumerable <HardwareFunction> bAndTetToColFunctions = allHardwareFunctions.Where( x => x.FunctionType == HardwareFunctionType.AAndTetToCol || x.FunctionType == HardwareFunctionType.CAndTetToCol || x.FunctionType == HardwareFunctionType.TAndTetToCol || x.FunctionType == HardwareFunctionType.GAndTetToCol); HardwareFunction closeAllValvesFunction = allHardwareFunctions.Single(x => x.FunctionType == HardwareFunctionType.CloseAllValves); int oligoSynthesisProcessRemainingTime = currentOligoSynthesisProcess.TotalTime; LogAction($"Starting a new oligo synthesis process. Total Time: {oligoSynthesisProcessRemainingTime} s"); foreach (OligoSynthesisActivity oligoSynthesisActivity in currentOligoSynthesisProcess.OligoSynthesisActivities.OrderBy(x => x.ChannelNumber)) { int oligoSynthesisActivityTotalTime = oligoSynthesisActivity.TotalTime; await Task.Run(async() => { await oligoSynthesizerRestService.StartSynthesis(oligoSynthesisActivity, bAndTetToColFunctions, closeAllValvesFunction, oligoSynthesisActivityTotalTime); }); oligoSynthesisProcessRemainingTime -= oligoSynthesisActivityTotalTime; LogAction($"Total remaining time: {oligoSynthesisProcessRemainingTime} s"); } //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Completed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); } catch (Exception ex) { //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Failed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); LogAction($"Oligo synthesis process failed: {ex.Message}"); } finally { await CloudService.SyncOfflineCacheAsync(); } }