Exemplo n.º 1
0
        public const string DescriptionHeaderName = "# CrossSync: "; // Don't modify this.

        #endregion Fields

        #region Methods

        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;
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public static bool Sync()
        {
            Properties.Settings settings = Properties.Settings.Default;
            if (!IsConfigured(settings)) return false;

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

            App secondApp = new App(settings.SecondUrl);
            secondApp.Auth(settings.SecondUsername, settings.SecondPassword);
            Schedule secondSchedule = new Schedule(secondApp);

            // sync span
            DateTime start = DateTime.Now.Date;
            DateTime end = start.AddMonths(1);

            // current events in first
            ScheduleEventCollection event1to2 = new ScheduleEventCollection();
            ScheduleEventCollection event1from2 = new ScheduleEventCollection();
            GetEvents(firstApp, firstSchedule, settings.SecondPostfix, start, end, event1to2, event1from2);

            // current events in second
            ScheduleEventCollection event2to1 = new ScheduleEventCollection();
            ScheduleEventCollection event2from1 = new ScheduleEventCollection();
            GetEvents(secondApp, secondSchedule, settings.FirstPostfix, start, end, event2to1, event2from1);

            // remove not modified
            UnsetNotModified(event1to2, event2to1, event2from1, settings.FirstPostfix);
            UnsetNotModified(event2to1, event1to2, event1from2, settings.SecondPostfix);

            // remove old copied events
            RemoveInvalidCopiedEvents(secondSchedule, event2from1);
            RemoveInvalidCopiedEvents(firstSchedule, event1from2);

            // add new copied events
            CopyValidEvents(secondSchedule, event1to2, settings.FirstPostfix);
            CopyValidEvents(firstSchedule, event2to1, settings.SecondPostfix);

            settings.LastSynchronized = DateTime.Now.ToString("o");
            settings.Save();

            return true;
        }