public DatabaseData SetDatabaseAsEdit(DatabaseData srcDatabaseData) { if (!databases.ContainsKey(srcDatabaseData.Definition.Path)) { throw new ApplicationException("Database not open in model"); } // Make a clone of the source database definition and give it a new name RrdDb rrdDb = new RrdDb(srcDatabaseData.Definition.Path, true); databaseDefinition = rrdDb.getRrdDef(); rrdDb.close(); DatabaseData dstDatabaseData = new DatabaseData(); dstDatabaseData.SourceDatabasePath = srcDatabaseData.Definition.Path; dstDatabaseData.Saved = false; dstDatabaseData.Definition = databaseDefinition; dstDatabaseData.Definition.Path = Path.GetFileNameWithoutExtension(databaseDefinition.Path) + "_"; dstDatabaseData.LastUpdated = dstDatabaseData.Definition.getStartDateTime(); dstDatabaseData.LastValue = double.NaN; DatabaseDirty = true; EditingDatabaseData = dstDatabaseData; databases.Add(dstDatabaseData.Definition.Path, dstDatabaseData); return(dstDatabaseData); }
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; } }
public void addDatasource(String sourcePath, String destPath, DsDef newDatasource) { if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.addDatasource(newDatasource); RrdDb rrdDest = new RrdDb(rrdDef); rrdSource.copyStateTo(rrdDest); rrdSource.close(); rrdDest.close(); }
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; } }
public void removeArchive(String sourcePath, String destPath, String consolFun, int steps) { if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); rrdDef.setPath(destPath); rrdDef.removeArchive(consolFun, steps); RrdDb rrdDest = new RrdDb(rrdDef); rrdSource.copyStateTo(rrdDest); rrdSource.close(); rrdDest.close(); }
public void resizeArchive(String sourcePath, String destPath, String consolFun, int numSteps, int newRows) { if (Util.sameFilePath(sourcePath, destPath)) { throw new RrdException("Source and destination paths are the same"); } if (newRows < 2) { throw new RrdException("New arcihve size must be at least 2"); } RrdDb rrdSource = new RrdDb(sourcePath); RrdDef rrdDef = rrdSource.getRrdDef(); ArcDef arcDef = rrdDef.findArchive(consolFun, numSteps); if (arcDef.getRows() != newRows) { arcDef.setRows(newRows); rrdDef.setPath(destPath); RrdDb rrdDest = new RrdDb(rrdDef); rrdSource.copyStateTo(rrdDest); rrdDest.close(); } rrdSource.close(); }