Beispiel #1
0
 public void Update(object ensure)
 {
     if (ensure != Null.Value && ensure != Undefined.Value && ensure is bool)
     {
         m_contentDatabase.Update((bool)ensure);
     }
     else
     {
         m_contentDatabase.Update();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, StringDictionary keyValues, out string output)
        {
            output         = string.Empty;
            Logger.Verbose = true;

            string dbserver = Params["dbserver"].Value;
            string dbname   = Params["dbname"].Value;

            if (string.IsNullOrEmpty(dbserver))
            {
                dbserver = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource;
            }
            SPWebApplication  webApp = SPWebApplication.Lookup(new Uri(Params["webapp"].Value));
            SPContentDatabase db     = null;

            foreach (SPContentDatabase tempDB in webApp.ContentDatabases)
            {
                if (tempDB.Name.ToLower() == dbname.ToLower())
                {
                    db = tempDB;
                    break;
                }
            }
            if (db != null)
            {
                throw new Exception("Content database already exists.");
            }

            SPObjectStatus status = (SPObjectStatus)Enum.Parse(typeof(SPObjectStatus), Params["status"].Value, true);

            db = webApp.ContentDatabases.Add(dbserver, dbname, null, null,
                                             int.Parse(Params["warningsitecount"].Value),
                                             int.Parse(Params["maxsites"].Value), (status == SPObjectStatus.Online?0:1));

            if (Params["searchserver"].UserTypedIn && !string.IsNullOrEmpty(Params["searchserver"].Value))
            {
                // If they specified a search server then we need to try and find a valid
                // matching search server using the server address property.
#if SP2010
                SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch");
#elif SP2013
                SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch4");
#endif
                SPServiceInstance searchServiceServer = null;
                foreach (SPServiceInstance tempsvc in service.Instances)
                {
                    if (!(tempsvc is SPSearchServiceInstance))
                    {
                        continue;
                    }

                    if (tempsvc.Status != SPObjectStatus.Online)
                    {
                        continue;
                    }

                    if (tempsvc.Server.Address.ToLowerInvariant() == Params["searchserver"].Value.ToLowerInvariant())
                    {
                        // We found a match so bug out of the loop.
                        searchServiceServer = tempsvc;
                        break;
                    }
                }
                if (searchServiceServer != null)
                {
                    db.SearchServiceInstance = searchServiceServer;
                }
                else
                {
                    Logger.Write("Search server \"{0}\" not found.", EventLogEntryType.Warning, Params["searchserver"].Value);
                }
            }
            else if (Params["searchserver"].UserTypedIn)
            {
                // The user specified the searchserver switch with no value which is what we use to indicate
                // clearing the value.
                db.SearchServiceInstance = null;
            }

            db.Update();

            return((int)ErrorCodes.NoError);
        }
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, StringDictionary keyValues, out string output)
        {
            output         = string.Empty;
            Logger.Verbose = true;

            if (Params["setmaxsitestocurrent"].UserTypedIn && Params["maxsites"].UserTypedIn)
            {
                throw new SPException(SPResource.GetString("ExclusiveArgs", new object[] { "setmaxsitestocurrent, maxsites" }));
            }

            string dbname = Params["dbname"].Value;

            SPWebApplication  webApp = SPWebApplication.Lookup(new Uri(Params["webapp"].Value));
            SPContentDatabase db     = null;

            foreach (SPContentDatabase tempDB in webApp.ContentDatabases)
            {
                if (tempDB.Name.ToLower() == dbname.ToLower())
                {
                    db = tempDB;
                    break;
                }
            }
            if (db == null)
            {
                throw new Exception("Content database not found.");
            }

            bool modified = false;

            if (Params["status"].UserTypedIn)
            {
                db.Status = (SPObjectStatus)Enum.Parse(typeof(SPObjectStatus), Params["status"].Value, true);
                modified  = true;
            }

            if (Params["maxsites"].UserTypedIn)
            {
                db.MaximumSiteCount = int.Parse(Params["maxsites"].Value);
                modified            = true;
            }
            else if (Params["setmaxsitestocurrent"].UserTypedIn)
            {
                if (db.CurrentSiteCount < db.WarningSiteCount)
                {
                    db.WarningSiteCount = db.CurrentSiteCount - 1;
                }
                db.MaximumSiteCount = db.CurrentSiteCount;

                modified = true;
            }

            if (Params["warningsitecount"].UserTypedIn)
            {
                db.WarningSiteCount = int.Parse(Params["warningsitecount"].Value);
                modified            = true;
            }

            if (Params["searchserver"].UserTypedIn && !string.IsNullOrEmpty(Params["searchserver"].Value))
            {
                // If they specified a search server then we need to try and find a valid
                // matching search server using the server address property.
#if SP2010
                SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch");
#elif SP2013
                SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch4");
#endif
                SPServiceInstance searchServiceServer = null;
                foreach (SPServiceInstance tempsvc in service.Instances)
                {
                    if (!(tempsvc is SPSearchServiceInstance))
                    {
                        continue;
                    }

                    if (tempsvc.Status != SPObjectStatus.Online)
                    {
                        continue;
                    }

                    if (tempsvc.Server.Address.ToLowerInvariant() == Params["searchserver"].Value.ToLowerInvariant())
                    {
                        // We found a match so bug out of the loop.
                        searchServiceServer = tempsvc;
                        break;
                    }
                }
                if (searchServiceServer != null)
                {
                    db.SearchServiceInstance = searchServiceServer;
                    modified = true;
                }
                else
                {
                    Logger.Write("Search server \"{0}\" not found.", EventLogEntryType.Warning, Params["searchserver"].Value);
                }
            }
            else if (Params["searchserver"].UserTypedIn)
            {
                // The user specified the searchserver switch with no value which is what we use to indicate
                // clearing the value.
                db.SearchServiceInstance = null;
                modified = true;
            }

            if (modified)
            {
                db.Update();
            }

            return((int)ErrorCodes.NoError);
        }