SetMetadata() public method

public SetMetadata ( SenseNet.ContentRepository content, string currentDirectory, bool isNewContent, bool needToValidate, bool updateReferences ) : bool
content SenseNet.ContentRepository
currentDirectory string
isNewContent bool
needToValidate bool
updateReferences bool
return bool
Exemplo n.º 1
0
        private void TreeWalker(string path, bool pathIsFile, Node folder, string indent, bool validate, bool aspects)
        {
            // get entries
            // get contents
            // foreach contents
            //   create contentinfo
            //   entries.remove(content)
            //   entries.remove(contentinfo.attachments)
            // foreach entries
            //   create contentinfo
            if (!aspects)
            {
                if (folder != null && (
                        String.Compare(folder.Path, Repository.AspectsFolderPath) == 0 ||
                        String.Compare(folder.Path, Repository.ContentTypesFolderPath) == 0))
                {
                    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, XsltOptions);
                    if (!contentInfo.FileIsHidden)
                    {
                        if (!Continuing || _continueFrom.StartsWith(path.ToLower()))
                        {
                            contentInfos.Add(contentInfo);
                        }
                    }
                    foreach (string attachmentName in contentInfo.Attachments)
                    {
                        var attachmentPath = Path.Combine(path, attachmentName);
                        RemovePath(paths, attachmentPath);

                        if (attachmentName == contentInfo.Name)
                        {
                            // Escaped children folder
                            var childrenPath = attachmentPath + ".Children";
                            if (Directory.Exists(childrenPath))
                            {
                                contentInfo.ChildrenFolder = childrenPath;
                                RemovePath(paths, childrenPath);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    PrintException(e, contentPath);
                    LogWriteError(contentPath + ";" + folder.Path);
                }
            }
            while (paths.Count > 0)
            {
                try
                {
                    var contentInfo = new ContentInfo(paths[0], folder, XsltOptions);
                    if (!contentInfo.FileIsHidden)
                    {
                        if (!Continuing || _continueFrom.StartsWith(path.ToLower()))
                        {
                            contentInfos.Add(contentInfo);
                        }
                    }
                }
                catch (Exception e)
                {
                    PrintException(e, paths[0]);
                    LogWriteError(paths[0] + ";" + folder.Path);
                }

                paths.RemoveAt(0);
            }

            foreach (ContentInfo contentInfo in contentInfos)
            {
                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;

                if (!Continuing)
                {
                    try
                    {
                        string mdp        = contentInfo.MetaDataPath.Replace(FSPath, RepositoryPath).Replace('\\', '/');
                        string parentPath = SenseNet.ContentRepository.Storage.RepositoryPath.GetParentPath(mdp);
                        if (contentInfo.Delete)
                        {
                            var rpath = SenseNet.ContentRepository.Storage.RepositoryPath.Combine(parentPath, contentInfo.Name);
                            if (Node.Exists(rpath))
                            {
                                LogWriteLine(indent, contentInfo.Name, " : [DELETE]");
                                Content.DeletePhysical(rpath);
                            }
                            else
                            {
                                LogWriteLine(indent, contentInfo.Name, " : [already deleted]");
                            }
                        }
                        else
                        {
                            if (folder == null)
                            {
                                folder = Node.LoadNode(parentPath);
                            }
                            content = CreateOrLoadContent(contentInfo, folder, out isNewContent);
                        }
                    }
                    catch (Exception ex)
                    {
                        PrintException(ex, contentInfo.MetaDataPath);
                        LogWriteError(contentInfo.MetaDataPath + ";" + folder.Path);
                    }
                }

                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);
                        LogWriteError(contentInfo.MetaDataPath + ";" + folder.Path);
                        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 || contentInfo.HasAspect)
                    {
                        LogWriteReference(contentInfo);
                        HasReference = true;
                    }
                }

                if (Continuing)
                {
                    LogWrite("Skipped: ");
                    LogWriteLine(contentInfo.MetaDataPath);
                }

                //-- recursion
                if (stepDown && content != null)
                {
                    Node node = null;
                    if (content != null)
                    {
                        node = content.ContentHandler;
                    }
                    if (node != null && (contentInfo.IsFolder || contentInfo.ChildrenFolder != null))//ML
                    {
                        TreeWalker(contentInfo.ChildrenFolder, false, node, indent + "  ", validate, aspects);
                    }
                }
            }
        }
Exemplo n.º 2
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        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);
                    }
                }
            }
        }