public static void SetTemplateHtml(TemplateInfo templateInfo, string html) { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, templateInfo.Main); PollUtils.WriteText(htmlPath, html); }
public static void ExportPoll(int siteId, string directoryPath, int pollId) { var pollInfo = PollManager.GetPollInfo(siteId, pollId); var filePath = PollUtils.PathCombine(directoryPath, pollInfo.Id + ".xml"); var feed = GetEmptyFeed(); foreach (var tableColumn in PollManager.Repository.TableColumns) { SetValue(feed.AdditionalElements, tableColumn, pollInfo); } var styleDirectoryPath = PollUtils.PathCombine(directoryPath, pollInfo.Id.ToString()); ExportFields(pollInfo.Id, styleDirectoryPath); var logInfoList = LogManager.Repository.GetLogInfoList(pollInfo.Id, 0, 0); foreach (var logInfo in logInfoList) { var entry = GetAtomEntry(logInfo); feed.Entries.Add(entry); } feed.Save(filePath); }
public static string GetTemplateHtml(TemplateInfo templateInfo) { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, templateInfo.Main); return(CacheGetFileContent(htmlPath)); }
public static void Edit(TemplateInfo templateInfo) { var directoryPath = Context.PluginApi.GetPluginPath(PollUtils.PluginId, "templates"); var configJson = Context.UtilsApi.JsonSerialize(templateInfo); var configPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, "config.json"); PollUtils.WriteText(configPath, configJson); }
public static bool IsHistoric(string directoryPath) { if (!PollUtils.IsFileExists(PollUtils.PathCombine(directoryPath, VersionFileName))) { return(true); } PollUtils.DeleteFileIfExists(PollUtils.PathCombine(directoryPath, VersionFileName)); return(false); }
public static void DeleteTemplate(string name) { if (string.IsNullOrEmpty(name)) { return; } var directoryPath = GetTemplatesDirectoryPath(); var templatePath = PollUtils.PathCombine(directoryPath, name); PollUtils.DeleteDirectoryIfExists(templatePath); }
private static TemplateInfo GetTemplateInfo(string templatesDirectoryPath, string name) { TemplateInfo templateInfo = null; var configPath = PollUtils.PathCombine(templatesDirectoryPath, name, "config.json"); if (PollUtils.IsFileExists(configPath)) { templateInfo = Context.UtilsApi.JsonDeserialize <TemplateInfo>(PollUtils.ReadText(configPath)); templateInfo.Name = name; } return(templateInfo); }
public static string GetListHtml() { var directoryPath = GetTemplatesDirectoryPath(); var htmlPath = PollUtils.PathCombine(directoryPath, "list.html"); var html = CacheUtils.Get <string>(htmlPath); if (html != null) { return(html); } html = PollUtils.ReadText(htmlPath); CacheUtils.Insert(htmlPath, html, 24); return(html); }
public static void Clone(string nameToClone, TemplateInfo templateInfo, string templateHtml = null) { var directoryPath = Context.PluginApi.GetPluginPath(PollUtils.PluginId, "templates"); PollUtils.CopyDirectory(PollUtils.PathCombine(directoryPath, nameToClone), PollUtils.PathCombine(directoryPath, templateInfo.Name), true); var configJson = Context.UtilsApi.JsonSerialize(templateInfo); var configPath = PollUtils.PathCombine(directoryPath, templateInfo.Name, "config.json"); PollUtils.WriteText(configPath, configJson); if (templateHtml != null) { SetTemplateHtml(templateInfo, templateHtml); } }
public static void ExportFields(int pollId, string styleDirectoryPath) { PollUtils.DeleteDirectoryIfExists(styleDirectoryPath); PollUtils.CreateDirectoryIfNotExists(styleDirectoryPath); var fieldInfoList = FieldManager.GetFieldInfoList(pollId); foreach (var fieldInfo in fieldInfoList) { var filePath = PollUtils.PathCombine(styleDirectoryPath, fieldInfo.Id + ".xml"); var feed = ExportFieldInfo(fieldInfo); if (fieldInfo.Items != null && fieldInfo.Items.Count > 0) { foreach (var itemInfo in fieldInfo.Items) { var entry = ExportTableStyleItemInfo(itemInfo); feed.Entries.Add(entry); } } feed.Save(filePath); } }
public static void ImportPoll(int siteId, string directoryPath, bool overwrite) { if (!Directory.Exists(directoryPath)) { return; } var isHistoric = IsHistoric(directoryPath); var filePaths = Directory.GetFiles(directoryPath); foreach (var filePath in filePaths) { var feed = AtomFeed.Load(new FileStream(filePath, FileMode.Open)); var pollInfo = new PollInfo(); foreach (var tableColumn in PollManager.Repository.TableColumns) { var value = GetValue(feed.AdditionalElements, tableColumn); pollInfo.Set(tableColumn.AttributeName, value); } pollInfo.SiteId = siteId; if (isHistoric) { pollInfo.Title = GetDcElementContent(feed.AdditionalElements, "InputName"); } var srcPollInfo = PollManager.GetPollInfo(siteId, pollInfo.Title); if (srcPollInfo != null) { if (overwrite) { PollManager.Repository.Delete(siteId, srcPollInfo.Id); } else { pollInfo.Title = PollManager.Repository.GetImportTitle(siteId, pollInfo.Title); } } pollInfo.Id = PollManager.Repository.Insert(pollInfo); var directoryName = GetDcElementContent(feed.AdditionalElements, "Id"); if (isHistoric) { directoryName = GetDcElementContent(feed.AdditionalElements, "InputID"); } var titleAttributeNameDict = new NameValueCollection(); if (!string.IsNullOrEmpty(directoryName)) { var fieldDirectoryPath = PollUtils.PathCombine(directoryPath, directoryName); titleAttributeNameDict = ImportFields(siteId, pollInfo.Id, fieldDirectoryPath, isHistoric); } foreach (AtomEntry entry in feed.Entries) { var logInfo = new LogInfo(); foreach (var tableColumn in LogManager.Repository.TableColumns) { var value = GetValue(entry.AdditionalElements, tableColumn); logInfo.Set(tableColumn.AttributeName, value); } var attributes = GetDcElementNameValueCollection(entry.AdditionalElements); foreach (string entryName in attributes.Keys) { logInfo.Set(entryName, attributes[entryName]); } if (isHistoric) { foreach (var title in titleAttributeNameDict.AllKeys) { logInfo.Set(title, logInfo.Get(titleAttributeNameDict[title])); } logInfo.AddDate = PollUtils.ToDateTime(GetDcElementContent(entry.AdditionalElements, "adddate")); } LogManager.Repository.Insert(pollInfo, logInfo); } } }