Пример #1
0
 public bool Load(XmlNode entryNode)
 {
     foreach (XmlNode node in entryNode.ChildNodes)
     {
         if (node.Name == "ID")
         {
             ProgramID id = new ProgramID();
             if (id.Load(node))
             {
                 ID = id;
             }
         }
         else if (node.Name == "Description")
         {
             Description = node.InnerText;
         }
         else if (node.Name == "FwRules")
         {
             foreach (XmlNode childNode in node.ChildNodes)
             {
                 FirewallRuleEx rule = new FirewallRuleEx();
                 rule.ProgID = ID;
                 if (rule.Load(childNode) && !Rules.ContainsKey(rule.guid))
                 {
                     Rules.Add(rule.guid, rule);
                 }
                 else
                 {
                     App.LogError("Failed to load Firewall RuleEx {0} in {1}", rule.Name != null ? rule.Name : "[un named]", this.Description);
                 }
             }
         }
         else if (node.Name == "DnsLog")
         {
             foreach (XmlNode childNode in node.ChildNodes)
             {
                 DnsEntry Entry = new DnsEntry(ID);
                 if (Entry.Load(childNode) && !DnsLog.ContainsKey(Entry.HostName))
                 {
                     DnsLog.Add(Entry.HostName, Entry);
                 }
                 else
                 {
                     App.LogError("Failed to load DnsLog Entry in {0}", this.Description);
                 }
             }
         }
         else
         {
             AppLog.Debug("Unknown Program Value, '{0}':{1}", node.Name, node.InnerText);
         }
     }
     return(ID != null);
 }
Пример #2
0
        public bool Load(XmlNode entryNode)
        {
            foreach (XmlNode node in entryNode.ChildNodes)
            {
                if (node.Name == "ID")
                {
                    ProgramID id = new ProgramID();
                    if (id.Load(node))
                    {
                        // COMPAT: remove service tag
                        ID = FirewallRuleEx.AdjustProgID(id);
                    }
                }
                else if (node.Name == "Description")
                {
                    Description = node.InnerText;
                }
                else if (node.Name == "ReceivedBytes")
                {
                    UInt64.TryParse(node.InnerText, out OldDownload);
                }
                else if (node.Name == "SentBytes")
                {
                    UInt64.TryParse(node.InnerText, out OldUpload);
                }
                else if (node.Name == "FwRules")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        FirewallRuleEx rule = new FirewallRuleEx();
                        rule.ProgID = ID; // todo: remove later, load loads this amyways
                        if (rule.Load(childNode) && !Rules.ContainsKey(rule.guid))
                        {
                            // COMPAT: update entry, old version did not save these data separatly
                            //if (ID.Type != ProgramID.Types.Global && (rule.BinaryPath == null && rule.ServiceTag == null && rule.AppSID == null))
                            //    rule.SetProgID(ID);

                            Rules.Add(rule.guid, rule);
                        }
                        else
                        {
                            Priv10Logger.LogError("Failed to load Firewall RuleEx {0} in {1}", rule.Name != null ? rule.Name : "[un named]", this.Description);
                        }
                    }
                }
                else if (node.Name == "DnsLog")
                {
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        DnsEntry Entry = new DnsEntry(ID);
                        if (Entry.Load(childNode) && !DnsLog.ContainsKey(Entry.HostName))
                        {
                            DnsLog.Add(Entry.HostName, Entry);
                        }
                        else
                        {
                            Priv10Logger.LogError("Failed to load DnsLog Entry in {0}", this.Description);
                        }
                    }
                }
                else
                {
                    AppLog.Debug("Unknown Program Value, '{0}':{1}", node.Name, node.InnerText);
                }
            }

            if (Description == null || Description.Substring(0, 2) == "@{")
            {
                Description = GetDescription();
            }

            return(ID != null);
        }