コード例 #1
0
        //Post data to Google Docs
        //Worksheets names within speadsheet have been set to the monitor names
        //Monitor name will be used to identify worksheet within which to post data.
        public static bool postDataWorkSheetByMonitor(ExternalSnapshots _externalSnapshots)
        {
            IDictionary<string, ListFeed> workSheetList = new Dictionary<string, ListFeed>();
            WorksheetFeed wsFeed = spreadSheet.Worksheets;
            AtomLink listFeedLink1;
            ListQuery listQuery1;
            ListFeed listFeed1;

            try
            {

                // loop on worksheets
                // Fetch the list feed of the worksheet.
                // The listfeed is required to post data to the worksheet
                // create collection of key/value pairs where the key is the worksheet name and the value is the listfeed for the worksheet
                foreach (WorksheetEntry ws in wsFeed.Entries)
                {

                    listFeedLink1 = ws.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
                    listQuery1 = new ListQuery(listFeedLink1.HRef.ToString());
                    listFeed1 = spreadSheetsService.Query(listQuery1);

                    workSheetList.Add(ws.Title.Text, listFeed1);
                }

                //row to post
                ListEntry row;

                //loop on the externalSnapshots.
                //each entry within the reultList will be used to compose a row for posting to the Goolge spreadsheet
                foreach (ExternalSnapshot externalSnapshot in _externalSnapshots.resultList)
                {
                    foreach (Data dataToPost in externalSnapshot.data)
                    {
                        row = new ListEntry();
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "id", Value = dataToPost.id.ToString() });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "type", Value = dataToPost.testType });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "name", Value = dataToPost.name });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "perf", Value = dataToPost.perf.ToString() });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "time", Value = dataToPost.time });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "status", Value = dataToPost.time });
                        row.Elements.Add(new ListEntry.Custom() { LocalName = "location", Value = externalSnapshot.locationShortName });

                        // Send the new row to the Google Spreadsheets API for insertion.
                        row = spreadSheetsService.Insert(workSheetList[dataToPost.name], row); ;

                    }
                }

            }
            catch (Exception _exception)
            {
                MessageBox.Show(_exception.Message);
                return false;
            }

            return true;
        }
コード例 #2
0
        private void buttonPostData_Click(object sender, RoutedEventArgs e)
        {
            //get data from Monitis account for all the locations from which your services are being monitored
            externalSnapshots = MonitisService.getExternalSnapshots(locationsUsed.listOfUsedLocationIds);
            //set column headers
            GoogleDocs.GoogleSpreadSheetService.setWorkSheetHeadersByWorksheet();
            if (GoogleDocs.GoogleSpreadSheetService.postDataWorkSheetByMonitor(externalSnapshots))
            {
                labelStatus.Content = "Posting to Google Spreadsheet completed!";
            } else
            {
                labelStatus.Content = "Error encountered whilst posting data to Google Spreadsheet!";
            }

            buttonPostData.IsEnabled = false;
        }
コード例 #3
0
        //this methos posts the data to the first workSheet withiin the spreadSheet
        public static void postDataToSameWorkSheet(ExternalSnapshots _externalSnapshots)
        {
            WorksheetFeed wsFeed = spreadSheet.Worksheets;
            WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

            // Define the URL to request the list feed of the worksheet.
            AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

            // Fetch the list feed of the worksheet.
            ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
            ListFeed listFeed = spreadSheetsService.Query(listQuery);

            ListEntry row;

            foreach (ExternalSnapshot externalSnapshot in _externalSnapshots.resultList)
            {
                foreach (Data dataToPost in externalSnapshot.data)
                {
                    row = new ListEntry();
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "id", Value = dataToPost.id.ToString() });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "type", Value = dataToPost.testType });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "name", Value = dataToPost.name });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "perf", Value = dataToPost.perf.ToString() });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "time", Value = dataToPost.time });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "status", Value = dataToPost.time });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "location", Value = externalSnapshot.locationShortName });

                    // Send the new row to the API for insertion.
                    row = spreadSheetsService.Insert(listFeed, row); ;

                }
            }
        }