示例#1
0
        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();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SPSite site = SPContext.Current.Site;

            RepoServiceClient repo = new RepoServiceClient(site);
            Response.ContentType = "text/javascript";

            string[] scriptNames = Request.QueryString["FilePaths"].Split(";");

            string results = "";

            foreach (string scriptName in scriptNames)
            {
                if (( scriptName ?? "" ).Trim() == "") continue;
                results += repo.Get(scriptName) + "\n";
            }

            Response.Write(results);
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SPContext.Current == null) return;

            var log = NaverticaLog.GetInstance();

            using (new SPMonitoredScope("PageHead"))
            {
                try
                {
                    SPSite site = SPContext.Current.Site;
                    ConfigServiceClient cfg = new ConfigServiceClient(site);
                    RepoServiceClient repo = new RepoServiceClient(site);

                    if (this.Request.QueryString["Reset"].ToBool())
                    {
                        cfg.Reset(site.Url);
                        repo.Reset();
                        PluginHost.Reset();
                    }

                    IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(site);
                    IEnumerable<IPageHead> executeInterfaces = serviceLocator.GetAllInstances<IPageHead>();

                    foreach (IPageHead pageInterface in executeInterfaces)
                    {
                        ModulesLiteral.Text += "<!-- NVR PageHead " + pageInterface.Category() + " start -->\n";
                        using (new SPMonitoredScope(pageInterface.Category()))
                        {
                            ModulesLiteral.Text += (string)pageInterface.LoadContents(cfg, repo);
                        }

                        ModulesLiteral.Text += "<!-- NVR PageHead " + pageInterface.Category() + " END -->\n";
                    }
                }
                catch (Exception ex)
                {
                    log.LogException(ex);
                }
            }
        }
示例#4
0
        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();
        }
示例#5
0
文件: CSS.cs 项目: NAVERTICA/SPTools
        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();
        }
示例#6
0
        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();
        }
示例#7
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();
            }
        }
示例#8
0
        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();
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // copy files and items via NVRFeatureReceiver
            base.FeatureActivated(properties);
            SPSite site = properties.Feature.Parent as SPSite;

            if (site == null) throw new NullReferenceException("Couldn't load parent site");

            // reset our internal list name cache - will be done by SPListEventReceivers in the future
            HttpRuntime.Cache.Remove("OpenlistDict_" + site.ID + site.RootWeb.ID);

            bool firstTimeInstallSiteConfig = false;
            bool firstTimeInstallSiteScripts = false;
            if (site.RootWeb.OpenList(Const.SITECONFIG_LIST_TITLE, false) == null) firstTimeInstallSiteConfig = true;
            if (site.RootWeb.OpenList(Const.SITESCRIPTS_LIST_TITLE, false) == null) firstTimeInstallSiteScripts = true;

            log.LogInfo(properties.Feature.Definition.DisplayName + " feature receiver starting");

            try
            {
                // Deploy SiteScripts library and SiteConfig list
                properties.Definition.Farm.Properties["NVR_ScriptsServiceBaseUrl"] = site.Url;
                SiteStructuresDefinitions.DeploySiteModel(site);
                SiteStructuresDefinitions.DeployRootWebStructures(site);
            }
            catch (Exception exc)
            {
                log.LogException(exc, "SPMeta2 deploying models");
            }

            try
            {
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.ListAdded, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.ListAdding, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.ListDeleted, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.ListDeleting, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldAdded, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldAdding, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldDeleted, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldDeleting, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldUpdated, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
                site.RootWeb.EventReceivers.Add(SPEventReceiverType.FieldUpdating, Const.NVR_DLL, Const.NVR_LIST_RECEIVER);
            }
            catch (Exception exc)
            {
                log.LogException(exc, "adding SPListEventReceivers to root web");
                throw;
            }

            // reset our internal list name cache - will be done by SPListEventReceivers in the future
            HttpRuntime.Cache.Remove("OpenlistDict_" + site.ID + site.RootWeb.ID);

            // REMOVE ACCESS
            if (firstTimeInstallSiteConfig)
            {
                try
                {
                    SPList SiteConfig = site.RootWeb.OpenList(Const.SITECONFIG_LIST_TITLE, false);
                    if (SiteConfig != null)
                    {
                        SiteConfig.RemoveRights();
                    }
                }
                catch (Exception exc)
                {
                    log.LogException(exc, "removing rights from SiteConfig");
                    throw;
                }
            }

            if (firstTimeInstallSiteScripts)
            {
                try
                {
                    SPList SiteScripts = site.RootWeb.OpenList(Const.SITESCRIPTS_LIST_TITLE, false);
                    if (SiteScripts != null)
                    {
                        SiteScripts.RemoveRights();
                    }
                }
                catch (Exception exc)
                {
                    log.LogException(exc, "removing rights from SiteScripts");
                    throw;
                }
            }

            try
            {
                ConfigServiceClient cfg = new ConfigServiceClient(site);
                RepoServiceClient repo = new RepoServiceClient(site);
                cfg.Reset(site.Url);
                repo.Reset();
                PluginHost.Reset();
            }
            catch (Exception e)
            {
                log.LogException(e);
                throw;
            }

            log.LogInfo(properties.Feature.Definition.DisplayName + " feature receiver finished");
        }
