public void ContentTypeTest()
        {
            GDataBatchStatus target   = new GDataBatchStatus(); // TODO: Initialize to an appropriate value
            string           expected = "TestValue";
            string           actual;

            target.ContentType = expected;
            actual             = target.ContentType;
            Assert.AreEqual(expected, actual);
        }
        public void StatusTest()
        {
            GDataBatchEntryData target   = new GDataBatchEntryData(); // TODO: Initialize to an appropriate value
            GDataBatchStatus    expected = new GDataBatchStatus();
            GDataBatchStatus    actual;

            target.Status = expected;
            actual        = target.Status;
            Assert.AreEqual(expected, actual);
        }
        public void CodeTest()
        {
            GDataBatchStatus target = new GDataBatchStatus(); // TODO: Initialize to an appropriate value
            int expected            = 27;                     // TODO: Initialize to an appropriate value
            int actual;

            target.Code = expected;
            actual      = target.Code;
            Assert.AreEqual(expected, actual);
        }
Example #4
0
        private void WriteDataImpl(string spreadsheetUri, string worksheetUri, StandardTableDataCM data, GoogleAuthDTO authDTO)
        {
            if (String.IsNullOrEmpty(spreadsheetUri))
            {
                throw new ArgumentNullException("Spreadsheet Uri parameter is required.");
            }
            if (string.IsNullOrEmpty(worksheetUri))
            {
                throw new ArgumentNullException("Worksheet Uri parameter is required.");
            }

            if (data != null && data.Table.Count > 0)
            {
                int MAX_ROWS = data.Table.Count;
                int MAX_COLS = data.Table[0].Row.Count;

                SpreadsheetEntry spreadsheet = FindSpreadsheet(spreadsheetUri, authDTO);
                if (spreadsheet == null)
                {
                    throw new ArgumentException("Cannot find a spreadsheet", "spreadsheetUri");
                }
                SpreadsheetsService service = (SpreadsheetsService)spreadsheet.Service;

                string worksheetId   = worksheetUri.Substring(worksheetUri.LastIndexOf('/') + 1, worksheetUri.Length - (worksheetUri.LastIndexOf('/') + 1));
                string spreadSheetId = spreadsheetUri;
                if (spreadSheetId.ToLower().Contains("http"))//remove http url
                {
                    spreadSheetId = spreadSheetId.Substring(spreadSheetId.LastIndexOf('/') + 1, spreadSheetId.Length - (spreadSheetId.LastIndexOf('/') + 1));
                }

                CellQuery cellQuery = new CellQuery(spreadSheetId, worksheetId, "private", "full");
                CellFeed  cellFeed  = service.Query(cellQuery);

                // Build list of cell addresses to be filled in
                List <CellAddress> cellAddrs = new List <CellAddress>();
                for (int row = 0; row < MAX_ROWS; row++)
                {
                    for (int col = 0; col < MAX_COLS; col++)
                    {
                        cellAddrs.Add(new CellAddress(row + 1, col + 1, data.Table[row].Row[col].Cell.Value));
                    }
                }

                // Prepare the update
                // GetCellEntryMap is what makes the update fast.
                Dictionary <String, CellEntry> cellEntries = GetCellEntryMap(service, cellFeed, cellAddrs);

                CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);
                foreach (CellAddress cellAddr in cellAddrs)
                {
                    CellEntry batchEntry = cellEntries[cellAddr.IdString];
                    batchEntry.InputValue = cellAddr.InputValue;
                    batchEntry.BatchData  = new GDataBatchEntryData(cellAddr.IdString, GDataBatchOperationType.update);
                    batchRequest.Entries.Add(batchEntry);
                }

                // Submit the update
                CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));

                // Check the results
                foreach (CellEntry entry in batchResponse.Entries)
                {
                    string batchId = entry.BatchData.Id;
                    if (entry.BatchData.Status.Code != 200)
                    {
                        GDataBatchStatus status = entry.BatchData.Status;
                        throw new Exception(string.Format("{0} failed ({1})", batchId, status.Reason));
                    }
                }
            }
        }
    static void Main(string[] args)
    {
        string key;

        // Command line parsing
        if (args.Length != 1)
        {
            Console.Error.WriteLine("Syntax: BatchCellUpdater <key>");
            return;
        }
        else
        {
            key = args[0];
        }

        // Prepare Spreadsheet Service
        SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");

        // TODO: Authorize the service object for a specific user (see other sections)

        CellQuery cellQuery = new CellQuery(key, "od6", "private", "full");
        CellFeed  cellFeed  = service.Query(cellQuery);

        // Build list of cell addresses to be filled in
        List <CellAddress> cellAddrs = new List <CellAddress>();

        for (uint row = 1; row <= MAX_ROWS; ++row)
        {
            for (uint col = 1; col <= MAX_COLS; ++col)
            {
                cellAddrs.Add(new CellAddress(row, col));
            }
        }

        // Prepare the update
        // GetCellEntryMap is what makes the update fast.
        Dictionary <String, CellEntry> cellEntries = GetCellEntryMap(service, cellFeed, cellAddrs);

        CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);

        foreach (CellAddress cellAddr in cellAddrs)
        {
            CellEntry batchEntry = cellEntries[cellAddr.IdString];
            batchEntry.InputValue = cellAddr.IdString;
            batchEntry.BatchData  = new GDataBatchEntryData(cellAddr.IdString, GDataBatchOperationType.update);
            batchRequest.Entries.Add(batchEntry);
        }

        // Submit the update
        CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));

        // Check the results
        bool isSuccess = true;

        foreach (CellEntry entry in batchResponse.Entries)
        {
            string batchId = entry.BatchData.Id;
            if (entry.BatchData.Status.Code != 200)
            {
                isSuccess = false;
                GDataBatchStatus status = entry.BatchData.Status;
                Console.WriteLine("{0} failed ({1})", batchId, status.Reason);
            }
        }

        Console.WriteLine(isSuccess ? "Batch operations successful." : "Batch operations failed");
    }