public override void AddSheet(ISheet sheet, int index) { XElement elementImplementation = (sheet as XMindSheet)?.Implementation; var bookImplementation = GetWorkbookElement(); if (elementImplementation == null) { // Logger.Warn("XMindWorkbook.AddSheet: sheet is not correct"); return; } // if (elementImplementation.Parent != bookImplementation) // { // Logger.Warn("XMindWorkbook.AddSheet: sheet must belong to same document"); // } var childElements = DOMUtils.GetChildElementsByTag(bookImplementation, TAG_SHEET); if (index >= 0 && index < childElements.Count()) { childElements.Where((e, i) => i == index) .First() .AddBeforeSelf(elementImplementation); } else { bookImplementation.Add(elementImplementation); } }
public override void AddSheet(ISheet sheet, int index) { Logger.Log.DebugTrace($"Add sheet {sheet.GetId()} to {Name}"); if (!(sheet is XMindSheet impl) || impl.Implementation is null) { const string errorMessage = "XMindWorkbook.AddSheet: sheet is not correct"; Logger.Log.Error(errorMessage); throw new ArgumentException(errorMessage); } XElement elementImplementation = impl.Implementation; var bookImplementation = GetWorkbookElement(); if (elementImplementation.Parent is object && elementImplementation.Parent != bookImplementation) { const string errorMessage = "XMindWorkbook.AddSheet: sheet must belong to same document"; Logger.Log.Error(errorMessage); throw new ArgumentException(errorMessage); } var childElements = DOMUtils.GetChildElementsByTag(bookImplementation, TAG_SHEET); if (index >= 0 && index < childElements.Count()) { childElements.Where((e, i) => i == index) .First() .AddBeforeSelf(elementImplementation); } else { bookImplementation.Add(elementImplementation); } }
public override void RemoveSheet(ISheet sheet) { XElement elementImplementation = (sheet as XMindSheet)?.Implementation; var bookImplementation = GetWorkbookElement(); if (elementImplementation == null) { // Logger.Warn("XMindWorkbook.RemoveSheet: sheet is not correct"); return; } if (elementImplementation.Parent != bookImplementation) { // Logger.Warn("XMindWorkbook.RemoveSheet: sheet must belong to same document"); } var childElements = DOMUtils .GetChildElementsByTag(bookImplementation, TAG_SHEET).ToList(); childElements .FirstOrDefault(el => el == elementImplementation)? .Remove(); }
public override void RemoveSheet(ISheet sheet) { if (!(sheet is XMindSheet xmindSheet) || xmindSheet.Implementation is null) { const string errorMessage = "Implementation was not found"; Logger.Log.Error(errorMessage); throw new ArgumentException(errorMessage); } XElement elementImplementation = xmindSheet.Implementation; var bookImplementation = GetWorkbookElement(); if (elementImplementation.Parent != bookImplementation) { // Logger.Warn("XMindWorkbook.RemoveSheet: sheet must belong to same document"); } var childElements = DOMUtils .GetChildElementsByTag(bookImplementation, TAG_SHEET).ToList(); childElements .FirstOrDefault(el => el == elementImplementation)? .Remove(); }