コード例 #1
0
        private static SPWeb attemptGetConfigStoreWeb(SPSite configSite, ConfigStoreType configStoreType, bool bThrowOnNotFound)
        {
            trace.WriteLineIf(traceSwitch.TraceVerbose, TraceLevel.Verbose, "attemptGetConfigStoreWeb(): Entered with SPSite named '{0}' " +
                              ", configStoreType '{1}' and 'throw exception on not found' param of '{2}'.", configSite, configStoreType, bThrowOnNotFound);

            // if we're looking for the global Config Store do we have an override web name specified in config?

            string sWebName     = null;
            bool   bUseRootWeb  = false;
            string sOverrideWeb = null;

            if (configStoreType == ConfigStoreType.Global)
            {
                sOverrideWeb = getAppSettingsValue(m_GlobalConfigWebAppSettingsKey);

                // if so, find web with this name. If not, default to root web..
                if (!string.IsNullOrEmpty(sOverrideWeb))
                {
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreWeb(): Found override web name '{0}' " +
                                      "specified in config, will attempt to find Config Store web with this name.", sOverrideWeb);
                }
                else
                {
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreWeb(): No override web name found in config, " +
                                      "will use root web of site '{0}'.", configSite.RootWeb.Url);
                    bUseRootWeb = true;
                }
            }
            else
            {
                trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreWeb(): Will attempt to find local Config " +
                                  "Store list in root web of site '{0}'.", configSite.RootWeb.Url);
                bUseRootWeb = true;
            }

            SPWeb configStoreWeb = null;

            if (bUseRootWeb)
            {
                configStoreWeb = configSite.RootWeb;
            }
            else
            {
                try
                {
                    configStoreWeb = configSite.AllWebs[sOverrideWeb];
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreWeb(): Successfully found web with name '{0}'.",
                                      configStoreWeb.Name);
                }
                catch (ArgumentException argExc)
                {
                    trace.WriteLineIf(traceSwitch.TraceWarning, TraceLevel.Warning, "attemptGetConfigStoreWeb(): Failed to find web named '{0}' " +
                                      "in site '{1}'!", sOverrideWeb, configSite.Url);
                    if (bThrowOnNotFound)
                    {
                        string sMessage =
                            string.Format(
                                "Unable to find configuration web in current site collection with name '{0}'.",
                                sOverrideWeb);
                        trace.WriteLineIf(traceSwitch.TraceError, TraceLevel.Error, "attemptGetConfigStoreWeb(): Since 'throw exception on not found' param was true, " +
                                          "throwing exception with message '{0}'.", sMessage);
                        throw new InvalidConfigurationException(sMessage, argExc);
                    }
                }
            }

            trace.WriteLineIf(traceSwitch.TraceVerbose, TraceLevel.Verbose, "attemptGetConfigStoreWeb(): Leaving.");
            return(configStoreWeb);
        }
コード例 #2
0
        private static SPList attemptGetConfigStoreList(SPWeb configStoreWeb, ConfigStoreType configStoreType, bool bThrowOnNotFound)
        {
            trace.WriteLineIf(traceSwitch.TraceVerbose, TraceLevel.Verbose, "attemptGetConfigStoreList(): Entered with SPWeb named '{0}', " +
                              "configStoreType '{1}' and 'throw exception on not found' param of '{2}'.", configStoreWeb.Title, configStoreType, bThrowOnNotFound);

            SPList configStoreList = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string sListName = null;

                if (configStoreType == ConfigStoreType.Global)
                {
                    string sOverrideList = getAppSettingsValue(m_GlobalConfigListAppSettingsKey);
                    if (string.IsNullOrEmpty(sOverrideList))
                    {
                        trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): Found override list name '{0}' " +
                                          "specified in config, will attempt to find Config Store list with this name.", sOverrideList);
                        sListName = sOverrideList;
                    }
                    else
                    {
                        trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): No override list name found in config, " +
                                          "will attempt to find Config Store list with default list name '{0}'.", m_DefaultListName);
                        sListName = m_DefaultListName;
                    }
                }
                else
                {
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): Will attempt to find local Config " +
                                      "Store list with default list name '{0}'.", m_DefaultListName);
                    sListName = m_DefaultListName;
                }

                try
                {
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): Fetching list from web...");
                    configStoreList = configStoreWeb.Lists[sListName];
                    trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): Successfully found Config Store " +
                                      "list named '{0}'.", sListName);
                }
                catch (ArgumentException argExc)
                {
                    trace.WriteLineIf(traceSwitch.TraceWarning, TraceLevel.Warning, "attemptGetConfigStoreList(): Failed to find list named '{0}' " +
                                      "in web '{1}'!", sListName, configStoreWeb.Title);
                    if (bThrowOnNotFound)
                    {
                        string sMessage = string.Format("Unable to find configuration list with name '{0}'.", sListName);
                        trace.WriteLineIf(traceSwitch.TraceError, TraceLevel.Error, "attemptGetConfigStoreList(): Since 'throw exception on not found' param was true, " +
                                          "throwing exception with message '{0}'.", sMessage);
                        throw new InvalidConfigurationException(sMessage, argExc);
                    }
                    else
                    {
                        trace.WriteLineIf(traceSwitch.TraceInfo, TraceLevel.Info, "attemptGetConfigStoreList(): Returning null.");
                    }
                }
            });

            trace.WriteLineIf(traceSwitch.TraceVerbose, TraceLevel.Verbose, "attemptGetConfigStoreList(): Leaving.");

            return(configStoreList);
        }