public Events LoadEvents(string dataSource, FixtureProfiles fixtureProfiles)
        {
            Events events;

            try {
                using (OleDbConnection connection = new OleDbConnection(DataServices.BuildJetConnectionString(dataSource, true))) {
                    connection.Open();
                    events = LoadEvents(connection, fixtureProfiles, new TimeSpan(0, 0, 10));
                }
            } 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 analysis format");
                }
                else
                {
                    throw;
                }
            } catch (InvalidOperationException ex) {
                if (ex.Message.Contains("provider is not registered"))
                {
                    throw new Exception("The MS 2007 Office System Driver is not installed on this system.\r\n\r\nPlease review System Requirements and Installation Troubleshooting.\r\n\r\n(" + ex.Message + ")");
                }
                else
                {
                    throw;
                }
            }
            return(events);
        }
        Event BuildEvent(OleDbConnection connection, OleDbDataReader reader, FixtureProfiles fixtureProfiles, TimeSpan interval)
        {
            int i       = 0;
            int idEvent = reader.GetInt32(i++);

            FixtureClass fixtureClass;
            Boolean      firstCycle = false;

            if (reader.IsDBNull(i))
            {
                fixtureClass = FixtureClasses.Unclassified;
            }
            else
            {
                fixtureClass = fixtureProfiles[reader.GetString(i)].FixtureClass;
                firstCycle   = reader.GetString(i).Contains("@");
            }
            i++;

            Event @event = new Event(fixtureClass);

            @event.ManuallyClassified = reader.GetBoolean(i++);
            @event.Channel            = (Channel)reader.GetInt16(i++);
            @event.FirstCycle         = firstCycle;

            using (OleDbCommand commandFlows = new OleDbCommand(BuildLoadFlowsCommand(idEvent), connection)) {
                using (OleDbDataReader readerFlows = commandFlows.ExecuteReader()) {
                    while (readerFlows.Read())
                    {
                        @event.Add(BuildFlow(readerFlows, interval));
                    }
                }
            }
            return(@event);
        }
Beispiel #3
0
        public Analysis Load(string dataSource)
        {
            string[] lines = System.IO.File.ReadAllLines(dataSource);

            if (IsOldVersion(lines))
            {
                throw new Exception("Please migrate the analysis file " + dataSource + " to version " + TwAssembly.Version() + " or later.");
            }

            double twConversionFactor = GetTwConversionFactor(lines);

            Attributes = LoadAttributes(lines);

            LogMeter log = LoadLog(lines);

            FixtureProfiles fixtureProfiles = LoadFixtureProfiles(lines);

            Events events = LoadEvents(lines);

            LoadFlows(lines, events);

            events.UpdateVolume();

            var analysis = new AnalysisDatabase(dataSource, events, log, fixtureProfiles);

            analysis.Events.ConversionFactor = twConversionFactor;
            analysis.Events.UpdateChannel();
            analysis.Events.UpdateSuperPeak();
            analysis.Events.UpdateLinkedList();
            analysis.Events.UpdateOriginalVolume();

            return(analysis);
        }
Beispiel #4
0
        FixtureProfiles LoadFixtureProfiles(string[] lines)
        {
            FixtureProfiles fixtureProfiles      = new FixtureProfiles();
            bool            fixtureProfilesFound = false;

            foreach (string line in lines)
            {
                if (line.Contains("@FIXTURE PROFILES"))
                {
                    fixtureProfilesFound = true;
                }
                else if (fixtureProfilesFound)
                {
                    if (string.IsNullOrEmpty(line) && !line.StartsWith("% ") || line.Contains("@DATA"))
                    {
                        break;
                    }
                    else if (!line.StartsWith("% FixtureClass"))
                    {
                        FixtureProfile fixtureProfile = new FixtureProfile(ToStringArray(line, ','));
                        fixtureProfiles.Add(fixtureProfile);
                    }
                }
            }
            return(fixtureProfiles);
        }
