private void ShareButton_Click(object sender, EventArgs e)
        {
            String           shareUserName = ShareUserNameTB.Text;
            IAccountSettings result        = userGoogleAccounts.SingleOrDefault(x => x.Name == ShareAccountsComboBox.SelectedItem.ToString());

            if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
            {
                googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
            }
            if (shareUserName != String.Empty && shareUserName != loggedUser.UserLogin)
            {
                Boolean res = loggedUser.ShareTheSettingAccount(googleSheetsAccountSettings, shareUserName, PermitChangesCB.Checked);
                if (res)
                {
                    RefreshSettings();
                    groupBox5.Visible    = false;
                    ShareUserNameTB.Text = null;
                }
                else
                {
                    label12.Text = "Please try later";
                }
            }
            else
            {
                MessageBox.Show("Error!");
                label12.Text = "Invalid user name!";
            }
        }
        private void CheckButton_Click(object sender, EventArgs e)
        {
            //check file
            GoogleSheetsAccountToken locTok = new GoogleSheetsAccountToken();

            locTok.TokenName    = "CheckFileName";
            locTok.RefreshToken = FileNameTB.Text;
            googleSheetsAccountSettings.Tokens.Add(locTok);
            googleSheetsAccountSettings = NewTestAccount(googleSheetsAccountSettings);
            if (googleSheetsAccountSettings.Tokens[1].RefreshToken != "This file does not exist")
            {
                StatusLabel.ForeColor = Color.Green;
                StatusLabel.Text      = "OK";
            }
            else
            {
                StatusLabel.ForeColor = Color.Red;
                StatusLabel.Text      = "This file does not exist";
            }
            if (googleSheetsAccountSettings.Tokens.Count > 0)
            {
                googleSheetsAccountSettings.Tokens.RemoveAt(googleSheetsAccountSettings.Tokens.Count - 1);
            }
            //if (listFeed != null)
            //{
            //    ShowMapping();
            //}
        }
        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 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();
 }
        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();
        }
Exemplo n.º 6
0
        public ServiceAccountDTO ConvertToDAO(IAccountSettings serviceAccount)
        {
            ServiceAccountDTO           target         = new ServiceAccountDTO();
            GoogleSheetsAccountSettings currentAccount = (GoogleSheetsAccountSettings)serviceAccount;

            target.ServiceAccountId   = currentAccount.ID;
            target.ServiceAccountName = currentAccount.Name;
            target.Source             = Sources.GoogleSheets;
            target.MinUpdateTime      = target.MinUpdateTime;
            target.AccountVersion     = serviceAccount.AccountVersion;

            List <TokenDTO>    tok   = new List <TokenDTO>();
            List <TemplateDTO> templ = new List <TemplateDTO>();

            if (currentAccount.Tokens != null && currentAccount.Tokens.Count > 0)
            {
                foreach (GoogleSheetsAccountToken token in currentAccount.Tokens)
                {
                    TokenDTO localtok = token.ConvertToDAO(token);
                    tok.Add(localtok);
                }
                target.Tokens = tok.ToArray();
            }
            if (currentAccount.Template != null && currentAccount.Template.Count > 0)
            {
                foreach (GoogleSheetsAccountTemplate template in currentAccount.Template)
                {
                    TemplateDTO locTemlate = template.ConvertToDAO(template);
                    templ.Add(locTemlate);
                }
                target.MappingTemplates = templ.ToArray();
            }
            return(target);
        }
Exemplo n.º 7
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;
        }
        //GoogleSheetsAccountSettings TestAccountSettings = new GoogleSheetsAccountSettings();
        private GoogleSheetsAccountSettings NewTestAccount(GoogleSheetsAccountSettings TestAccountSettings)
        {
            IAccountSettings ias;

            SettingsManager.AccountSettingsTest(TestAccountSettings, out ias);
            TestAccountSettings = (GoogleSheetsAccountSettings)ias;
            return(TestAccountSettings);
        }
        // удаление аккаунта
        private void DeleteAccountGBButton_Click(object sender, EventArgs e)
        {
            String           selectedAccountName;
            IAccountSettings result = userGoogleAccounts.SingleOrDefault(x => x.Name == GR4ComboBox.SelectedItem.ToString());

            if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
            {
                googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
            }
            if (GR4ComboBox.SelectedItem != null && (GR4ComboBox.SelectedItem.ToString() == googleSheetsAccountSettings.Name))
            {
                selectedAccountName = GR4ComboBox.SelectedItem.ToString();
            }
            else
            {
                selectedAccountName = String.Empty;
            }
            if (selectedAccountName != String.Empty)
            {
                Boolean deleteResult;

                if (DialogResult.Yes == MessageBox.Show(
                        String.Format("Delete this Account: {0}.", selectedAccountName), "Confirm", MessageBoxButtons.YesNo))
                {
                    if (googleSheetsAccountSettings.Owner)
                    {
                        if (DialogResult.Yes == MessageBox.Show(
                                String.Format("Delete this account for all users?", selectedAccountName), "Confirm", MessageBoxButtons.YesNo))
                        {
                            deleteResult = loggedUser.DeleteAccount(googleSheetsAccountSettings, true);
                        }
                        else
                        {
                            deleteResult = loggedUser.DeleteAccount(googleSheetsAccountSettings, false);
                        }
                    }
                    else
                    {
                        deleteResult = loggedUser.DeleteAccount(googleSheetsAccountSettings, false);
                    }

                    if (deleteResult)
                    {
                        groupBox4.Visible = false;
                        RefreshSettings();
                    }
                    else
                    {
                        MessageBox.Show("Error. Try later");
                    }
                }
            }
        }
 private void DeleteTemplateButton_Click(object sender, EventArgs e)
 {
     if (TemplateComboBox.SelectedItem != null)
     {
         IAccountSettings result = userGoogleAccounts.SingleOrDefault(x => x.Name == accName);
         if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
         {
             googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
         }
         googleSheetsAccountSettings.Template.RemoveAt(TemplateComboBox.SelectedIndex);
         if (SettingsManager.SaveOrUpdateAccount(googleSheetsAccountSettings))
         {
             RefreshMapSetting();
         }
     }
 }
 private void ActivateTemplateButton_Click(object sender, EventArgs e)
 {
     if (TemplateComboBox.SelectedItem != null) // допилить!
     {
         IAccountSettings result = userGoogleAccounts.SingleOrDefault(x => x.Name == accName);
         if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
         {
             googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
         }
         // [a1-b1][a2-b2]...[an-bn]
         if (googleSheetsAccountSettings.Tokens.Count > 0)
         {
             googleSheetsAccountTemplate = googleSheetsAccountSettings.Template.SingleOrDefault(x => x.TemplateName == TemplateComboBox.SelectedItem.ToString());
             //googleSheetsAccountTemplate
         }
     }
 }
        private void RefreshMapSetting()
        {
            label13.Text = "";
            MappingDataView.DataSource = null;
            MappingDataView.SelectAll();
            MappingDataView.ClearSelection();
            TemplateComboBox.Items.Clear();
            IAccountSettings result = userGoogleAccounts.SingleOrDefault(x => x.Name == AccountsNameComboBox.SelectedItem.ToString());

            if (SettingsManager.GetDetailsForAccount(loggedUser, result.ID) != null)
            {
                googleSheetsAccountSettings = (GoogleSheetsAccountSettings)SettingsManager.GetDetailsForAccount(loggedUser, result.ID);
            }
            foreach (var item in googleSheetsAccountSettings.Template)
            {
                TemplateComboBox.Items.Add(item.TemplateName);
            }
        }