Beispiel #1
0
        private static bool loopReading(string fullName)
        {
            FileInfo fileInfo = new FileInfo(fullName);

            if (fileInfo.IsReadOnly)
            {
                return(false);
            }

            using (TextFieldParser csvReader = new TextFieldParser(fullName))
            {
                csvReader.SetDelimiters(new string[] { "," });
                csvReader.HasFieldsEnclosedInQuotes = true;

                //Give up Fields' name.
                string[] colFields = csvReader.ReadFields();

                while (!csvReader.EndOfData)
                {
                    string[] fieldData = csvReader.ReadFields();
                    try
                    {
                        LiftSensorRaw raw = transformSensorRaw(fieldData);
                        transformRawToDB(raw);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                fileInfo.IsReadOnly = true;
            }
            return(true);
        }
Beispiel #2
0
        private static void transformRawToDB(LiftSensorRaw structRaw)
        {
            IMapSensorData mapSensorData = new MapSensorData();

            LiftChairs liftChairs = new LiftChairs
            {
                Date    = (new DateTime(1970, 1, 1, 0, 0, 0)).AddHours(8).AddSeconds(structRaw.date),
                Section = mapSensorData.mapToSection(structRaw.sec),
                RPM     = mapSensorData.mapToRPM(structRaw.rpm),
                Current = mapSensorData.mapToCurrent(structRaw.current),
                Temp    = mapSensorData.mapToTemp(structRaw.temp)
            };

            csvModel.LiftChairs.Add(liftChairs);
            csvModel.SaveChanges();
        }