Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        public void UpdateDataSource(DatabaseData srcDatabase, DsDef updatedDsDef, DsDef originalDsDef)
        {
            RrdDb database = null;

            try
            {
                database = new RrdDb(srcDatabase.Definition.Path, false);
                Datasource datasource = database.getDatasource(originalDsDef.getDsName());
                if (datasource == null)
                {
                    throw new ArgumentException(updatedDsDef.getDsName() + " datasource don't exist");
                }
                if (datasource.DsName != updatedDsDef.DsName)
                {
                    datasource.setDsName(updatedDsDef.getDsName());
                }
                datasource.setDsType(updatedDsDef.getDsType());
                datasource.setHeartbeat(updatedDsDef.getHeartbeat());
                datasource.setMaxValue(updatedDsDef.getMaxValue(), true);
                datasource.setMinValue(updatedDsDef.getMinValue(), true);
            }
            catch (FileNotFoundException ex)
            {
                Logger.Error("Update datasource failed", ex);
                throw new ApplicationException("Can't update datasource until database saved!", ex);
            }
            finally
            {
                if (database != null)
                {
                    database.close();
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public DatabaseData CreateDatabase(RrdDef rrdDef)
 {
     EditingDatabaseData                    = new DatabaseData();
     EditingDatabaseData.Definition         = rrdDef;
     EditingDatabaseData.LastUpdated        = rrdDef.getStartDateTime();
     EditingDatabaseData.LastValue          = double.NaN;
     EditingDatabaseData.SourceDatabasePath = null;
     DatabaseDirty = true;
     return(EditingDatabaseData);
 }
Ejemplo n.º 5
0
 public bool RemoveDatabase(DatabaseData srcDatabase)
 {
     if (databases.ContainsKey(srcDatabase.Definition.Path))
     {
         databases.Remove(srcDatabase.Definition.Path);
         return(true);
     }
     EditingDatabaseData = null;
     DatabaseDirty       = false;
     return(true);
 }
Ejemplo n.º 6
0
      private void LoadTree(DatabaseData databaseData)
      {
         RrdDef databaseDefinition = databaseData.Definition;
         string databaseName = Path.GetFileNameWithoutExtension(databaseDefinition.Path);
         TreeNode databaseNode;
         TreeNode[] databaseNodes = rrdDbTreeView.Nodes.Find(databaseDefinition.Path, true);
         if (databaseNodes.Length == 0)
         {
            databaseNode = rrdDbTreeView.Nodes.Add(databaseDefinition.Path, databaseName);
            if (!databaseData.Saved)
               databaseNode.Text += "*";
         }
         else
         {
            databaseNode = databaseNodes[0];
            if (!databaseData.Saved
               && !databaseNode.Text.Contains("*"))
               databaseNode.Text += "*";
         }


         databaseNode.Tag = databaseData;

         databaseNode.Nodes.Clear();
         var datasources = databaseNode.Nodes.Add(dataSourceNodesName, dataSourceNodesName);
         foreach (var datasource in databaseDefinition.getDsDefs())
         {
            TreeNode datasourceNode = datasources.Nodes.Add(datasource.DsName);
            datasourceNode.Tag = datasource;
            foreach (var arcDef in databaseDefinition.getArcDefs())
            {
               string nodeText = string.Format("RRA:{0}:{1}:{2}:{3}", arcDef.getConsolFun().Name,
                                                arcDef.Xff, arcDef.Steps, arcDef.Rows);
               var archiveNode = datasourceNode.Nodes.Add(nodeText);
               archiveNode.Tag = arcDef;
            }
         }
         databaseNode.Nodes.Add(archiveNodesName, archiveNodesName);
      }
Ejemplo n.º 7
0
      private void LoadDatabaseView(DatabaseData databaseData)
      {
         dataSourceListView.Columns.Clear();
         dataSourceListView.Columns.Add("Name");
         dataSourceListView.Columns.Add("Value", 200);

         dataSourceListView.Items.Clear();
         ListViewItem lvi = dataSourceListView.Items.Add("Tick");
         lvi.SubItems.Add(databaseData.Definition.getStepTimeSpan().ToString());
         lvi = dataSourceListView.Items.Add(dataSourceNodesName);
         lvi.SubItems.Add(databaseData.Definition.getDsCount().ToString());
         lvi = dataSourceListView.Items.Add(archiveNodesName);
         lvi.SubItems.Add(databaseData.Definition.getArcCount().ToString());
         lvi = dataSourceListView.Items.Add("Estimated size");
         lvi.SubItems.Add(databaseData.Definition.getEstimatedSize().ToString());
         if (databaseData.LastUpdated != DateTime.MinValue)
         {
            lvi = dataSourceListView.Items.Add("Last update time");
            lvi.SubItems.Add(databaseData.LastUpdated.ToString());
         }
         lvi = dataSourceListView.Items.Add("Last Value");
         lvi.SubItems.Add(databaseData.LastValue.ToString());
      }
Ejemplo n.º 8
0
        public FetchData GetArchiveData(DatabaseData databaseData, string dataSourceName, ArcDef archiveDefinition)
        {
            RrdDb database = null;

            try
            {
                database = new RrdDb(databaseData.Definition.getPath(), true);
                int      datasourceIndex  = database.getDsIndex(dataSourceName);
                Archive  archive          = database.getArchive(new ConsolFun(archiveDefinition.getConsolFun().Name), archiveDefinition.Steps);
                Robin    robin            = archive.getRobin(datasourceIndex);
                double[] values           = robin.getValues();
                DateTime archiveStartTime = archive.getStartDateTime();
                TimeSpan tick             = new TimeSpan(archive.getArcStep() * TimeSpan.TicksPerSecond);

                FetchData fetchedData = new FetchData(archive.getArcStep(), archive.getEndTime(), new string[] { dataSourceName });
                long[]    timestamps  = new long[archive.getRows()];
                long      offset      = archive.getStartTime();
                for (var i = 0; i < archive.getRows(); i++)
                {
                    timestamps[i] = offset;
                    offset       += archive.getArcStep();
                }
                fetchedData.setTimestamps(timestamps);
                double[][] value = new double[1][];
                value[0] = values;
                fetchedData.setValues(value);
                return(fetchedData);
            }
            finally
            {
                if (database != null)
                {
                    database.close();
                }
            }
        }
Ejemplo n.º 9
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;
     }
 }
Ejemplo n.º 10
0
 public void ArchivesSelected(DatabaseData databaseData)
 {
    List<ArchiveDisplayData> archives = new List<ArchiveDisplayData>();
    foreach (ArcDef arcDef in databaseData.Definition.getArcDefs())
    {
       archives.Add(new ArchiveDisplayData()
       {
          ConsolFunctionName = arcDef.getConsolFun().Name,
          RowCount = arcDef.getRows(),
          Steps = arcDef.getSteps(),
          Xff = arcDef.getXff(),
          StartTime = DateTime.MinValue,
          EndTime = DateTime.MaxValue
       });
    }
    rrdDbForm.SetArchiveData(archives.ToArray());
 }
Ejemplo n.º 11
0
 public string DumpDatabaseDefinition(DatabaseData database)
 {
    return database.Definition.dump();
 }
Ejemplo n.º 12
0
      public void DatasourceArchiveSelected(DatabaseData database, object datasource, object archiveDefinition)
      {
         if (!model.IsDatabase(database.Definition.Path))
            return;
         DsDef dsDef = datasource as DsDef;

         ArcDef selectedArchive = archiveDefinition as ArcDef;
         FetchData fetchedData = model.GetArchiveData(database, dsDef.DsName, selectedArchive);
         rrdDbForm.SetArchiveDumpData(fetchedData);
         rrdDbForm.SetDocumentName(Path.GetFileNameWithoutExtension(database.Definition.getPath()));
      }
Ejemplo n.º 13
0
 public void SetDatabaseDefinition(DatabaseData databaseData)
 {
    LoadTree(databaseData);
 }
Ejemplo n.º 14
0
      public FetchData GetArchiveData(DatabaseData databaseData, string dataSourceName, ArcDef archiveDefinition)
      {
         RrdDb database = null;
         try
         {
            database = new RrdDb(databaseData.Definition.getPath(), true);
            int datasourceIndex = database.getDsIndex(dataSourceName);
            Archive archive = database.getArchive(new ConsolFun(archiveDefinition.getConsolFun().Name), archiveDefinition.Steps);
            Robin robin = archive.getRobin(datasourceIndex);
            double[] values = robin.getValues();
            DateTime archiveStartTime = archive.getStartDateTime();
            TimeSpan tick = new TimeSpan(archive.getArcStep() * TimeSpan.TicksPerSecond);

            FetchData fetchedData = new FetchData(archive.getArcStep(), archive.getEndTime(), new string[] { dataSourceName });
            long[] timestamps = new long[archive.getRows()];
            long offset = archive.getStartTime();
            for (var i = 0; i < archive.getRows(); i++)
            {
               timestamps[i] = offset;
               offset += archive.getArcStep();
            }
            fetchedData.setTimestamps(timestamps);
            double[][] value = new double[1][];
            value[0] = values;
            fetchedData.setValues(value);
            return fetchedData;

         }
         finally
         {
            if (database != null)
               database.close();
         }
      }
Ejemplo n.º 15
0
 public bool RemoveDatabase(DatabaseData srcDatabase)
 {
    if (databases.ContainsKey(srcDatabase.Definition.Path))
    {
       databases.Remove(srcDatabase.Definition.Path);
       return true;
    }
    EditingDatabaseData = null;
    DatabaseDirty = false;
    return true;
 }
Ejemplo n.º 16
0
 public void DatabaseUpdated(DatabaseData srcDatabaseData)
 {
    DatabaseData reloadedData;
    if (srcDatabaseData != null)
       reloadedData = model.ReloadDatabase(srcDatabaseData);
    else
       reloadedData = model.EditingDatabaseData;
    rrdDbForm.SetDatabaseDefinition(reloadedData);
    TreeForm.SetDatabaseDefinition(reloadedData);
 }
Ejemplo n.º 17
0
      public void SetDatabaseDefinition(DatabaseData databaseData)
      {
         LoadDatabaseView(databaseData);

//         Text = string.Format("RrdDb Configuration [{0}{1}]", Path.GetFileNameWithoutExtension(rrdDef.Path), dirty ? "*" : "");
      }
Ejemplo n.º 18
0
 public void StartEditDatabase(DatabaseData srcDatabaseData)
 {
    DatabaseData dstDatabaseData = model.SetDatabaseAsEdit(srcDatabaseData);
    TreeForm.SetDatabaseDefinition(dstDatabaseData);
    TreeForm.SetEditMode(true);
 }
Ejemplo n.º 19
0
      public DatabaseData CreateDatabase(RrdDef rrdDef)
      {

         EditingDatabaseData = new DatabaseData();
         EditingDatabaseData.Definition = rrdDef;
         EditingDatabaseData.LastUpdated = rrdDef.getStartDateTime();
         EditingDatabaseData.LastValue = double.NaN;
         EditingDatabaseData.SourceDatabasePath = null;
         DatabaseDirty = true;
         return EditingDatabaseData;
      }
Ejemplo n.º 20
0
      public void UpdateDataSource(DatabaseData srcDatabase, DsDef updatedDsDef, DsDef originalDsDef)
      {
         RrdDb database = null;

         try
         {
            database = new RrdDb(srcDatabase.Definition.Path, false);
            Datasource datasource = database.getDatasource(originalDsDef.getDsName());
            if (datasource == null)
               throw new ArgumentException(updatedDsDef.getDsName() + " datasource don't exist");
            if (datasource.DsName != updatedDsDef.DsName)
               datasource.setDsName(updatedDsDef.getDsName());
            datasource.setDsType(updatedDsDef.getDsType());
            datasource.setHeartbeat(updatedDsDef.getHeartbeat());
            datasource.setMaxValue(updatedDsDef.getMaxValue(), true);
            datasource.setMinValue(updatedDsDef.getMinValue(), true);

         }
         catch (FileNotFoundException ex)
         {
            Logger.Error("Update datasource failed", ex);
            throw new ApplicationException("Can't update datasource until database saved!", ex);
         }
         finally
         {
            if (database != null)
               database.close();
         }
      }
Ejemplo n.º 21
0
 public bool DatabaseUnsaved(DatabaseData databaseData)
 {
    if (model.EditingDatabaseData == null)
       return false;
    return databaseData.Definition.Path == model.EditingDatabaseData.Definition.Path;
 }
Ejemplo n.º 22
0
 public void DatasourcesSelected(DatabaseData database)
 {
    rrdDbForm.SetDatasourceData(model.GetDataSourceDefinitions(database));
    rrdDbForm.SetDocumentName(Path.GetFileNameWithoutExtension(database.Definition.getPath()));
 }
Ejemplo n.º 23
0
 public DsDef[] GetDataSourceDefinitions(DatabaseData databaseData)
 {
    return databaseData.Definition.getDsDefs();
 }
Ejemplo n.º 24
0
 public DsDef[] GetDataSourceDefinitions(DatabaseData databaseData)
 {
     return(databaseData.Definition.getDsDefs());
 }
Ejemplo n.º 25
0
      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;
      }
Ejemplo n.º 26
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;
    }
 }
Ejemplo n.º 27
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);
      }
Ejemplo n.º 28
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;
         }
      }
Ejemplo n.º 29
0
 public void RemoveDatabase(DatabaseData databaseData)
 {
    if (model.RemoveDatabase(databaseData))
       TreeForm.RemoveDatabaseDefinition(databaseData.Definition.Path);
 }