/// <summary> /// Loads gallery content data by gallery identifier /// </summary> /// <param name="id"></param> /// <param name="bSync">True - automatic synchronization is required</param> /// <returns></returns> public static void SaveGalleryContent(int id, GalleryContent content, bool bSync = true) { Action action = delegate() { XmlSerializer serializer = new XmlSerializer(typeof(GalleryContent)); using (FileStream fstream = new FileStream(GetGallerySourcePath(id), FileMode.Create, FileAccess.Write)) { serializer.Serialize(fstream, content); } }; if (bSync) { lock (GetGallerySyncRoot(id)) { action(); } } else { action(); } }
public static void SaveContent(this CuratedGallery gallery, GalleryContent content, bool bSync = true) { GalleryRuntime.SaveGalleryContent(gallery.ID, content, bSync); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="templateID"></param> /// <returns></returns> public static CuratedGallery CreateGallery(string name, Nullable<int> templateID = null) { //try to create gallery in the storage OperationResult<OperationResults, CuratedGallery> rslt = null; try { rslt = GalleryRuntime.GalleryRepository.CreateGallery(name, templateID); } catch (Exception ex) { Logger.WriteError(ex, "Gallery creation was failed"); throw; } if (rslt.Result != OperationResults.Success) throw new Exception("Gallery creation was failed"); var gallery = rslt.Output; lock (gallery.GetSyncRoot()) { string galleryRoot = gallery.GetDevPath(); string galeryOutput = gallery.GetOutputPath(); Directory.CreateDirectory(galleryRoot); Directory.CreateDirectory(galeryOutput); Directory.CreateDirectory(gallery.GetContentPath()); IGalleryTemplate template = GetTemplate(gallery.TemplateID); var content = new GalleryContent() { Name = name, Font = template.GallerySettings.DefaultFontFamily == null ? null : new GalleryFont() { FamilyName = template.GallerySettings.DefaultFontFamily.Name } }; content.GalleryImageSizes.AddRange(template.GallerySettings.ImageSizes.Select(x => ObjectMapper.DoMapping<GalleryImageSize>(x))); //add content file as system. It must be ignored content.SystemFilePathes.Add(GetGallerySourcePath(gallery.ID).Substring(galleryRoot.Length)); //relevant output path var reloutputPath = galeryOutput.Substring(galleryRoot.Length).TrimEnd('\\'); //ignore template cover if (template.Icon != null && template.Icon.Type == ImageSourceTypes.LocalFile) content.SystemFilePathes.Add(string.Format("{0}\\{1}", reloutputPath, template.Icon.Source)); if (!string.IsNullOrEmpty(template.DescriptorFilepath)) content.SystemFilePathes.Add(string.Format("{0}\\{1}", reloutputPath, template.DescriptorFilepath)); gallery.SaveContent(content, false); } return gallery; }