示例#1
0
        public DatabaseData ReloadDatabase(DatabaseData srcDatabase)
        {
            if (!databases.ContainsKey(srcDatabase.Definition.Path))
            {
                throw new ApplicationException("Database to reload don't exist");
            }

            try
            {
                RrdDb        database = new RrdDb(srcDatabase.Definition.Path);
                DatabaseData data     = new DatabaseData();
                data.Saved       = true;
                data.Definition  = database.getRrdDef();
                data.LastUpdated = database.getLastUpdateDateTime();
                data.LastValue   = database.getLastDatasourceValue(database.getDsNames()[0]);
                databases[srcDatabase.Definition.Path] = data;
                database.close();
                return(data);
            }
            catch (Exception ex)
            {
                Logger.Error("Fail to add database", ex);
                throw;
            }
        }
示例#2
0
        public void ImportData(string dataPath, DatabaseData databaseData, TimeSpan expectedTick)
        {
            if (model.ReadOnly)
            {
                throw new ApplicationException("Can't import data. Database readonly");
            }


            List <string>      columns     = new List <string>();
            List <FetchedData> unifiedData = ReadAndUnifyData(dataPath, out columns);

            string databasePath = databaseData.Definition.Path;
            RrdDb  database     = new RrdDb(databasePath, false);

            int[] dsIndexes = new int[columns.Count];
            for (int i = 0; i < columns.Count; i++)
            {
                dsIndexes[i] = database.getDsIndex(columns[i]);
            }


            string[] dsNames = database.getDsNames();
            rrd4n.DataAccess.Data.Sample sample = new rrd4n.DataAccess.Data.Sample(databasePath, dsNames, 0);

            foreach (var data in unifiedData)
            {
                sample.setDateTime(data.TimeStamp);
                for (int i = 0; i < data.Values.Count; i++)
                {
                    sample.setValue(dsIndexes[i], data.Values[i]);
                }

                try
                {
                    // When using file access abstraction
                    //dbAccess.StoreData(sample);

                    //Without abstraction
                    database.store(sample);
                    sample.clearValues();
                }
                catch (ArgumentException)
                {
                }
                model.DatabaseDirty = true;
            }
            database.close();
            OpenDatabase(databasePath);
        }
示例#3
0
        public void StoreData(rrd4n.DataAccess.Data.Sample sample)
        {
            RrdDb rrdDb = null;

            try
            {
                rrdDb = new RrdDb(DataPath + sample.DatabasePath, false);
                Sample coreSample = new Sample(rrdDb.getPath(), rrdDb.getDsNames(), sample.Time);
                coreSample.setValues(sample.Values);
                rrdDb.store(coreSample);
            }
            finally
            {
                if (rrdDb != null)
                {
                    rrdDb.close();
                }
            }
        }
示例#4
0
 public DatabaseData AddDatabase(string databasePath)
 {
     if (databases.ContainsKey(databasePath))
     {
         return(databases[databasePath]);
     }
     try
     {
         RrdDb        database = new RrdDb(databasePath);
         DatabaseData data     = new DatabaseData();
         data.Saved       = true;
         data.Definition  = database.getRrdDef();
         data.LastUpdated = database.getLastUpdateDateTime();
         data.LastValue   = database.getLastDatasourceValue(database.getDsNames()[0]);
         databases.Add(databasePath, data);
         database.close();
         return(databases[databasePath]);
     }
     catch (Exception ex)
     {
         Logger.Error("Fail to add database", ex);
         throw;
     }
 }