コード例 #1
0
 public virtual XElement GetSaveElement()
 {
     return(XMLStorageAttribute.WriteToElement(this));
 }
コード例 #2
0
        internal static XElement GetNodeSaveElement(Computer node)
        {
            var result = new XElement("computer");

            result.SetAttributeValue("name", node.name);
            result.SetAttributeValue("ip", node.ip);
            result.SetAttributeValue("type", node.type);
            var spec = "none";

            if (node.os.netMap.mailServer.Equals(node))
            {
                spec = "mail";
            }
            if (node.os.thisComputer.Equals(node))
            {
                spec = "player";
            }
            result.SetAttributeValue("spec", spec);
            result.SetAttributeValue("id", node.idName);
            if (node.icon != null)
            {
                result.SetAttributeValue("icon", node.icon);
            }
            if (node.attatchedDeviceIDs != null)
            {
                result.SetAttributeValue("devices", node.attatchedDeviceIDs);
            }
            if (node.HasTracker)
            {
                result.SetAttributeValue("tracker", "true");
            }

            var locationTag = new XElement("location");

            locationTag.SetAttributeValue("x", node.location.X.ToString(CultureInfo.InvariantCulture));
            locationTag.SetAttributeValue("y", node.location.Y.ToString(CultureInfo.InvariantCulture));
            result.Add(locationTag);

            var securityTag = new XElement("security");

            securityTag.SetAttributeValue("level", node.securityLevel);
            securityTag.SetAttributeValue("traceTime", node.traceTime.ToString(CultureInfo.InvariantCulture));
            if (node.startingOverloadTicks > 0f)
            {
                securityTag.SetAttributeValue("proxyTime", (node.hasProxy ? node.startingOverloadTicks.ToString(CultureInfo.InvariantCulture) : "-1"));
            }
            securityTag.SetAttributeValue("portsToCrack", node.portsNeededForCrack);
            securityTag.SetAttributeValue("adminIP", node.adminIP);
            result.Add(securityTag);

            var    adminTag = new XElement("admin");
            string adminType;

            switch (node.admin)
            {
            case null:
                adminType = "none";
                break;

            case BaseAdministrator pfAdmin:
                adminTag  = XMLStorageAttribute.WriteToElement(pfAdmin);
                adminType = node.admin.GetType().Name;
                break;

            case FastBasicAdministrator _:
                adminType = "fast";
                break;

            case FastProgressOnlyAdministrator _:
                adminType = "progress";
                break;

            case BasicAdministrator _:
                adminType = "basic";
                break;

            default:
                adminType = node.admin.GetType().Name;
                break;
            }

            adminTag.SetAttributeValue("type", adminType);
            adminTag.SetAttributeValue("resetPass", node.admin?.ResetsPassword ?? false);
            adminTag.SetAttributeValue("isSuper", node.admin?.IsSuper ?? false);
            result.Add(adminTag);


            var linksTag = new XElement("links");
            var links    = new StringBuilder();

            foreach (var link in node.links)
            {
                links.Append(" " + link);
            }

            linksTag.SetValue(links.ToString());
            result.Add(linksTag);

            if (node.firewall != null)
            {
                result.Add(GetFirewallSaveElement(node.firewall));
            }

            var portsOpenTag = new XElement("portsOpen");
            var ports        = new StringBuilder();

            for (var i = 0; i < node.portsOpen.Count; i++)
            {
                ports.Append(" " + node.ports[i]);
            }
            portsOpenTag.SetValue(ports);
            result.Add(portsOpenTag);

            var portRemaps = GetPortRemappingSaveElement(node.PortRemapping);

            if (portRemaps != null)
            {
                result.Add(portRemaps);
            }

            var usersTag = new XElement("users");

            foreach (var detail in node.users)
            {
                usersTag.Add(GetUserDetailSaveElement(detail));
            }

            result.Add(usersTag);

            if (node.Memory != null)
            {
                result.Add(GetMemoryContentsSaveElement(node.Memory));
            }


            var daemonsTag = new XElement("daemons");

            daemonsTag.Add(node.daemons.Select(GetDaemonSaveElement).ToArray());

            result.Add(daemonsTag);

            result.Add(GetFilesystemSaveElement(node.files));

            var eventResult = EventManager <SaveComputerEvent> .InvokeAll(new SaveComputerEvent(node.os, node, result));

            return(eventResult.Cancelled ? null : eventResult.Element);
        }