コード例 #1
0
        public string Serialize(int mode)
        {
            string result = "";

            if (mode == SerializeAsFullJson)
            {
                if (Name != null)
                {
                    result += "\"" + CFunctions.EscapeJson(Name) + "\": { ";
                }
                if (Type > -1)
                {
                    result += "\"type\":\"" + CDiscoveredTypes.Values[Type].Replace(" ", "-").ToLower() + "\", ";
                }
                if (Metrics != null)
                {
                    result += Metrics.Serialize(SerializeAsFullJson);
                }
                if (Attributes != null)
                {
                    result += Attributes.Serialize(SerializeAsFullJson);
                }
            }
            else if (mode == SerializeAsShortJson)
            {
                result += "{";
                if (Metrics != null)
                {
                    result += Metrics.Serialize(SerializeAsShortJson);
                }
                if (Attributes != null)
                {
                    result += Attributes.Serialize(SerializeAsShortJson);
                }
            }
            result  = result.TrimEnd(new char[] { ',', ' ' });
            result += "}";
            return(result);
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        public string Serialize(int mode)
        {
            string result = "";

            if (mode == SerializeAsFullJson)
            {
                foreach (int type in _attributes.Keys)
                {
                    string tstr = new CAttributeType(type).ToString().Replace(" ", "").ToLower();
                    result += "\"" + tstr + "\":\"" + CFunctions.EscapeJson(_attributes[type]) + "\", ";
                }
            }
            else if (mode == SerializeAsShortJson)
            {
                foreach (int type in _attributes.Keys)
                {
                    if (type != CAttributeType.Reference && type != CAttributeType.Created && type != CAttributeType.Accessed)
                    {
                        result += "\"" + type + "\":\"" + CFunctions.EscapeJson(_attributes[type]) + "\", ";
                    }
                }
            }
            return(result);
        }