Пример #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 ServiceAccount Convert(IAccountSettings service)
        {
            ServiceAccount target = new ServiceAccount();
            GoogleSheetsAccountSettings serviceAccount = (GoogleSheetsAccountSettings)service;

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

            if (serviceAccount.Tokens != null && serviceAccount.Tokens.Count > 0)
            {
                foreach (GoogleSheetsAccountToken token in serviceAccount.Tokens)
                {
                    Token targetToken = new Token();
                    targetToken = token.Convert(token);
                    target.Tokens.Add(targetToken);
                }
            }
            if (serviceAccount.Templates != null && serviceAccount.Templates.Count > 0)
            {
                foreach (GoogleSheetsAccountTemplate template in serviceAccount.Templates)
                {
                    Template targetTemplate = new Template();
                    targetTemplate = template.Convert(template);
                    target.MappingTemplates.Add(targetTemplate);
                }
            }
            return(target);
        }
Пример #3
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);
        }
Пример #4
0
 public bool Equals(IAccountSettings accountToCompare)
 {
     if (accountToCompare is GoogleSheetsAccountSettings)
     {
         GoogleSheetsAccountSettings GSAccountToCompere = (GoogleSheetsAccountSettings)accountToCompare;
         return(this.ID == GSAccountToCompere.ID && this.AccountVersion == GSAccountToCompere.AccountVersion);
     }
     return(false);
 }
Пример #5
0
        public IAdapter GetAdapter(IAccountSettings account)
        {
            GoogleSheetsAccountSettings gsAccount = (GoogleSheetsAccountSettings)account;

            allTokensInAccount = gsAccount.Tokens;

            parameters.ClientId     = Constants.googleSheetsCLIENT_ID;
            parameters.ClientSecret = Constants.googleSheetsCLIENT_SECRET;
            parameters.RedirectUri  = Constants.googleSheetsREDIRECT_URI;
            parameters.Scope        = Constants.googleSheetsSCOPE;
            if (allTokensInAccount.Count != 0)
            {
                parameters.AccessToken  = allTokensInAccount[0].RefreshToken;
                parameters.AccessCode   = allTokensInAccount[0].RefreshToken;
                parameters.RefreshToken = allTokensInAccount[0].RefreshToken;
                OAuthUtil.RefreshAccessToken(parameters);

                ReadGSFile();
            }
            return(this);
        }
Пример #6
0
        private bool CheckFileGS(string FileName, GoogleSheetsAccountSettings accountForTestGS)
        {
            bool result = false;
            SpreadsheetsService   service        = new SpreadsheetsService(Constants.googleSheetsAppName);
            GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, Constants.googleSheetsAppName, parameters);

            service.RequestFactory = requestFactory;
            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed  feed  = service.Query(query);
            SpreadsheetEntry spreadsheet;

            for (int i = 0; i < feed.Entries.Count; i++)
            {
                if (feed.Entries[i].Title.Text == FileName)
                {
                    spreadsheet = (SpreadsheetEntry)feed.Entries[i];
                    WorksheetFeed  wsFeed       = spreadsheet.Worksheets;
                    WorksheetEntry worksheet    = (WorksheetEntry)wsFeed.Entries[0];
                    AtomLink       listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
                    ListQuery      listQuery    = new ListQuery(listFeedLink.HRef.ToString());
                    listFeed = service.Query(listQuery);
                    result   = true;
                    break;
                }
                else
                {
                    result = false;
                }
            }

            //if (listFeed != null)
            //{
            //    //ShowMapping();
            //}

            return(result);
        }
Пример #7
0
        private bool CheckFileGS(string FileName, GoogleSheetsAccountSettings accountForTestGS)
        {
            bool result = false;
            SpreadsheetsService service = new SpreadsheetsService(Constants.googleSheetsAppName);
            GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, Constants.googleSheetsAppName, parameters);
            service.RequestFactory = requestFactory;
            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = service.Query(query);
            SpreadsheetEntry spreadsheet;
            for (int i = 0; i < feed.Entries.Count; i++)
            {
                if (feed.Entries[i].Title.Text == FileName)
                {
                    spreadsheet = (SpreadsheetEntry)feed.Entries[i];
                    WorksheetFeed wsFeed = spreadsheet.Worksheets;
                    WorksheetEntry worksheet = (WorksheetEntry)wsFeed.Entries[0];
                    AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
                    ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
                    listFeed = service.Query(listQuery);
                    result = true;
                    break;
                }
                else
                {
                    result = false;
                }
            }

            //if (listFeed != null)
            //{
            //    //ShowMapping();
            //}

            return result;
        }
        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;
        }