public async void QueryForPartiesAttending() { ICloudService cloudService = ServiceLocator.Instance.Resolve <ICloudService>(); ICloudTable <PartyDetails> Table = cloudService.GetTable <PartyDetails>(); ICollection <PartyDetails> attendeeDetails = await Table.ReadAllItemsAsync(); List <PartyDetailsItem> carouselItems = new List <PartyDetailsItem>(); List <Image> carouselImages = new List <Image>(); if (attendeeDetails == null || attendeeDetails.Count < 0) { return; } ICollection <PartyDetails> partiesAttending = new List <PartyDetails>(); ICollection <PartyDetails> partiesHosting = new List <PartyDetails>(); foreach (var item in attendeeDetails) { if (item.userId == App.UserDetails.userId) { partiesHosting.Add(item); } else { partiesAttending.Add(item); } } ImageHelper.LoadedImages.Clear(); PartiesAttending.AddRange(partiesAttending); PartiesHosting.AddRange(partiesHosting); }
async Task <bool> IsUserRegisteredInTheCloud(ILoginProvider loginProvider) { ICloudTable <UserDetails> Table = GetTable <UserDetails>(); string tableId = loginProvider.RetrieveTableIdFromSecureStore(); Account account = loginProvider.RetreiveAccountFromSecureStore(); if (tableId == null) { ICollection <UserDetails> tempUserDetailsList = await Table.ReadAllItemsAsync(); UserDetails userDetails = tempUserDetailsList.FirstOrDefault(x => x.userId == client.CurrentUser.UserId); account.Properties.Add("table_id", userDetails.Id); loginProvider.SaveAccountInSecureStore(account); App.UserDetails = userDetails; } else { UserDetails tempUserDetails = await Table.ReadItemAsync(tableId); App.UserDetails = tempUserDetails; } if (App.UserDetails != null) { return(true); } return(false); }
private async Task Connect() { try { logTable = await CloudService.GetTableAsync <Log>(); ICollection <Log> logs = await logTable.ReadAllItemsAsync(); Items.AddRange(logs.OrderByDescending(x => x.CreatedAt)); if (SynthesizerSettings == null || string.IsNullOrWhiteSpace(SynthesizerSettings.AppServiceUrl) || string.IsNullOrWhiteSpace(SynthesizerSettings.SynthesizerApiUrl)) { LogAction("Settings are not configured"); return; } LogAction($"Connecting to {SynthesizerSettings.AppServiceUrl}"); signalService = new SignalService(SynthesizerSettings.AppServiceUrl); signalService.MessageReceived += SignalMessageReceived; LogAction($"Connected to {SynthesizerSettings.AppServiceUrl}"); string connectResponse = await signalService.Connect(); LogAction(connectResponse); UserId = GetCurrentUserId(); string joinGroupResponse = await signalService.JoinGroup(UserId); LogAction(joinGroupResponse); valveRestService = new ValveRestService(SynthesizerSettings.SynthesizerApiUrl); oligoSynthesizerRestService = new OligoSynthesizerRestService(SynthesizerSettings.SynthesizerApiUrl, LogAction); } catch (Exception ex) { LogAction($"Connection failed: {ex.Message}"); } }
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(); } }