Пример #1
0
        public override Log Load(string dataSource)
        {
            try {
                var log = new LogMeter(dataSource);

                string[] lines = System.IO.File.ReadAllLines(dataSource);

                log.FileName = dataSource;

                log.Customer = ReadCustomer(lines);
                log.Meter    = ReadMeter(lines);
                log.Flows    = ReadFlows(lines, TimeSpan.FromSeconds(log.Meter.StorageInterval.GetValueOrDefault()));

                if (log.Flows.Count > 0)
                {
                    log.StartTime = log.Flows[0].StartTime;
                    log.EndTime   = log.Flows[log.Flows.Count - 1].EndTime;
                }

                log.Update();
                return(log);
            } catch (System.Data.OleDb.OleDbException ex) {
                if (ex.Message.Contains("Could not find file"))
                {
                    throw new Exception("Could not find file");
                }
                else
                {
                    throw;
                }
            }
        }
Пример #2
0
        public override Log Load(string dataSource)
        {
            //dataSource = ConvertFromAccess97(dataSource);

            var log = new LogMeter(dataSource);

            try {
                using (OleDbConnection connection = new OleDbConnection(DataServices.BuildJetConnectionString(dataSource, true))) {
                    connection.Open();
                    using (OleDbCommand command = new OleDbCommand()) {
                        command.Connection = connection;

                        log.FileName = dataSource;
                        log.Customer = AddCustomer(command);
                        log.Meter    = AddMeter(command);
                        log.Flows    = AddFlows(command, TimeSpan.FromSeconds(log.Meter.StorageInterval.GetValueOrDefault()), log);

                        if (log.Flows.Count > 0)
                        {
                            log.StartTime = log.Flows[0].StartTime;
                            log.EndTime   = log.Flows[log.Flows.Count - 1].EndTime;
                        }
                    }

                    log.Update();
                    return(log);
                }
            } catch (System.Data.OleDb.OleDbException ex) {
                if (ex.Message.Contains("Could not find file"))
                {
                    throw new Exception("Could not find file");
                }
                else if (ex.Message.Contains("Unrecognized database format"))
                {
                    throw new Exception("Unrecognized logger format");
                }
                else if (ex.Message.Contains("Cannot open a database created with a previous version of your application"))
                {
                    throw new Exception("The Microsoft Access 2007 Runtime is not properly installed on this system. Historically, this error has occured when Access 2010 or later has been run on this system.\r\n\r\nPlease review the " + TwAssembly.Title() + " System Requirements and reinstall/repair the Access 2007 Runtime.\r\n\r\n The original error message was: " + ex.Message);
                }
                else
                {
                    throw;
                }
            } catch (InvalidOperationException ex) {
                if (ex.Message.Contains("provider is not registered"))
                {
                    throw new Exception("The Microsoft Access 2007 Runtime is not installed on this system.\r\n\r\nPlease review the " + TwAssembly.Title() + " System Requirements and install the Access 2007 Runtime.\r\n\r\n(" + ex.Message + ")");
                }
                else
                {
                    throw;
                }
            }
        }
Пример #3
0
        public override Log Load(string dataSource)
        {
            try {
                var log = new LogMeter(dataSource);
                log.Customer = new LogMeterCustomer();
                log.Meter    = new LogMeterMeter();

                string[] lines = System.IO.File.ReadAllLines(dataSource);

                log.FileName = dataSource;

                dateTimeFormat     = GetDateTimeFormat(dataSource, dateTimeFormat);
                seconds            = GetInterval(lines);
                nutationRate       = GetNutationRate(dataSource, nutationRate);
                log.Meter.Nutation = nutationRate;
                multiplier         = (60.0 / (double)seconds) * nutationRate;
                log.Customer.ID    = GetSiteId(lines);

                log.Flows = ReadFlows(lines, TimeSpan.FromSeconds(seconds));

                if (log.Flows.Count > 0)
                {
                    log.StartTime = log.Flows[0].StartTime;
                    log.EndTime   = log.Flows[log.Flows.Count - 1].EndTime;
                }

                log.Update();
                return(log);
            } catch (System.Data.OleDb.OleDbException ex) {
                if (ex.Message.Contains("Could not find file"))
                {
                    throw new Exception("Could not find file");
                }
                else
                {
                    throw;
                }
            }
        }