Example #1
0
        public MetadataNode(ContentNode contentNode)
        {
            if (contentNode.NodeType != Content.ContentNode.ContentNodeType.Metadata)
            {
                throw new Exception("Error, invalid content node type.");
            }
            this.ContentNode = contentNode;
            string file = Path.Combine(contentNode.PhysicalPath, ".properties.xml");

            if (!File.Exists(file))
            {
                return;
            }

            XDocument doc = PropertyFileHelper.OpenReadWithoutLock(file);

            this.ValidFrom  = ConvertHelper.ToDateTime(doc.Root.GetElementValue("ValidFrom"), DateTime.MinValue);
            this.ExpiryTime = ConvertHelper.ToDateTime(doc.Root.GetElementValue("ExpiryTime"), DateTime.MinValue);
            if (this.ValidFrom == DateTime.MinValue)
            {
                this.ValidFrom = null;
            }
            if (this.ExpiryTime == DateTime.MinValue)
            {
                this.ExpiryTime = null;
            }
            this.AvailableForUKLicense    = ConvertHelper.ToBoolean(doc.Root.GetElementValue("AvailableForUKLicense", "1"), true);
            this.AvailableForNonUKLicense = ConvertHelper.ToBoolean(doc.Root.GetElementValue("AvailableForNonUKLicense", "1"), true);
        }
Example #2
0
 private static void GetProperties(string path, out DateTime validFrom, out DateTime expiryTime,
                                   out bool availableForUKLicense, out bool availableForNonUKLicense)
 {
     // verify the metadata is not disabled
     try
     {
         string    propertiesXml = Path.Combine(path, ".properties.xml");
         XDocument doc           = PropertyFileHelper.OpenReadWithoutLock(propertiesXml);
         if (!string.Equals(doc.Root.GetElementValue("Type"), "Metadata", StringComparison.OrdinalIgnoreCase))
         {
             validFrom                = DateTime.MinValue;
             expiryTime               = DateTime.MaxValue;
             availableForUKLicense    = true;
             availableForNonUKLicense = true;
             return;
         }
         validFrom  = ConvertHelper.ToDateTime(doc.Root.GetElementValue("ValidFrom"), DateTime.MinValue);
         expiryTime = ConvertHelper.ToDateTime(doc.Root.GetElementValue("ExpiryTime"), DateTime.MaxValue);
         if (expiryTime == DateTime.MinValue)
         {
             expiryTime = DateTime.MaxValue;
         }
         availableForUKLicense    = ConvertHelper.ToBoolean(doc.Root.GetElementValue("AvailableForUKLicense", "1"), true);
         availableForNonUKLicense = ConvertHelper.ToBoolean(doc.Root.GetElementValue("AvailableForNonUKLicense", "1"), true);
     }
     catch
     {
         validFrom                = DateTime.MinValue;
         expiryTime               = DateTime.MaxValue;
         availableForUKLicense    = true;
         availableForNonUKLicense = true;
     }
 }
Example #3
0
        public void Save()
        {
            string file = this.ContentNode.RealPhysicalPath + "\\.properties.xml";

            cmSite domain = SiteManager.GetSiteByDistinctName(ContentNode.ContentTree.DistinctName);

            ContentTree.EnsureDirectoryExistsForFile(domain, file);

            PropertyFileHelper.Save(file, new { @Controller = this.Controller, @RouteName = this.RouteName, @IsInherited = false });
        }
Example #4
0
        public void Save()
        {
            string file = this.ContentNode.RealPhysicalPath + "\\.properties.xml";

            cmSite domain = SiteManager.GetSiteByDistinctName(ContentNode.ContentTree.DistinctName);

            ContentTree.EnsureDirectoryExistsForFile(domain, file);

            PropertyFileHelper.Save(file, new {
                @ValidFrom                = this.ValidFrom,
                @ExpiryTime               = this.ExpiryTime,
                @AvailableForUKLicense    = this.AvailableForUKLicense,
                @AvailableForNonUKLicense = this.AvailableForNonUKLicense,
                @IsInherited              = false
            }, true);
        }
Example #5
0
        /// <summary>
        /// Read first available entry in given path
        /// </summary>
        /// <param name="paths"></param>
        /// <returns></returns>
        private static string ReadFirstAvailableEntry(List <string> paths)
        {
            foreach (string path in paths)
            {
                string   physicalPath;
                FileInfo fileInfo;
                try
                {
                    physicalPath = HostingEnvironment.MapPath(path);
                    fileInfo     = new FileInfo(physicalPath);
                    if (!fileInfo.Exists)
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }

                // verify the metadata is not disabled
                try
                {
                    string    propertiesXml = Path.Combine(Path.GetDirectoryName(physicalPath), ".properties.xml");
                    XDocument doc           = PropertyFileHelper.OpenReadWithoutLock(propertiesXml);
                    if (string.Compare(doc.Root.GetElementValue("IsDisabled", "false"), "true", true) == 0)
                    {
                        continue;
                    }
                }
                catch
                {
                }

                // if value is empty, then continue
                if (fileInfo.Length == 0L)
                {
                    continue;
                }
                string ret = WinFileIO.ReadWithoutLock(physicalPath);
                if (!string.IsNullOrWhiteSpace(ret))
                {
                    return(ret);
                }
            }
            return(string.Empty);
        }
