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); }
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); }
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); }