Beispiel #1
0
 public GetCommand(GBaseService service,
                   GBaseUriFactory uriFactory,
                   string url)
     : base(service, uriFactory)
 {
     this.url = url;
 }
Beispiel #2
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses command-line options</summary>
        /// <param name="args">command-line arguments</summary>
        /// <param name="argsIndex">the first argument to check in
        /// args</param>
        /// <param name="applicationName">name of the current application
        /// </param>
        /// <returns>the rest of the command-line argument (the first
        /// argument that's not an option</returns>
        //////////////////////////////////////////////////////////////////////
        public string[] Init(string[] args,
                             int argsIndex,
                             string applicationName)
        {
            while (argsIndex < args.Length && args[argsIndex].StartsWith("-"))
            {
                string arg = args[argsIndex];
                argsIndex++;
                if (argsIndex >= args.Length)
                {
                    FatalError("Expected a parameter value " + "after " + arg);
                }
                string value = args[argsIndex];
                argsIndex++;
                if (!ParseArg(arg, value))
                {
                    FatalError("Unknown parameter: " + arg);
                }
            }

            // service.query does a GET on the url above and parses the result,
            // which is an ATOM feed with some extensions (called the Google Base
            // data API items feed).
            service = new GBaseService(applicationName, developerKey);

            // Return the rest of the arguments
            if (argsIndex > 0)
            {
                string[] newargs = new string[args.Length - argsIndex];
                System.Array.Copy(args, argsIndex, newargs, 0, newargs.Length);
                return(newargs);
            }
            return(args);
        }
Beispiel #3
0
 public QueryCommand(GBaseService service,
                     GBaseUriFactory uriFactory,
                     string queryString)
     : base(service, uriFactory)
 {
     this.queryString = queryString;
 }
Beispiel #4
0
 public DeleteCommand(GBaseService service,
                      GBaseUriFactory uriFactory,
                      string uri)
     : base(service, uriFactory)
 {
     this.uri = new Uri(uri);
 }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>Loads a test file with an error return</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseErrorTest()
        {
            Tracing.TraceMsg("Entering GoogleBaseErrorTest");

            FeedQuery query = new FeedQuery();

            Uri uri = new Uri(CreateUri(this.resourcePath + "batcherror.xml"));

            query.Uri = uri;
            Service service = new GBaseService(this.ApplicationName, this.gBaseKey);


            AtomFeed errorFeed = service.Query(query);

            foreach (AtomEntry errorEntry in errorFeed.Entries)
            {
                GDataBatchEntryData data = errorEntry.BatchData;
                if (data.Status.Code == 400)
                {
                    Assert.IsTrue(data.Status.Errors.Count == 2);
                    GDataBatchError error = data.Status.Errors[0];

                    Assert.IsTrue(error.Type == "data");
                    Assert.IsTrue(error.Field == "expiration_date");
                    Assert.IsTrue(error.Reason != null);
                    Assert.IsTrue(error.Reason.StartsWith("Invalid type specified"));

                    error = data.Status.Errors[1];

                    Assert.IsTrue(error.Type == "data");
                    Assert.IsTrue(error.Field == "price_type");
                    Assert.IsTrue(error.Reason == "Invalid price type");
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchDelete()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchDelete");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);

                Tracing.TraceMsg("Queried");

                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");


                AtomFeed batchFeed = new AtomFeed(new Uri(this.gBaseURI), service);

                // set the default operation.
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.delete;

                Tracing.TraceMsg("Pouet ?");

                int i = 1;
                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    AtomEntry batchEntry = new AtomEntry();
                    batchEntry.Id = entry.Id;

                    batchEntry.BatchData      = new GDataBatchEntryData();
                    batchEntry.BatchData.Id   = i.ToString();
                    batchEntry.BatchData.Type = GDataBatchOperationType.delete;

                    batchFeed.Entries.Add(batchEntry);
                    i++;
                }
                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));
                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 200, "Status code should be 200, is:" + data.Status.Code);
                }
            }
        }
        public void GoogleBaseBatchInsert()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchUpload");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;



                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);

                // this should have a batch URI

                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                AtomFeed batchFeed = new AtomFeed(new Uri(this.gBaseURI), service);

                // set the default operation. Unneeded, as the default is insert,
                // but want to make sure the code is complete
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.delete;



                for (int i = 0; i < 20; i++)
                {
                    AtomEntry entry = ObjectModelHelper.CreateGoogleBaseEntry(i);
                    entry.BatchData = new GDataBatchEntryData();

                    entry.BatchData.Type = GDataBatchOperationType.insert;
                    entry.BatchData.Id   = i.ToString();

                    batchFeed.Entries.Add(entry);
                }

                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 201, "Status code should be 201, is:" + data.Status.Code);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchUpdateSameFeed()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchUpdateSameFeed");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);
                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                int i = 0;

                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    entry.BatchData      = new GDataBatchEntryData();
                    entry.BatchData.Id   = i.ToString();
                    entry.BatchData.Type = GDataBatchOperationType.update;
                    entry.Title.Text     = "Updated";
                    i++;
                }



                AtomFeed resultFeed = service.Batch(baseFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    Assert.IsTrue(data.Status.Code == 200, "Status code should be 200, is:" + data.Status.Code);
                }
            }
        }
Beispiel #9
0
        // Keywords initialisation
        public string[] Init(string[] keywords, string dKey, string applicationName)
        {
            int keywordsIndex = 0;

            developerKey = dKey;

            // service.query does a GET on the url above and parses the result,
            // which is an ATOM feed with some extensions (called the Google Base
            // data API items feed).
            service = new GBaseService(applicationName, developerKey);

            // Return the rest of the arguments
            if (keywordsIndex > 0)
            {
                string[] newkeywords = new string[keywords.Length - keywordsIndex];
                System.Array.Copy(keywords, keywordsIndex, newkeywords, 0, newkeywords.Length);
                return(newkeywords);
            }
            return(keywords);
        }
