////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GR(GDataRequestType type, Uri uriTarget, GDataRequestFactory factory) { this.type = type; this.targetUri = uriTarget; this.factory = factory; this.useGZip = this.factory.UseGZip; // use gzip setting from factory }
/// <summary> /// this is a helper function for external utilities. It is not worth /// running the other insert/saves through here, as this would involve /// double buffering/copying of the bytes /// </summary> /// <param name="targetUri"></param> /// <param name="payload"></param> /// <param name="type"></param> /// <returns>Stream</returns> public Stream StringSend(Uri targetUri, String payload, GDataRequestType type) { Tracing.Assert(targetUri != null, "targetUri should not be null"); if (targetUri == null) { throw new ArgumentNullException("targetUri"); } Tracing.Assert(payload != null, "payload should not be null"); if (payload == null) { throw new ArgumentNullException("payload"); } IGDataRequest request = this.RequestFactory.CreateRequest(type, targetUri); request.Credentials = this.Credentials; Stream outputStream = request.GetRequestStream(); StreamWriter w = new StreamWriter(outputStream); w.Write(payload); w.Flush(); request.Execute(); w.Close(); return(request.GetResponseStream()); }
/// <summary>default constructor</summary> internal GDataRequest(GDataRequestType type, Uri uriTarget, GDataRequestFactory factory) { _type = type; _targetUri = uriTarget; _factory = factory; _useGZip = _factory.UseGZip; // use gzip setting from factory }
/// <summary>default constructor</summary> internal GDataRequest(GDataRequestType type, Uri uriTarget, GDataRequestFactory factory) { this.type = type; this.targetUri = uriTarget; this.factory = factory; this.useGZip = this.factory.UseGZip; // use gzip setting from factory }
/// <summary> /// this is a helper function for to send binary data to a resource /// it is not worth running the other insert/saves through here, as this would involve /// double buffering/copying of the bytes /// </summary> /// <param name="targetUri"></param> /// <param name="inputStream"></param> /// <param name="type"></param> /// <param name="contentType">the contenttype to use in the request, if NULL is passed, factory default is used</param> /// <param name="slugHeader">the slugHeader to use in the request, if NULL is passed, factory default is used</param> /// <returns>Stream</returns> public Stream StreamSend(Uri targetUri, Stream inputStream, GDataRequestType type, string contentType, string slugHeader) { return(StreamSend(targetUri, inputStream, type, contentType, slugHeader, null, null)); }
public AsyncSendData(AsyncDataHandler handler, Uri uriToUse, Stream stream, GDataRequestType type, string contentType, string slugHeader, SendOrPostCallback callback, object userData, bool parseFeed) : this(handler, uriToUse, null, null, callback, userData, parseFeed) { this.DataStream = stream; this.type = type; this.contentType = contentType; this.slugHeader = slugHeader; }
public AsyncSendData(AsyncDataHandler handler, Uri uriToUse, Stream stream, GDataRequestType type, string contentType, string slugHeader, SendOrPostCallback callback, object userData, bool parseFeed) : this(handler, uriToUse, null, null, callback, userData, parseFeed) { DataStream = stream; _type = type; _contentType = contentType; _slugHeader = slugHeader; }
/// <summary> /// this is a helper function for to send binary data asyncronous to a resource /// The async returned object will contain the output stream /// </summary> /// <param name="targetUri"></param> /// <param name="inputStream"></param> /// <param name="type"></param> /// <param name="contentType">the contenttype to use in the request, if NULL is passed, factory default is used</param> /// <param name="slugHeader">the slugHeader to use in the request, if NULL is passed, factory default is used</param> /// <param name="userData">a unique identifier to associate this request with</param> /// <returns></returns> public void StreamSendStreamAsync(Uri targetUri, Stream inputStream, GDataRequestType type, string contentType, string slugHeader, object userData) { StreamSendAsync(targetUri, inputStream, type, contentType, slugHeader, userData, false); }
/// <summary> /// this is a helper function for to send binary data asyncronous to a resource /// </summary> /// <param name="targetUri"></param> /// <param name="inputStream"></param> /// <param name="type"></param> /// <param name="contentType">the contenttype to use in the request, if NULL is passed, factory default is used</param> /// <param name="slugHeader">the slugHeader to use in the request, if NULL is passed, factory default is used</param> /// <param name="userData">a unique identifier to associate this request with</param> /// <param name="parseFeed">indicates if the async operation should try to parse the server returned stream, or just return the stream</param> /// <returns></returns> private void StreamSendAsync(Uri targetUri, Stream inputStream, GDataRequestType type, string contentType, string slugHeader, object userData, bool parseFeed) { AsyncSendData data = new AsyncSendData(this, targetUri, inputStream, type, contentType, slugHeader, this.ProgressReportDelegate, userData, parseFeed); WorkerSendEventHandler workerDelegate = new WorkerSendEventHandler(AsyncStreamSendWorker); this.AsyncStarter(data, workerDelegate, userData); }
/// <summary>Inserts an AtomBase entry against a Uri</summary> /// <param name="feedUri">the uri for the feed this object should be posted against</param> /// <param name="baseEntry">the entry to be inserted</param> /// <param name="type">the type of request to create</param> /// <param name="data">the async data payload</param> /// <returns> the response as a stream</returns> internal virtual Stream EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data) { Tracing.Assert(feedUri != null, "feedUri should not be null"); if (feedUri == null) { throw new ArgumentNullException("feedUri"); } Tracing.Assert(baseEntry != null, "baseEntry should not be null"); if (baseEntry == null) { throw new ArgumentNullException("baseEntry"); } this.versionInfo.ImprintVersion(baseEntry); IGDataRequest request = this.RequestFactory.CreateRequest(type, feedUri); request.Credentials = this.Credentials; ISupportsEtag eTarget = request as ISupportsEtag; ISupportsEtag eSource = baseEntry as ISupportsEtag; if (eTarget != null && eSource != null) { eTarget.Etag = eSource.Etag; } request.ContentStore = baseEntry; request.IsBatch = type == GDataRequestType.Batch; if (data != null) { GDataGAuthRequest gr = request as GDataGAuthRequest; if (gr != null) { gr.AsyncData = data; } } Stream outputStream = request.GetRequestStream(); baseEntry.SaveToXml(outputStream); request.Execute(); outputStream.Close(); return(request.GetResponseStream()); }
/// <summary>Inserts an AtomBase entry against a Uri</summary> /// <param name="feedUri">the uri for the feed this object should be posted against</param> /// <param name="baseEntry">the entry to be inserted</param> /// <param name="type">the type of request to create</param> /// <returns> the response as a stream</returns> public Stream EntrySend(Uri feedUri, AtomEntry baseEntry, GDataRequestType type) { return(this.EntrySend(feedUri, baseEntry, type, null)); }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GAuthSubRequest(GDataRequestType type, Uri uriTarget, GAuthSubRequestFactory factory) : base(type, uriTarget, factory) { this.factory = factory; }
/// <summary>default constructor</summary> internal GDataGAuthRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory) : base(type, uriTarget, factory as GDataRequestFactory) { // need to remember the factory, so that we can pass the new authtoken back there if need be this.factory = factory; }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return new GDataGAuthRequest(type, uriTarget, this); }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataLoggingRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory, string strInputFileName, string strOutputFileName, string strCombinedLogFileName) : base(type, uriTarget, factory) { this.strInput = strInputFileName; this.strOutput = strOutputFileName; this.strCombined = strCombinedLogFileName; }
////////////////////////////////////////////////////////////////////// /// <summary>Inserts an AtomBase entry against a Uri</summary> /// <param name="feedUri">the uri for the feed this object should be posted against</param> /// <param name="baseEntry">the entry to be inserted</param> /// <param name="type">the type of request to create</param> /// <returns> the response as a stream</returns> ////////////////////////////////////////////////////////////////////// public Stream StreamInsert(Uri feedUri, AtomBase baseEntry, GDataRequestType type) { Tracing.Assert(feedUri != null, "feedUri should not be null"); if (feedUri == null) { throw new ArgumentNullException("feedUri"); } Tracing.Assert(baseEntry != null, "baseEntry should not be null"); if (baseEntry == null) { throw new ArgumentNullException("baseEntry"); } IGDataRequest request = this.RequestFactory.CreateRequest(type,feedUri); request.Credentials = this.Credentials; Stream outputStream = request.GetRequestStream(); baseEntry.SaveToXml(outputStream); request.Execute(); outputStream.Close(); return request.GetResponseStream(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Inserts an AtomBase entry against a Uri. The overloaded /// version here will check if this is an AbstractEntry and if it has /// a media property set. If so, it will create a mime multipart envelope</summary> /// <param name="feedUri">the uri for the feed this object should be posted against</param> /// <param name="baseEntry">the entry to be inserted</param> /// <param name="type">the type of request to create</param> /// <param name="data">the async data payload</param> /// <returns> the response as a stream</returns> ////////////////////////////////////////////////////////////////////// internal override Stream EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data) { if (feedUri == null) { throw new ArgumentNullException("feedUri"); } //Tracing.Assert(baseEntry != null, "baseEntry should not be null"); if (baseEntry == null) { throw new ArgumentNullException("baseEntry"); } AbstractEntry entry = baseEntry as AbstractEntry; // if the entry is not an abstractentry or if no media is set, do the default if (entry == null || entry.MediaSource == null) { return(base.EntrySend(feedUri, baseEntry, type, data)); } Stream outputStream = null; Stream inputStream = null; try { IGDataRequest request = this.RequestFactory.CreateRequest(type, feedUri); request.Credentials = this.Credentials; GDataRequest r = request as GDataRequest; if (r != null) { r.ContentType = MediaService.MimeContentType; r.Slug = entry.MediaSource.Name; GDataRequestFactory f = this.RequestFactory as GDataRequestFactory; if (f != null) { f.CustomHeaders.Add("MIME-version: 1.0"); } } if (data != null) { GDataGAuthRequest gr = request as GDataGAuthRequest; if (gr != null) { gr.AsyncData = data; } } outputStream = request.GetRequestStream(); inputStream = entry.MediaSource.GetDataStream(); StreamWriter w = new StreamWriter(outputStream); w.WriteLine("Media multipart posting"); CreateBoundary(w, GDataRequestFactory.DefaultContentType); baseEntry.SaveToXml(outputStream); w.WriteLine(); CreateBoundary(w, entry.MediaSource.ContentType); WriteInputStreamToRequest(inputStream, outputStream); w.WriteLine(); w.WriteLine("--" + MediaService.MimeBoundary + "--"); w.Flush(); request.Execute(); outputStream.Close(); outputStream = null; return(request.GetResponseStream()); } catch (Exception) { throw; } finally { if (outputStream != null) { outputStream.Close(); } if (inputStream != null) { inputStream.Close(); } } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Inserts an AtomBase entry against a Uri. The overloaded /// version here will check if this is an AbstractEntry and if it has /// a media property set. If so, it will create a mime multipart envelope</summary> /// <param name="feedUri">the uri for the feed this object should be posted against</param> /// <param name="baseEntry">the entry to be inserted</param> /// <param name="type">the type of request to create</param> /// <param name="data">the async data payload</param> /// <returns> the response as a stream</returns> ////////////////////////////////////////////////////////////////////// internal override Stream EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data) { if (feedUri == null) { throw new ArgumentNullException("feedUri"); } Tracing.Assert(baseEntry != null, "baseEntry should not be null"); if (baseEntry == null) { throw new ArgumentNullException("baseEntry"); } AbstractEntry entry = baseEntry as AbstractEntry; // if the entry is not an abstractentry or if no media is set, do the default if (entry == null || entry.MediaSource == null) { return base.EntrySend(feedUri, baseEntry, type, data); } Stream outputStream = null; Stream inputStream=null; try { IGDataRequest request = this.RequestFactory.CreateRequest(type,feedUri); request.Credentials = this.Credentials; GDataRequest r = request as GDataRequest; if (r != null) { r.ContentType = MediaService.MimeContentType; r.Slug = entry.MediaSource.Name; GDataRequestFactory f = this.RequestFactory as GDataRequestFactory; if (f != null) { f.CustomHeaders.Add("MIME-version: 1.0"); } } if (data != null) { GDataGAuthRequest gr = request as GDataGAuthRequest; if (gr != null) { gr.AsyncData = data; } } outputStream = request.GetRequestStream(); inputStream = entry.MediaSource.Data; StreamWriter w = new StreamWriter(outputStream); w.WriteLine("Media multipart posting"); CreateBoundary(w, GDataRequestFactory.DefaultContentType); baseEntry.SaveToXml(outputStream); w.WriteLine(); CreateBoundary(w, entry.MediaSource.ContentType); WriteInputStreamToRequest(inputStream, outputStream); w.WriteLine(); w.WriteLine("--" + MediaService.MimeBoundary + "--"); w.Flush(); request.Execute(); outputStream.Close(); outputStream = null; return request.GetResponseStream(); } catch (Exception) { throw; } finally { if (outputStream != null) { outputStream.Close(); } if (inputStream != null) { inputStream.Close(); } } }
/// <summary>default constructor</summary> public virtual IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return(new GDataRequest(type, uriTarget, this)); }
/// <summary> /// default constructor. /// </summary> public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return(new GOAuth2Request(type, uriTarget, this)); }
/// <summary> /// this is a helper function for external utilities. It is not worth /// running the other insert/saves through here, as this would involve /// double buffering/copying of the bytes /// </summary> /// <param name="targetUri"></param> /// <param name="payload"></param> /// <param name="type"></param> /// <returns>Stream</returns> public Stream StringSend(Uri targetUri, String payload, GDataRequestType type) { Tracing.Assert(targetUri != null, "targetUri should not be null"); if (targetUri == null) { throw new ArgumentNullException("targetUri"); } Tracing.Assert(payload != null, "payload should not be null"); if (payload == null) { throw new ArgumentNullException("payload"); } IGDataRequest request = this.RequestFactory.CreateRequest(type,targetUri); request.Credentials = this.Credentials; Stream outputStream = request.GetRequestStream(); StreamWriter w = new StreamWriter(outputStream); w.Write(payload); w.Flush(); request.Execute(); w.Close(); return request.GetResponseStream(); }
/// <summary> /// this is a helper function for to send binary data to a resource /// it is not worth running the other insert/saves through here, as this would involve /// double buffering/copying of the bytes /// </summary> /// <param name="targetUri"></param> /// <param name="inputStream"></param> /// <param name="type"></param> /// <param name="contentType">the contenttype to use in the request, if NULL is passed, factory default is used</param> /// <param name="slugHeader">the slugHeader to use in the request, if NULL is passed, factory default is used</param> /// <returns>Stream</returns> public Stream StreamSend(Uri targetUri, Stream inputStream, GDataRequestType type, string contentType, string slugHeader) { Tracing.Assert(targetUri != null, "targetUri should not be null"); if (targetUri == null) { throw new ArgumentNullException("targetUri"); } if (inputStream == null) { Tracing.Assert(inputStream != null, "payload should not be null"); throw new ArgumentNullException("payload"); } if (type != GDataRequestType.Insert && type != GDataRequestType.Update) { Tracing.Assert(type != GDataRequestType.Insert && type != GDataRequestType.Update,"type needs to be insert or update"); throw new ArgumentNullException("type"); } IGDataRequest request = this.RequestFactory.CreateRequest(type,targetUri); request.Credentials = this.Credentials; // set the contenttype of the request if (contentType != null) { GDataRequest r = request as GDataRequest; if (r != null) { r.ContentType = contentType; } } if (slugHeader != null) { GDataRequest r = request as GDataRequest; if (r != null) { r.Slug = slugHeader; } } Stream outputStream = request.GetRequestStream(); BinaryWriter w = new BinaryWriter(outputStream); const int size = 4096; byte[] bytes = new byte[4096]; int numBytes; while((numBytes = inputStream.Read(bytes, 0, size)) > 0) { w.Write(bytes, 0, numBytes); } w.Flush(); request.Execute(); w.Close(); return request.GetResponseStream(); }
/// <summary> /// this is a helper function for to send binary data to a resource /// it is not worth running the other insert/saves through here, as this would involve /// double buffering/copying of the bytes /// </summary> /// <param name="targetUri"></param> /// <param name="inputStream"></param> /// <param name="type"></param> /// <param name="contentType">the contenttype to use in the request, if NULL is passed, factory default is used</param> /// <param name="slugHeader">the slugHeader to use in the request, if NULL is passed, factory default is used</param> /// <param name="etag">The http etag to pass into the request</param> /// <param name="data">The async data needed for notifications</param> /// <returns>Stream from the server response. You should close this stream explicitly.</returns> private Stream StreamSend(Uri targetUri, Stream inputStream, GDataRequestType type, string contentType, string slugHeader, string etag, AsyncSendData data) { Tracing.Assert(targetUri != null, "targetUri should not be null"); if (targetUri == null) { throw new ArgumentNullException("targetUri"); } if (inputStream == null) { Tracing.Assert(inputStream != null, "payload should not be null"); throw new ArgumentNullException("inputStream"); } if (type != GDataRequestType.Insert && type != GDataRequestType.Update) { Tracing.Assert(type != GDataRequestType.Insert && type != GDataRequestType.Update, "type needs to be insert or update"); throw new ArgumentNullException("type"); } IGDataRequest request = this.RequestFactory.CreateRequest(type, targetUri); request.Credentials = this.Credentials; if (data != null) { GDataGAuthRequest gr = request as GDataGAuthRequest; if (gr != null) { gr.AsyncData = data; } } // set the contenttype of the request if (contentType != null) { GDataRequest r = request as GDataRequest; if (r != null) { r.ContentType = contentType; } } if (slugHeader != null) { GDataRequest r = request as GDataRequest; if (r != null) { r.Slug = slugHeader; } } if (etag != null) { ISupportsEtag ise = request as ISupportsEtag; if (ise != null) { ise.Etag = etag; } } Stream outputStream = request.GetRequestStream(); WriteInputStreamToRequest(inputStream, outputStream); request.Execute(); outputStream.Close(); return(new GDataReturnStream(request)); }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// public virtual IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return new GDataRequest(type, uriTarget, this); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return(new GDataLoggingRequest(type, uriTarget, this, this.strInput, this.strOutput, this.strCombined)); }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataRequest(GDataRequestType type, Uri uriTarget, GDataRequestFactory factory) { this.type = type; this.targetUri = uriTarget; if (uriTarget.OriginalString.StartsWith("http:")) { factory.UseSSL = false; } this.factory = factory; this.useGZip = this.factory.UseGZip; // use gzip setting from factory }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataGAuthRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory) : base(type, uriTarget, factory as GDataRequestFactory) { // need to remember the factory, so that we can pass the new authtoken back there if need be this.factory = factory; }
/// <summary>default constructor</summary> public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return new GDataGAuthRequest(type, uriTarget, this); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { return new GDataLoggingRequest(type, uriTarget, this, this.strInput, this.strOutput, this.strCombined); }
/// <summary> /// default constructor. /// </summary> internal GOAuth2Request(GDataRequestType type, Uri uriTarget, GOAuth2RequestFactory factory) : base(type, uriTarget, factory) { _factory = factory; }
public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget) { this.RefreshToken(); return(base.CreateRequest(type, uriTarget)); }