GetValueFromContent() 공개 정적인 메소드

Simple way to parse an XML tag for content. Doesn't confirm that the file is valid XML
public static GetValueFromContent ( string startTag, string endTag, string content ) : string
startTag string The start tag
endTag string The end tag
content string The content to be parsed.
리턴 string
예제 #1
0
        private void sendAssemblyToPeer(string address, object state)
        {
            const int buffSize     = 4096;
            var       uploadBuffer = new byte[buffSize];
            var       theOrganism  = (TeleportState)state;
            var       assemblyName = ((Species)theOrganism.OrganismState.Species).AssemblyInfo.FullName;

            byte[] assemblyBuf;

            var req = checkToSeeIfPeerHasThisAssembly(address, assemblyName, out assemblyBuf);

            writeAssemblyNameToRequest(req, assemblyBuf);
            var assemblyVersionResponse = getAssemblyVersionResponse(req);

            sendAssemblyIfNecessary(buffSize, state, address, assemblyVersionResponse, uploadBuffer);
            req = sendObjectState(state, address);
            var response = sendRequest(req);

            _engine.WriteProtocolInfo("sendAssemblyToPeer: Organism state sent.");

            // Look for <organismArrived>false</organismArrived>, because that means the organism
            // didn't make it and should be teleported locally
            if (NetworkEngine.GetValueFromContent("<organismArrived>", "</organismArrived>", response) == "false")
            {
                var errorMessage = "The organism didn't arrive on their side for some reason.";
                if (NetworkEngine.GetValueFromContent("<reason>", "</reason>", response) != null)
                {
                    errorMessage = "The organism didn't arrive on the remote peer. " +
                                   NetworkEngine.GetValueFromContent("<reason>", "</reason>", response);
                }
                throw new AbortPeerDiscussionException(errorMessage);
            }

            return;
        }
예제 #2
0
        private NameValueCollection getPeerTerrariumInfo(string address)
        {
            address = "http://" + address + ":" + _httpPort + "/version";
            string content;
            var    peerInfo = new NameValueCollection();

            var req = (HttpWebRequest)WebRequest.Create(address);

            req.UserAgent = "Microsoft .NET Terrarium";
            req.Timeout   = _networkTimeoutMsec;

            using (var resp = req.GetResponse())
            {
                using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.ASCII))
                {
                    content = reader.ReadToEnd();
                    reader.Close();
                }
                resp.Close();
            }

            var tempString = NetworkEngine.GetValueFromContent("<major>", "</major>", content);
            var major      = Convert.ToInt32(tempString);

            tempString = NetworkEngine.GetValueFromContent("<minor>", "</minor>", content);
            var minor = Convert.ToInt32(tempString);

            tempString = NetworkEngine.GetValueFromContent("<build>", "</build>", content);
            var build = Convert.ToInt32(tempString);

            var currentChannel = NetworkEngine.GetValueFromContent("<channel>", "</channel>", content);

            peerInfo["major"] = major.ToString();
            peerInfo["minor"] = minor.ToString();
            peerInfo["build"] = build.ToString();

            if (currentChannel != null)
            {
                peerInfo["channel"] = currentChannel;
            }

            return(peerInfo);
        }