public void SetDeviceOptions(ZPushAccount account, SyncTimeFrame timeFrame) { try { Logger.Instance.Debug(this, "Setting sync time frame for {0} to {1}", account, timeFrame); // First set the server value. using (ZPushConnection connection = account.Connect()) using (ZPushWebServiceDevice deviceService = connection.DeviceService) { deviceService.Execute(new SetDeviceOptionsRequest(timeFrame)); } // And the local value account.SyncTimeFrame = timeFrame; Logger.Instance.Debug(this, "Set sync time frame for {0} to {1}", account, timeFrame); // Sync ThisAddIn.Instance.SendReceive(account.Account); } catch (Exception x) { Logger.Instance.Warning(this, "Exception setting sync time frame for {0} to {1}: {2}", account, timeFrame, x); } }
public static string ToDisplayString(this SyncTimeFrame _this) { string s = Properties.Resources.ResourceManager.GetString("SyncTimeFrame_" + _this.ToString()); if (s == null) { return(_this.ToString()); } return(s); }
public static bool IsShorterThan(this SyncTimeFrame _this, SyncTimeFrame other) { if (_this == SyncTimeFrame.ALL) { return(false); // ALL can not be shorter than anything } if (other == SyncTimeFrame.ALL) { return(true); // Always true, if this was ALL, already returned above, so this must be shorter } return((int)_this < (int)other); }
private void CheckTimeFrameDirty() { if (SelectedAccount != null) { SyncTimeFrame timeFrame = (SyncTimeFrame)comboTimeFrame.SelectedIndex; bool isDirty = timeFrame != SelectedAccount.SyncTimeFrame; buttonApplyTimeFrame.Enabled = buttonResetTimeFrame.Enabled = isDirty; } else { buttonApplyTimeFrame.Enabled = buttonResetTimeFrame.Enabled = false; } }
public static bool IsOneMonthOrLess(this SyncTimeFrame sync) { return(sync <= SyncTimeFrame.MONTH_1 && sync != SyncTimeFrame.ALL); }
public SuggestedSyncTimeFrame(long storeSize, SyncTimeFrame timeFrame) : this() { this.storeSize = storeSize; this.timeFrame = timeFrame; }
private void CheckTotalSize(ZPushConnection connection) { if (!CheckStoreSize || _checkedStoreSize) { return; } // Only works on 2.5 // If we don't have the version yet, try again later if (connection.Account.ZPushVersion == null) { return; } // Only check once _checkedStoreSize = true; // If it's not 2.5, don't check again if (!connection.Account.ZPushVersion.IsAtLeast(2, 5)) { return; } try { Logger.Instance.Debug(this, "Fetching size information for account {0}", connection.Account); using (ZPushWebServiceInfo infoService = connection.InfoService) { UserStoreInfo info = infoService.Execute(new GetUserStoreInfoRequest()); Logger.Instance.Debug(this, "Size information: {0}", info); SyncTimeFrame suggested = SuggestSyncTimeFrame(info); if (suggested.IsShorterThan(connection.Account.SyncTimeFrame)) { // Suggest shorter time frame, if not already done string lastCheckedSize = connection.Account.Account[KEY_CHECKED_SIZE]; if (!string.IsNullOrWhiteSpace(lastCheckedSize)) { try { SyncTimeFrame old = (SyncTimeFrame)int.Parse(lastCheckedSize); if (old >= suggested) { Logger.Instance.Trace(this, "Not suggesting reduced sync time frame again: {0}: {2} -> {1}", info, suggested, old); return; } } catch (Exception e) { Logger.Instance.Warning(this, "Invalid lastCheckedSize: {0}: {1}", lastCheckedSize, e); } } Logger.Instance.Debug(this, "Suggesting reduced sync time frame: {0}: {2} -> {1}", info, suggested, connection.Account.SyncTimeFrame); // Suggest a shorter timeframe DialogResult result = MessageBox.Show(ThisAddIn.Instance.Window, string.Format(Properties.Resources.SyncState_StoreSize_Body, info.storesize.ToSizeString(SizeUtil.Size.MB), suggested.ToDisplayString()), Properties.Resources.SyncState_StoreSize_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == DialogResult.OK) { // Set the sync time frame Logger.Instance.Debug(this, "Applying reduced sync time frame: {0}: {2} -> {1}", info, suggested, connection.Account.SyncTimeFrame); connection.Account.SyncTimeFrame = suggested; } } connection.Account.Account[KEY_CHECKED_SIZE] = ((int)suggested).ToString(); } } catch (Exception e) { Logger.Instance.Warning(this, "Error suggesting size: {0}", e); } }
public SetDeviceOptionsRequest(SyncTimeFrame timeFrame) { Parameters.Add("filtertype", (int)timeFrame); }