private static ListEntry InsertRow(SpreadsheetsService service, WorksheetEntry entry, NameValueCollection parameters) { logger.Debug("inserting row..."); AtomLink listFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery query = new ListQuery(listFeedLink.HRef.ToString()); ListFeed feed = service.Query(query); ListEntry newRow = new ListEntry(); foreach(string key in parameters) { ListEntry.Custom curElement = new ListEntry.Custom(); curElement.Value = parameters[key]; curElement.LocalName = key; newRow.Elements.Add(curElement); } // add datetime ListEntry.Custom el = new ListEntry.Custom(); el.Value = parameters["data"]; el.LocalName = DateTime.Now.ToString() ; newRow.Elements.Add(el); ListEntry insertedRow = feed.Insert(newRow); return insertedRow; }
public void PopulateNewWorksheet(OAuth2ClientCredentials clientCredentials, string refreshToken, string spreadsheetTitle, TypesByMarketGroup[] typesByMarketGroups, MarketStatTypesBySolarSystem[] marketStatTypes) { IUnityContainer unityContainer = UnityContainerFactory.GetUnityContainer(); IGoogleSpreadsheetAccessor googleSpreadsheetAccessor = unityContainer.Resolve<IGoogleSpreadsheetAccessor>(); string worksheetTitle = DateTime.Now.ToString(); IEnumerable<invType> types = typesByMarketGroups.SelectMany(t => t.Types); // row for headers + row for each type, plus row for each market group int rowCount = types.Count() + typesByMarketGroups.Count() + 1; // name column plus buy & sell stats for each system int columnCount = 1 + (6 * marketStatTypes.Length); ListEntry.Custom[,] listEntries = new ListEntry.Custom[rowCount, columnCount]; // populate header row listEntries[0, 0] = new ListEntry.Custom() { LocalName = "Name" }; PopulateRow(marketStatTypes, listEntries, 0, null); int marketGroupRowIndex = 1; foreach (var typesByMarketGroup in typesByMarketGroups) { listEntries[marketGroupRowIndex, 0] = new ListEntry.Custom() { LocalName = "Name", Value = typesByMarketGroup.MarketGroup.marketGroupName }; for (int typeCounter = 0; typeCounter < typesByMarketGroup.Types.Count(); typeCounter++) { int rowIndex = typeCounter + marketGroupRowIndex + 1; invType invType = typesByMarketGroup.Types.ElementAt(typeCounter); listEntries[rowIndex, 0] = new ListEntry.Custom() { LocalName = "Name", Value = invType.typeName }; PopulateRow(marketStatTypes, listEntries, rowIndex, invType); } marketGroupRowIndex += typesByMarketGroup.Types.Count() + 1; } googleSpreadsheetAccessor.PopulateNewWorksheet(clientCredentials, refreshToken, spreadsheetTitle, worksheetTitle, listEntries); }
private static void PopulateRow(MarketStatTypesBySolarSystem[] marketStatTypes, ListEntry.Custom[,] listEntries, int rowIndex, invType invType) { int baseColumnIndex = 0; for (int solarSystemCounter = 0; solarSystemCounter < marketStatTypes.Length; solarSystemCounter++) { mapSolarSystem mapSolarSystem = marketStatTypes[solarSystemCounter].MapSolarSystem; // for typeId, SolarSystemId, get Buy and Sell MarketStatType marketStatType = null; if (invType != null) { marketStatType = marketStatTypes[solarSystemCounter].MarketStatTypes.Where(m => m.Id == invType.typeID).FirstOrDefault(); } listEntries[rowIndex, baseColumnIndex + 1] = new ListEntry.Custom() { LocalName = string.Format("{0} Buy Min", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Buy.Min.ToString() : string.Empty, }; listEntries[rowIndex, baseColumnIndex + 2] = new ListEntry.Custom() { LocalName = string.Format("{0} Buy Avg", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Buy.Avg.ToString() : string.Empty, }; listEntries[rowIndex, baseColumnIndex + 3] = new ListEntry.Custom() { LocalName = string.Format("{0} Buy Max", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Buy.Max.ToString() : string.Empty, }; listEntries[rowIndex, baseColumnIndex + 4] = new ListEntry.Custom() { LocalName = string.Format("{0} Sell Min", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Sell.Min.ToString() : string.Empty, }; listEntries[rowIndex, baseColumnIndex + 5] = new ListEntry.Custom() { LocalName = string.Format("{0} Sell Avg", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Sell.Avg.ToString() : string.Empty, }; listEntries[rowIndex, baseColumnIndex + 6] = new ListEntry.Custom() { LocalName = string.Format("{0} Sell Max", mapSolarSystem.solarSystemName), Value = marketStatType != null ? marketStatType.Sell.Max.ToString() : string.Empty, }; baseColumnIndex += 6; } }
/// <summary> /// Inserts a new row in the specified worksheet. /// </summary> /// <param name="service">an authenticated SpreadsheetsService object</param> /// <param name="entry">the worksheet into which the row will be inserted</param> /// <returns>the inserted ListEntry object, representing the new row</returns> private static ListEntry InsertRow(SpreadsheetsService service, WorksheetEntry entry) { AtomLink listFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery query = new ListQuery(listFeedLink.HRef.ToString()); ListFeed feed = service.Query(query); ListEntry firstRow = feed.Entries[0] as ListEntry; ListEntry newRow = new ListEntry(); Console.WriteLine(); Console.WriteLine("Inserting a new row..."); foreach (ListEntry.Custom element in firstRow.Elements) { Console.Write("Enter the value of column \"{0}\": ", element.LocalName); String elementValue = Console.ReadLine(); ListEntry.Custom curElement = new ListEntry.Custom(); curElement.LocalName = element.LocalName; curElement.Value = elementValue; newRow.Elements.Add(curElement); } ListEntry insertedRow = feed.Insert(newRow); Console.WriteLine("Successfully inserted new row: \"{0}\"", insertedRow.Content.Content); return insertedRow; }
private void DoListUpdate() { String[] commaSplit = this.listUpdateTextBox.Text.Split(','); ListEntry entry = (ListEntry)editUriTable[this.listEntryComboBox.Text]; for (int i=0; i < commaSplit.Length; i++) { String[] pair = commaSplit[i].Split('='); // Make the new replacement custom ListEntry.Custom custom = new ListEntry.Custom(); custom.LocalName = pair[0]; if (pair.Length == 2) { custom.Value = pair[1]; } else { custom.Value = null; entry.Elements.Remove(custom); continue; } // Set the replacement custom int index = entry.Elements.IndexOf(custom); entry.Elements[index] = custom; } AtomEntry retEntry = service.Update(entry); }
private void DoListInsert() { String[] commaSplit = this.listAddTextBox.Text.Split(','); ListEntry entry = new ListEntry(); for (int i=0; i < commaSplit.Length; i++) { String[] pair = commaSplit[i].Split('='); ListEntry.Custom custom = new ListEntry.Custom(); custom.LocalName = pair[0]; custom.Value = pair[1]; entry.Elements.Add(custom); } AtomEntry retEntry = service.Insert(new Uri(this.worksheetListView.SelectedItems[0].SubItems[2].Text), entry); }
private void InsertRow(string pPlayerOne, string pPlayerTwo, string pBetAmount, ListFeed pFeed) { DateTime tDateTime = DateTime.Today; string tDate = tDateTime.Day + "/" + tDateTime.Month + "/" + tDateTime.Year; int tBetAmount = ConvertBetToInt(pBetAmount); int tCommission = (int)(tBetAmount * 0.10); int tAdminFee; if (tBuyinMode == true) { tAdminFee = (int)(tCommission * 0.10); } else { tAdminFee = (int)(tCommission * 0.30); } ListEntry tNewRow = new ListEntry(); ListEntry.Custom tElementDate = new ListEntry.Custom(); tElementDate.LocalName = "date"; tElementDate.Value = tDate; ListEntry.Custom tElementPlayer1 = new ListEntry.Custom(); tElementPlayer1.LocalName = "nameofplayer1"; tElementPlayer1.Value = pPlayerOne; ListEntry.Custom tElementPlayer2 = new ListEntry.Custom(); tElementPlayer2.LocalName = "nameofplayer2"; tElementPlayer2.Value = pPlayerTwo; ListEntry.Custom tElementPlayer1Bet = new ListEntry.Custom(); tElementPlayer1Bet.LocalName = "player1bet"; tElementPlayer1Bet.Value = tBetAmount.ToString(); ListEntry.Custom tElementPlayer2Bet = new ListEntry.Custom(); tElementPlayer2Bet.LocalName = "player2bet"; tElementPlayer2Bet.Value = tBetAmount.ToString(); ListEntry.Custom tElementCommission = new ListEntry.Custom(); tElementCommission.LocalName = "commission"; tElementCommission.Value = tCommission.ToString(); ListEntry.Custom tElementAdminFee = new ListEntry.Custom(); tElementAdminFee.LocalName = "commisionforadmin"; tElementAdminFee.Value = tAdminFee.ToString(); tNewRow.Elements.Add(tElementAdminFee); tNewRow.Elements.Add(tElementCommission); tNewRow.Elements.Add(tElementDate); tNewRow.Elements.Add(tElementPlayer1); tNewRow.Elements.Add(tElementPlayer1Bet); tNewRow.Elements.Add(tElementPlayer2); tNewRow.Elements.Add(tElementPlayer2Bet); var tResult = pFeed.Insert(tNewRow) as ListEntry; }
private static void InsertRow(SpreadsheetsService service, WorksheetEntry entry,List<String > data) { AtomLink listFeedLink = entry.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null); ListQuery query = new ListQuery(listFeedLink.HRef.ToString()); ListFeed feed = service.Query(query); ListEntry newRow = new ListEntry(); List<String> localName = new List<string>(); localName.Add("date"); localName.Add("filename"); localName.Add("photographe"); localName.Add("format"); // localName.Add("orderCD"); // localName.Add("chamber number"); int n = 0; foreach (string value in data) { ListEntry.Custom curElement = new ListEntry.Custom(); curElement.LocalName = localName[n]; curElement.Value = value; newRow.Elements.Add(curElement); n++; } ListEntry insertedRow = feed.Insert(newRow) as ListEntry; //return insertedRow; }