Esempio n. 1
0
        public ConfigGuidList GetConfigGuidList(ConfigServiceClient cfg)
        {
            var filters = new Dictionary<ConfigFilterType, string>
            {
                { ConfigFilterType.App, this.Category() },
                { ConfigFilterType.Url, this.Context.Request.RawUrl }
            };

            if (SPContext.Current.List != null)
            {
                filters.Add(ConfigFilterType.ListType, SPContext.Current.List.BaseType.ToString());
            }

            if (SPContext.Current.ListItem != null)
            {
                filters.Add(ConfigFilterType.ContentType, SPContext.Current.ListItem.ContentTypeId.ToString());
            }

            return cfg.Filter(SPContext.Current.Web, filters);
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //using (SPLongOperation longOperation = new SPLongOperation(this.Page))
            {
                SPSite site = SPContext.Current.Site;

                StringBuilder result = new StringBuilder();
                ConfigServiceClient configurations = null;
                RepoServiceClient scripts;
                SPList siteConfig = null;
                SPList siteScripts = null;

                IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(site);
                IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>();
                typeMappings.Site = site;

                #region Services

                PrintHeader("NVRServices");

                #region NVRConfigService

                string cfgSvcValue;

                try
                {
                    configurations = new ConfigServiceClient(site);
                    cfgSvcValue = configurations.ServiceApplicationIisGuid().ToString();
                }
                catch (Exception exc)
                {
                    cfgSvcValue = exc.Message;
                    return;
                }

                PrintRow("NVRConfigService", cfgSvcValue);

                #endregion

                #region NVRRepoService

                string scriptsSvcValue;

                try
                {
                    scripts = new RepoServiceClient(site);
                    scriptsSvcValue = scripts.ServiceApplicationIisGuid().ToString();
                }
                catch (Exception exc)
                {
                    scriptsSvcValue = exc.Message;
                }
                PrintRow("NVRRepoService", scriptsSvcValue);

                Separator();

                #endregion

                #endregion

                #region PageHeads

                PrintHeader("IPageHead");

                IEnumerable<IPageHead> pageHeadInstances = serviceLocator.GetAllInstances<IPageHead>();

                foreach (IPageHead pageInterface in pageHeadInstances)
                {
                    PrintRow(pageInterface.GetType().Name, "");
                }

                Separator();

                #endregion

                #region  ILOGGING

                PrintHeader("ILogging");

                IEnumerable<ILogging> logInstances = serviceLocator.GetAllInstances<ILogging>();

                if (logInstances.Count() == 0)
                {
                    PrintRow("NO LOGGING INTERFACE FOUND!!!", "");
                }

                foreach (ILogging logInterface in logInstances)
                {
                    PrintRow(logInterface.GetType().Name, "");
                }

                Separator();

                #endregion

                #region IExecute

                PrintHeader("IExecute");
                IEnumerable<IExecuteScript> executeInterfaces = serviceLocator.GetAllInstances<IExecuteScript>();
                if (executeInterfaces.Count() == 0)
                {
                    PrintRow("NO EXECUTE INTERFACE FOUND!!!", "");
                }

                foreach (IExecuteScript execInterface in executeInterfaces)
                {
                    PrintRow(execInterface.GetType().Name, "");
                }

                Separator();

                #endregion

                #region NVR LISTS

                PrintHeader("SiteConfig");

                #region SiteConfig

                try
                {
                    siteConfig = site.RootWeb.OpenList("SiteConfig", true);
                    PrintRow("SPList " + siteConfig.InternalName(), "OK");
                }
                catch (Exception exc)
                {
                    PrintRow(siteConfig.InternalName(), exc.Message);
                    return;
                }

                var siteConfigCt = siteConfig.ContentTypes.GetContentType("NVR_SiteConfigJSON");
                if (siteConfigCt == null)
                {
                    PrintRow("SPContentType NVR_SiteConfigJSON", "NOT FOUND");
                    return;
                }
                PrintRow("SPContentType NVR_SiteConfigJSON", "OK");

                try
                {
                    if (!siteConfig.ContainsFieldIntName(SiteStructuresDefinitions.SiteConfigFields)) throw new SPFieldNotFoundException(siteConfig, SiteStructuresDefinitions.SiteConfigFields);
                    PrintRow("Required Fields", "OK");
                }
                catch (Exception exc)
                {
                    PrintRow("Required Fields", exc.Message);
                }

                try
                {
                    SPListItem reloadItem = siteConfig.Items.Cast<SPListItem>().Where(i => i.ContentTypeId == siteConfigCt.Id).FirstOrDefault();
                    configurations.Reload(reloadItem);
                    PrintRow("SiteConfig Reload CFG", "OK");
                }
                catch (Exception exc)
                {
                    PrintRow("SiteConfig Reload CFG", exc.Message);
                }

                try
                {
                    var filters = new Dictionary<ConfigFilterType, string>
                    {
                        { ConfigFilterType.App, "JavaScripts" },
                        { ConfigFilterType.Url, this.Context.Request.RawUrl }
                    };

                    if (SPContext.Current.List != null)
                    {
                        filters.Add(ConfigFilterType.ListType, SPContext.Current.List.BaseType.ToString());
                    }

                    if (SPContext.Current.ListItem != null)
                    {
                        filters.Add(ConfigFilterType.ContentType, SPContext.Current.ListItem.ContentTypeId.ToString());
                    }

                    configurations.Filter(SPContext.Current.Web, filters);
                    PrintRow("SiteConfig Filter CFG", "OK");
                }
                catch (Exception exc)
                {
                    PrintRow("SiteConfig Filter CFG", exc.Message);
                }

                Separator();

                #endregion

                #region SiteScripts

                PrintHeader("SiteScripts");

                try
                {
                    siteScripts = site.RootWeb.OpenList("SiteScripts", true);
                    PrintRow("SPList " + siteScripts.InternalName(), "OK");
                }
                catch (Exception exc)
                {
                    PrintRow(siteScripts.InternalName(), exc.Message);
                    return;
                }

                var siteScriptsCt = siteScripts.ContentTypes.GetContentType("NVR_SiteScripts");
                if (siteScriptsCt == null)
                {
                    PrintRow("SPContentType NVR_SiteScripts", "NOT FOUND");
                }
                else
                {
                    PrintRow("SPContentType NVR_SiteScripts", "OK");
                }

                Separator();

                #endregion

                #endregion

                #region Plugins

                PrintHeader("Plugins");
                PluginHost.Reset();
                PluginHost.Init(site);
                List<string> plugins = PluginHost.List(site);

                foreach (var pluginName in plugins)
                {
                    IPlugin plugin = PluginHost.Get(site, pluginName);

                    PrintRow(plugin.Name(), plugin.Description());
                }

                #endregion

                /*
                longOperation.LeadingHTML = "Updating. . .";
                longOperation.TrailingHTML = "Totok se nezobrazilo";
                longOperation.Begin();
             * */

                //EndOperation(longOperation, System.Web.HttpUtility.JavaScriptStringEncode(result.ToString()));

                Content.Text = result.ToString();
            }
        }
Esempio n. 3
0
        /// <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);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        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);
            }
        }