コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ncroll/EveAccountancy
        private static RefreshTokenData GetRefreshTokenData(OAuth2ClientCredentials credentials, IEveAccountancyManager eveAccountancyManager)
        {
            RefreshTokenData refreshTokenData = eveAccountancyManager.GetRefreshTokenData();

            if (refreshTokenData == null || string.IsNullOrWhiteSpace(refreshTokenData.RefreshToken))
            {
                string authorizationUrl = eveAccountancyManager.GetGoogleAuthorizationUrl(credentials);
                string accessCode = string.Empty;

                while (string.IsNullOrWhiteSpace(accessCode))
                {
                    Console.WriteLine("Please visit");
                    Console.WriteLine();
                    Console.WriteLine(authorizationUrl);
                    Console.WriteLine();
                    Console.Write("and enter your access code: ");
                    accessCode = Console.ReadLine();
                }

                string refreshToken = eveAccountancyManager.GetGoogleRefreshToken(credentials, accessCode);
                refreshTokenData = new RefreshTokenData()
                {
                    RefreshToken = refreshToken,
                };
                eveAccountancyManager.SaveRefreshTokenData(refreshTokenData);
            }

            return refreshTokenData;
        }
コード例 #3
0
        public string GetAuthorizationUrl(OAuth2ClientCredentials clientCredentials)
        {
            OAuth2Parameters parameters = GetOAuthParameters(clientCredentials);
            string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);

            return authorizationUrl;
        }
コード例 #4
0
        public string GetGoogleRefreshToken(OAuth2ClientCredentials clientCredentials, string accessCode)
        {
            Logger.Write("EveAccountancyManager: Getting Google refresh token");
            IUnityContainer unityContainer = UnityContainerFactory.GetUnityContainer();
            IGoogleSpreadsheetAccessor googleSpreadsheetAccessor = unityContainer.Resolve<IGoogleSpreadsheetAccessor>();

            return googleSpreadsheetAccessor.GetRefreshToken(clientCredentials, accessCode);
        }
コード例 #5
0
        public string GetGoogleAuthorizationUrl(OAuth2ClientCredentials clientCredentials)
        {
            Logger.Write("EveAccountancyManager: Getting Google authorication URL");
            IUnityContainer unityContainer = UnityContainerFactory.GetUnityContainer();
            IGoogleSpreadsheetAccessor googleSpreadsheetAccessor = unityContainer.Resolve<IGoogleSpreadsheetAccessor>();

            return googleSpreadsheetAccessor.GetAuthorizationUrl(clientCredentials);
        }
コード例 #6
0
        public string GetRefreshToken(OAuth2ClientCredentials clientCredentials, string accessCode)
        {
            OAuth2Parameters parameters = GetOAuthParameters(clientCredentials);
            parameters.AccessCode = accessCode;
            OAuthUtil.GetAccessToken(parameters);

            return parameters.RefreshToken;
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        public void PopulateNewWorksheet(OAuth2ClientCredentials clientCredentials, string refreshToken, string spreadsheetTitle, TypesByMarketGroup[] typesByMarketGroup, MarketStatTypesBySolarSystem[] marketStatTypes)
        {
            Logger.Write(string.Format("EveAccountancyManager: Writing to spreadsheet {0}", spreadsheetTitle));
            IUnityContainer unityContainer = UnityContainerFactory.GetUnityContainer();
            ISpreadsheetEngine spreadsheetEngine = unityContainer.Resolve<ISpreadsheetEngine>();

            spreadsheetEngine.PopulateNewWorksheet(clientCredentials, refreshToken, spreadsheetTitle, typesByMarketGroup, marketStatTypes);
        }
コード例 #9
0
 public void PopulateNewWorksheet(OAuth2ClientCredentials clientCredentials, string refreshToken, string spreadsheetTitle, TypesByMarketGroup[] typesByMarketGroup, MarketStatTypesBySolarSystem[] marketStatTypes)
 {
 }
コード例 #10
0
        private SpreadsheetsService GetSpreadsheetService(OAuth2ClientCredentials clientCredentials, string refreshToken)
        {
            OAuth2Parameters parameters = GetOAuthParameters(clientCredentials, refreshToken);
            GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, _kApplicationName, parameters);
            SpreadsheetsService service = new SpreadsheetsService(_kApplicationName);
            service.RequestFactory = requestFactory;

            return service;
        }
コード例 #11
0
        private OAuth2Parameters GetOAuthParameters(OAuth2ClientCredentials clientCredentials, string refreshToken)
        {
            OAuth2Parameters parameters = GetOAuthParameters(clientCredentials);
            parameters.RefreshToken = refreshToken;
            OAuthUtil.RefreshAccessToken(parameters);

            return parameters;
        }
コード例 #12
0
        private OAuth2Parameters GetOAuthParameters(OAuth2ClientCredentials clientCredentials)
        {
            string scope = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds";
            string redirectUri = "urn:ietf:wg:oauth:2.0:oob";
            OAuth2Parameters parameters = new OAuth2Parameters()
            {
                ClientId = clientCredentials.ClientId,
                ClientSecret = clientCredentials.ClientSecret,
                RedirectUri = redirectUri,
                Scope = scope,
            };

            return parameters;
        }