public object LoadContents(ConfigServiceClient cfg, RepoServiceClient repo) { if (cfg == null || repo == null) throw new ArgumentNullException(); StringBuilder scriptsResult = new StringBuilder(); var cfgScripts = GetConfigGuidList(cfg); foreach (Guid cfgId in cfgScripts) { PageHeadConfig c = (PageHeadConfig)cfg.GetBranch<PageHeadConfig>(cfgId, this.Category()); if (c != null) { string libFilePaths = ""; foreach (string scriptFileName in c.LibLinks) { if (string.IsNullOrWhiteSpace(scriptFileName)) continue; string scriptName = scriptFileName.ToLowerInvariant().EndsWith(".js") ? scriptFileName : scriptFileName + ".js"; libFilePaths += scriptName + ";"; } if (!string.IsNullOrWhiteSpace(libFilePaths)) scriptsResult.Append("<script type='text/javascript' src='/_layouts/Navertica.SPTools/GetScript.aspx?FilePaths=").Append(libFilePaths).Append("'></script>").AppendLine(); // v SiteConfigu mohou byt jen jmena souboru z adresare dane aplikace v SiteScripts, // nikdy primo kod, ktery by se vkladal do stranky (mozna u javascriptu by to tak byt nemuselo) foreach (string scriptFileName in c.ScriptLinks) { if (string.IsNullOrWhiteSpace(scriptFileName)) continue; /*string scriptName = scriptFileName.ToLowerInvariant().EndsWith(".js") ? scriptFileName : scriptFileName + ".js";*/ string scriptBody = repo.GetJavaScript(scriptFileName); scriptsResult.Append(scriptBody); } } } return scriptsResult.ToString(); }
public object LoadContents(ConfigServiceClient cfg, RepoServiceClient repo) { if (cfg == null || repo == null) throw new ArgumentNullException(); StringBuilder stylesResult = new StringBuilder(); stylesResult.Append("<style>").AppendLine(); var cfgStyles = GetConfigGuidList(cfg); foreach (Guid cfgId in cfgStyles) { PageHeadConfig c = (PageHeadConfig) cfg.GetBranch<PageHeadConfig>(cfgId, this.Category()); if (c != null) { // v SiteConfigu mohou byt jen jmena souboru z adresare dane aplikace v SiteScripts, // nikdy primo kod, ktery by se vkladal do stranky (mozna u css by to tak byt nemuselo) foreach (string scriptFileName in c.StyleLinks) { if (string.IsNullOrWhiteSpace(scriptFileName)) continue; string scriptName = scriptFileName.ToLowerInvariant().EndsWith(".css") ? scriptFileName : scriptFileName + ".css"; var scriptKvp = repo.Get(scriptName); if (scriptKvp != null) { stylesResult.Append("/* " + scriptName + " start */\n"); stylesResult.Append(scriptKvp.StringUnicode); stylesResult.Append("/* " + scriptName + " end */\n"); } } } } stylesResult.Append("</style>"); return stylesResult.ToString(); }
/// <summary> /// Executes the specified content db id. /// </summary> /// <param name="contentDbId">The content db id.</param> public override void Execute(Guid contentDbId) { ILogging log = NaverticaLog.GetInstance(); List<KeyValuePair<string, object>> executionResults = new List<KeyValuePair<string, object>>(); SPWebApplication webApplication = this.Parent as SPWebApplication; if (webApplication == null) { log.LogError(this.Name + ": cannot get SPWebApplication!!!"); return; } //Vetsinou je jen jedna ale muze jich byt vice //SPContentDatabase contentDb = webApplication.ContentDatabases[0]; foreach (SPContentDatabase contentDb in webApplication.ContentDatabases) { for (int i = 0; i < contentDb.Sites.Count; i++) { using (SPSite site = contentDb.Sites[i]) { try { ConfigServiceClient configurations = new ConfigServiceClient(site); log.LogInfo("JOB " + this.Name + " RAN at site: " + site.Url); ConfigGuidList cfgs = configurations.Filter(site.RootWeb, new Dictionary<ConfigFilterType, string> { { ConfigFilterType.App, this.Name } }); if (cfgs.Count == 0) continue; PluginHost.Init(site); foreach (var cfgguid in cfgs) { PluginConfig cfg = (PluginConfig) configurations.GetBranch<PluginConfig>(cfgguid, "TimerJob"); if (cfg == null) continue; foreach (KeyValuePair<string, KeyValuePair<string, JObject>> kvp in cfg.PluginConfigs) { string pluginName = kvp.Key; IPlugin plugin = TimerJobPluginHost.Get(site, pluginName); if (plugin == null) { log.LogError(string.Format( "TimerJobPlugin named {0} was not found in loaded plugins, skipping execution", pluginName)); continue; } TimerJobPluginConfig timerPluginConfig = ConfigBranch.GetInstance<TimerJobPluginConfig>(kvp.Value.Value.ToString()); if (!timerPluginConfig.EnabledToRun) continue; try { using (new SPMonitoredScope("Executing TimerJobPlugin " + pluginName)) { object result = plugin.Execute(timerPluginConfig, site); executionResults.Add(new KeyValuePair<string, object>(pluginName + "|" + kvp.Value.Key, result)); } } catch (Exception e) { log.LogError(string.Format("TimerJobPlugin named {0} has thrown {1}", pluginName, e, e.InnerException, e.StackTrace, e.Source)); } } } string logstr = log.LogInfo("TimerJobPlugins ran:\n" + executionResults.Select( kvp => string.Format("Ran TimerJobPlugin|config name {0} with result:{1}\n\n", kvp.Key, ( kvp.Value ?? "null" ).ToString())).JoinStrings("\n")); } catch (Exception e) { log.LogException(e); } } } } }
public object LoadContents(ConfigServiceClient cfg, RepoServiceClient repo) { StringBuilder sb = new StringBuilder(); var cfgScripts = GetConfigGuidList(cfg); if (cfgScripts.Count == 0) return null; sb.AppendLine("<script type='text/javascript' src='/_layouts/15/NVR.SPTools/libs/Intro/intro.js'></script>").AppendLine(); sb.AppendLine("<link type=\"text/css\" rel=\"stylesheet\" href=\"/_layouts/15/NVR.SPTools/libs/Intro/introjs.css\" />"); sb.AppendLine("<script type='text/javascript'>"); sb.AppendLine(@" function ReplaceHelp(){ window.helpDiv = document.createElement('div'); helpDiv.className = 'ms-core-menu-box ms-core-defaultFont'; window.helpUl = document.createElement('ul'); helpUl.className = 'ms-core-menu-list'; helpDiv.appendChild(helpUl); window.createHelpLi= function(fn, title){ var li = document.createElement('li'); li.className='ms-core-menu-item'; var a = document.createElement('a'); a.className = 'ms-core-menu-link'; a.href = 'javascript:;'; a.title = title; a.innerText = title; a.onclick = function(){window.helpDialog.close(); fn(); return false;} li.appendChild(a); window.helpUl.appendChild(li); } var help = $('span#ms-help a'); createHelpLi(function(){TopHelpButtonClick('HelpHome','');return false;}, 'Default Help'); help[0].onclick = function(){ window.helpDialog = SP.UI.ModalDialog.showModalDialog({ title:'Help Menu', x:window.innerWidth-350, y:0, html: helpDiv, autoSize: true, showClose: true, }); return false; }; SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs('helpReplace'); } SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.ModalDialog', function(){_spBodyOnLoadFunctionNames.push('ReplaceHelp');}); "); sb.AppendLine("</script>"); foreach (Guid cfgId in cfgScripts) { ConfigBranch c = cfg.GetBranch<ConfigBranch>(cfgId, this.Category()); IntroConfig introConfig = ConfigBranch.GetInstance<IntroConfig>(c); string theme = !string.IsNullOrEmpty(introConfig.Theme) ? introConfig.Theme : "introjs-nassim"; sb.AppendLine("<link type=\"text/css\" rel=\"stylesheet\" href=\"/_layouts/15/NVR.SPTools/libs/Intro/themes/" + theme + ".css\" />"); string functionName = "startIntro" + cfgId.ToString("N"); sb.AppendLine("<script type='text/javascript'>"); sb.AppendLine("function " + functionName + "(){"); sb.AppendLine("var intro = introJs();"); sb.AppendLine("intro.setOptions({ steps: ["); string cultureName = CultureInfo.CurrentUICulture.Name; for (int i = 0; i < introConfig.Steps.Count; i++) { IntroConfig.IntroStep introStep = introConfig.Steps[i]; string intro = "Intro " + cultureName; sb.AppendLine("{"); if (introStep.Intro != null) { var introTitle = introStep.Intro.SingleOrDefault(l => l.Language == cultureName); if (introTitle != null) { intro = introTitle.Title; } } if (!string.IsNullOrEmpty(introStep.Element)) { sb.AppendLine("element: " + introStep.Element + ","); } if (!string.IsNullOrEmpty(introStep.Position)) { sb.AppendLine("position: \"" + introStep.Position + "\","); } sb.AppendLine("intro: \"" + intro + "\""); sb.AppendLine("}"); if (i < introConfig.Steps.Count - 1) { sb.AppendLine(","); } } sb.AppendLine("]});"); sb.AppendLine("intro.start();"); sb.AppendLine("}"); string title = "help"; if (introConfig.Title != null) { var helpTitle = introConfig.Title.SingleOrDefault(l => l.Language == cultureName); if (helpTitle != null) { title = helpTitle.Title; } } //function(){} sb.AppendLine("SP.SOD.executeOrDelayUntilScriptLoaded( function(){createHelpLi(" + functionName + ",'" + title + "')},'helpReplace');"); //sb.AppendLine("SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.ModalDialog', function(){_spBodyOnLoadFunctionNames.push(\"createHelpLi(" + functionName + ",'" + title + "')\");});"); sb.AppendLine("</script>"); } return sb.ToString(); }