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 }); }
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); }
/// <summary> /// Write the metadata entry /// </summary> /// <param name="site"></param> /// <param name="path"></param> /// <param name="lang">If language is null, then default value is written</param> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public static bool Save(cmSite site, string path, string lang, string name, string value) { string postfix = string.IsNullOrWhiteSpace(lang) ? string.Empty : "." + lang; string physicalPath = HostingEnvironment.MapPath( string.Format("~/Views/{0}/{1}/.{2}{3}", site.DistinctName, path.TrimStart('/').TrimEnd('/'), name, postfix) ); ContentTree.EnsureDirectoryExistsForFile(site, physicalPath); SqlQuery <cmRevision> query = new SqlQuery <cmRevision>(); string filePath; string localFile; string metadataPath = path.TrimEnd('/') + "/." + name + postfix; if (File.Exists(physicalPath)) { // nothing changed if (WinFileIO.ReadWithoutLock(physicalPath) == value) { return(false); } // if last revision not exist, backup first { RevisionAccessor ra = DataAccessor.CreateInstance <RevisionAccessor>(); cmRevision revision = ra.GetLastRevision(site.ID, metadataPath); if (revision == null || !File.Exists(Revisions.GetLocalPath(revision.FilePath))) { localFile = Revisions.GetNewFilePath(out filePath); File.Copy(physicalPath, localFile); revision = new cmRevision(); revision.Comments = string.Format("No revision found for [{0}], language=[{1}], make a backup.", name, lang.DefaultIfNullOrEmpty("default")); revision.SiteID = site.ID; revision.FilePath = filePath; revision.Ins = DateTime.Now; revision.RelativePath = metadataPath; revision.UserID = CustomProfile.Current.UserID; query.Insert(revision); } } } else if (!string.IsNullOrWhiteSpace(site.TemplateDomainDistinctName)) { string inheritedPath = HostingEnvironment.MapPath( string.Format("~/Views/{0}/{1}/.{2}{3}", site.TemplateDomainDistinctName, path.TrimStart('/').TrimEnd('/'), name, postfix) ); if (File.Exists(inheritedPath)) { // nothing changed if (WinFileIO.ReadWithoutLock(inheritedPath) == value) { return(false); } } else if (string.IsNullOrWhiteSpace(value)) { return(false); } } else if (string.IsNullOrWhiteSpace(value)) { return(false); } using (FileStream fs = new FileStream(physicalPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite)) { fs.SetLength(0); using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { sw.Write(value); } } // copy the file to backup localFile = Revisions.GetNewFilePath(out filePath); File.Copy(physicalPath, localFile); // save to cmRevision { cmRevision revision = new cmRevision(); revision.Comments = string.Format("update the entry [{0}], language=[{1}].", name, lang.DefaultIfNullOrEmpty("default")); revision.SiteID = site.ID; revision.FilePath = filePath; revision.Ins = DateTime.Now; revision.RelativePath = metadataPath; revision.UserID = CustomProfile.Current.UserID; query.Insert(revision); } return(true); }