public string GetContent(string file) { int fileId = 0; if (int.TryParse(file, out fileId)) { var f = FileManager.Instance.GetFile(fileId); if (f != null) { var fileContent = FileManager.Instance.GetFileContent(f); if (fileContent != null) { using (var reader = new StreamReader(fileContent, Encoding.UTF8)) { return(reader.ReadToEnd()); } } } return(""); } else { var f = FileUri.FromPath(file); if (f.FileExists) { return(File.ReadAllText(f.PhysicalFilePath)); } return(""); } }
public string Execute(Page page, TemplateFiles files, string templateVirtualFolder, object model) { var sourceFileUri = new FileUri(templateVirtualFolder + "/" + files.Template); try { string source = File.ReadAllText(sourceFileUri.PhysicalFilePath); string sourceFolder = sourceFileUri.UrlFolder; var hbs = HandlebarsDotNet.Handlebars.Create(); RegisterHelpers(hbs); RegisterScriptHelper(hbs); RegisterHandlebarsHelper(hbs); RegisterRegisterStylesheetHelper(hbs, page, sourceFolder); RegisterRegisterScriptHelper(hbs, page, sourceFolder); if (files.PartialTemplates != null) { foreach (var part in files.PartialTemplates.Where(t => t.Value.ClientSide == false)) { RegisterTemplate(hbs, part.Key, templateVirtualFolder + "/" + part.Value.Template); } } return(CompileTemplate(hbs, source, model)); } catch (Exception ex) { Log.Logger.Error(string.Format("Failed to render Handlebar template source:[{0}], model:[{1}]", sourceFileUri.PhysicalFilePath, model), ex); throw new TemplateException("Failed to render Handlebar template " + sourceFileUri.PhysicalFilePath, ex, model, sourceFileUri.PhysicalFilePath); } }
public FileTreeViewItem([NotNull] FileUri fileUri) : base(fileUri.Site) { Assert.ArgumentNotNull(fileUri, nameof(fileUri)); FileUri = fileUri; Icon = new Icon("Resources/16x16/document.png"); }
private FileUri CheckFiles(TemplateManifest templateManifest, TemplateFiles files) { if (files == null) { throw new Exception("Manifest.json missing or incomplete"); } var templateUri = new FileUri(templateManifest.ManifestFolderUri, files.Template); if (!templateUri.FileExists) { throw new Exception("Template " + templateUri.UrlFilePath + " don't exist"); } if (files.PartialTemplates != null) { foreach (var partial in files.PartialTemplates) { var partialTemplateUri = new FileUri(templateManifest.ManifestFolderUri, partial.Value.Template); if (!partialTemplateUri.FileExists) { throw new Exception("PartialTemplate " + partialTemplateUri.UrlFilePath + " don't exist"); } } } return(templateUri); }
private string GenerateOutputDetail(Page page, TemplateManifest templateManifest, TemplateFiles files, JToken dataJson, string settingsJson) { // detail template var templateVirtualFolder = templateManifest.ManifestFolderUri.UrlFolder; if (!string.IsNullOrEmpty(files.Template)) { string physicalTemplateFolder = HostingEnvironment.MapPath(templateVirtualFolder); FileUri templateUri = CheckFiles(templateManifest, files); if (dataJson != null) { var mf = new ModelFactorySingle(_renderinfo.Data, settingsJson, physicalTemplateFolder, _renderinfo.Template.Manifest, _renderinfo.Template, files, _module, PortalSettings.Current); mf.Detail = true; object model; if (templateUri.Extension != ".hbs") // razor { model = mf.GetModelAsDynamic(); } else // handlebars { if (OpenContentControllerFactory.Instance.OpenContentGlobalSettingsController.GetFastHandlebars()) { model = mf.GetModelAsDictionary(); } else { model = mf.GetModelAsDynamic(); } } if (!string.IsNullOrEmpty(_renderinfo.Template.Manifest.DetailMetaTitle)) { HandlebarsEngine hbEngine = new HandlebarsEngine(); //page.Title MetaTitle = hbEngine.Execute(_renderinfo.Template.Manifest.DetailMetaTitle, model); } if (!string.IsNullOrEmpty(_renderinfo.Template.Manifest.DetailMetaDescription)) { HandlebarsEngine hbEngine = new HandlebarsEngine(); //PageUtils.SetPageDescription(page, hbEngine.Execute(_renderinfo.Template.Manifest.DetailMetaDescription, model)); MetaDescription = hbEngine.Execute(_renderinfo.Template.Manifest.DetailMetaDescription, model); } if (!string.IsNullOrEmpty(_renderinfo.Template.Manifest.DetailMeta)) { HandlebarsEngine hbEngine = new HandlebarsEngine(); //PageUtils.SetPageMeta(page, hbEngine.Execute(_renderinfo.Template.Manifest.DetailMeta, model)); MetaOther = hbEngine.Execute(_renderinfo.Template.Manifest.DetailMeta, model); } return(ExecuteTemplate(page, templateManifest, files, templateUri, model)); } else { return(""); } } else { return(""); } }
private static void IncludeResourses(Page page, RenderInfo renderInfo) { var template = renderInfo.Template; if (template != null) { if (template.MainTemplateUri() != null) { if (!App.Services.CreateGlobalSettingsRepository(PortalSettings.Current.PortalId).GetCompositeCss()) { var cssfilename = new FileUri(Path.ChangeExtension(template.MainTemplateUri().FilePath, "css")); if (cssfilename.FileExists) { App.Services.ClientResourceManager.RegisterStyleSheet(page, cssfilename.UrlFilePath); } } var jsfilename = new FileUri(Path.ChangeExtension(template.MainTemplateUri().FilePath, "js")); if (jsfilename.FileExists) { App.Services.ClientResourceManager.RegisterScript(page, jsfilename.UrlFilePath, 100); } } if (renderInfo.IsDetailPageRequest && template.DetailTemplateUri() != null) { var cssfilename = new FileUri(Path.ChangeExtension(template.DetailTemplateUri().FilePath, "css")); if (cssfilename.FileExists) { App.Services.ClientResourceManager.RegisterStyleSheet(page, cssfilename.UrlFilePath); } } App.Services.ClientResourceManager.RegisterScript(page, "~/DesktopModules/OpenContent/js/opencontent.js"); } }
private string GenerateListOutput(Page page, TemplateManifest templateManifest, TemplateFiles files, IEnumerable <IDataItem> dataList, string settingsJson) { var templateVirtualFolder = templateManifest.ManifestFolderUri.UrlFolder; if (!string.IsNullOrEmpty(files.Template)) { string physicalTemplateFolder = HostingEnvironment.MapPath(templateVirtualFolder); FileUri templateUri = CheckFiles(templateManifest, files); if (dataList != null) { ModelFactoryMultiple mf = new ModelFactoryMultiple(dataList, settingsJson, physicalTemplateFolder, _renderinfo.Template.Manifest, _renderinfo.Template, files, _module, PortalSettings.Current); object model; if (templateUri.Extension != ".hbs") // razor { model = mf.GetModelAsDynamic(); } else // handlebars { if (OpenContentControllerFactory.Instance.OpenContentGlobalSettingsController.GetFastHandlebars()) { model = mf.GetModelAsDictionary(); } else { model = mf.GetModelAsDynamic(); } } return(ExecuteTemplate(page, templateManifest, files, templateUri, model)); } } return(""); }
/// <summary> /// Возвращает файл. /// </summary> /// <param name="fileUniqueID">Уникальный идентификатор файла.</param> /// <param name="loadOptions">Опции загрузки файла.</param> /// <param name="throwIfNotExists">Выдать ислючение если файл не найден.</param> /// <returns></returns> public IFile GetFile(Guid fileUniqueID, GetFileOptions loadOptions = null, bool throwIfNotExists = true) { FileUri fileUri = new FileUri(this.Url, fileUniqueID); File file = this.TypedStorage.GetFileInternal(fileUri, loadOptions, throwIfNotExists); return(file); }
internal static Manifest GetFileManifest(FolderUri folder) { try { Manifest manifest = null; var file = new FileUri(folder.UrlFolder, "manifest.json"); if (file.FileExists) { string cacheKey = folder.UrlFolder + "manifest.json"; manifest = (Manifest)DataCache.GetCache(cacheKey); if (manifest == null) { string content = File.ReadAllText(file.PhysicalFilePath); manifest = JsonConvert.DeserializeObject <Manifest>(content); DataCache.SetCache(cacheKey, manifest, new DNNCacheDependency(file.PhysicalFilePath)); } } return(manifest); } catch (Exception ex) { Log.Logger.Error($"Failed to load manifest from folder {folder.UrlFolder}. Error: {ex}"); throw; } }
private string GenerateListOutput(Page page, TemplateManifest templateManifest, TemplateFiles files, IEnumerable <IDataItem> dataList, string settingsJson) { if (!string.IsNullOrEmpty(files.Template)) { FileUri templateUri = CheckFiles(templateManifest, files); if (dataList != null) { ModelFactoryMultiple mf = new ModelFactoryMultiple(dataList, settingsJson, _renderinfo.Template.Manifest, _renderinfo.Template, files, _module); object model; if (templateUri.Extension != ".hbs") // razor { model = mf.GetModelAsDynamic(); } else // handlebars { if (!App.Services.CreateGlobalSettingsRepository(_module.PortalId).GetLegacyHandlebars()) { model = mf.GetModelAsDictionary(); } else { model = mf.GetModelAsDynamic(); } } return(ExecuteTemplate(page, templateManifest, files, templateUri, model)); } } return(""); }
private void cmdBuilder_Click(object sender, EventArgs e) { if (scriptList.SelectedValue.EndsWith("schema.json")) { var settings = ModuleContext.OpenContentSettings(); FileUri template = settings.Template.MainTemplateUri(); string templateFolder = Path.GetDirectoryName(template.FilePath); string scriptFile = templateFolder + "/" + scriptList.SelectedValue.Replace("schema.json", "builder.json"); string srcFile = Server.MapPath(scriptFile); var schema = JsonUtils.LoadJsonFromFile(templateFolder + "/" + scriptList.SelectedValue) as JObject; var options = JsonUtils.LoadJsonFromFile(templateFolder + "/" + scriptList.SelectedValue.Replace("schema.json", "options.json")) as JObject; JObject builder = new JObject(); if (schema != null && schema["items"] != null) { builder["formtype"] = "array"; builder["formfields"] = GetBuilder(schema["items"] as JObject, options != null && options["items"] != null ? options["items"] as JObject : null); } else { builder["formtype"] = "object"; builder["formfields"] = GetBuilder(schema, options); } if (!File.Exists(srcFile)) { File.WriteAllText(srcFile, builder.ToString()); } Response.Redirect(Globals.NavigateURL(), true); } }
private string ExecuteRazor(FileUri template, dynamic model) { string webConfig = template.PhysicalFullDirectory; webConfig = webConfig.Remove(webConfig.LastIndexOf("\\")) + "\\web.config"; if (!File.Exists(webConfig)) { string filename = HostingEnvironment.MapPath("~/DesktopModules/OpenContent/Templates/web.config"); File.Copy(filename, webConfig); } var writer = new StringWriter(); try { var razorEngine = new RazorEngine("~/" + template.FilePath, ModuleContext, LocalResourceFile); razorEngine.Render(writer, model); } catch (Exception ex) { LoggingUtils.RenderEngineException(this, ex); string stack = string.Join("\n", ex.StackTrace.Split('\n').Where(s => s.Contains("\\Portals\\") && s.Contains("in")).Select(s => s.Substring(s.IndexOf("in"))).ToArray()); throw new TemplateException("Failed to render Razor template " + template.FilePath + "\n" + stack, ex, model, template.FilePath); } return(writer.ToString()); }
private void cmdCustom_Click(object sender, EventArgs e) { var settings = ModuleContext.OpenContentSettings(); TemplateManifest template = settings.Template; string templateFolder = template.ManifestFolderUri.UrlFolder; string templateDir = Server.MapPath(templateFolder); string moduleDir = Server.MapPath(ModuleTemplateDirectory); if (!Directory.Exists(moduleDir)) { Directory.CreateDirectory(moduleDir); } foreach (var item in Directory.GetFiles(moduleDir)) { File.Delete(item); } foreach (var item in Directory.GetFiles(templateDir)) { File.Copy(item, moduleDir + Path.GetFileName(item)); } ModuleController mc = new ModuleController(); var newtemplate = new FileUri(ModuleTemplateDirectory, "schema.json"); mc.UpdateModuleSetting(ModuleId, "template", newtemplate.FilePath); ModuleContext.Settings["template"] = newtemplate.FilePath; settings = ModuleContext.OpenContentSettings(); InitEditor(settings.Template); }
private void scriptList_SelectedIndexChanged(object sender, EventArgs e) { FileUri template = ModuleContext.OpenContentSettings().Template.MainTemplateUri(); var scriptFile = new FileUri(template.UrlFolder, scriptList.SelectedValue); DisplayFile(scriptFile); }
private void DisplayFile(FileUri file) { lError.Visible = false; lError.Text = ""; plSource.Text = file.FilePath; string srcFile = file.PhysicalFilePath; if (File.Exists(srcFile)) { txtSource.Text = File.ReadAllText(srcFile); } else { txtSource.Text = ""; } SetFileType(srcFile); cmdBuilder.Visible = scriptList.SelectedValue.EndsWith("schema.json") && scriptList.SelectedValue != "form-schaema.json"; var schemaFile = new FileUri(file.FolderPath, "schema.json"); string schema = ""; if (schemaFile.FileExists) { schema = File.ReadAllText(schemaFile.PhysicalFilePath); } DotNetNuke.UI.Utilities.ClientAPI.RegisterClientVariable(Page, "schema", schema, true); }
private void InitEditor(TemplateManifest template) { LoadFiles(template); var scriptFile = new FileUri(template.ManifestFolderUri.UrlFolder, scriptList.SelectedValue); DisplayFile(scriptFile); }
private void DisplayFile(FileUri file) { //string TemplateFolder = template.Directory; //TemplateFolder = OpenContentUtils.ReverseMapPath(TemplateFolder); //string scriptFile = TemplateFolder + "/" + scriptList.SelectedValue; //plSource.Text = scriptFile; //string srcFile = Server.MapPath(scriptFile); lError.Visible = false; lError.Text = ""; plSource.Text = file.FilePath; string srcFile = file.PhysicalFilePath; if (File.Exists(srcFile)) { txtSource.Text = File.ReadAllText(srcFile); } else { txtSource.Text = ""; } SetFileType(srcFile); cmdBuilder.Visible = scriptList.SelectedValue.EndsWith("schema.json") && scriptList.SelectedValue != "form-schaema.json"; var schemaFile = new FileUri(file.FolderPath, "schema.json"); string schema = ""; if (schemaFile.FileExists) { schema = File.ReadAllText(schemaFile.PhysicalFilePath); } DotNetNuke.UI.Utilities.ClientAPI.RegisterClientVariable(Page, "schema", schema, true); }
internal static TemplateManifest ToTemplateManifest(this FileUri templateUri) { TemplateManifest templateManifest; GetManifest(new TemplateKey(templateUri), out templateManifest); return(templateManifest); }
private void GetFiles([NotNull] IEnumerable <ItemHeader> files, [NotNull] GetChildrenDelegate callback) { Debug.ArgumentNotNull(files, nameof(files)); Debug.ArgumentNotNull(callback, nameof(callback)); var result = new List <BaseTreeViewItem>(); foreach (var child in files) { var fileUri = new FileUri(Site, child.Path, child.HasChildren); var fileName = ((IItemData)child).GetData("ServerFileName") ?? string.Empty; var item = new FileTreeViewItem(fileUri) { Text = child.Name, Updated = child.Updated, ServerFileName = fileName }; if (child.HasChildren) { item.Icon = new Icon("Resources/16x16/folder.png"); item.Add(DummyTreeViewItem.Instance); } result.Add(item); } callback(result); }
public static JObject LoadLocalizationJsonV2(FolderUri templateDir, string culture) { var localizationFilename = new FileUri(templateDir, $"localization.{culture}.json"); JObject localizationJson = JsonUtils.LoadJsonFromCacheOrDisk(localizationFilename) as JObject; return(localizationJson); }
public void InvalidateImage(Uri uri) { string path = Path.Combine(this.StorageUri.Uri, Path.GetFileName(uri.AbsolutePath)); FileUri cacheFileUri = _fileSystem.CreateFileUri(path); InvalidateImage(cacheFileUri); }
private void NotifyDownloadSubscribers(Uri sourceUri, FileUri localUri, bool success = true) { _downloading.Remove(sourceUri.AbsoluteUri); var subscriptions = _downloadedSubscriptions .Where(s => s.SourceUri.AbsoluteUri == sourceUri.AbsoluteUri) .ToList(); if (subscriptions == null || subscriptions.Count == 0) { return; } foreach (var s in subscriptions) { if (success) { s.Success?.Invoke(localUri); } else { s.Error?.Invoke(localUri); } _downloadedSubscriptions.Remove(s); } }
public void InvalidateImage(FileUri imageUri) { List <int> toRemove = new List <int>(); foreach (var kvp in _registeredSets) { if (kvp.Value == imageUri.AbsolutePath) { toRemove.Add(kvp.Key); } } if (toRemove.Count > 0) { foreach (int key in toRemove) { UnregisterSetImageForView(key); } } object image = _cache.Remove(imageUri.AbsolutePath); if (image != null) { _loaderPlatform.ReleaseImage(image); } }
public static string ReadFileFromDisk(FileUri file) { if (file == null) { return(null); } if (!file.FileExists) { return(null); } string fileContent; try { fileContent = File.ReadAllText(file.PhysicalFilePath); if (string.IsNullOrWhiteSpace(fileContent)) { return(null); } } catch (Exception ex) { var mess = $"Error reading file [{file.FilePath}]"; App.Services.Logger.Error(mess, ex); throw new Exception(mess, ex); } return(fileContent); }
protected int LoadFileCache(Dictionary <StringAtom, FileUri> cache, FileUri uri, StringAtom path) { int count = 0; FileLoc loc; loc.uri = uri; loc.modPath = this.ModPath; string txt = util.File.LoadTxt(loc, App.Language, path.Str); if (txt == null) { return(0); } StringReader sr = new StringReader(txt); while (true) { string line = sr.ReadLine(); if (line == null) { break; } string regline = line.Trim(); if (!string.IsNullOrEmpty(regline)) { StringAtom realpath = StringAtom.FromStr(regline); cache[realpath] = uri; ++count; } } sr.Close(); return(count); }
public int GetHashCode(object obj) { int hashCode = (ClientRequestId.GetHashCode() + FileUri.GetHashCode() + RelativeUri.GetHashCode() + Started.GetHashCode()) / 4; Log.Debug($"hashCode {hashCode}"); return(hashCode); }
private string GenerateOutputSingle(Page page, FileUri template, JToken dataJson, string settingsJson, TemplateFiles files) { if (template != null) { if (dataJson != null) { ModelFactorySingle mf; if (_renderinfo.Data == null) { // demo data mf = new ModelFactorySingle(_renderinfo.DataJson, settingsJson, _renderinfo.Template.Manifest, _renderinfo.Template, files, _module); } else { mf = new ModelFactorySingle(_renderinfo.Data, settingsJson, _renderinfo.Template.Manifest, _renderinfo.Template, files, _module); } if (template.Extension != ".hbs") // razor { dynamic model = mf.GetModelAsDynamic(); if (LogContext.IsLogActive) { var logKey = "Render single item template"; LogContext.Log(_module.ViewModule.ModuleId, logKey, "template", template.FilePath); LogContext.Log(_module.ViewModule.ModuleId, logKey, "model", model); } return(ExecuteRazor(template, model)); } else // handlebars { object model; if (!App.Services.CreateGlobalSettingsRepository(PortalSettings.Current.PortalId).GetLegacyHandlebars()) { model = mf.GetModelAsDictionary(); } else { model = mf.GetModelAsDynamic(); } if (LogContext.IsLogActive) { var logKey = "Render single item template"; LogContext.Log(_module.ViewModule.ModuleId, logKey, "template", template.FilePath); LogContext.Log(_module.ViewModule.ModuleId, logKey, "model", model); } HandlebarsEngine hbEngine = new HandlebarsEngine(); return(hbEngine.Execute(page, template, model)); } } else { return(""); } } else { return(""); } }
public TemplateManifest GetTemplateManifest(FileUri template) { if (Templates != null && Templates.ContainsKey(template.FileNameWithoutExtension)) { return(Templates[template.FileNameWithoutExtension]); } return(null); }
public FileUriSelectedObject([NotNull] FileUri fileUri, [NotNull] string serverFileName = "") : base(fileUri.Site) { Assert.ArgumentNotNull(fileUri, nameof(fileUri)); Assert.ArgumentNotNull(serverFileName, nameof(serverFileName)); FileUri = fileUri; ServerFileName = serverFileName; }
public static string GetSorterName([NotNull] FileUri fileUri) { Assert.ArgumentNotNull(fileUri, nameof(fileUri)); var key = GetKey(fileUri); return(AppHost.Settings.GetString("ContentTree\\FileSorting", key, string.Empty)); }
public void Start(int maxMapperNo, int maxReducerNo, FileUri mapFuncFileName, FileUri reduceFuncFileName, IEnumerable<FileUri> filesToProcess) { maxMapperNo = filesToProcess.Count(); this.mapWorkers = this.InitMapThreads(1, maxMapperNo); this.keys = this.PerformMap(mapFuncFileName, filesToProcess); this.keys = this.keys.Distinct().OrderBy(k => k).ToList(); this.reduceWorkers = this.InitReduceThreads(maxMapperNo + 1, maxReducerNo); var reducersAssignment = this.TransferIntermediateFiles(this.keys); this.PerformReduce(reduceFuncFileName, reducersAssignment); }
private List<string> PerformMap(FileUri mapFuncFileName, IEnumerable<FileUri> filesToProcess) { var keys = new List<string>(); var index = 0; foreach (var file in filesToProcess) { var worker = this.mapWorkers[(index++) % this.mapWorkers.Count]; worker.Start(BluepathStorage.GetFileNameStatic(file.Uri), BluepathStorage.GetFileNameStatic(mapFuncFileName.Uri)); } for (var i = 0; i < this.mapWorkers.Count; i++) { this.mapWorkers[i].Join(); } for (var i = 0; i < this.mapWorkers.Count; i++) { keys.AddRange((IEnumerable<string>)this.mapWorkers[i].Result); } return keys; }
private void PerformReduce(FileUri reduceFuncFileName, Dictionary<string, int> assignments) { var index = 0; foreach (var assignment in assignments) { var worker = this.reduceWorkers[assignment.Value]; worker.Start(assignment.Key, BluepathStorage.GetFileNameStatic(reduceFuncFileName.Uri)); } for (var i = 0; i < this.reduceWorkers.Count; i++) { this.reduceWorkers[i].Join(); } }