/// <summary> /// Loads a specific item from disk /// </summary> private Item DoLoadItem(string path, AdvancedLoadOptions options, out ItemLoadResult loadResult) { Assert.ArgumentNotNullOrEmpty(path, "path"); Assert.ArgumentNotNull(options, "options"); if (File.Exists(path)) { using (TextReader fileReader = new StreamReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { LogLocalized("Loading item from path {0}.", new object[] { PathUtils.UnmapItemPath(path, options.Root) }); bool disabledLocally = ItemHandler.DisabledLocally; try { ItemHandler.DisabledLocally = true; Item result = null; try { var serializedItem = SyncItem.ReadItem(new Tokenizer(fileReader)); _itemsProcessed++; if(_itemsProcessed % 500 == 0 && _itemsProcessed > 1) options.Progress.ReportStatus(string.Format("Processed {0} items", _itemsProcessed), MessageType.Debug); if (options.Preset.Exclude.MatchesTemplate(serializedItem.TemplateName)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded its template name, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return null; } if (options.Preset.Exclude.MatchesTemplateId(serializedItem.TemplateID)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded its template ID, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return null; } if (options.Preset.Exclude.MatchesId(serializedItem.ID)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded it by ID, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return null; } if (options.Preset.Exclude.MatchesPath(path)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded it by path, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return null; } var newOptions = new LoadOptions(options); // in some cases we want to force an update for this item only if (!options.ForceUpdate && ShouldForceUpdate(serializedItem, options.Progress)) { options.Progress.ReportStatus(string.Format("[FORCED] {0}:{1}", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Info); newOptions.ForceUpdate = true; } result = ItemSynchronization.PasteSyncItem(serializedItem, newOptions, true); loadResult = ItemLoadResult.Success; } catch (ParentItemNotFoundException ex) { result = null; loadResult = ItemLoadResult.Error; string error = "Cannot load item from path '{0}'. Probable reason: parent item with ID '{1}' not found.".FormatWith( PathUtils.UnmapItemPath(path, options.Root), ex.ParentID); options.Progress.ReportStatus(error, MessageType.Error); LogLocalizedError(error); } catch (ParentForMovedItemNotFoundException ex2) { result = ex2.Item; loadResult = ItemLoadResult.Error; string error = "Item from path '{0}' cannot be moved to appropriate location. Possible reason: parent item with ID '{1}' not found." .FormatWith(PathUtils.UnmapItemPath(path, options.Root), ex2.ParentID); options.Progress.ReportStatus(error, MessageType.Error); LogLocalizedError(error); } return result; } finally { ItemHandler.DisabledLocally = disabledLocally; } } } loadResult = ItemLoadResult.Error; return null; }
/// <summary> /// Loads a specific item from disk /// </summary> private Item DoLoadItem(string path, AdvancedLoadOptions options, out ItemLoadResult loadResult) { Assert.ArgumentNotNullOrEmpty(path, "path"); Assert.ArgumentNotNull(options, "options"); if (File.Exists(path)) { using (TextReader fileReader = new StreamReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { LogLocalized("Loading item from path {0}.", new object[] { PathUtils.UnmapItemPath(path, options.Root) }); bool disabledLocally = ItemHandler.DisabledLocally; try { ItemHandler.DisabledLocally = true; Item result = null; try { var serializedItem = SyncItem.ReadItem(new Tokenizer(fileReader)); _itemsProcessed++; if (_itemsProcessed % 500 == 0 && _itemsProcessed > 1) { options.Progress.ReportStatus(string.Format("Processed {0} items", _itemsProcessed), MessageType.Debug); } if (options.Preset.Exclude.MatchesTemplate(serializedItem.TemplateName)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded its template name, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return(null); } if (options.Preset.Exclude.MatchesTemplateId(serializedItem.TemplateID)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded its template ID, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return(null); } if (options.Preset.Exclude.MatchesId(serializedItem.ID)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded it by ID, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return(null); } if (options.Preset.Exclude.MatchesPath(path)) { options.Progress.ReportStatus(string.Format("[SKIPPED] {0}:{1} because the preset excluded it by path, but the item was on disk", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Warning); loadResult = ItemLoadResult.Skipped; return(null); } var newOptions = new LoadOptions(options); // in some cases we want to force an update for this item only if (!options.ForceUpdate && ShouldForceUpdate(serializedItem, options.Progress)) { options.Progress.ReportStatus(string.Format("[FORCED] {0}:{1}", serializedItem.DatabaseName, serializedItem.ItemPath), MessageType.Info); newOptions.ForceUpdate = true; } result = ItemSynchronization.PasteSyncItem(serializedItem, newOptions, true); loadResult = ItemLoadResult.Success; } catch (ParentItemNotFoundException ex) { result = null; loadResult = ItemLoadResult.Error; string error = "Cannot load item from path '{0}'. Probable reason: parent item with ID '{1}' not found.".FormatWith( PathUtils.UnmapItemPath(path, options.Root), ex.ParentID); options.Progress.ReportStatus(error, MessageType.Error); LogLocalizedError(error); } catch (ParentForMovedItemNotFoundException ex2) { result = ex2.Item; loadResult = ItemLoadResult.Error; string error = "Item from path '{0}' cannot be moved to appropriate location. Possible reason: parent item with ID '{1}' not found." .FormatWith(PathUtils.UnmapItemPath(path, options.Root), ex2.ParentID); options.Progress.ReportStatus(error, MessageType.Error); LogLocalizedError(error); } return(result); } finally { ItemHandler.DisabledLocally = disabledLocally; } } } loadResult = ItemLoadResult.Error; return(null); }