Example #6
0
 private static bool IsInherited(string path)
 {
     // verify the metadata is inherited
     try
     {
         string    propertiesXml = Path.Combine(path, ".properties.xml");
         XDocument doc           = PropertyFileHelper.OpenReadWithoutLock(propertiesXml);
         if (!string.Equals(doc.Root.GetElementValue("Type"), "Metadata", StringComparison.OrdinalIgnoreCase))
         {
             return(true);
         }
         return(string.Equals(doc.Root.GetElementValue("IsInherited", "false"), "true", StringComparison.OrdinalIgnoreCase));
     }
     catch
     {
         return(true);
     }
 }
Example #7
0
        public PageNode(ContentNode contentNode)
        {
            if (contentNode.NodeType != Content.ContentNode.ContentNodeType.Page)
            {
                throw new Exception("Error, invalid content node type.");
            }
            this.ContentNode = contentNode;
            string file = Path.Combine(contentNode.PhysicalPath, ".properties.xml");

            if (!File.Exists(file))
            {
                return;
            }

            XDocument doc = PropertyFileHelper.OpenReadWithoutLock(file);

            this.Controller = doc.Root.GetElementValue("Controller");
            this.RouteName  = doc.Root.GetElementValue("RouteName").DefaultIfNullOrEmpty(contentNode.RelativePath.Replace('/', '_'));
        }
Example #8
0
        public static void EnsureDirectoryExists(cmSite domain, string dirname)
        {
            if (Directory.Exists(dirname))
            {
                return;
            }

            string parentDir = Path.GetDirectoryName(dirname);

            EnsureDirectoryExists(domain, parentDir);

            // create the directory then look up in template dir
            Directory.CreateDirectory(dirname);

            if (!string.IsNullOrWhiteSpace(domain.TemplateDomainDistinctName))
            {
                string replaced    = string.Format(@"\Views\{0}\", domain.TemplateDomainDistinctName);
                string templateDir = Regex.Replace(dirname
                                                   , string.Format(@"\\Views\\{0}\\", domain.DistinctName.Replace("-", "\\-"))
                                                   , replaced
                                                   , RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled
                                                   );
                if (templateDir.Contains(replaced) && Directory.Exists(templateDir))
                {
                    ContentNode.ContentNodeType nodeType = ContentNode.ContentNodeType.Directory;
                    string propertyXml = Path.Combine(templateDir, ".properties.xml");
                    if (File.Exists(propertyXml))
                    {
                        XDocument doc = PropertyFileHelper.OpenReadWithoutLock(propertyXml);
                        if (!Enum.TryParse <ContentNode.ContentNodeType>(doc.Root.GetElementValue("Type"), out nodeType))
                        {
                            nodeType = ContentNode.ContentNodeType.Directory;
                        }
                    }

                    propertyXml = Path.Combine(dirname, ".properties.xml");
                    PropertyFileHelper.Save(propertyXml, new { @IsInherited = true, @Type = nodeType });
                }
            }
        }
Example #9
0
        }     //

        /// <summary>
        ///
        /// </summary>
        /// <param name="contentTree"></param>
        /// <param name="physicalPath"></param>
        /// <param name="relativePath"></param>
        /// <param name="isFile"></param>
        public ContentNode(ContentTree contentTree, string physicalPath, string relativePath, bool isFile)
        {
            Children = new ConcurrentDictionary <string, ContentNode>(StringComparer.OrdinalIgnoreCase);

            this.NodeStatus   = ContentNodeStatus.Normal;
            this.PhysicalPath = physicalPath;
            this.RelativePath = relativePath;
            this.ContentTree  = contentTree;
            this.NodeType     = ContentNodeType.None;
            contentTree.AllNodes[relativePath] = this;

            if (isFile)
            {
                switch (Path.GetExtension(relativePath))
                {
                case ".ascx":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.PartialView;
                    break;

                case ".aspx":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.View;
                    break;

                case ".ashx":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.HttpHandler;
                    break;

                case ".master":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.PageTemplate;
                    break;

                case ".htm":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.StaticContent;
                    break;

                case ".snippet":
                    this.DisplayName = Path.GetFileNameWithoutExtension(physicalPath);
                    this.NodeType    = ContentNodeType.HtmlSnippet;
                    break;

                default:
                    this.DisplayName = Path.GetFileName(physicalPath);
                    this.NodeType    = ContentNodeType.None;
                    break;
                }
            }// file
            else
            {
                this.DisplayName = Path.GetFileName(physicalPath);
                NodeType         = ContentNodeType.Directory;

                string xml = string.Format("{0}\\.properties.xml", this.PhysicalPath);
                if (File.Exists(xml))
                {
                    XDocument doc  = PropertyFileHelper.OpenReadWithoutLock(xml);
                    XElement  root = doc.Root;

                    ContentNodeType nodeType;
                    if (Enum.TryParse <ContentNodeType>(root.GetElementValue("Type"), out nodeType))
                    {
                        NodeType = nodeType;
                    }
                    if (string.Compare(root.GetElementValue("IsInherited", "false"), "true", true) == 0)
                    {
                        this.NodeStatus = ContentNodeStatus.Inherited;
                    }
                    if (string.Compare(root.GetElementValue("IsDisabled", "false"), "true", true) == 0)
                    {
                        this.IsDisabled = true;
                    }
                }

                LoadChildren();
            } // directory
        }     //