private string AutoDiscover(ZPushAccount account)
        {
            // Check for a cached entry
            URLCached cached = account.GetFeatureData <URLCached>(this, TXT_KDISCOVER);

            // Only cache actual URLs, not missing urls
            if (cached != null)
            {
                return(cached.Url);
            }

            // Perform a cached auto discover
            try
            {
                Logger.Instance.Debug(this, "Starting kdiscover: {0}", account.Account.DomainName);
                string url = PerformAutoDiscover(account);
                Logger.Instance.Debug(this, "Finished kdiscover: {0}: {1}", account.Account.DomainName, url);
                account.SetFeatureData(this, TXT_KDISCOVER, new URLCached(url));
                return(url);
            }
            catch (System.Exception e)
            {
                Logger.Instance.Warning(this, "Exception during kdiscover: {0}: {1}", account.Account.DomainName, e);
                account.SetFeatureData(this, TXT_KDISCOVER, null);
                return(null);
            }
        }
예제 #2
0
        private void CheckSyncStalled(ZPushAccount account)
        {
            if (!CheckSyncStall)
            {
                return;
            }

            // Check the inbox folder
            using (IFolder inbox = account.Account.Store.GetDefaultFolder(DefaultFolder.Inbox))
            {
                string syncId = (string)inbox.GetProperty(OutlookConstants.PR_ZPUSH_SYNC_ID);

                // If it's syncing, it's not stalled
                if (syncId != null && syncId != "0")
                {
                    return;
                }

                SyncSession sync = account.GetFeatureData <SyncSession>(this, null);

                // If the last sync time hasn't changed, it hasn't actually synced yet
                if (sync.LastSyncTime != null && _syncStallLastSyncTime == sync.LastSyncTime)
                {
                    return;
                }
                _syncStallLastSyncTime = sync.LastSyncTime;

                // Get the sync state
                string folderId = (string)inbox.GetProperty(OutlookConstants.PR_ZPUSH_FOLDER_ID);
                if (folderId != null)
                {
                    // Check if the folder has synced. In that case, it's not stalled.
                    if (sync.HasFolderSynced(folderId))
                    {
                        return;
                    }
                }
            }

            // It is not syncing, check for a stall
            if (_syncStallStarted == null)
            {
                _syncStallStarted = DateTime.Now;
            }
            else if (_syncStallStarted.Value.Add(CheckSyncStallPeriod) <= DateTime.Now)
            {
                // We have a stall
                if (!_syncStallAsked)
                {
                    // Set the flag to prevent asking again
                    _syncStallAsked = true;

                    // And alert the user
                    SyncStalled(account);
                }
            }
        }
        public ICollection <SharedFolder> GetCachedFolders(ZPushAccount zpush)
        {
            Dictionary <SyncId, SharedFolder> shared = zpush.GetFeatureData <Dictionary <SyncId, SharedFolder> >(this, KEY_SHARES);

            if (shared == null)
            {
                return(null);
            }
            return(shared.Values);
        }
 private void Watcher_ZPushAccountChange(ZPushAccount account)
 {
     if (_button != null)
     {
         if (account == null)
         {
             _button.IsPressed = false;
         }
         else
         {
             _button.IsPressed = IsOOFEnabled(account.GetFeatureData <ActiveSync.SettingsOOF>(this, "OOF"));
         }
     }
 }
예제 #5
0
        private void CheckSyncState(ZPushAccount account)
        {
            // TODO: we probably want one invocation for all accounts
            using (ZPushConnection connection = account.Connect())
            {
                // Check total size
                CheckTotalSize(connection);

                // Update sync state
                using (ZPushWebServiceDevice deviceService = connection.DeviceService)
                {
                    // Fetch
                    DeviceDetails details = deviceService.Execute(new GetDeviceDetailsRequest());
                    if (details != null)
                    {
                        bool wasSyncing = false;

                        // Create or update session
                        SyncSession session = account.GetFeatureData <SyncSession>(this, null);
                        if (session == null)
                        {
                            session = new SyncSession(this, account);
                        }
                        else
                        {
                            wasSyncing = session.IsSyncing;
                        }

                        session.Add(details);

                        // Store with the account
                        account.SetFeatureData(this, null, session);

                        if (wasSyncing != session.IsSyncing)
                        {
                            // Sync state has changed, update the schedule
                            Watcher.Sync.SetTaskSchedule(_task, account, session.IsSyncing ? CheckPeriodSync : (TimeSpan?)null);
                        }
                    }
                }
            }

            // Update the total for all accounts
            UpdateTotalSyncState();

            // Check for stalls
            CheckSyncStalled(account);
        }
        public SharedFolder GetSharedFolder(IFolder folder)
        {
            if (folder == null)
            {
                return(null);
            }

            // Check that we can get the id
            SyncId folderId = folder.SyncId;

            Logger.Instance.Trace(this, "GetSharedFolder1: {0}", folderId);
            if (folderId == null || !folderId.IsCustom)
            {
                return(null);
            }

            // Get the ZPush account
            ZPushAccount account = Watcher.Accounts.GetAccount(folder);

            Logger.Instance.Trace(this, "GetSharedFolder2: {0}", account);
            if (account == null)
            {
                return(null);
            }

            // Get the shared folders
            Dictionary <SyncId, SharedFolder> shared = account.GetFeatureData <Dictionary <SyncId, SharedFolder> >(this, KEY_SHARES);

            Logger.Instance.Trace(this, "GetSharedFolder3: {0}", shared?.Count);
            if (shared == null)
            {
                return(null);
            }

            SharedFolder share = null;

            shared.TryGetValue(folderId, out share);
            Logger.Instance.Trace(this, "GetSharedFolder4: {0}", share);

            return(share);
        }