private void CheckAccount_Click(object sender, EventArgs e)
        {
            isNewToken          = false;
            LinkToGetToken.Text = null;
            accName             = AccountsNameComboBox.SelectedItem.ToString();
            IAccountSettings result = userGoogleAccounts.SingleOrDefault(x => x.Name == accName);

            if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
            {
                googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
            }
            if (googleSheetsAccountSettings.Tokens.Count == 0)
            {
                TokenStatusLabel.Text      = "Get a new token";
                TokenStatusLabel.ForeColor = Color.Red;
                GoogleSheetsAccountToken locTok = new GoogleSheetsAccountToken();
                locTok.TokenName = "GetNewToken";
                googleSheetsAccountSettings.Tokens.Add(locTok);
                googleSheetsAccountSettings = NewTestAccount(googleSheetsAccountSettings);

                LinkToGetToken.Text = googleSheetsAccountSettings.Tokens.Last().RefreshToken;
                if (googleSheetsAccountSettings.Tokens.Count > 0)
                {
                    googleSheetsAccountSettings.Tokens.RemoveAt(0);
                }
                isNewToken = true;
            }
            else
            {
                TokenStatusLabel.ForeColor = Color.Green;
                TokenStatusLabel.Text      = "You already have a token";
                UseSaveToken_Click(null, null);
            }
        }
        private void EnterAccessTokenButton_Click(object sender, EventArgs e)
        {
            string token = AccessTokenTextBox.Text;
            GoogleSheetsAccountToken locTok = new GoogleSheetsAccountToken();

            locTok.TokenName    = "EnterAccessToken";
            locTok.RefreshToken = token;

            googleSheetsAccountSettings.Tokens.Add(locTok);
            googleSheetsAccountSettings = NewTestAccount(googleSheetsAccountSettings);

            googleSheetsAccountToken.RefreshToken = googleSheetsAccountSettings.Tokens[0].RefreshToken;
            if (googleSheetsAccountSettings.Tokens.Count > 0)
            {
                googleSheetsAccountSettings.Tokens.RemoveAt(0);
            }
            googleSheetsAccountToken.TokenName = "Token" + googleSheetsAccountSettings.Name;
            googleSheetsAccountSettings.Tokens.Add(googleSheetsAccountToken);
            SettingsManager.SaveOrUpdateAccount(googleSheetsAccountSettings);
            ((Control)this.tabPage2).Enabled = true;
            LinkToGetToken.Text        = null;
            AccessTokenTextBox.Text    = null;
            TokenStatusLabel.ForeColor = Color.DarkTurquoise;
            TokenStatusLabel.Text      = "New token is saved";
            RefreshMapSetting();
        }
 private void UseSaveToken_Click(object sender, EventArgs e)
 {
     if (isNewToken)
     {
         GoogleSheetsAccountToken locTok = new GoogleSheetsAccountToken();
         locTok.TokenName = "UseSaveToken";
         googleSheetsAccountSettings.Tokens.Add(locTok);
         googleSheetsAccountSettings = NewTestAccount(googleSheetsAccountSettings);
         if (googleSheetsAccountSettings.Tokens.Count > 0)
         {
             googleSheetsAccountSettings.Tokens.RemoveAt(0);
         }
     }
     else
     {
         GoogleSheetsAccountToken locTok = new GoogleSheetsAccountToken();
         locTok.TokenName    = "UseSaveToken";
         locTok.RefreshToken = googleSheetsAccountSettings.Tokens[0].RefreshToken;
         googleSheetsAccountSettings.Tokens.Add(locTok);
         NewTestAccount(googleSheetsAccountSettings);
         if (googleSheetsAccountSettings.Tokens.Count > 0)
         {
             googleSheetsAccountSettings.Tokens.RemoveAt(googleSheetsAccountSettings.Tokens.Count - 1);
         }
     }
     ((Control)this.tabPage2).Enabled = true;
     RefreshMapSetting();
 }
Пример #4
0
        public IAccountSettings ConvertFromDAO(ServiceAccountDTO serviceAccount)
        {
            GoogleSheetsAccountSettings target = new GoogleSheetsAccountSettings();

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

            if (serviceAccount.Tokens.Length > 0)
            {
                foreach (TokenDTO token in serviceAccount.Tokens)
                {
                    GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
                    targetToken = (GoogleSheetsAccountToken)targetToken.ConvertFromDAO(token);
                    target.Tokens.Add(targetToken);
                }
            }
            if (serviceAccount.MappingTemplates.Length > 0)
            {
                foreach (TemplateDTO template in serviceAccount.MappingTemplates)
                {
                    GoogleSheetsAccountTemplate targetTemplate = new GoogleSheetsAccountTemplate();
                    targetTemplate = (GoogleSheetsAccountTemplate)targetTemplate.ConvertFromDAO(template);
                    target.Template.Add(targetTemplate);
                }
            }
            return(target);
        }
        public IAccountSettings ConvertFromDAO(ServiceAccountDTO serviceAccount)
        {
            GoogleSheetsAccountSettings target = new GoogleSheetsAccountSettings();
            target.ID = serviceAccount.ServiceAccountId;
            target.Name = serviceAccount.ServiceAccountName;
            target.Source = serviceAccount.Source;
            target.Tokens = new List<GoogleSheetsAccountToken>();
            target.Template = new List<GoogleSheetsAccountTemplate>();
            target.MinUpdateTime = serviceAccount.MinUpdateTime;
            target.AccountVersion = serviceAccount.AccountVersion;

            if (serviceAccount.Tokens.Length > 0)
            {
                foreach (TokenDTO token in serviceAccount.Tokens)
                {
                    GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
                    targetToken = (GoogleSheetsAccountToken)targetToken.ConvertFromDAO(token);
                    target.Tokens.Add(targetToken);
                }
            }
            if (serviceAccount.MappingTemplates.Length > 0)
            {
                foreach (TemplateDTO template in serviceAccount.MappingTemplates)
                {
                    GoogleSheetsAccountTemplate targetTemplate = new GoogleSheetsAccountTemplate();
                    targetTemplate = (GoogleSheetsAccountTemplate)targetTemplate.ConvertFromDAO(template);
                    target.Template.Add(targetTemplate);
                }
            }
            return target;
        }
Пример #6
0
        public IAccountToken ConvertFromDAO(TokenDTO token)
        {
            GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();

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

            return(targetToken);
        }
Пример #7
0
        public TokenDTO ConvertToDAO(IAccountToken token)
        {
            TokenDTO target = new TokenDTO();
            GoogleSheetsAccountToken currentToken = (GoogleSheetsAccountToken)token;

            target.TokenName = currentToken.TokenName;
            target.TokenId   = currentToken.TokenId;
            List <TokenForSerialization> tokenList = new List <TokenForSerialization>();

            TokenForSerialization password = new TokenForSerialization();

            password.Key   = "RefreshToken";
            password.Value = currentToken.RefreshToken;
            tokenList.Add(password);

            target.Tokens = tokenList.ToArray();
            return(target);
        }
        public IAccountToken ConvertFromDAO(TokenDTO token)
        {
            GoogleSheetsAccountToken targetToken = new GoogleSheetsAccountToken();
            targetToken.TokenId = token.TokenId;
            targetToken.TokenName = token.TokenName;
            if (token.Tokens.Length > 0)
            {
                targetToken.RefreshToken = (from tok in token.Tokens
                                            where tok.Key == "RefreshToken"
                                            select tok.Value).SingleOrDefault();
            }

            return targetToken;
        }