Пример #1
0
        public IAccountSettings Convert(ServiceAccount serviceAccount)
        {
            GoogleSheetsAccountSettings target = new GoogleSheetsAccountSettings();

            target.ID             = serviceAccount.ServiceAccountId;
            target.Name           = serviceAccount.ServiceAccountName;
            target.Source         = serviceAccount.Source;
            target.Tokens         = new List <GoogleSheetsAccountToken>();
            target.MinUpdateTime  = serviceAccount.MinUpdateTime;
            target.AccountVersion = serviceAccount.AccountVersion;

            if (serviceAccount.Tokens.Count > 0)
            {
                foreach (Token token in serviceAccount.Tokens)
                {
                    GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
                    targetToken = (GoogleSheetsAccountToken)targetToken.Convert(token);
                    target.Tokens.Add(targetToken);
                }
            }
            if (serviceAccount.MappingTemplates.Count > 0)
            {
                foreach (Template template in serviceAccount.MappingTemplates)
                {
                    GoogleSheetsAccountTemplate targetTemplate = new GoogleSheetsAccountTemplate();
                    targetTemplate = (GoogleSheetsAccountTemplate)targetTemplate.Convert(template);
                    if (target.Templates != null)
                    {
                        target.Templates.Add(targetTemplate);
                    }
                }
            }
            return(target);
        }
Пример #2
0
        public IAccountSettings TestAccount(IAccountSettings accountnForTest)
        {
            parameters.ClientId     = Constants.googleSheetsCLIENT_ID;
            parameters.ClientSecret = Constants.googleSheetsCLIENT_SECRET;
            parameters.RedirectUri  = Constants.googleSheetsREDIRECT_URI;
            parameters.Scope        = Constants.googleSheetsSCOPE;

            GoogleSheetsAccountSettings accountForTestGS = (GoogleSheetsAccountSettings)accountnForTest;
            GoogleSheetsAccountToken    tokenForTest     = accountForTestGS.Tokens.First();
            Boolean result = false;

            if (tokenForTest != null)
            {
                foreach (GoogleSheetsAccountToken gast in accountForTestGS.Tokens)
                {
                    if (gast.TokenName == "GetNewToken")
                    {
                        string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
                        gast.RefreshToken = authorizationUrl;
                    }
                    else if (gast.TokenName == "EnterAccessToken")
                    {
                        parameters.AccessToken = gast.RefreshToken;
                        parameters.AccessCode  = gast.RefreshToken;
                        OAuthUtil.GetAccessToken(parameters);
                        gast.RefreshToken = parameters.RefreshToken;
                    }
                    else if (gast.TokenName == "UseSaveToken")
                    {
                        parameters.AccessToken  = gast.RefreshToken;
                        parameters.AccessCode   = gast.RefreshToken;
                        parameters.RefreshToken = gast.RefreshToken;
                        OAuthUtil.RefreshAccessToken(parameters);
                    }
                    else if (gast.TokenName == "CheckFileName")
                    {
                        parameters.AccessToken  = accountForTestGS.Tokens[0].RefreshToken;
                        parameters.AccessCode   = accountForTestGS.Tokens[0].RefreshToken;
                        parameters.RefreshToken = accountForTestGS.Tokens[0].RefreshToken;
                        bool result2;
                        result2 = CheckFileGS(gast.RefreshToken, accountForTestGS);
                        if (!result2)
                        {
                            gast.RefreshToken = "This file does not exist";
                        }
                        else
                        {
                            gast.RefreshToken = "OK";
                        }
                    }
                }

                result = true;
            }

            accountForTestGS.TestResult = result;
            return(accountForTestGS);
        }
Пример #3
0
        public Token Convert(IAccountToken token)
        {
            Token targetToken = new Token();
            GoogleSheetsAccountToken paramToken = (GoogleSheetsAccountToken)token;

            targetToken.TokenId   = paramToken.TokenId;
            targetToken.TokenName = paramToken.TokenName;
            targetToken.Tokens.Add("RefreshToken", paramToken.RefreshToken);

            return(targetToken);
        }
Пример #4
0
        public IAccountToken Convert(Token token)
        {
            GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();

            targetToken.TokenId   = token.TokenId;
            targetToken.TokenName = token.TokenName;
            if (token.Tokens.Count > 0)
            {
                targetToken.RefreshToken = (from tok in token.Tokens
                                            where tok.Key == "RefreshToken"
                                            select tok.Value).SingleOrDefault();
            }

            return(targetToken);
        }
        public IAccountSettings Convert(ServiceAccount serviceAccount)
        {
            GoogleSheetsAccountSettings target = new GoogleSheetsAccountSettings();
            target.ID = serviceAccount.ServiceAccountId;
            target.Name = serviceAccount.ServiceAccountName;
            target.Source = serviceAccount.Source;
            target.Tokens = new List<GoogleSheetsAccountToken>();
            target.MinUpdateTime = serviceAccount.MinUpdateTime;
            target.AccountVersion = serviceAccount.AccountVersion;

            if (serviceAccount.Tokens.Count > 0)
            {
                foreach (Token token in serviceAccount.Tokens)
                {
                    GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
                    targetToken = (GoogleSheetsAccountToken)targetToken.Convert(token);
                    target.Tokens.Add(targetToken);
                }
            }
            if (serviceAccount.MappingTemplates.Count > 0)
            {
                foreach (Template template in serviceAccount.MappingTemplates)
                {
                    GoogleSheetsAccountTemplate targetTemplate = new GoogleSheetsAccountTemplate();
                    targetTemplate = (GoogleSheetsAccountTemplate)targetTemplate.Convert(template);
                    if (target.Templates != null)
                        target.Templates.Add(targetTemplate);
                }
            }
            return target;
        }
        public IAccountToken Convert(Token token)
        {
            GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
            targetToken.TokenId = token.TokenId;
            targetToken.TokenName = token.TokenName;
            if (token.Tokens.Count > 0)
            {
                targetToken.RefreshToken = (from tok in token.Tokens
                                            where tok.Key == "RefreshToken"
                                            select tok.Value).SingleOrDefault();
            }

            return targetToken;
        }