private FolderImporter(ImportContext importContext, ContentTypeImporter contentTypeImporter, PermissionsImporter permissionsImporter) : base("folders", importContext, contentTypeImporter, permissionsImporter) { Dictionary <string, FolderInfo> folderDictionary = new Dictionary <string, FolderInfo>(); using (XmlReader folders = this.ImportContext.LoadIndex("folders")) { int currentDepth = 0; Dictionary <string, List <FolderInfo> > accumulated = new Dictionary <string, List <FolderInfo> >(); int accumulatedCount = 0; using (ObjectPool <SharePointSession> .Ref sessionRef = this.ImportContext.SessionFactory?.GetSession()) { SharePointSession session = sessionRef?.Target; outer : while (folders.ReadToFollowing("folder")) { string location = null; string path = null; using (XmlReader folder = folders.ReadSubtree()) { // We're only interested in the <location> and <path> elements, so if they're not there // we simply move on to the next folder if (!folder.ReadToFollowing("path")) { goto outer; } path = "/" + folder.ReadElementContentAsString(); if (!folder.ReadToFollowing("location")) { goto outer; } location = folder.ReadElementContentAsString(); } int thisDepth = (path == "/" ? 0 : thisDepth = Tools.CountChars(path, '/')); // If we've changed depths, we process what we've accumulated so far if (thisDepth > currentDepth) { if (session != null) { Log.Info(string.Format("Creating {0} folders in the target environment, depth {1}", accumulatedCount, thisDepth)); try { ProcessAccumulatedFolders(session, accumulated); } catch (Exception e) { Log.Error("Failed to process the current accumulated folder batch"); throw e; } } accumulated.Clear(); accumulatedCount = 0; currentDepth = thisDepth; } // A new folder to handle... FolderInfo f = new FolderInfo(this.ImportContext.FormatMetadataLocation(location)); List <FolderInfo> l = null; if (!accumulated.ContainsKey(f.SafePath)) { l = new List <FolderInfo>(); accumulated[f.SafePath] = l; } else { l = accumulated[f.SafePath]; } /* * if (thisDepth == 0) * { * // Check to see if this is a cabinet we want to avoid * if (XmlConvert.ToBoolean(XmlTools.GetAttributeValue(xml, "dctm:is_private"))) * { * Log.Info(string.Format("Skipping private cabinet [{0}]", f.FullPath)); * continue; * } * } */ l.Add(f); accumulatedCount++; folderDictionary[f.FullPath] = f; } if ((session != null) && accumulatedCount > 0) { Log.Info(string.Format("Creating {0} folders in the target environment, depth {1}", accumulated.Count, currentDepth + 1)); try { ProcessAccumulatedFolders(session, accumulated); } catch (Exception e) { Log.Error("Failed to process the last accumulated folder batch"); throw e; } } } } this.Folders = folderDictionary; }