Пример #1
0
        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;
        }
Пример #2
0
        /// <summary>
        /// Updates the online spreadsheet according the maps file
        /// </summary>
        /// 
        public static void SheetSync(bool ForceSync)
        {
            Bot.SteamFriends.SetPersonaName("[" + ImpMaster.Maplist.Count.ToString() + "] " + Bot.DisplayName);

            if ((GroupChatHandler.OnlineSync.StartsWith("true", StringComparison.OrdinalIgnoreCase) && !SyncRunning) || ForceSync)
            {
                SyncRunning = true;
                //Log.Interface ("Beginning Sync");
                OAuth2Parameters parameters = new OAuth2Parameters();
                parameters.ClientId = GroupChatHandler.CLIENT_ID;
                parameters.ClientSecret = GroupChatHandler.CLIENT_SECRET;
                parameters.RedirectUri = GroupChatHandler.REDIRECT_URI;
                parameters.Scope = GroupChatHandler.SCOPE;
                parameters.AccessType = "offline";
                parameters.RefreshToken = GroupChatHandler.GoogleAPI;
                OAuthUtil.RefreshAccessToken(parameters);
                string accessToken = parameters.AccessToken;

                GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, GroupChatHandler.IntegrationName, parameters);
                SpreadsheetsService service = new SpreadsheetsService(GroupChatHandler.IntegrationName);
                service.RequestFactory = requestFactory;
                SpreadsheetQuery query = new SpreadsheetQuery(SpreadSheetURI);
                SpreadsheetFeed feed = service.Query(query);
                SpreadsheetEntry spreadsheet = (SpreadsheetEntry)feed.Entries[0];
                WorksheetFeed wsFeed = spreadsheet.Worksheets;
                WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];

                worksheet.Cols = 5;
                worksheet.Rows = Convert.ToUInt32(ImpMaster.Maplist.Count + 1);

                worksheet.Update();

                CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;
                CellFeed cellFeed = service.Query(cellQuery);
                CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);

                int Entries = 1;

                foreach (var item in ImpMaster.Maplist)
                {
                    Entries = Entries + 1;
                    foreach (CellEntry cell in cellFeed.Entries)
                    {
                        if (cell.Title.Text == "A" + Entries.ToString())
                        {
                            cell.InputValue = item.Key;
                        }
                        if (cell.Title.Text == "B" + Entries.ToString())
                        {
                            cell.InputValue = item.Value.Item1;

                        }
                        if (cell.Title.Text == "C" + Entries.ToString())
                        {
                            cell.InputValue = item.Value.Item2.ToString();

                        }
                        if (cell.Title.Text == "D" + Entries.ToString())
                        {
                            cell.InputValue = item.Value.Item3.ToString();

                        }
                        if (cell.Title.Text == "E" + Entries.ToString())
                        {
                            cell.InputValue = item.Value.Item4.ToString();
                        }
                    }
                }

                cellFeed.Publish();
                CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));
                // Log.Interface("Completed Sync");
                SyncRunning = false;

            }
            else if (GroupChatHandler.OnlineSync.StartsWith("true", StringComparison.OrdinalIgnoreCase))
            {
                GroupChatHandler.SpreadsheetSync = true;
            }
        }