Exemple #1
0
        public PeloponneseClient(XElement processDetails, ILogger logger)
        {
            httpClient = new NotHttpClient.NotHttpClient(false, 1, 10000, logger);

            string guidString = Environment.GetEnvironmentVariable(Constants.EnvJobGuid);

            if (guidString == null)
            {
                throw new ApplicationException("Can't find environment variable " + Constants.EnvJobGuid);
            }
            this.jobGuid = Guid.Parse(guidString);

            serverAddress = Environment.GetEnvironmentVariable(Constants.EnvManagerServerUri);
            if (serverAddress == null)
            {
                throw new ApplicationException("Can't find environment variable " + Constants.EnvManagerServerUri);
            }

            groupName = Environment.GetEnvironmentVariable(Constants.EnvProcessGroup);
            if (groupName == null)
            {
                throw new ApplicationException("Can't find environment variable " + Constants.EnvProcessGroup);
            }

            processIdentifier = Environment.GetEnvironmentVariable(Constants.EnvProcessIdentifier);
            if (processIdentifier == null)
            {
                throw new ApplicationException("Can't find environment variable " + Constants.EnvProcessIdentifier);
            }

            XElement details = new XElement("ProcessDetails");

            details.Add(processDetails);

            string status = details.ToString();

            string registration = String.Format("{0}register?guid={1}&group={2}&identifier={3}", serverAddress, jobGuid.ToString(), groupName, processIdentifier);

            NotHttpClient.IHttpRequest request = httpClient.CreateRequest(registration);
            // throw an exception and exit if we don't get the registration response within 30 seconds
            request.Timeout = 30 * 1000;
            request.Method  = "POST";

            using (Stream upload = request.GetRequestStream())
            {
                using (StreamWriter sw = new StreamWriter(upload))
                {
                    sw.Write(status);
                }
            }

            using (NotHttpClient.IHttpResponse response = request.GetResponse())
            {
                // discard the response
            }
        }
Exemple #2
0
        public void NotifyCleanShutdown()
        {
            StringBuilder sb = new StringBuilder(serverAddress);

            sb.Append("startshutdown");

            NotHttpClient.IHttpRequest request = httpClient.CreateRequest(sb.ToString());
            // throw an exception if we don't get the response within 30 seconds
            request.Timeout = 30 * 1000;
            request.Method  = "POST";

            using (Stream rStream = request.GetRequestStream())
            {
                // no data
            }

            using (NotHttpClient.IHttpResponse status = request.GetResponse())
            {
                using (Stream response = status.GetResponseStream())
                {
                    // ignore
                }
            }
        }