Exemplo n.º 1
0
 public ConfigEntry(DictionaryNVR itemdict, SPWeb web)
 {
     if (itemdict == null) throw new ArgumentNullException();
     if (web == null) throw new ArgumentNullException();
     if (itemdict.Count == 0) throw new ArgumentValidationException("itemdict", "empty");
     InitFromDictionary(itemdict, web);
 }
Exemplo n.º 2
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            using (new SPMonitoredScope("Navertica.SharePoint.Pages. Execute"))
            {
                SPSite site = SPContext.Current.Site;
                SPWeb web = null;
                bool dispose = false;

                RepoServiceClient scriptrepo = new RepoServiceClient(site);
                ILogging log = NaverticaLog.GetInstance();

                //Pokud neni explicitne uveden web nacitame contextovy web. Pri volani na konkretnim webu muzeme pouzit (pro optimalizaci vykonu)  /cfp/_layouts/15/Execute.aspx?List=&item=&atd.....
                try
                {
                    if (!string.IsNullOrEmpty(Request["Web"]))
                    {
                        web = site.OpenW(( Request["Web"] ?? "/" ), true);
                        dispose = true;
                    }
                    else
                    {
                        web = SPContext.Current.Web;
                    }
                }
                catch (Exception exc)
                {
                    var msg = "Could not get Web " + exc;
                    LogError(log, msg);
                    return;
                }

                web.RunWithAllowUnsafeUpdates(() =>
                {
                    #region Scope data

                    DictionaryNVR scopeData = new DictionaryNVR
                    {
                        { "Request", Request },
                        { "Response", Response },
                        { "site", site },
                        { "Server", Server },
                        { "web", web },
                        { "Page", Page },
                        { "Cache", Cache }
                    };

                    if (!string.IsNullOrEmpty(Request["List"]))
                    {
                        try
                        {
                            SPList list = web.OpenList(Request["List"], true);
                            scopeData["list"] = list;

                            if (!string.IsNullOrEmpty(Request["Item"]))
                            {
                                try
                                {
                                    int id = int.Parse(Request["Item"]);
                                    SPListItem item = list.GetItemById(id);
                                    scopeData["item"] = item;
                                }
                                catch (Exception)
                                {
                                    LogError(log, "Could not get item with '" + Request["Item"] + "'");
                                    return;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            LogError(log, "Could not get list '" + Request["List"] + "' at web " + web.Url);
                            return;
                        }
                    }

                    #endregion

                    if (!string.IsNullOrWhiteSpace(Request["PluginName"]))
                    {
                        ExecutePluginName(scopeData, site, log);
                    }
                    else
                    {
                        LogError(log, "Execute.aspx needs PluginName");
                    }
                });

                if (dispose) web.Dispose();
            }
        }
Exemplo n.º 3
0
        private void InitFromDictionary(DictionaryNVR itemdict, SPWeb web)
        {
            if (itemdict == null || web == null) throw new ArgumentNullException();
            Urls = ((string)itemdict["NVR_SiteConfigUrl"] ?? "").Split('\n','|'); // HACK for newline not saving in field problem
            ContentTypes = ((string)itemdict["NVR_SiteConfigContentType"] ?? "").Split('\n');
            ListTypes = ((string)itemdict["NVR_SiteConfigListType"] ?? "").Split('\n');
            Apps = ((string) itemdict["NVR_SiteConfigApp"] ?? "").Split('\n', ',');
            Order = int.Parse((itemdict["NVR_SiteConfigOrder"] ?? "0").ToString());
            JsonConfigBody = (string)itemdict["NVR_SiteConfigJSON"];
            Active = (bool)itemdict["NVR_SiteConfigActive"];
            Approved = (bool)itemdict["NVR_SiteConfigApproved"];

            if (!itemdict.ContainsKey("NVR_SiteConfigActiveFor") || itemdict["NVR_SiteConfigActiveFor"] == null || string.IsNullOrWhiteSpace((string)itemdict["NVR_SiteConfigActiveFor"]))
                ActiveForUsers = null;
            else
                ActiveForUsers = web.GetSPPrincipals((string)itemdict["NVR_SiteConfigActiveFor"]).GetLogins().ToArray();

            _itemId = (Guid)itemdict["_ItemUniqueId"];

            Deserialize();
        }
Exemplo n.º 4
0
        private void ExecutePluginName(DictionaryNVR scopeData, SPSite site, ILogging log)
        {
            try
            {
                // TODO - config could be filtered based on plugin name and referrer
                // now it's up to the plugin itself to load what it needs

                PluginHost.Init(site);

                string pluginName = Request["PluginName"];

                IPlugin plugin = ExecutePagePluginHost.Get(site, pluginName);
                if (plugin == null)
                {
                    log.LogError(string.Format("ExecuteScriptPlugin named {0} was not found in loaded plugins, skipping execution", pluginName));
                    return;
                }

                try
                {
                    using (new SPMonitoredScope("Executing ExecuteScriptPlugin " + pluginName))
                    {
                        var res = plugin.Execute(null, scopeData);
                        log.LogInfo("Executed " + pluginName + " with result:\n", res ?? "NULL");
                    }
                }
                catch (Exception e)
                {
                    log.LogError(string.Format("ExecuteScriptPlugin named {0} has thrown {1}", pluginName, e),
                        e.InnerException, e.StackTrace, e.Source);
                }
            }
            catch (Exception exc)
            {
                log.LogException("Exception in Execute.aspx, Script " + Request["ScriptPath"], exc);
                Response.Write("Exception in script\n" + exc);
                Response.StatusCode = 500;
                Response.StatusDescription = "Exception in script";
                return;
            }
        }