示例#10
0
            private Stream OpenResourceInputStream(string path)
            {
                string pathtofile = RepoServiceClient.NormalizedFilePath(path);
                if (FullPathsToAllFilesAndFolders.Contains(pathtofile))
                {
                    RepoServiceClient scriptrepo = new RepoServiceClient(Site);

                    var kvp = scriptrepo.Get(pathtofile);
                    if (kvp != null)
                        return new MemoryStream(kvp.BinaryData);
                }
                return null;
            }
示例#11
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();
            }
        }
示例#12
0
        public static string Reload(string fileNamePath, SPSite site)
        {
            RepoServiceClient repo = new RepoServiceClient(site);
            fileNamePath = RepoServiceClient.NormalizedFilePath(fileNamePath);

            var log = NaverticaLog.GetInstance();
            using (new SPMonitoredScope("ReloadPlugin"))
            {
                if (repo.FullPathsToAllFilesAndFolders.Contains(fileNamePath) && fileNamePath.ToLowerInvariant().Contains("plugin"))
                {
                    try
                    {
                        var result = repo.Execute(fileNamePath, new ScriptContext());
                        if (result != null)
                        {
                            List<string> errors = new List<string>();
                            foreach(string s1 in result.Keys)
                                {
                                    if (s1.StartsWith("_ERROR "))
                                    {
                                        errors.Add(log.LogError("Error loading plugin ", s1, result[s1]));
                                    }
                                }

                            if (errors.Count > 0) return "Errors:\n" + string.Join("\n", errors);
                            return "Success " + fileNamePath;
                        }
                    }
                    catch (Exception ee)
                    {
                        return log.LogError("Exception loading plugin ", fileNamePath, ee);
                    }
                    return "Failed " + fileNamePath;
                }
                return "Not a file/plugin, skipped " + fileNamePath;
            }
        }
示例#13
0
        public static void LoadPlugins(SPSite site)
        {
            RepoServiceClient repo = new RepoServiceClient(site);

            var log = NaverticaLog.GetInstance();
            using (new SPMonitoredScope("LoadPlugins"))
            {
                foreach (string s in repo.FullPathsToAllFilesAndFolders)
                {
                    if (s.ToLowerInvariant().Contains("plugin"))
                    {
                        try
                        {
                            ScriptContext result = repo.Execute(s, new ScriptContext());
                            if (result != null)
                            {
                                foreach(string s1 in result.Keys)
                                {
                                    if (s1.StartsWith("_ERROR "))
                                    {
                                        log.LogError("Error loading plugin ", s, result[s1]);
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            log.LogError("Error loading plugin ", s, e);
                        }
                    }
                }
            }
        }