Beispiel #5
0
 void WriteFixtureProfiles(System.Text.StringBuilder text, FixtureProfiles fixtureProfiles)
 {
     if (fixtureProfiles != null)
     {
         WriteFixtureProfilesHeader(text);
         WriteFixtureProfilesData(text, fixtureProfiles);
     }
 }
Beispiel #6
0
 void WriteFixtureProfilesData(System.Text.StringBuilder text, FixtureProfiles fixtureProfiles)
 {
     foreach (FixtureProfile fixtureProfile in fixtureProfiles)
     {
         WriteFixtureProfile(text, fixtureProfile);
         WriteLine(text);
     }
     WriteLine(text);
 }
        FixtureProfiles LoadFixtureProfiles(OleDbConnection connection)
        {
            FixtureProfiles fixtureProfiles = new FixtureProfiles();

            using (OleDbCommand command = new OleDbCommand(BuildLoadFixtureProfilesCommand(), connection)) {
                using (OleDbDataReader reader = command.ExecuteReader()) {
                    while (reader.Read())
                    {
                        fixtureProfiles.Add(BuildFixtureProfile(reader).Normalize());
                    }
                }
            }
            return(fixtureProfiles);
        }
        Events LoadEvents(OleDbConnection connection, FixtureProfiles fixtureProfiles, TimeSpan interval)
        {
            Events events = new Events();

            using (OleDbCommand command = new OleDbCommand(BuildLoadEventsCommand(), connection)) {
                using (OleDbDataReader reader = command.ExecuteReader()) {
                    while (reader.Read())
                    {
                        events.Add(BuildEvent(connection, reader, fixtureProfiles, interval));
                    }
                }
            }
            events.UpdateChannel();
            events.UpdateSuperPeak();
            events.UpdateLinkedList();
            events.UpdateOriginalVolume();

            return(events);
        }
        FixtureProfile Apply(Event @event)
        {
            var            fixtureProfilesThisFixture = GetFixtureProfiles(@event.FixtureClass);
            FixtureProfile fixtureProfile             = null;

            if (fixtureProfilesThisFixture.Count == 0)
            {
                fixtureProfile = AddFixture(@event);
                return(fixtureProfile);
            }
            else if (fixtureProfilesThisFixture.Count == 1)
            {
                fixtureProfile = fixtureProfilesThisFixture[0];
                Apply(fixtureProfile, @event);
            }
            else
            {
                fixtureProfile = FixtureProfiles.GetMostSimilar(fixtureProfilesThisFixture, @event);
                Apply(fixtureProfile, @event);
            }
            SelectRow(RowFromProfile(fixtureProfile));
            return(fixtureProfile);
        }
        int GetInsertPosition(FixtureProfiles fixtureProfiles, FixtureClass fixtureClass)
        {
            for (int i = fixtureProfiles.Count - 1; i >= 0; i--)
            {
                if (fixtureProfiles[i].FixtureClass == fixtureClass)
                {
                    return(i + 1);
                }
                else if (fixtureClass == FixtureClasses.Irrigation)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Faucet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Bathtub ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Shower ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Clotheswasher ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Toilet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Faucet)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Bathtub ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Shower ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Clotheswasher ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Toilet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Bathtub)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Shower ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Clotheswasher ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Toilet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Shower)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Clotheswasher ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Toilet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Clotheswasher)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Toilet ||
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Toilet)
                {
                    if (
                        fixtureProfiles[i].FixtureClass == FixtureClasses.Leak
                        )
                    {
                        return(i + 1);
                    }
                }
                else if (fixtureClass == FixtureClasses.Leak)
                {
                    ;
                }
                else
                {
                    return(fixtureProfiles.Count);
                }
            }

            return(0);
        }
Beispiel #11
0
 public Events LoadEvents(string dataSource, FixtureProfiles fixtureProfiles)
 {
     throw new NotImplementedException();
 }