public RemoteFetchData FetchData(string databaseName, long startTimeTick, long endTimeTick, string consolFunctionName, long resolution) { RrdDb database = null; try { log.DebugFormat("Read data from {0}", databaseName); var nameValueCollection = (NameValueCollection)ConfigurationManager.GetSection("rrdbfileserver"); string dataBasePath = nameValueCollection["databasepath"]; log.DebugFormat("Database path:{0}", dataBasePath + databaseName); database = new RrdDb(dataBasePath + databaseName, true); FetchRequest fetchRequest = new FetchRequest(null, consolFunctionName, startTimeTick, endTimeTick, resolution); FetchData data = database.fetchData(fetchRequest); database.close(); RemoteFetchData remoteData = new RemoteFetchData(); remoteData.Timestamps = data.getTimestamps(); remoteData.Values = data.getValues(); remoteData.ArchiveEndTimeTicks = data.getArcEndTime(); remoteData.ArchiveSteps = data.getArcStep(); remoteData.DatasourceNames = data.getDsNames(); if (debugEnabled) { log.DebugFormat("Read data from {0} to {1}.", rrd4n.Common.Util.getDate(startTimeTick), rrd4n.Common.Util.getDate(endTimeTick)); } return(remoteData); } catch (Exception ex) { log.Error("Fetchdata exception", ex); throw; } finally { if (database != null) { database.close(); } } }
public rrd4n.DataAccess.Data.FetchData GetData(rrd4n.DataAccess.Data.FetchRequest request) { RrdDb rrdDb = null; try { string dataPath; if (DataPath.Contains("${APPDATA}")) { dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); dataPath += DataPath.Substring(10); } else { dataPath = DataPath; } rrdDb = new RrdDb(dataPath + request.DatabasePath); FetchRequest coreRequest = new FetchRequest(rrdDb.getPath(), request.ConsolidateFunctionName, request.FetchStart, request.FetchEnd, request.Resolution); FetchData coreFetchData = rrdDb.fetchData(coreRequest); return(new rrd4n.DataAccess.Data.FetchData(coreFetchData.getArcStep(), coreFetchData.getArcEndTime(), coreFetchData.getDsNames()) { Values = coreFetchData.getValues(), Timestamps = coreFetchData.getTimestamps() }); } finally { if (rrdDb != null) { rrdDb.close(); } } }