| 815 | | bool result = mClient->_CheckCalendar(node, cal); |
| 816 | | |
| 817 | | // Always keep disconnected cache in sync with server |
| 818 | | if (result && (mCacheClient != NULL)) |
| 819 | | { |
| 820 | | // If cache does not exist, create it |
| 821 | | if (!mCacheClient->_TestCalendar(node)) |
| 822 | | { |
| 823 | | mCacheClient->_CreateCalendar(node); |
| 824 | | mCacheClient->_WriteFullCalendar(node, cal); |
| | 815 | bool result = false; |
| | 816 | |
| | 817 | // See if offline or disconnected |
| | 818 | if (IsOffline() || IsDisconnected()) |
| | 819 | { |
| | 820 | // Nothing to do here. We will assume that local files are always |
| | 821 | // up to date. |
| | 822 | } |
| | 823 | else |
| | 824 | { |
| | 825 | // Look for local cache first |
| | 826 | if ((mCacheClient != NULL) && !mCacheIsPrimary) |
| | 827 | { |
| | 828 | // Read in the calendar cache if it exists |
| | 829 | if (mCacheClient->_TestCalendar(node)) |
| | 830 | mCacheClient->_ReadFullCalendar(node, cal); |
| | 831 | |
| | 832 | // Sync cache with server doing playback if needed |
| | 833 | SyncFromServer(node, cal); |
| 828 | | // Get temp copy of cached calendar |
| 829 | | iCal::CICalendar temp; |
| 830 | | mCacheClient->_ReadFullCalendar(node, temp); |
| 831 | | |
| 832 | | // Sync changes in cache |
| 833 | | bool server_changed = false; |
| 834 | | if (temp.GetETag() == cal.GetETag()) |
| 835 | | { |
| 836 | | if (temp.NeedsSync()) |
| 837 | | { |
| 838 | | // Local overwrites server |
| 839 | | cal.Clear(); |
| 840 | | mCacheClient->_ReadFullCalendar(node, cal); |
| 841 | | cal.ClearRecording(); |
| 842 | | server_changed = true; |
| 843 | | } |
| 844 | | } |
| 845 | | else |
| 846 | | { |
| 847 | | if (!temp.NeedsSync()) |
| 848 | | { |
| 849 | | // Server overwrites local - nothing to do just fall through to write |
| 850 | | } |
| 851 | | else |
| 852 | | { |
| 853 | | // Sync the two |
| 854 | | iCal::CICalendarSync sync(temp, cal); |
| 855 | | sync.Sync(); |
| 856 | | |
| 857 | | // Local overwrites server |
| 858 | | cal.Clear(); |
| 859 | | mCacheClient->_ReadFullCalendar(node, cal); |
| 860 | | cal.ClearRecording(); |
| 861 | | } |
| 862 | | } |
| 863 | | |
| 864 | | // Update the server if needed |
| 865 | | if (server_changed) |
| 866 | | { |
| 867 | | mClient->_WriteFullCalendar(node, cal); |
| 868 | | } |
| 869 | | |
| 870 | | // Now write out the new cache data, this will overwrite any recorded |
| 871 | | // changes that have been sync'd so they will not be sync'd again |
| 872 | | mCacheClient->_WriteFullCalendar(node, cal); |
| 873 | | } |
| 874 | | } |
| 875 | | |
| | 837 | // Just read full calendar from server |
| | 838 | result = mClient->_CalendarChanged(node, cal); |
| | 839 | if (result) |
| | 840 | ReadFullCalendar(node, cal); |
| | 841 | } |
| | 842 | } |
| | 843 | |