コード例 #1
0
        public MainViewModelShould()
        {
            // Arrange
            // Create a droplet bin model and populate with 3 wells
            // with 2 having counts below 300           
            _dropletBin = new DropletBin()
            {
                PlateDropletInfo = new PlateDropletInfo()
                {
                    Version = 01,
                    DropletInfo = new DropletInfo()
                    {
                        Wells = new List<Well>()
                        {
                            new Well()
                            {
                                WellName = "A01",
                                WellIndex = 0,
                                DropletCount = 500
                            },
                            new Well()
                            {
                                WellName = "A02",
                                WellIndex = 1,
                                DropletCount = 100
                            },
                            new Well()
                            {
                                WellName = "A03",
                                WellIndex = 2,
                                DropletCount = 250
                            },
                        }
                    }
                }
            };


            _mockJsonDataService = new Mock<IJsonDataService>();
            _mockJsonDataService.Setup<DataTable>(dt => dt.GetDataTableFromJson())
                                .Returns(new DataTable());

            _mockJsonDataService.Setup<DropletBin>(d => d.GetDropletBinFromJson())
                             .Returns(_dropletBin);


            _mockFileIOService = new Mock<IFileIOService>();
            _mockFileIOService.Setup(x => x.OpenDatafile())
                .Returns(TestFilePath);      

            _sut = new MainViewModel(_mockJsonDataService.Object, _mockFileIOService.Object);

        }
コード例 #2
0
        public DropletBin GetDropletBin(string filePath)
        {
            DropletBin dropletBin = null;

            try
            {
                var rawJsonFile = File.ReadAllText(filePath);

                dropletBin = JsonConvert.DeserializeObject <DropletBin>(rawJsonFile);
            }
            catch (Exception ex)
            {
                //todo: Logging
            }
            return(dropletBin);
        }
コード例 #3
0
        private int GetLowDropletCount(DropletBin dropletBin)
        {
            if (dropletBin == null)
            {
                return(-1);
            }

            var lowCount = 0;

            foreach (var well in dropletBin.PlateDropletInfo.DropletInfo.Wells)
            {
                if (well.DropletCount < DropletThreshold)
                {
                    lowCount++;
                }
            }
            return(lowCount);
        }
コード例 #4
0
        public DataTable GetDataTableFromJson()
        {
            DropletBin  dropletBin = null;
            List <Well> wells      = null; // Rep. the array of droplet counts.
            DataTable   table      = null;

            try
            {
                // Get the deserialized JSON.
                dropletBin = GetDropletBinFromJson();

                // Need to sort the JSON droplet count array, so we put them in a list
                foreach (var well in dropletBin.PlateDropletInfo.DropletInfo.Wells)
                {
                    _wells.Add(well);
                }
                _wells.Sort(); // See Well class for property that we sort on: WellIndex

                // Populate an in memory data table for easy display by consuming dataGrid
                table = new DataTable();


                // Setup columns
                var      columnCount = _wells.Count / NumberOfRowsForTable;
                string[] columnNames = new string[columnCount + 1];

                columnNames[0] = "-";
                for (int i = 1; i < columnCount + 1; i++)
                {
                    columnNames[i] = i.ToString();
                }

                foreach (var cn in columnNames)
                {
                    table.Columns.Add(cn, typeof(string));
                }

                // Organize the wells array into 8 x xx rows
                var rows = _wells.Select(i => i.DropletCount).ToArray();

                // This list is from the WellNames of each well array item. See the original JSON.
                List <char> ids = new List <char>()
                {
                    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
                };
                int itemsPerRow = 0;
                for (int i = 0; i < NumberOfRowsForTable; i++)
                {
                    object[] values = new object[columnNames.Length];
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (j == 0) // add Id
                        {
                            values[j] = ids.First <char>();
                            ids.RemoveAt(j);
                        }
                        values[j + 1] = rows[j + itemsPerRow];
                    }
                    itemsPerRow += columnCount;
                    table.Rows.Add(values);
                }
                ClearCollections();
            }
            catch (Exception ex)
            {
                //todo: Logging
            }
            return(table);
        }