//--------------------------------------------------------------------------------------------------------------------- public override bool SaveDiskAs(int diskId, String caption) { HttpWebRequest request = context.GetSslRequest(String.Format("{0}/compute/{1}", Provider.AccessPoint, RemoteId), "PUT", "text/xml", OwnerId); try { context.AddDebug(3, caption); if (Storages[diskId] != null) { Stream requestStream = request.GetRequestStream(); MonoXmlWriter writer = MonoXmlWriter.Create(requestStream); writer.WriteStartElement("COMPUTE"); writer.WriteElementString("ID", Id.ToString()); writer.WriteElementString("NAME", Name); writer.WriteStartElement("DISK"); writer.WriteAttributeString("id", Storages[diskId].Id.ToString()); writer.WriteStartElement("SAVE_AS"); writer.WriteAttributeString("name", caption); writer.WriteEndElement(); // </SAVE_AS> writer.WriteEndElement(); // </DISK> writer.WriteEndElement(); // </COMPUTE> writer.Close(); requestStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); return(true); } catch (Exception e) { context.AddError("Error saving disk " + diskId + " OCCI server returned: " + e.Message); return(false); } }
//--------------------------------------------------------------------------------------------------------------------- /// <summary>Creates the instance on the cloud provider and stores the record in the local database.</summary> public override bool Create() { HttpWebRequest request = context.GetSslRequest(String.Format("{0}/compute", Provider.AccessPoint), "POST", "text/xml"); try { Stream requestStream = request.GetRequestStream(); MonoXmlWriter writer = MonoXmlWriter.Create(requestStream); WriteXmlForProvider(writer, null); writer.Close(); requestStream.Close(); // Get response stream. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); Load(doc.DocumentElement); //Console.WriteLine(StringUtils.GetXmlFromStream(response.GetResponseStream(), true)); response.Close(); } catch (Exception e) { context.ReturnError(e.Message); } Store(); return(true); }
public string modifyJob(string sessionID, string jobName, string[] @params) { // TODO: Use Mono standard serialisation instead of the manually creating the SOAP XML request message (SubmitExt()) StringWriter stringWriter = new StringWriter(); MonoXmlWriter writer = MonoXmlWriter.Create(stringWriter); //XmlWriter writer = XmlWriter.Create(new StreamWriter("/Users/floeschau/Programming/ify.mono/release/ws-test-client/wsServer_createTask_5.xml")); writer.WriteStartDocument(); writer.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); writer.WriteNamespaceDefinition("xsd", "http://www.w3.org/2001/XMLSchema"); writer.WriteNamespaceDefinition("xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteNamespaceDefinition("enc", "http://schemas.xmlsoap.org/soap/encoding/"); writer.WriteNamespaceDefinition("wss", "http://tempuri.org/eo.gridEngine.frontEnd.ContactService"); writer.WritePrefixStartElement("soap", "Body"); writer.WriteAttributeString("soap", "encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/"); writer.WritePrefixStartElement("wss", "modifyJob"); writer.WriteElementString("sessionID", sessionID); writer.WriteElementString("jobName", jobName); writer.WriteStartElement("params"); writer.WritePrefixAttributeString("xsi", "type", "xsd:string"); writer.WritePrefixAttributeString("enc", "arrayType", "xsd:string[" + @params.Length + "]"); writer.WritePrefixAttributeString("enc", "offset", "[0]"); for (int i = 0; i < @params.Length; i++) { writer.WriteElementString("item", @params[i]); } if (@params.Length == 0) { writer.WriteElementString("item", ""); } writer.WriteEndElement(); // </params> writer.WriteEndElement(); // </wss:modifyJob> writer.WriteEndElement(); // </soap:Body> writer.WriteEndElement(); // </soap:Envelope> writer.WriteEndDocument(); writer.Close(); stringWriter.Close(); return(ReceiveSoapResponse("modifyJob", "result", stringWriter.ToString())); }
//--------------------------------------------------------------------------------------------------------------------- protected bool SendHttpOperation(string method, string state) { HttpWebRequest request = context.GetSslRequest(String.Format("{0}/compute/{1}", Provider.AccessPoint, RemoteId), method, "text/xml", OwnerId); try { if (state != null) { Stream requestStream = request.GetRequestStream(); MonoXmlWriter writer = MonoXmlWriter.Create(requestStream); WriteXmlForProvider(writer, state); writer.Close(); requestStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); request = context.GetSslRequest(String.Format("{0}/compute/{1}", Provider.AccessPoint, RemoteId), "GET", null, OwnerId); // Get response stream. response = (HttpWebResponse)request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); Load(doc.DocumentElement); response.Close(); return(true); } catch (WebException e) { HttpWebResponse responseError = (HttpWebResponse)e.Response; StreamReader reader = new StreamReader(responseError.GetResponseStream(), Encoding.UTF8); String responseString = reader.ReadToEnd(); responseError.Close(); throw new Exception(responseString); } catch (Exception e) { throw e; } }