static void BuildFromRemote(Library library, SynchronisationStates synchronisation_states) { // --- TODO: Replace this with a pretty interface class ------------------------------------------------ if (false) { } else if (library.WebLibraryDetail.IsIntranetLibrary) { SynchronisationStateBuilder_Intranet.BuildFromRemote(library, synchronisation_states); } else { throw new Exception(String.Format("Did not understand how to build from remote for library {0}", library.WebLibraryDetail.Title)); } // ----------------------------------------------------------------------------------------------------- }
/// <summary> /// Builds a map of SynchronisationState objects of the form /// filename -> SynchronisationState /// </summary> /// <returns></returns> internal static SynchronisationStates Build(Library library, Dictionary <string, string> historical_sync_file) { SynchronisationStates synchronisation_states = new SynchronisationStates(); StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(library), "Building sync state from local history", 0, 1); BuildFromHistoricalSyncFile(historical_sync_file, ref synchronisation_states); StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(library), "Building sync state from local files", 0, 1); BuildFromLocal(library, ref synchronisation_states); StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(library), "Building sync state from Web/Intranet Library", 0, 1); BuildFromRemote(library, ref synchronisation_states); FilterSynchronisationStates(ref synchronisation_states); return(synchronisation_states); }
private static void FilterSynchronisationStates(ref SynchronisationStates synchronisation_states) { HashSet <string> ineligible_keys = new HashSet <string>(); foreach (var pair in synchronisation_states) { if (!SynchronisationFileTypes.extensions.Contains(pair.Value.extension)) { Logging.Warn("Not syncing unsupported extension of {0} in {1}", pair.Value.extension, pair.Value.filename); ineligible_keys.Add(pair.Key); } } foreach (string key in ineligible_keys) { synchronisation_states.Remove(key); } }
private static void BuildFromHistoricalSyncFile(Dictionary <string, string> historical_sync_file, ref SynchronisationStates synchronisation_states) { foreach (var pair in historical_sync_file) { synchronisation_states[pair.Key].md5_previous = pair.Value; } }
internal static SynchronisationAction Build(WebLibraryDetail web_library_detail, SynchronisationStates synchronisation_states) { SynchronisationAction synchronisation_action = new SynchronisationAction(); List <SynchronisationState> synchronisation_state_list = new List <SynchronisationState>(synchronisation_states.Values); for (int i = 0; i < synchronisation_state_list.Count; ++i) { SynchronisationState synchronisation_state = synchronisation_state_list[i]; if (false || (0 == i % 20 && synchronisation_state_list.Count < 100) || (0 == i % 100 && synchronisation_state_list.Count < 1000) || (0 == i % 500) ) { StatusManager.Instance.UpdateStatus(StatusCodes.SYNC_META(web_library_detail), "Determining sync action", i, synchronisation_state_list.Count); } // NB: Ordering of these statements is important so don't reorder them! // Not local, not remote: something dodgy in the history file, ignore it if (null == synchronisation_state.md5_local && null == synchronisation_state.md5_remote) { synchronisation_action.states_dodgy.Add(synchronisation_state); } // If we don't have it locally but we do remotely else if (null == synchronisation_state.md5_local && null != synchronisation_state.md5_remote) { synchronisation_action.states_to_download.Add(synchronisation_state); } // If we don't have it remotely, but we do locally else if (null != synchronisation_state.md5_local && null == synchronisation_state.md5_remote) { synchronisation_action.states_to_upload.Add(synchronisation_state); } // If local and remote match, do nothing else if (0 == synchronisation_state.md5_local.CompareTo(synchronisation_state.md5_remote)) { synchronisation_action.states_already_synced.Add(synchronisation_state); } // If local and remote don't match, but local has not changed else if (0 == synchronisation_state.md5_local.CompareTo(synchronisation_state.md5_previous)) { synchronisation_action.states_to_download.Add(synchronisation_state); } // If local and remote don't match, but remote has not changed else if (0 == synchronisation_state.md5_remote.CompareTo(synchronisation_state.md5_previous)) { synchronisation_action.states_to_upload.Add(synchronisation_state); } // If local and remote don't match and neither match the previous value, we have a merge conflict else { synchronisation_action.states_to_merge.Add(synchronisation_state); } } return(synchronisation_action); }