/////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// returns a new batchfeed with all the currently dirty entries in it
        /// </summary>
        /// <param name="defaultOperation">the default operation to execute</param>
        /// <returns>AtomFeed</returns>
        public AtomFeed CreateBatchFeed(GDataBatchOperationType defaultOperation)
        {
            AtomFeed batchFeed = null;

            if (this.Batch != null)
            {
                batchFeed = new AtomFeed(this);
                // set the default operation.
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = defaultOperation;

                int id = 1;
                foreach (AtomEntry entry in this.Entries)
                {
                    if (entry.Dirty)
                    {
                        AtomEntry batchEntry = batchFeed.Entries.CopyOrMove(entry);
                        batchEntry.BatchData    = new GDataBatchEntryData();
                        batchEntry.BatchData.Id = id.ToString(CultureInfo.InvariantCulture);
                        id++;
                        entry.Dirty = false;
                    }
                }
            }
            return(batchFeed);
        }
        /// <summary>
        /// reads the current positioned reader and creates a operationtype enum
        /// </summary>
        /// <param name="reader">XmlReader positioned at the start of the status element</param>
        /// <returns>GDataBatchOperationType</returns>
        protected GDataBatchOperationType ParseOperationType(XmlReader reader)
        {
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            GDataBatchOperationType type = GDataBatchOperationType.Default;

            object localname = reader.LocalName;

            if (localname.Equals(_nameTable.BatchOperation))
            {
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        localname = reader.LocalName;
                        if (localname.Equals(_nameTable.Type))
                        {
                            type = (GDataBatchOperationType)Enum.Parse(
                                typeof(GDataBatchOperationType), Utilities.DecodedValue(reader.Value), true);
                        }
                    }
                }
            }

            return(type);
        }
        public void GDataBatchEntryDataConstructorTest1()
        {
            GDataBatchOperationType type   = GDataBatchOperationType.update;
            GDataBatchEntryData     target = new GDataBatchEntryData(type);

            Assert.IsNotNull(target);
            Assert.AreEqual(type, target.Type);
        }
        public void TypeTest()
        {
            GDataBatchFeedData      target   = new GDataBatchFeedData(); // TODO: Initialize to an appropriate value
            GDataBatchOperationType expected = GDataBatchOperationType.insert;
            GDataBatchOperationType actual;

            target.Type = expected;
            actual      = target.Type;
            Assert.AreEqual(expected, actual);
        }
        public void GDataBatchEntryDataConstructorTest()
        {
            string ID = "TestValue"; // TODO: Initialize to an appropriate value
            GDataBatchOperationType type   = GDataBatchOperationType.update;
            GDataBatchEntryData     target = new GDataBatchEntryData(ID, type);

            Assert.IsNotNull(target);
            Assert.AreEqual(type, target.Type);
            Assert.AreEqual(ID, target.Id);
        }
Exemple #6
0
        /// <summary>
        /// performs a batch operation.
        /// </summary>
        /// <param name="feed">the original feed, used to find the batch endpoing </param>
        /// <param name="entries">List of entries of type Y, that are to be batched</param>
        /// <param name="defaultOperation">indicates the default batch operationtype</param>
        /// <returns></returns>
        public Feed <Y> Batch <Y>(List <Y> entries, Feed <Y> feed, GDataBatchOperationType defaultOperation) where Y : Entry, new()
        {
            if (feed == null || feed.AtomFeed == null)
            {
                throw new ArgumentNullException("Invalid feed passed in");
            }

            if (feed.AtomFeed.Batch == null)
            {
                throw new ArgumentException("Feed has no valid batch endpoint");
            }
            return(this.Batch(entries, new Uri(feed.AtomFeed.Batch), defaultOperation));
        }
        /// <summary>
        /// takes a list of products, adds batch operation and adds each item to a feed
        /// </summary>
        /// <param name="products">the list of products to add to a feed</param>
        /// <returns>the created ProductFeed</returns>
        protected ProductFeed CreateBatchFeed(List <ProductEntry> products, GDataBatchOperationType operation)
        {
            ProductFeed feed = new ProductFeed(null, this);

            foreach (ProductEntry product in products)
            {
                if (product.BatchData != null)
                {
                    product.BatchData.Type = operation;
                }
                else
                {
                    product.BatchData = new GDataBatchEntryData(operation);
                }

                feed.Entries.Add(product);
            }

            return(feed);
        }
