| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace crusherScanner
- {
- // TODO: Caution memory leak be here. Consider flushing buffer SIDs after a period of time.
- internal class LimsAccess
- {
- /// <summary>
- /// Buffer of sample ID's from LIMS or sample list file.
- /// </summary>
- private static HashSet<string> SIDs = new();
- /// <summary>
- /// Check if barcode is found in LIMS samples.
- /// </summary>
- /// <param name="barcode">Barcode as string to check LIMS for.</param>
- public static Scan IsInLims(Scan barcode)
- {
- // Is sample ID in buffer
- if(CheckBuffer(barcode))
- {
- barcode.isInLims = true;
- return barcode;
- }
- // LIMS connection enabled, ask LIMS for sample ID.
- if (Properties.Settings.Default.LimsConnection)
- {
- //TODO: Actully check LIMS for sample ID. And fill buffer.
- barcode.isInLims = true;
- return barcode;
- //https://www.guru99.com/c-sharp-access-database.html#:~:text=Code%20Explanation%3A-%201%20The%20first%20step%20is%20to,connection%20to%20the%20database.%20...%20More%20items...%20
- //string connetionString;
- //SqlConnection cnn;
- //connetionString = @"Data Source=WIN-50GP30FGO75;Initial Catalog=Demodb;User ID=sa;Password=demol23";
- //cnn = new SqlConnection(connetionString);
- //cnn.Open();
- //MessageBox.Show("Connection Open !");
- //cnn.Close();
- //or
- //https://dax.tips/2020/08/24/using-visual-studio-code-to-query-power-bi/
- }
- else // LIMS connection disabled. Check for a fall back file or return true.
- {
- if (CheckFileStore("sampleList.csv") && CheckFileStore(Properties.Settings.Default.OreDefWorkFile + "\\sampleList.csv") && CheckBuffer(barcode))
- {
- barcode.isInLims = true;
- return barcode;
- }
- else
- {
- barcode.isInLims = false;
- return barcode;
- }
- }
- }
- /// <summary>
- /// Check if the sample list file is available and load into the buffer.
- /// </summary>
- /// <returns></returns>
- private static bool CheckFileStore(string LimsList)
- {
- // No file list found, assume no checking and return true.
- if(!File.Exists(LimsList))
- {
- return true;
- }
- // File list found, load into buffer and check if barcode exists.
- using FileStream sampleList = new(LimsList, FileMode.Open, System.IO.FileAccess.Read, FileShare.None);
- {
- using StreamReader Reader = new(sampleList);
- {
- while (true)
- {
- var line = Reader.ReadLine();
- if (line != null && line != "")
- {
- SIDs.Add(line.Trim());
- }
- else
- {
- break;
- }
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Check to see if the sample ID is in the buffer.
- /// </summary>
- /// <param name="barcode">barcode (sample ID)</param>
- /// <returns></returns>
- private static bool CheckBuffer(Scan barcode)
- {
- if(SIDs.Contains(barcode.barcode))
- {
- return true;
- }
- return false;
- }
- }
- }
|