internal NameValueCollection SetResourceDataParams(string resourceid, string dataname, ResourceDataType datatype) { NameValueCollection param = new NameValueCollection(); param.Add("OPERATION", "SETRESOURCEDATA"); param.Add("VERSION", "1.0.0"); param.Add("SESSION", m_sessionID); param.Add("CLIENTAGENT", m_userAgent); if (m_locale != null) param.Add("LOCALE", m_locale); param.Add("RESOURCEID", resourceid); param.Add("DATANAME", dataname); param.Add("DATATYPE", datatype.ToString()); return param; }
public override void SetResourceData(string resourceid, string dataname, ResourceDataType datatype, Stream stream, OSGeo.MapGuide.MaestroAPI.Utility.StreamCopyProgressDelegate callback) { MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgByteReader reader = null; string tmpPath = null; //If stream is under our hard-coded limit (and it's seekable, which is how we're able to get that number), use the //overload of MgByteSource that accepts a byte[]. Otherwise dump the stream to a temp file and use the //file name overload (otherwise if our input stream happens to be several GBs, we run risk of //System.OutOfMemoryExceptions being thrown back at us) if (stream.CanSeek && stream.Length < (MAX_INPUT_STREAM_SIZE_MB * 1024 * 1024)) { byte[] data = Utility.StreamAsArray(stream); MgByteSource source = new MgByteSource(data, data.Length); reader = source.GetReader(); } else { tmpPath = Path.GetTempFileName(); using (FileStream fs = File.OpenWrite(tmpPath)) { stream.CopyTo(fs); } MgByteSource source = new MgByteSource(tmpPath); reader = source.GetReader(); } try { res.SetResourceData(new MgResourceIdentifier(resourceid), dataname, datatype.ToString(), reader); LogMethodCall("MgResourceService::SetResourceData", true, resourceid, dataname, datatype.ToString(), "MgByteReader"); } finally { if (!string.IsNullOrEmpty(tmpPath) && File.Exists(tmpPath)) { //Be a responsible citizen and clean up our temp files when done try { File.Delete(tmpPath); } catch { } } } }
public System.Net.WebRequest SetResourceData(string id, string dataname, ResourceDataType datatype, System.IO.Stream outStream, System.IO.Stream content, Utility.StreamCopyProgressDelegate callback) { if (m_sessionID == null) throw new Exception("Connection is not yet logged in"); NameValueCollection param = new NameValueCollection(); param.Add("OPERATION", "SETRESOURCEDATA"); param.Add("VERSION", "1.0.0"); param.Add("SESSION", m_sessionID); param.Add("CLIENTAGENT", m_userAgent); if (m_locale != null) param.Add("LOCALE", m_locale); param.Add("RESOURCEID", id); param.Add("DATANAME", dataname); param.Add("DATATYPE", datatype.ToString()); //This does not appear to be used anywhere in the MG WebTier code //anyway, set this if stream supports seeking if (content.CanSeek) param.Add("DATALENGTH", content.Length.ToString()); string boundary; System.Net.WebRequest req = PrepareFormContent(outStream, out boundary); EncodeFormParameters(boundary, param, outStream); AppendFormContent("DATA", "content.bin", boundary, outStream, content, callback); req.ContentLength = outStream.Length; return req; }