Exemple #8
0
        /// <summary>
        /// performs a batch operation.
        /// </summary>
        /// <param name="batchUri">the batch endpoint of the service</param>
        /// <param name="entries">List of entries of type Y, that are to be batched</param>
        /// <param name="defaultOperation">The default operation to be used for all entries</param>
        /// <returns></returns>
        public Feed <Y> Batch <Y>(List <Y> entries, Uri batchUri, GDataBatchOperationType defaultOperation) where Y : Entry, new()
        {
            if (entries.Count > 0)
            {
                AtomFeed batchFeed = new AtomFeed(batchUri, null);
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = defaultOperation;
                foreach (Y e in entries)
                {
                    batchFeed.Entries.Add(e.AtomEntry);
                }

                FeedQuery q = PrepareQuery <FeedQuery>(batchUri.AbsoluteUri);

                AtomFeed resultFeed = this.Service.Batch(batchFeed, q.Uri);
                Feed <Y> f          = new Feed <Y>(resultFeed);
                return(f);
            }

            return(null);
        }
        /// <summary>
        /// takes a list of products, adds batch operation and adds each item to a feed
        /// </summary>
        /// <param name="products">the list of products to add to a feed</param>
        /// <returns>the created ProductFeed</returns>
        protected ProductFeed CreateBatchFeed(List<ProductEntry> products, GDataBatchOperationType operation) {
            ProductFeed feed = new ProductFeed(null, this);

            foreach(ProductEntry product in products)
            {
                if (product.BatchData != null) {
                    product.BatchData.Type = operation;
                }
                else {
                    product.BatchData = new GDataBatchEntryData(operation);
                }

                feed.Entries.Add(product);
            }

            return feed;
        }
Exemple #10
0
        /////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// returns a new batchfeed with all the currently dirty entries in it
        /// </summary>
        /// <param name="defaultOperation">the default operation to execute</param>
        /// <returns>AtomFeed</returns>
        public AtomFeed CreateBatchFeed(GDataBatchOperationType defaultOperation)
        {
            AtomFeed batchFeed = null;
            
            if (this.Batch != null)
            {

                batchFeed = new AtomFeed(this);
                // set the default operation. 
                batchFeed.BatchData = new GDataBatchFeedData();
                batchFeed.BatchData.Type = defaultOperation;
    
                int id = 1; 
                foreach (AtomEntry entry in this.Entries)
                {
                    if (entry.Dirty == true)
                    {
                        int i = batchFeed.Entries.Add(entry); 
                        AtomEntry batchEntry = batchFeed.Entries[i]; 
                        batchEntry.BatchData = new GDataBatchEntryData();
                        batchEntry.BatchData.Id = id.ToString(); 
                        id++;
                        entry.Dirty = false;
                    }
                }
    
            }
            return batchFeed;
        }
 /// <summary>
 /// Constructor for the batch data
 /// </summary>
 /// <param name="type">The batch operation to be performed</param>
 public GDataBatchEntryData(GDataBatchOperationType type)
 {
     this.Type = type;
 }
Exemple #12
0
 /// <summary>
 /// constructor, sets the default for the operation type
 /// </summary>
 public GDataBatchEntryData()
 {
     this.operationType = GDataBatchOperationType.Default;
 }
Exemple #13
0
 /// <summary>
 /// constructor, set's the default for the operation type
 /// </summary>
 public GDataBatchFeedData()
 {
     this.operationType = GDataBatchOperationType.Default;
 }
Exemple #14
0
 /// <summary>
 /// Constructor for batch data
 /// </summary>
 /// <param name="id">The batch ID of this entry</param>
 /// <param name="type">The batch operation to be performed</param>
 public GDataBatchEntryData(string id, GDataBatchOperationType type)
     : this(type) {
     this.Id = id;
 }
 /// <summary>
 /// constructor, set's the default for the operation type
 /// </summary>
 public GDataBatchFeedData()
 {
     this.operationType = GDataBatchOperationType.Default;
 }
 /// <summary>
 /// constructor, sets the default for the operation type
 /// </summary>
 public GDataBatchEntryData()
 {
     this.operationType = GDataBatchOperationType.Default;
 }
Exemple #17
0
 /// <summary>
 /// Constructor for the batch data
 /// </summary>
 /// <param name="type">The batch operation to be performed</param>
 public GDataBatchEntryData(GDataBatchOperationType type)
 {
     this.Type = type;
 }
 /// <summary>
 /// Constructor for batch data
 /// </summary>
 /// <param name="id">The batch ID of this entry</param>
 /// <param name="type">The batch operation to be performed</param>
 public GDataBatchEntryData(string id, GDataBatchOperationType type)
     : this(type) {
     this.Id = id;
 }
Exemple #19
0
 /// <summary>
 /// Constructor for batch data
 /// </summary>
 /// <param name="ID">The batch ID of this entry</param>
 /// <param name="type">The batch operation to be performed</param>
 public GDataBatchEntryData(string ID, GDataBatchOperationType type) : this(type)
 {
     this.Id = ID;
 }