Beispiel #10
0
 protected CommandBase(GBaseService service, GBaseUriFactory uriFactory)
 {
     this.service    = service;
     this.uriFactory = uriFactory;
 }
Beispiel #11
0
 public BatchCommand(GBaseService service,
                     GBaseUriFactory uriFactory)
     : base(service, uriFactory)
 {
 }
Beispiel #12
0
 public UpdateCommand(GBaseService service,
                      GBaseUriFactory uriFactory)
     : base(service, uriFactory)
 {
 }
Beispiel #13
0
 public InsertCommand(GBaseService service, GBaseUriFactory uriFactory)
     : base(service, uriFactory)
 {
 }
        /////////////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a batch upload test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseBatchMix()
        {
            Tracing.TraceMsg("Entering GoogleBaseBatchMix");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);


            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);
                // this should have a batch URI
                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                AtomFeed batchFeed = new AtomFeed(baseFeed);

                // set the default operation.
                batchFeed.BatchData      = new GDataBatchFeedData();
                batchFeed.BatchData.Type = GDataBatchOperationType.insert;

                int  id      = 1;
                bool fUpdate = true;
                foreach (AtomEntry entry in baseFeed.Entries)
                {
                    AtomEntry batchEntry = batchFeed.Entries.CopyOrMove(entry);

                    if (fUpdate == true)
                    {
                        batchEntry.BatchData      = new GDataBatchEntryData();
                        batchEntry.BatchData.Id   = id.ToString();
                        batchEntry.BatchData.Type = GDataBatchOperationType.update;
                        batchEntry.Title.Text     = "Updated";
                        fUpdate = false;
                    }
                    else
                    {
                        batchEntry.BatchData      = new GDataBatchEntryData();
                        batchEntry.BatchData.Id   = id.ToString();
                        batchEntry.BatchData.Type = GDataBatchOperationType.delete;
                        fUpdate = true;
                    }


                    // insert one
                    id++;
                    batchEntry                = ObjectModelHelper.CreateGoogleBaseEntry(1);
                    batchEntry.BatchData      = new GDataBatchEntryData();
                    batchEntry.BatchData.Type = GDataBatchOperationType.insert;
                    batchEntry.BatchData.Id   = id.ToString();
                    batchFeed.Entries.Add(batchEntry);
                    id++;
                }



                AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));

                foreach (AtomEntry resultEntry in resultFeed.Entries)
                {
                    GDataBatchEntryData data = resultEntry.BatchData;
                    int testcode             = 200;
                    if (data.Type == GDataBatchOperationType.insert)
                    {
                        testcode = 201;
                    }
                    Assert.IsTrue(data.Status.Code == testcode, "Status code should be: " + testcode + ", is:" + data.Status.Code);
                }
            }
        }
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleBaseAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Base AuthenticationTest");

            FeedQuery query   = new FeedQuery();
            Service   service = new GBaseService(this.ApplicationName, this.gBaseKey);

            int iCount;

            if (this.gBaseURI != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                service.RequestFactory = this.factory;

                query.Uri = new Uri(this.gBaseURI);
                AtomFeed baseFeed = service.Query(query);


                // this should have a batch URI

                Assert.IsTrue(baseFeed.Batch != null, "This is a base Feed, it should have batch URI");

                ObjectModelHelper.DumpAtomObject(baseFeed, CreateDumpFileName("AuthenticationTest"));
                iCount = baseFeed.Entries.Count;

                String strTitle = "Dinner time" + Guid.NewGuid().ToString();

                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // get the first entry
                    AtomEntry entry = baseFeed.Entries[0];

                    entry            = ObjectModelHelper.CreateGoogleBaseEntry(1);
                    entry.Title.Text = strTitle;

                    GBaseEntry newEntry = baseFeed.Insert(entry) as GBaseEntry;

                    newEntry.PublishingPriority = new PublishingPriority("high");

                    GBaseEntry updatedEntry = newEntry.Update() as GBaseEntry;

                    //  publishing priority does not seem to be echoed back
                    // Assert.IsTrue(updatedEntry.PublishingPriority.Value == "high");
                    iCount++;
                    Tracing.TraceMsg("Created google base  entry");

                    // try to get just that guy.....
                    FeedQuery singleQuery = new FeedQuery();
                    singleQuery.Uri = new Uri(newEntry.SelfUri.ToString());

                    AtomFeed newFeed = service.Query(singleQuery);

                    AtomEntry sameGuy = newFeed.Entries[0];

                    Assert.IsTrue(sameGuy.Title.Text.Equals(newEntry.Title.Text), "both titles should be identical");
                }

                baseFeed = service.Query(query);


                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in baseFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
                        if (String.Compare(entry.Title.Text, strTitle) == 0)
                        {
                            entry.Content.Content = "Maybe stay until breakfast";
                            entry.Content.Type    = "text";
                            entry.Update();
                            Tracing.TraceMsg("Updated entry");
                        }
                    }
                }

                baseFeed = service.Query(query);

                if (baseFeed != null && baseFeed.Entries.Count > 0)
                {
                    // look for the one with dinner time...
                    foreach (AtomEntry entry in baseFeed.Entries)
                    {
                        Tracing.TraceMsg("Entrie title: " + entry.Title.Text);
                        if (String.Compare(entry.Title.Text, strTitle) == 0)
                        {
                            entry.Delete();
                            iCount--;
                            Tracing.TraceMsg("deleted entry");
                        }
                    }
                }
                baseFeed            = service.Query(query);
                service.Credentials = null;
            }
        }