Ejemplo n.º 1
0
        private void syncInterval_Reload()
        {
            Properties.Settings settings = Properties.Settings.Default;

            int interval = settings.SyncInterval / 60;

            for (int i = 0; i < intervals.Length; i++)
            {
                if (i == 0 && interval < 1)
                {
                    this.syncInterval.SelectedIndex = i;
                }
                else if (i > 0 && interval > 0 && int.Parse(intervals[i]) == interval)
                {
                    this.syncInterval.SelectedIndex = i;
                }
            }
        }
Ejemplo n.º 2
0
        private void SettingForm_Load(object sender, EventArgs e)
        {
            Properties.Settings settings = Properties.Settings.Default;

            if (!settings.Upgraded)
            {
                settings.Upgrade();
                settings.Upgraded = true;
                settings.Save();
                settings.Reload();
            }

            SetTimerInterval(settings);
            this.timer.Start();

            CybozuException ex;

            if (Program.CanSync(out ex))
            {
                this.syncButton.Enabled = true;
            }
            else
            {
                this.WindowState = FormWindowState.Normal;
                ShowMessageIfLicenseError(ex);
            }

            this.syncInterval.Items.AddRange(intervals);
            syncInterval_Reload();

            lastSync_Reload();

            // product name, version number
            this.productName.Text   = Application.ProductName;
            this.versionNumber.Text = string.Format("Version {0}", Application.ProductVersion);
        }
Ejemplo n.º 3
0
        public static bool CanSync(out CybozuException ex)
        {
            ex = null;

            Properties.Settings settings = Properties.Settings.Default;
            if (!IsConfigured(settings))
            {
                return(false);
            }

            App      firstApp, secondApp;
            Schedule firstSchedule, secondSchedule;

            try
            {
                firstApp = new App(settings.FirstUrl);
                firstApp.Auth(settings.FirstUsername, settings.FirstPassword);
                firstSchedule = new Schedule(firstApp);

                secondApp = new App(settings.SecondUrl);
                secondApp.Auth(settings.SecondUsername, settings.SecondPassword);
                secondSchedule = new Schedule(secondApp);
            }
            catch (CybozuException e)
            {
                // fail to auth
                ex = e;
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 private void SetTimerInterval(Properties.Settings settings)
 {
     this.timer.Interval = Math.Max(30, (int)settings.SyncInterval) * 60 * 1000;
 }
Ejemplo n.º 5
0
        private bool Apply()
        {
            if (string.IsNullOrEmpty(this.firstUrl.Text) && string.IsNullOrEmpty(this.secondUrl.Text))
            {
                this.syncButton.Enabled = false;
                Properties.Settings.Default.Save();
                return(true);
            }

            string url1 = TrimUrl(this.firstUrl.Text);

            if (string.IsNullOrEmpty(url1))
            {
                MessageBox.Show(string.Format(Resources.Account1Error, Resources.URLIsInvalid), Resources.ProductName);
                return(false);
            }

            string url2 = TrimUrl(this.secondUrl.Text);

            if (string.IsNullOrEmpty(url2))
            {
                MessageBox.Show(string.Format(Resources.Account2Error, Resources.URLIsInvalid), Resources.ProductName);
                return(false);
            }

            App app;

            try
            {
                app = new App(url1);
                app.Auth(this.firstUsername.Text, this.firstPassword.Text);
            }
            catch (CybozuException ex)
            {
                if (!ShowMessageIfLicenseError(ex))
                {
                    MessageBox.Show(string.Format(Resources.Account1Error, ex.Message), Resources.ProductName);
                }
                return(false);
            }
            catch (UriFormatException ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            catch (WebException ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            if (string.IsNullOrEmpty(this.firstPostfix.Text))
            {
                MessageBox.Show(string.Format(Resources.Account1Error, Resources.PostfixIsNecessary), Resources.ProductName);
                return(false);
            }

            try
            {
                app = new App(url2);
                app.Auth(this.secondUsername.Text, this.secondPassword.Text);
            }
            catch (CybozuException ex)
            {
                if (!ShowMessageIfLicenseError(ex))
                {
                    MessageBox.Show(string.Format(Resources.Account2Error, ex.Message), Resources.ProductName);
                }
                return(false);
            }
            catch (UriFormatException ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            catch (WebException ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            if (string.IsNullOrEmpty(this.secondPostfix.Text))
            {
                MessageBox.Show(string.Format(Resources.Account2Error, Resources.PostfixIsNecessary), Resources.ProductName);
                return(false);
            }

            this.firstUrl.Text  = url1;
            this.secondUrl.Text = url2;

            Properties.Settings settings = Properties.Settings.Default;

            int intervalIndex = this.syncInterval.SelectedIndex;

            if (intervalIndex >= 0)
            {
                int nextInterval = (int)(double.Parse(intervals[intervalIndex]) * 60);
                if (settings.SyncInterval != nextInterval)
                {
                    settings.SyncInterval = nextInterval;
                    SetTimerInterval(settings);
                }
            }

            this.syncButton.Enabled = true;
            settings.Save();

            return(true);
        }