Exemple #1
0
        internal void UpdateEntry(CDatabaseEntry entry)
        {
            SQLiteDataReader  reader        = ExecuteParameterizedReader("SELECT * FROM ea_objects WHERE uid=@0", entry.Id);
            CDiscoveredConfig existingprops = new CDiscoveredConfig();

            while (reader.Read()) // read existing attributes
            {
                if (entry.Reference.ToStringNz() == "")
                {
                    entry.Reference = reader["ref"].ToStringNz();
                }
                if (entry.Created.ToStringNz() == "")
                {
                    entry.Created = reader["created"].ToStringNz();
                }
                if (entry.Accessed.ToStringNz() == "")
                {
                    entry.Accessed = reader["accessed"].ToStringNz();
                }
                if (entry.Type.ToStringNz() == "")
                {
                    entry.Type = reader["type"].ToStringNz();
                }
                existingprops = CDiscoveredConfig.Deserialize(reader["attributes"].ToStringNz());
            }
            if (existingprops.Attributes != null && existingprops.Attributes.Count() > 0)
            {
                CDiscoveredConfig newprops = CDiscoveredConfig.Deserialize(entry.Attributes);
                existingprops.Merge(newprops);
                entry.Attributes = existingprops.Serialize(CDiscoveredAttributes.SerializeAsShortJson);
                ExecuteParameterizedNonQuery("UPDATE ea_objects SET name=@1, ref=@2, type=@3, parent=@4, created=@5, accessed=@6, attributes=@7 WHERE uid=@0", entry.Id, entry.Name, entry.Reference, entry.Type, entry.Parent, entry.Created, entry.Accessed, entry.Attributes);
            }
        }
Exemple #2
0
 internal void AddEntry(CDatabaseEntry entry)
 {
     if (_DBTryInitialize())
     {
         // check if an entry already exists
         ExecuteParameterizedNonQuery("INSERT INTO ea_objects (uid, name, ref, type, parent, created, accessed, attributes) VALUES (@0, @1, @2, @3, @4, @5, @6, @7)", entry.Id, entry.Name, entry.Reference, entry.Type, entry.Parent, entry.Created, entry.Accessed, entry.Attributes);
         // - or -
         // add ea_event and ea_event_text if not already available for event type
     }
 }
        public void ExportDiscoveredConfig(CDiscoveredConfig oc, CService server = null, bool rolluptotals = false)
        {
            if (oc.Attributes != null && oc.Name.Length > 0)
            {
                if (server != null && rolluptotals)
                {
                    // create grouping objects
                    AddGroupingInfo(server, oc);

                    // rollup totals by group and repair object parent properties
                    oc = UpdateGroupingInfo(server, oc);
                }
                CDatabaseEntry entry = new CDatabaseEntry();
                entry.Id         = oc.Id.ToString();
                entry.Reference  = oc.Attributes.Get(CAttributeType.Reference);
                entry.Created    = oc.Attributes.Get(CAttributeType.Created);
                entry.Accessed   = oc.Attributes.Get(CAttributeType.Accessed);
                entry.Name       = CFunctions.EscapeJson(oc.Name);
                entry.Type       = oc.Type.ToString();
                entry.Parent     = CFunctions.StringJoin(";", oc.Owner);
                entry.Attributes = oc.Serialize(CDiscoveredConfig.SerializeAsShortJson);
                if (!ExportedEntries.Contains(entry.Id))
                {
                    _DBConn.AddEntry(entry);
                    ExportedEntries.Add(entry.Id);
                }
                else
                {
                    _DBConn.UpdateEntry(entry);
                }
            }
            if (oc.ChildObjects != null)
            {
                foreach (CDiscoveredConfig obj in oc.ChildObjects)
                {
                    ExportDiscoveredConfig(obj, server, rolluptotals);
                }
            }
        }