Exemple #1
0
        private void OnRemove_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected kites?", "Remove Kite", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (!this.kitePanel.GetChecked(this.data.Kites))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "No kites selected", true);
                    return;
                }

                List <string> kitenames = new List <string>();

                foreach (PkKite kite in this.data.Kites.Values)
                {
                    if (kite.Fly)
                    {
                        kitenames.Add(kite.Domain);
                    }
                }

                if (PkService.DeleteKites(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, kitenames))
                {
                    foreach (string kite in kitenames)
                    {
                        this.data.Kites.Remove(kite);
                    }

                    this.kitePanel.RemoveKites();
                    this.data.Save();
                }
            }
        }
Exemple #2
0
            private void OnOk_Click(object sender, EventArgs e)
            {
                string email    = this.emailTextBox.Text;
                string kiteName = this.kiteTextBox.Text;
                string password = this.passwordTextBox.Text;

                if (!this.ValidateEmail(email))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid email address", true);
                    return;
                }
                if (string.IsNullOrEmpty(kiteName))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid kite name", true);
                    return;
                }

                if (string.IsNullOrEmpty(password))
                {
                    if (this.agreeCheckBox.Checked)
                    {
                        if (PkService.CreateAccount(email, kiteName))
                        {
                            PkLogging.Logger(PkLogging.Level.Info, "An email containing your password and details has been sent to " + email, true);
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        PkLogging.Logger(PkLogging.Level.Warning, "You must agree to the terms of service to continue.", true);
                    }
                }
                else
                {
                    PkServiceInfo info = PkService.Login(email, password, false);

                    if (info != null)
                    {
                        PkLogging.Logger(PkLogging.Level.Info, "Successfully signed in.");

                        password = "";
                        this.passwordTextBox.Text = "";

                        this.RememberMe  = this.rememberCheckBox.Checked;
                        this.ServiceInfo = info;

                        PkLoginForm parent = (this.Parent as PkLoginForm);
                        parent.Close_Login();
                    }
                    else
                    {
                        return;
                    }
                }
            }
Exemple #3
0
 private void RenewLogin()
 {
     while (true)
     {
         // Renew login every 50 minutes
         Thread.Sleep(50 * 60 * 1000);
         if (!this.IsDisposed)
         {
             PkService.Login(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, true);
         }
     }
 }
Exemple #4
0
        private void LogIn()
        {
            if (this.data.Options.RememberMe)
            {
                PkServiceInfo info = PkService.Login(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, true);

                if (info != null)
                {
                    PkLogging.Logger(PkLogging.Level.Info, "Successfully logged in.");
                }
                else
                {
                    PkSplashForm.CloseSplashScreen();
                    this.ShowLoginForm();
                }
            }
            else
            {
                PkSplashForm.CloseSplashScreen();
                this.ShowLoginForm();
            }
        }
Exemple #5
0
        private void OnAdd_Click(object sender, EventArgs e)
        {
            using (PkAddKiteForm addKite = new PkAddKiteForm())
            {
                Dictionary <string, string[]> domains = PkService.GetAvailableDomains(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials);

                addKite.SetComboBox(domains);

                var result = addKite.ShowDialog();

                if (result == DialogResult.OK)
                {
                    if (PkService.AddKite(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, addKite.Kitename))
                    {
                        PkKite kite = new PkKite();
                        kite.Domain = addKite.Kitename;
                        kite.Secret = this.data.ServiceInfo.Secret;
                        this.data.Kites.Add(kite.Domain, kite);
                        this.kitePanel.AddKite(kite);
                        this.data.Save();
                    }
                }
            }
        }
Exemple #6
0
        private void SynchronizeAccountInfo()
        {
            PkData serviceData = PkService.GetAccountInfo(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials);
            Dictionary <string, double> kiteStats = PkService.GetKiteStats(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials);

            if (serviceData != null && kiteStats != null)
            {
                //Update info about account and kites if it has been manipulated outside of this program

                this.data.ServiceInfo.Secret = serviceData.ServiceInfo.Secret;

                this.data.ServiceInfo.DaysLeft = serviceData.ServiceInfo.DaysLeft;

                this.data.ServiceInfo.MbLeft = serviceData.ServiceInfo.MbLeft;

                List <string> removeDomain = new List <string>();

                //If any kites have been removed, remove them
                foreach (string domain in this.data.Kites.Keys)
                {
                    if (!serviceData.Kites.ContainsKey(domain))
                    {
                        removeDomain.Add(domain);
                    }
                }

                //If any kites are disabled, remove them
                foreach (string domain in kiteStats.Keys)
                {
                    if (kiteStats[domain] < 0)
                    {
                        removeDomain.Add(domain);
                    }
                }

                foreach (string domain in removeDomain)
                {
                    if (this.data.Kites.ContainsKey(domain))
                    {
                        this.data.Kites.Remove(domain);
                    }
                }

                foreach (string domain in serviceData.Kites.Keys)
                {
                    //If new kites have been added, add them, unless they are disabled
                    if (!this.data.Kites.ContainsKey(domain) && kiteStats[domain] > 0)
                    {
                        if (String.IsNullOrEmpty(serviceData.Kites[domain].Secret))
                        {
                            serviceData.Kites[domain].Secret = this.data.ServiceInfo.Secret;
                        }
                        this.data.Kites.Add(domain, serviceData.Kites[domain]);
                    }

                    if (this.data.Kites.ContainsKey(domain))
                    {
                        //Update kite secret if it has changed
                        if (!this.data.Kites[domain].Secret.Equals(serviceData.Kites[domain].Secret) &&
                            !String.IsNullOrEmpty(serviceData.Kites[domain].Secret))
                        {
                            this.data.Kites[domain].Secret = serviceData.Kites[domain].Secret;
                        }
                    }
                }

                PkLogging.Logger(PkLogging.Level.Info, "All kites are up to date.");
            }

            if (this.data.Options.RememberMe)
            {
                this.data.Save();
            }
        }