public object LoadContents(ConfigServiceClient cfg, RepoServiceClient repo) { if (cfg == null) throw new ArgumentNullException(); StringBuilder ribbonResult = new StringBuilder(); ribbonResult.Append("<script type='text/javascript'>").AppendLine(); //ribbonResult.Append("make sure createButtons function is loaded") ribbonResult.Append("var controlProperties = [];").AppendLine(); var cfgRibbons = GetConfigGuidList(cfg); string hideElements = ""; foreach (Guid cfgId in cfgRibbons) { string c = cfg.GetBranchJson(cfgId, this.Category()); if (c != null) { JObject jc = JObject.Parse(c); if (jc["error"] != null) { ribbonResult.Append("console.error('problem loading ribbon config: " + jc["error"] + "');"); continue; } //List<string> jControlProperties = jc["controlProperties"].ToObject<List<string>>(); JToken jControlProperties = jc["controlProperties"]; hideElements = (jc["hideSelector"] ?? "").ToString(); foreach (JObject controlProperty in jControlProperties) { string json = controlProperty.ToString(); ribbonResult.Append("controlProperties.push("); ribbonResult.Append(json); ribbonResult.Append(");").AppendLine(); } } } ribbonResult.Append("EnsureScriptFunc('createButtons.js', 'createButtons', function() {" + "EnsureScriptFunc('ribbon', 'SP.Ribbon.PageManager', function() {" + "if(controlProperties.length!=0)" + "createButtons(controlProperties);" + (!string.IsNullOrEmpty(hideElements) ? ("$('" + hideElements.Replace("'", "\\'") + "').hide();") : "") + "});" + "});").AppendLine(); ribbonResult.Append("</script>"); return ribbonResult.ToString(); }
public object LoadContents(ConfigServiceClient cfg, RepoServiceClient repo) { if (cfg == null) throw new ArgumentNullException(); StringBuilder translationsResult = new StringBuilder(); translationsResult.Append("<script type='text/javascript'>").AppendLine(); //ribbonResult.Append("make sure createButtons function is loaded") translationsResult.Append("if(!typeof(NVRHlasky)=='object' && $.isEmptyObject(NVRHlasky)){var NVRHlasky = {};}").AppendLine();//if Hlasky != emptyObject => Expand object instead var cfgTranslations = GetConfigGuidList(cfg); foreach (Guid cfgId in cfgTranslations) { string c = cfg.GetBranchJson(cfgId, this.Category()); if (c != null) { JObject jc = JObject.Parse(c); if (jc["error"] != null) { translationsResult.Append("console.error('problem loading translations config: " + jc["error"] + "');"); continue; } JToken jTranslations = jc["Hlasky"]; //translations = (jc["Hlasky"] ?? "").ToString(); foreach (JProperty translation in jTranslations) { var key = translation.Name; var value = translation.Value; translationsResult.Append("NVRHlasky = $.extend({}, NVRHlasky, {\"" + key + "\": " + value + "});").AppendLine(); } } } translationsResult.Append("</script>"); return translationsResult.ToString(); }
private void RunAllValid(SPItemEventProperties props) { ILogging log = NaverticaLog.GetInstance(); string eventName = Global + props.EventType.ToString(); if (props.ListItem == null) // ItemAdding { log.LogInfo("props.ListItem == null in list ", props.List.DefaultViewUrl, eventName); return; } ConfigServiceClient configurations = new ConfigServiceClient(props.Site); List<KeyValuePair<string, object>> executionResults = new List<KeyValuePair<string, object>>(); try { ConfigGuidList cfgs = configurations.Filter(props.ListItem, eventName); if (cfgs.Count == 0) return; log.LogInfo(eventName, "item url", props.ListItem.FormUrlDisplay(true)); PluginHost.Init(props.Site); foreach (var cfgguid in cfgs) { var c = configurations.GetBranchJson(cfgguid, ""); //get completeBranch//configurations.GetBranchJson(cfgguid, eventName); if (c != null) { JObject jc = JObject.Parse(c); JObject eventBranch = (JObject) jc[eventName]; if (eventBranch == null) { log.LogError("Missing event branch in config: " + eventName); return; } foreach (KeyValuePair<string, JToken /* really string */> kvp in eventBranch) { string pluginName = kvp.Value.ToString(); IPlugin plugin = ItemReceiverPluginHost.Get(props.Site, pluginName); if (plugin == null) { log.LogError(string.Format("ItemReceiverScriptPlugin named {0} was not found in loaded plugins, skipping execution", pluginName)); continue; } try { // plugin config itself should be in another root branch ItemReceiverPluginConfig pluginConfig = ConfigBranch.GetInstance<ItemReceiverPluginConfig>(jc[kvp.Key].ToString()); // on by default, as is ShP standard if (!( pluginConfig.EventFiringEnabled ?? true )) { this.EventFiringEnabled = false; } object result = plugin.Execute(pluginConfig, props); executionResults.Add(new KeyValuePair<string, object>(kvp.Value.ToString(), result)); } catch (Exception e) { log.LogError(string.Format("ItemReceiverScriptPlugin named {0} has thrown {1}", pluginName, e, e.InnerException, e.StackTrace, e.Source)); } } } } string logstr = log.LogInfo("ItemReceiverScriptPlugins ran:\n" + executionResults.Select( kvp => string.Format("Ran ItemReceiverScriptPlugin|config name {0} with result:{1}\n\n", kvp.Key, ( kvp.Value ?? "null" ).ToString())).JoinStrings("\n")); } catch (Exception e) { log.LogException(e); } }