public override void Log(LoggingEntery LE) { IniFile Ini = new IniFile(Path.Combine(Environment.CurrentDirectory, "GoogleDocs.ini")); // nir start //////////////////////////////////////////////////////////////////////////// // STEP 1: Configure how to perform OAuth 2.0 //////////////////////////////////////////////////////////////////////////// // TODO: Update the following information with that obtained from // https://code.google.com/apis/console. After registering // your application, these will be provided for you. //string CLIENT_ID = "339569043085-6k0io9kdubi7a3g3jes4m76t614fkccr.apps.googleusercontent.com"; // This is the OAuth 2.0 Client Secret retrieved // above. Be sure to store this value securely. Leaking this // value would enable others to act on behalf of your application! //string CLIENT_SECRET = "wWC4Wcb12RbQg4YuGWJtkh4j"; // Space separated list of scopes for which to request access. //string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds"; // This is the Redirect URI for installed applications. // If you are building a web application, you have to set your // Redirect URI at https://code.google.com/apis/console. //tring REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"; //////////////////////////////////////////////////////////////////////////// // STEP 2: Set up the OAuth 2.0 object //////////////////////////////////////////////////////////////////////////// // OAuth2Parameters holds all the parameters related to OAuth 2.0. OAuth2Parameters parameters = new OAuth2Parameters(); // Set your OAuth 2.0 Client Id (which you can register at // https://code.google.com/apis/console). parameters.ClientId = Ini.IniReadValue(ConnectSection,"ClientID"); // Set your OAuth 2.0 Client Secret, which can be obtained at // https://code.google.com/apis/console. parameters.ClientSecret = Ini.IniReadValue(ConnectSection,"ClientSecret"); // Set your Redirect URI, which can be registered at // https://code.google.com/apis/console. parameters.RedirectUri = Ini.IniReadValue(ConnectSection,"RedirectURI"); // Set your refresh token parameters.RefreshToken = Ini.IniReadValue(ConnectSection,"RefreshToken"); parameters.AccessToken = Ini.IniReadValue(ConnectSection,"LastAccessToken"); // Set the scope for this particular service. parameters.Scope = Ini.IniReadValue(ConnectSection,"Scope"); // Get the authorization url. The user of your application must visit // this url in order to authorize with Google. If you are building a // browser-based application, you can redirect the user to the authorization // url. //string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); //Console.WriteLine(authorizationUrl); //Console.WriteLine("Please visit the URL above to authorize your OAuth " // + "request token. Once that is complete, type in your access code to " // + "continue..."); //////////////////////////////////////////////////////////////////////////// // STEP 4: Get the Access Token //////////////////////////////////////////////////////////////////////////// // Once the user authorizes with Google, the request token can be exchanged // for a long-lived access token. If you are building a browser-based // application, you should parse the incoming request token from the url and // set it in OAuthParameters before calling GetAccessToken(). OAuthUtil.RefreshAccessToken(parameters);//parameters.AccessToken; Ini.IniWriteValue(ConnectSection,"LastAccessToken",parameters.AccessToken); // Console.WriteLine("OAuth Access Token: " + accessToken); //////////////////////////////////////////////////////////////////////////// // STEP 5: Make an OAuth authorized request to Google //////////////////////////////////////////////////////////////////////////// // Initialize the variables needed to make the request GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "OctoTipPlus", parameters); SpreadsheetsService myService = new SpreadsheetsService("OctoTipPlus"); myService.RequestFactory = requestFactory; // nir end string User = Ini.IniReadValue("UserLogin","User"); string Password = Ini.IniReadValue("UserLogin","Password"); // SpreadsheetsService myService = new SpreadsheetsService("MySpreadsheetIntegration-v1"); //myService.setUserCredentials(User,Password); SpreadsheetQuery Squery = new SpreadsheetQuery(); string Sender = LE.Sender; Squery.Title = Sender; Squery.Exact = true; SpreadsheetFeed Sfeed; try { Sfeed = myService.Query(Squery); } catch (Google.GData.Client.InvalidCredentialsException e) { throw(new Exception(string.Format("Credentials error in google acount for user:{0}",User),e)); } if(Sfeed.Entries.Count == 0) { //DriveService service1 = new DriveService(); //service.SetAuthenticationToken(parameters.AccessToken);//.setUserCredentials(User,Password); //Google.GData.Client.GOAuth2RequestFactory requestf = new Google.GData.Client.GOAuth2RequestFactory(null, "OctoTipPlus",parameters); OAuthUtil.RefreshAccessToken(parameters);//parameters.AccessToken; Ini.IniWriteValue(ConnectSection,"LastAccessToken",parameters.AccessToken); Google.GData.Documents.DocumentsService service = new Google.GData.Documents.DocumentsService("OctoTipPlus"); GOAuth2RequestFactory requestFactory2 = new GOAuth2RequestFactory(null, "OctoTipPlus", parameters); service.RequestFactory = requestFactory2; //service.RequestFactory=requestf; // Instantiate a DocumentEntry object to be inserted. Google.GData.Documents.DocumentEntry entry = new Google.GData.Documents.DocumentEntry(); // Set the document title entry.Title.Text = LE.Sender; // Add the document category entry.Categories.Add(Google.GData.Documents.DocumentEntry.SPREADSHEET_CATEGORY); // Make a request to the API and create the document. Google.GData.Documents.DocumentEntry newEntry = service.Insert( Google.GData.Documents.DocumentsListQuery.documentsBaseUri, entry); Squery = new SpreadsheetQuery(); Squery.Title = Sender; Squery.Exact = true; Sfeed = myService.Query(Squery); } SpreadsheetEntry spreadsheet = (SpreadsheetEntry)Sfeed.Entries[0]; WorksheetEntry ProtocolWorksheetEntry=null; AtomLink link = spreadsheet.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null); WorksheetQuery Wquery = new WorksheetQuery(link.HRef.ToString()); WorksheetFeed Wfeed = myService.Query(Wquery); foreach (WorksheetEntry worksheet in Wfeed.Entries) { if (worksheet.Title.Text==LE.SubSender) { ProtocolWorksheetEntry = worksheet; } } if (ProtocolWorksheetEntry==null) { // cteate new worksheet WorksheetEntry worksheet = new WorksheetEntry(); worksheet.Title.Text = LE.SubSender; worksheet.Cols = 3; worksheet.Rows = 5; // Send the local representation of the worksheet to the API for // creation. The URL to use here is the worksheet feed URL of our // spreadsheet. WorksheetFeed wsFeed = spreadsheet.Worksheets; ProtocolWorksheetEntry = myService.Insert(wsFeed, worksheet); CellFeed cellFeed= ProtocolWorksheetEntry.QueryCellFeed(); CellEntry cellEntry= new CellEntry (1, 1,DateHeader); cellFeed.Insert(cellEntry); cellEntry= new CellEntry (1, 2, MessageHeader); cellFeed.Insert(cellEntry); } // Define the URL to request the list feed of the worksheet. AtomLink listFeedLink = ProtocolWorksheetEntry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); // Fetch the list feed of the worksheet. ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString()); ListFeed listFeed = myService.Query(listQuery); string Message = string.Format("{0}\n{1}",LE.Title,LE.Message); // Create a local representation of the new row. ListEntry row = new ListEntry(); row.Elements.Add(new ListEntry.Custom() { LocalName = DateHeader, Value = DateTime.Now.ToString() }); row.Elements.Add(new ListEntry.Custom() { LocalName = MessageHeader, Value = Message }); // Send the new row to the API for insertion. myService.Insert(listFeed, row); }
private static Dictionary<string, CellEntry> CreateEntryCellsMap(SpreadsheetsService service, CellFeed cellFeed, List<ExcelCell> cells) { Dictionary<string, CellEntry> res = new Dictionary<string, CellEntry>(); CellFeed batchRequest = new CellFeed(new Uri(cellFeed.Self), service); foreach (ExcelCell cell in cells) { if (cell.GetEntry() == null) { CellEntry batchEntry = new CellEntry(cell.Row, cell.Column, cell.GetBatchID()); batchEntry.Id = new AtomId(string.Format("{0}/{1}", cellFeed.Self, cell.GetBatchID())); batchEntry.BatchData = new GDataBatchEntryData(cell.GetBatchID(), GDataBatchOperationType.query); batchRequest.Entries.Add(batchEntry); } else { if (!res.ContainsKey(cell.GetBatchID())) { res.Add(cell.GetBatchID(), cell.GetEntry()); } } } if (batchRequest.Entries.Count > 0) { CellFeed queryBatchResponse = (CellFeed) service.Batch(batchRequest, new Uri(cellFeed.Batch)); foreach (CellEntry entry in queryBatchResponse.Entries) { res.Add(entry.BatchData.Id, entry); } } return res; }
public CellEntry this[uint row, uint column] { get { // let's find the cell foreach (CellEntry entry in this.Entries) { CellEntry.CellElement cell = entry.Cell; if (cell.Row == row && cell.Column == column) { return(entry); } } // if we are here, we need to get the entry from the service string url = CellUri(row, column); CellQuery query = new CellQuery(url); CellFeed feed = this.Service.Query(query) as CellFeed; CellEntry newEntry = feed.Entries[0] as CellEntry; this.Entries.Add(newEntry); // we don't want this one to show up in the batch feed on it's own newEntry.Dirty = false; return(newEntry); } }
public Google2uCell(CellEntry in_entry) { if (in_entry == null) return; _MyCell = in_entry; RowNum = (int) _MyCell.Row; ColNum = (int) _MyCell.Column; }
public void CreateHeader(WorksheetEntry worksheet, IList<string> cellHeaders) { var cellFeed = GetCellFeed(worksheet); for (var i = 0; i < cellHeaders.Count; i++) { var cellEntry = new CellEntry(1, (uint)(i + 1), cellHeaders[i]); cellFeed.Insert(cellEntry); } }
public ExcelCell(ExcelRow row, CellEntry entry) { _entry = entry; _row = row; if (null != entry) { Column = entry.Column; Row = entry.Row; decimal val; if (ApiUtils.TryDecimalParse(entry.NumericValue, out val)) { Value = val; } } }
public void PopulateNewWorksheet(OAuth2ClientCredentials clientCredentials, string refreshToken, string spreadsheetTitle, string worksheetTitle, ListEntry.Custom[,] listEntries) { SpreadsheetsService service = GetSpreadsheetService(clientCredentials, refreshToken); SpreadsheetQuery query = new SpreadsheetQuery() { Title = spreadsheetTitle, }; SpreadsheetFeed feed = service.Query(query); if (feed.Entries.Count == 0) throw new SpreadsheetNotFoundException(string.Format("Spreadsheet with title {0} not found", spreadsheetTitle)); WorksheetEntry worksheet = CreateWorksheet(worksheetTitle, (uint)listEntries.GetLength(0), (uint)listEntries.GetLength(1), service, feed); CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink); CellFeed cellFeed = service.Query(cellQuery); for (int i = 0; i < listEntries.GetLength(1); i++) { CellEntry cellEntry = new CellEntry(1, (uint)i + 1, listEntries[0, i].LocalName); service.Insert(cellFeed, cellEntry); } AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString()); ListFeed listFeed = service.Query(listQuery); for (int i = 1; i < listEntries.GetLength(0); i++) { ListEntry row = new ListEntry(); for (int j = 0; j < listEntries.GetLength(1); j++) { if (listEntries[i, j] != null) { listEntries[i, j].LocalName = listEntries[i, j].LocalName.ToLower().Replace(" ",""); row.Elements.Add(listEntries[i, j]); } } LoggerUtil.LogMessage(string.Format("Adding row for {0}", listEntries[i, 0].Value)); service.Insert(listFeed, row); } }
/// <summary> /// Get cells in the given <paramref name="worksheet" />. /// </summary> /// <param name="worksheet">The <typeparamref name="Google.GData.Spreadsheets.WorksheetEntry" /> from which the wcells should be returned.</param> /// <returns>Returns a <typeparamref name="Google.GData.Spreadsheets.CellEntry" /> array.</returns> public virtual CellEntry[] GetCells(WorksheetEntry worksheet) { if (worksheet == null) { worksheet = GetWorksheets(null)[0]; } var query = new CellQuery(worksheet.CellFeedLink); query.ReturnEmpty = ReturnEmptyCells.yes; this.cellFeed = this.service.Query(query); var result = new CellEntry[this.cellFeed.Entries.Count]; this.cellFeed.Entries.CopyTo(result, 0); return result; }
/// <summary> /// Updates a single <paramref name="cell"/> with <paramref name="content"/> /// </summary> /// <param name="cell">The <typeparamref name="Google.GData.Spreadsheets.CellEntry" /> which should be updated.</param> /// <param name="content">The updated value. (empty string for deleting the cell's content)</param> /// <exception cref="System.ArgumentNullException"><paramref name="cell"/> is null.</exception> public virtual void UpdateCell(CellEntry cell, string content) { if (cell == null) { throw new ArgumentNullException("cell"); } if (content == null) { content = String.Empty; } cell.InputValue = content; cell.Update(); }
/// <summary> /// Get cells in the given <paramref name="worksheet" />. /// </summary> /// <param name="query">The <typeparamref name="Google.GData.Spreadsheets.CellQuery" /> which should be executed.</param> /// <returns>Returns a <typeparamref name="Google.GData.Spreadsheets.CellEntry" /> array.</returns> /// <exception cref="System.ArgumentNullException"><paramref name="query"/> is null.</exception> public virtual CellEntry[] GetCells(CellQuery query) { if (query == null) { throw new ArgumentNullException("query"); } this.cellFeed = this.service.Query(query); var result = new CellEntry[this.cellFeed.Entries.Count]; this.cellFeed.Entries.CopyTo(result, 0); return result; }
private CellEntry[,] GetCellEntryArray(string workbookKey, string SheetName) { WorksheetQuery wsQuery = new WorksheetQuery(String.Format(@"http://spreadsheets.google.com/feeds/worksheets/{0}/private/full", workbookKey)); AtomEntryCollection worksheetEntries = MySpreadsheetService.Query(wsQuery).Entries; CellEntry[,] ce = null; AtomLink MySheetLink = worksheetEntries.First(x => x.Title.Text == SheetName).Links.FindService(GDataSpreadsheetsNameTable.CellRel, AtomLink.ATOM_TYPE); CellQuery MySheetQuery = new CellQuery(MySheetLink.HRef.Content); CellFeed MySheetFeed = MySpreadsheetService.Query(MySheetQuery); AtomEntryCollection MySheetEntries = MySheetFeed.Entries; ce = new CellEntry[MySheetFeed.RowCount.IntegerValue, MySheetFeed.ColCount.IntegerValue]; for (int i = 0; i < MySheetEntries.Count; i++) { CellEntry entry = MySheetEntries[i] as CellEntry; //google doc is a 1 based array, convert to 0 based ce[entry.Row - 1, entry.Column - 1] = entry; } return ce; }
private void DoCellInsert() { // If there is data to insert then do so CellEntry entry = new CellEntry(); CellEntry.CellElement cell = new CellEntry.CellElement(); cell.InputValue = this.cellUpdateDataTextBox.Text; cell.Row = UInt32.Parse(this.cellUpdateRowTextBox.Text); cell.Column = UInt32.Parse(this.cellUpdateColumnTextBox.Text); entry.Cell = cell; service.Insert(new Uri(this.worksheetListView.SelectedItems[0].SubItems[1].Text), entry); }
internal void SetEntry(CellEntry entry) { _entry = entry; _row.MergeEntry(entry); }
public void SaveToCell(WorksheetEntry worksheet, uint row, uint col, string value) { var cellFeed = GetCellFeed(worksheet); var cellEntry = new CellEntry(row, col, value); cellFeed.Insert(cellEntry); }
public static void setWorkSheetHeadersByWorksheet() { IDictionary<string, WorksheetEntry> workSheetList = new Dictionary<string, WorksheetEntry>(); WorksheetFeed wsFeed = spreadSheet.Worksheets; //WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0]; CellQuery cellQuery ; CellFeed cellFeed ; CellEntry cellEntry1 ; CellEntry cellEntry2 ; CellEntry cellEntry3 ; CellEntry cellEntry4 ; CellEntry cellEntry5 ; CellEntry cellEntry6 ; CellEntry cellEntry7 ; foreach (WorksheetEntry ws in wsFeed.Entries) { //workSheetList.Add(ws.Title.Text, ws); // Fetch the cell feed of the worksheet. cellQuery = new CellQuery(ws.CellFeedLink); cellFeed = spreadSheetsService.Query(cellQuery); cellEntry1 = new CellEntry(1, 1, "id"); cellEntry2 = new CellEntry(1, 2, "name"); cellEntry3 = new CellEntry(1, 3, "type"); cellEntry4 = new CellEntry(1, 4, "time"); cellEntry5 = new CellEntry(1, 5, "perf"); cellEntry6 = new CellEntry(1, 6, "status"); cellEntry7 = new CellEntry(1, 7, "location"); cellFeed.Insert(cellEntry1); cellFeed.Insert(cellEntry2); cellFeed.Insert(cellEntry3); cellFeed.Insert(cellEntry4); cellFeed.Insert(cellEntry5); cellFeed.Insert(cellEntry6); cellFeed.Insert(cellEntry7); } }
public static void setWorkSheetHeaders() { WorksheetFeed wsFeed = spreadSheet.Worksheets; WorksheetEntry worksheet = ((WorksheetEntry)wsFeed.Entries[0]); // Fetch the cell feed of the worksheet. CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink); CellFeed cellFeed = spreadSheetsService.Query(cellQuery); CellEntry cellEntry1 = new CellEntry(1, 1, "id"); CellEntry cellEntry2 = new CellEntry(1, 2, "name"); CellEntry cellEntry3 = new CellEntry(1, 3, "type"); CellEntry cellEntry4 = new CellEntry(1, 4, "time"); CellEntry cellEntry5 = new CellEntry(1, 5, "perf"); CellEntry cellEntry6 = new CellEntry(1, 6, "status"); CellEntry cellEntry7 = new CellEntry(1, 6, "location"); cellFeed.Insert(cellEntry1); cellFeed.Insert(cellEntry2); cellFeed.Insert(cellEntry3); cellFeed.Insert(cellEntry4); cellFeed.Insert(cellEntry5); cellFeed.Insert(cellEntry6); cellFeed.Insert(cellEntry7); }
public void InsertRecord(WorksheetEntry worksheet, string day, string text) { var cellQuery = new CellQuery(worksheet.CellFeedLink); var cellFeed = _service.Query(cellQuery); uint currentColumn = 0; uint currentRow = 0; foreach (CellEntry c in cellFeed.Entries) { if (currentRow == 0 && c.InputValue == day) { currentColumn = c.Column; currentRow = c.Row; } else if (c.Column == currentColumn) currentRow = c.Row; } if (currentRow >= worksheet.Rows) { worksheet.Rows += 1; worksheet.Update(); } Debug.WriteLine("Inserting on Row:{0}, Column:{1}", currentRow + 1, currentColumn); var cell = new CellEntry(currentRow + 1, currentColumn, text); cellFeed.Insert(cell); }
internal void MergeEntry(CellEntry newEntry) { CellEntry old = null; foreach (CellEntry obj in _entry) { if (obj.Column == newEntry.Column && obj.Row == newEntry.Row) { old = obj; break; } } if (null != old) { _entry.Remove(old); } _entry.Add(newEntry); }