Esempio n. 1
0
        public IEnumerable <MeterData> GetFileData(int index)
        {
            YokogawaFile yokoFile = FileUtility.GetFile(index);

            return(yokoFile.GetData());
        }
Esempio n. 2
0
        public FileImport ImportFile(YokogawaFile yokoFile)
        {
            FileImport result = GetFileImport(yokoFile.Index);

            if (result != null)
            {
                return(result);
            }

            var data = yokoFile.GetData();

            var count = 0;

            if (data != null)
            {
                count = data.Count();
            }

            using (var statelessSession = _sessionFactory.OpenStatelessSession())
                using (var statelessTransaction = statelessSession.BeginTransaction())
                {
                    try
                    {
                        result = new FileImport()
                        {
                            FileIndex  = yokoFile.Index,
                            FilePath   = yokoFile.FilePath,
                            ImportDate = DateTime.Now,
                            LineCount  = count
                        };

                        statelessSession.Insert(result);

                        if (count > 0)
                        {
                            var items = data.Select(x => new MeterData()
                            {
                                FileIndex = yokoFile.Index,
                                LineIndex = x.LineIndex,
                                Header    = x.Header,
                                TimeStamp = x.TimeStamp,
                                Value     = x.Value
                            });

                            foreach (var item in items)
                            {
                                statelessSession.Insert(item);
                            }
                        }

                        statelessTransaction.Commit();

                        return(result);
                    }
                    catch
                    {
                        statelessTransaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        statelessSession.Close();
                    }
                }
        }