Пример #1
0
        private static List<RunElement> readFileToDB(Stream file)
        {
            using(StreamReader sr = new StreamReader(file))
            {
                string line;
                string[] tempData;
                RunElement tempElement;

                // to prevent errors reset stream then fake reading in the data labels
                file.Position = 0;
                sr.ReadLine();

                List<RunElement> data = new List<RunElement>(); //list of time snapshots

                int runElementId = 0;
                // read all the data in the file
                while((line=sr.ReadLine())!=null)
                {
                    tempData = line.Split(',');

                    //Make a RunElement to put this snapshot of data into
                    tempElement = new RunElement();

                    //go through each item in tempdata
                    for(int i = 0; i<tempData.Count(); i++)
                    {
                        tempElement.Data.Add(new Data(Convert.ToSingle(tempData[i])));
                    }
                    tempElement.Number = runElementId;
                    runElementId++;
                    data.Add(tempElement);
                }
                return data;
            }
        }
 public bool Add_RunElement_to_RunData(string name, RunElement element)
 {
     RunData temp = Get_RunData_object(name);
     temp.Runs.Add(element);
     _db.SaveChanges();
     return true;
 }
 public void Add_RunElement_to_RunDataTest()
 {
     EF_RunDataRepository target = new EF_RunDataRepository();
     string name = "Test Run";
     int runNumber = 43;
     target.Add_New_Run(name, new List<DataLabel>());// add object to db
     RunElement element = new RunElement(new List<float>(), runNumber);
     bool expected = true;
     bool actual;
     actual = target.Add_RunElement_to_RunData(name, element);
     Assert.AreEqual(expected, actual);
     Assert.AreEqual(runNumber, target.Get_RunData_object(name).Runs[0].Number);
     actual = target.Delete_RunData_object(name);    //delect the object
     Assert.IsTrue(actual);
 }
        public bool Add_RunElement_to_RunData(string name, RunElement element)
        {
            bool found_matching_run = false;
            foreach (RunData item in _db)
            {
                if (item.Name == name)
                {
                    item.Runs.Add(element);
                    found_matching_run = true;
                }
            }

            if (!found_matching_run)
            {
                RunData temp = new RunData();
                temp.Name = name;
                temp.Runs.Add(element);
                _db.Add(temp);
                found_matching_run = true;
            }
            return found_matching_run;
        }
        private RunData make_dummy_RunData_object(string name)
        {
            RunData runData = new RunData(name);
            DataLabel dataLabel = new DataLabel(name);
            Analyzer analyzer = new Analyzer(new IAnalyzer_dummy_class(name, "decs"));
            RunElement runElement = new RunElement(new List<float>() { 34.2f, 23.2f }, 3);  // auto adds data object

            runData.Runs.Add(runElement);
            dataLabel.Analyzers.Add(analyzer);
            runData.DataLabels.Add(dataLabel);

            return runData;
        }