public static void LogWriteReference(ContentInfo contentInfo) { StreamWriter writer = OpenRefLog(); WriteToRefLog(writer, contentInfo.ContentId, '\t', contentInfo.MetaDataPath); CloseLog(writer); }
private static void WriteInfo(ContentInfo contentInfo) { Console.ReadKey(true); LogWriteLine("PAUSED: ", CR, contentInfo.MetaDataPath); Console.WriteLine("Errors: " + _exceptions); Console.Write("press any key to continue... "); Console.ReadKey(); LogWriteLine("CONTINUED"); }
private static void UpdateReference(int contentId, string metadataPath, bool validate) { var contentInfo = new ContentInfo(metadataPath, null); LogWrite(" "); LogWriteLine(contentInfo.Name); SNC.Content content = SNC.Content.Load(contentId); if (content != null) { try { if (!contentInfo.UpdateReferences(content, validate)) PrintFieldErrors(content, contentInfo.MetaDataPath); } catch (Exception e) { PrintException(e, contentInfo.MetaDataPath); } } else { LogWrite("---------- Content does not exist. MetaDataPath: "); LogWrite(contentInfo.MetaDataPath); LogWrite(", ContentId: "); LogWrite(contentInfo.ContentId); LogWrite(", ContentTypeName: "); LogWrite(contentInfo.ContentTypeName); } }
//private static void UpdateReferences(List<ContentInfo> postponedList) //{ // LogWriteLine(); // LogWriteLine("=========================== Update references"); // LogWriteLine(); // foreach (ContentInfo contentInfo in postponedList) // { // LogWrite(" "); // LogWriteLine(contentInfo.Name); // SNC.Content content = SNC.Content.Load(contentInfo.ContentId); // if (content != null) // { // try // { // if (!contentInfo.UpdateReferences(content)) // PrintFieldErrors(content, contentInfo.MetaDataPath); // } // catch (Exception e) // { // PrintException(e, contentInfo.MetaDataPath); // } // } // else // { // LogWrite("---------- Content does not exist. MetaDataPath: "); // LogWrite(contentInfo.MetaDataPath); // LogWrite(", ContentId: "); // LogWrite(contentInfo.ContentId); // LogWrite(", ContentTypeName: "); // LogWrite(contentInfo.ContentTypeName); // } // } // LogWriteLine(); //} private static Content CreateOrLoadContent(ContentInfo contentInfo, Node folder, out bool isNewContent) { var path = RepositoryPath.Combine(folder.Path, contentInfo.Name); var content = Content.Load(path); if (content == null) { content = Content.CreateNew(contentInfo.ContentTypeName, folder, contentInfo.Name); isNewContent = true; } else { isNewContent = false; } return content; }
private static void TreeWalker(string path, bool pathIsFile, Node folder, string indent, List<ContentInfo> postponedList, bool validate) { // get entries // get contents // foreach contents // create contentinfo // entries.remove(content) // entries.remove(contentinfo.attachments) // foreach entries // create contentinfo if (folder.Path.StartsWith(Repository.ContentTypesFolderPath)) { //-- skip CTD folder LogWrite("Skipped path: "); LogWriteLine(path); return; } string currentDir = pathIsFile ? Path.GetDirectoryName(path) : path; List<ContentInfo> contentInfos = new List<ContentInfo>(); List<string> paths; List<string> contentPaths; if (pathIsFile) { paths = new List<string>(new string[] { path }); contentPaths = new List<string>(); if (path.ToLower().EndsWith(".content")) contentPaths.Add(path); } else { paths = new List<string>(Directory.GetFileSystemEntries(path)); contentPaths = new List<string>(Directory.GetFiles(path, "*.content")); } foreach (string contentPath in contentPaths) { paths.Remove(contentPath); try { var contentInfo = new ContentInfo(contentPath, folder); if (!contentInfo.IsHidden) contentInfos.Add(contentInfo); foreach (string attachmentName in contentInfo.Attachments) { var attachmentPath = Path.Combine(path, attachmentName); if (!paths.Remove(attachmentPath)) { for (int i = 0; i < paths.Count; i++) { if (paths[i].Equals(attachmentPath, StringComparison.OrdinalIgnoreCase)) { paths.RemoveAt(i); break; } } } } } catch (Exception e) { PrintException(e, contentPath); } } while (paths.Count > 0) { try { var contentInfo = new ContentInfo(paths[0], folder); if (!contentInfo.IsHidden) contentInfos.Add(contentInfo); } catch (Exception e) { PrintException(e, paths[0]); } paths.RemoveAt(0); } foreach (ContentInfo contentInfo in contentInfos) { var continuing = false; var stepDown = true; if (_continueFrom != null) { continuing = true; if (contentInfo.MetaDataPath == _continueFrom) { _continueFrom = null; continuing = false; } else { stepDown = _continueFrom.StartsWith(contentInfo.MetaDataPath); } } var isNewContent = true; Content content = null; try { content = CreateOrLoadContent(contentInfo, folder, out isNewContent); } catch (Exception ex) { PrintException(ex, contentInfo.MetaDataPath); } if (!continuing && content != null) { LogWriteLine(indent, contentInfo.Name, " : ", contentInfo.ContentTypeName, isNewContent ? " [new]" : " [update]"); try { if (Console.KeyAvailable) WriteInfo(contentInfo); } catch { } //-- SetMetadata without references. Continue if the setting is false or exception was thrown. try { if (!contentInfo.SetMetadata(content, currentDir, isNewContent, validate, false)) PrintFieldErrors(content, contentInfo.MetaDataPath); if (content.ContentHandler.Id == 0) content.ContentHandler.Save(); } catch (Exception e) { PrintException(e, contentInfo.MetaDataPath); continue; } if (contentInfo.ClearPermissions) { content.ContentHandler.Security.RemoveExplicitEntries(); if (!(contentInfo.HasReference || contentInfo.HasPermissions || contentInfo.HasBreakPermissions)) { content.ContentHandler.Security.RemoveBreakInheritance(); } } if (contentInfo.HasReference || contentInfo.HasPermissions || contentInfo.HasBreakPermissions) { LogWriteReference(contentInfo); postponedList.Add(contentInfo); } } //-- recursion if (stepDown && content != null) { if (contentInfo.IsFolder) { if (content.ContentHandler != null) TreeWalker(contentInfo.ChildrenFolder, false, content.ContentHandler, indent + " ", postponedList, validate); } } } }