//////////////////////////////////////////////////////////////////////
 /// <summary>Writes a feed or entry to stdout.</summary>
 //////////////////////////////////////////////////////////////////////
 protected void WriteToStandardOutput(AtomBase atomBase)
 {
     XmlTextWriter xmlWriter = new XmlTextWriter(Console.Out);
     xmlWriter.Formatting = Formatting.Indented;
     xmlWriter.Indentation = 2;
     atomBase.SaveToXml(xmlWriter);
     xmlWriter.Flush();
 }
Ejemplo n.º 2
0
        /// <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());
        }
Ejemplo n.º 3
0
       /////////////////////////////////////////////////////////////////////////////




       //////////////////////////////////////////////////////////////////////
       /// <summary>dump feeds</summary> 
       /// <param name="theOne">the filenam</param>
       //////////////////////////////////////////////////////////////////////
       public static void DumpAtomObject(AtomBase atom, string baseName)
       {
           if (atom != null)
           {
               StreamWriter stream = new StreamWriter(baseName, false, System.Text.Encoding.UTF8); 
               XmlTextWriter writer =  new XmlTextWriter(stream);
               writer.Formatting = Formatting.Indented;
               writer.WriteStartDocument(false);
               atom.SaveToXml(writer);
               writer.Flush();
               writer.Close();
               stream.Close();
           }
       }
Ejemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////////////
 

        //////////////////////////////////////////////////////////////////////
        /// <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();
                }
            }
        }
Ejemplo n.º 5
0
        //////////////////////////////////////////////////////////////////////
        /// <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();
        }
Ejemplo n.º 6
0
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <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();
                }
            }
        }