public HardwareFunction CreateHardwareFunction() { HardwareFunction hardwareFunction = new HardwareFunction() { Number = 999, Name = "test", Description = "test description", ApiUrl = "/macro/f999", HttpMethodType = HttpMethodType.POST }; return(GetOrCreate(() => hardwareFunction)); }
public async Task <HardwareFunctionItemViewModel> GetHardwareFunction(HardwareFunctionType hardwareFunctionType) { HardwareFunction trayOutHardwareFunction = await unitOfWork.GetAll <HardwareFunction>().SingleAsync(x => x.FunctionType == hardwareFunctionType); return(new HardwareFunctionItemViewModel() { Id = trayOutHardwareFunction.Id, Name = trayOutHardwareFunction.Name, Number = trayOutHardwareFunction.Number, ApiUrl = trayOutHardwareFunction.ApiUrl, FunctionType = trayOutHardwareFunction.FunctionType, }); }
private async Task AssignChannelNumbers(IEnumerable <GeneSynthesisActivity> geneSynthesisActivities) { var allChannels = await channelConfigurationService.GetChannelConfigurations(); IList <ChannelConfigurationItemViewModel> availableChannels = allChannels.ToList(); foreach (GeneSynthesisActivity geneSynthesisActivity in geneSynthesisActivities) { ChannelConfigurationItemViewModel channel = availableChannels.FirstOrDefault( x => geneSynthesisActivity.DNASequence.StartsWith(x.StartNucleotide)); geneSynthesisActivity.ChannelNumber = channel.ChannelNumber; HardwareFunction channelApiFunction = unitOfWork.GetById <HardwareFunction>(channel.HardwareFunction.Id); geneSynthesisActivity.ChannelApiFunctionId = channelApiFunction.Id; geneSynthesisActivity.ChannelApiFunction = channelApiFunction; availableChannels.Remove(channel); } }
public async Task <JsonResult> SetSyringePump(ManualControlViewModel manualControlViewModel) { try { User currentUser = manualControlService.GetCurrentUser(); HardwareFunction syringePumpHardwareFunction = await unitOfWork.GetAll <HardwareFunction>() .SingleAsync(x => x.FunctionType == manualControlViewModel.SelectedSyringePumpFunction); string apiUrl; if (manualControlViewModel.SelectedSyringePumpFunction == HardwareFunctionType.SyringePumpDraw) { apiUrl = string.Format(syringePumpHardwareFunction.ApiUrl, manualControlViewModel.SyringePumpStepMode ? 1 : 0, manualControlViewModel.SyringePumpFlow, manualControlViewModel.SyringePumpVolume); } else { apiUrl = string.Format(syringePumpHardwareFunction.ApiUrl, manualControlViewModel.SyringePumpStepMode ? 1 : 0, manualControlViewModel.SyringePumpFlow); } await signalHubContext.Clients.Group(currentUser.Id).addMessage( new SignalMessage { Message = apiUrl, SignalType = SignalType.SyringePump }); return(JsonSuccess(string.Empty)); } catch (Exception ex) { return(JsonError(ex.Message)); } }
public async Task StartSynthesis(OligoSynthesisActivity oligoSynthesisActivity, IEnumerable <HardwareFunction> bAndTetToColFunctions, HardwareFunction closeAllValvesFunction, int oligoSynthesisActivityTotalTime) { try { isRunning = true; if (oligoSynthesisActivity.DNASequence.Length < 2) { throw new Exception($"DNA sequence length should be >= 2: {oligoSynthesisActivity.DNASequence}"); } logAction( $"Starting oligo synthesis activity. CH '{oligoSynthesisActivity.ChannelNumber}': SEQ '{oligoSynthesisActivity.DNASequence}' : Time '{oligoSynthesisActivityTotalTime} s'"); string dnaSequence = oligoSynthesisActivity.DNASequence.Substring(1, oligoSynthesisActivity.DNASequence.Length - 1); await ExecuteHardwareFunction(oligoSynthesisActivity.ChannelApiFunction.ApiUrl); foreach (char nucleotide in dnaSequence.ToCharArray()) { foreach (CycleStep cycleStep in oligoSynthesisActivity.SynthesisCycle.CycleSteps.OrderBy(x => x.Number)) { bool isCycleStepApplicable = IsCycleStepApplicable(nucleotide, cycleStep); if (isCycleStepApplicable) { string cycleStepApiUrl = GetCycleStepApiUrl(cycleStep, nucleotide, bAndTetToColFunctions); logAction( $"CH '{oligoSynthesisActivity.ChannelNumber}': SEQ '{oligoSynthesisActivity.DNASequence}': NUC '{nucleotide}' : STEP '{cycleStep.Number}' : TIME: {cycleStep.StepTime} : FUNC '{cycleStepApiUrl}': NAME '{cycleStep.HardwareFunction.Name}'"); await ExecuteHardwareFunction(cycleStepApiUrl); await Task.Delay(cycleStep.StepTime * 1000); logAction($"Opened valves: {cycleStep.HardwareFunction.Description}"); await ExecuteHardwareFunction(closeAllValvesFunction.ApiUrl); oligoSynthesisActivityTotalTime -= cycleStep.StepTime; logAction($"Remaining time: {oligoSynthesisActivityTotalTime} s "); if (cycleStep.SafeStep && IsSuspended) { logAction("Synthesis suspended"); while (isSuspended) { await Task.Delay(100); } logAction("Synthesis resumed"); } if (cycleStep.SafeStep && IsForceStopRequested) { ResetStates(); logAction("Synthesis stopped"); return; } } } } logAction( $"Synthesis completed. CH '{oligoSynthesisActivity.ChannelNumber}': SEQ '{oligoSynthesisActivity.DNASequence}'"); } catch (Exception ex) { logAction( $"Synthesis failed: CH '{oligoSynthesisActivity.ChannelNumber}': SEQ '{oligoSynthesisActivity.DNASequence}'. Message: {ex.Message}"); await ExecuteHardwareFunction(closeAllValvesFunction.ApiUrl); } finally { ResetStates(); } }
private async Task StartGeneSynthesisProcess() { ICloudTable <GeneSynthesisProcess> geneSynthesisProcessTable = null; GeneSynthesisProcess currentGeneSynthesisProcess = null; try { await AwaitPreviousSynthesisProcess(); LogAction("Syncing gene synthesis process..."); var currentUserId = GetCurrentUserId(); await CloudService.SyncOfflineCacheAsync(); LogAction("Sync completed."); geneSynthesisProcessTable = await CloudService.GetTableAsync <GeneSynthesisProcess>(); var allGeneSynthesisProcesses = await geneSynthesisProcessTable.ReadAllItemsAsync(); currentGeneSynthesisProcess = allGeneSynthesisProcesses.Where(x => x.Gene.UserId == currentUserId) .OrderByDescending(x => x.CreatedAt) .FirstOrDefault(); if (currentGeneSynthesisProcess == null) { LogAction("Gene 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); SynthesisProcessTotalTime = currentGeneSynthesisProcess.TotalTime; MessagingCenter.Send <LogsViewModel>(this, "SynthesisProcessStarted"); int geneSynthesisProcessRemainingTime = currentGeneSynthesisProcess.TotalTime; LogAction($"Starting a new gene synthesis process. Total Time: {geneSynthesisProcessRemainingTime} s"); foreach (GeneSynthesisActivity geneSynthesisActivity in currentGeneSynthesisProcess.GeneSynthesisActivities.OrderBy(x => x.ChannelNumber)) { int oligoSynthesisActivityTotalTime = geneSynthesisActivity.TotalTime; await Task.Run(async() => { await oligoSynthesizerRestService.StartSynthesis(geneSynthesisActivity, bAndTetToColFunctions, closeAllValvesFunction, oligoSynthesisActivityTotalTime); }); geneSynthesisProcessRemainingTime -= oligoSynthesisActivityTotalTime; LogAction($"Total remaining time: {geneSynthesisProcessRemainingTime} s"); } //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Completed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); } catch (Exception ex) { //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Failed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); LogAction($"Gene synthesis process failed: {ex.Message}"); } finally { await CloudService.SyncOfflineCacheAsync(); } }
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(); } }