Example #1
0
 private SyncTimeFrame SuggestSyncTimeFrame(UserStoreInfo info)
 {
     foreach (SuggestedSyncTimeFrame suggested in SUGGESTED_SYNC_TIME_FRAMES)
     {
         if (info.storesize >= suggested.storeSize)
         {
             return(suggested.timeFrame);
         }
     }
     return(SyncTimeFrame.ALL);
 }
Example #2
0
        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);
            }
        }