コード例 #1
0
        public void BackupFarm(SPFarm farm, bool prepare)
        {
            if (prepare)
            {
                PrepareSystem();
            }

            if (_includeIis)
            {
                // Export the IIS settings.
                string iisBakPath = Path.Combine(_path, "iis_full.bak");
                if (_overwrite && File.Exists(iisBakPath))
                {
                    File.Delete(iisBakPath);
                }
                if (!_overwrite && File.Exists(iisBakPath))
                {
                    throw new SPException(
                              string.Format("The IIS backup file '{0}' already exists - specify '-overwrite' to replace the file.", iisBakPath));
                }

                //Utilities.RunCommand("cscript", string.Format("{0}\\iiscnfg.vbs /export /f \"{1}\" /inherited /children /sp /lm", Environment.SystemDirectory, iisBakPath), false);
                using (DirectoryEntry de = new DirectoryEntry("IIS://localhost"))
                {
                    Logger.Write("Exporting full IIS settings....");
                    string decryptionPwd = string.Empty;
                    de.Invoke("Export", new object[] { decryptionPwd, iisBakPath, "/lm", FLAG_EXPORT_INHERITED_SETTINGS });
                }
            }
            SPEnumerator enumerator = new SPEnumerator(farm);

            InitiateEnumerator(enumerator);
        }
コード例 #2
0
        public void BackupWebApplication(SPWebApplication webApp, bool prepare)
        {
            if (prepare)
            {
                PrepareSystem();
            }

            SPEnumerator enumerator = new SPEnumerator(webApp);

            InitiateEnumerator(enumerator);
        }
コード例 #3
0
        private void InitiateEnumerator(SPEnumerator enumerator)
        {
            if (enumerator != null)
            {
                // Listen for web application events so that we can export the settings for the specified application.
                enumerator.SPWebApplicationEnumerated += new SPEnumerator.SPWebApplicationEnumeratedEventHandler(OnSPWebApplicationEnumerated);

                enumerator.SPSiteEnumerated += new SPEnumerator.SPSiteEnumeratedEventHandler(OnSPSiteEnumerated);
                enumerator.Enumerate();
            }
        }
コード例 #4
0
        public void BackupWebApplication(List <SPWebApplication> webApps, bool prepare)
        {
            if (prepare)
            {
                PrepareSystem();
            }

            foreach (SPWebApplication webApp in webApps)
            {
                SPEnumerator enumerator = new SPEnumerator(webApp);
                InitiateEnumerator(enumerator);
            }
        }
コード例 #5
0
        protected override void UpdateDataObject()
        {
            ShouldProcessReason reason;

            if (!base.ShouldProcess("Set Quotas", null, null, out reason))
            {
                if (reason == ShouldProcessReason.WhatIf)
                {
                    m_whatIf = true;
                }
            }

            SPFarm       farm       = SPFarm.Local;
            SPWebService webService = farm.Services.GetValue <SPWebService>("");

            m_quotaColl = webService.QuotaTemplates;
            m_setQuota  = !SyncExistingOnly.IsPresent;


            if (QuotaTemplate != null)
            {
                m_quota = QuotaTemplate.Read();
                if (m_quota == null)
                {
                    throw new SPCmdletException("The specified quota template name could not be found.");
                }
            }

            SPEnumerator enumerator = null;

            switch (ParameterSetName)
            {
            case "SPSite1":
            case "SPSite2":
                Sync(Site.Read());
                return;

            case "SPWebApplication1":
            case "SPWebApplication2":
                enumerator = new SPEnumerator(WebApplication.Read());
                break;

            default:
                enumerator = new SPEnumerator(Farm.Read());
                break;
            }

            enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated;
            enumerator.Enumerate();
        }
コード例 #6
0
        /// <summary>
        /// Executes 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 scope = Params["scope"].Value.ToLowerInvariant();

            SPFarm       farm       = SPFarm.Local;
            SPWebService webService = farm.Services.GetValue <SPWebService>("");

            m_quotaColl = webService.QuotaTemplates;
            m_setQuota  = Params["setquota"].UserTypedIn;

            if (Params["quota"].UserTypedIn)
            {
                m_quota = m_quotaColl[Params["quota"].Value];
                if (m_quota == null)
                {
                    throw new ArgumentException("The specified quota template name could not be found.");
                }
            }

            SPEnumerator enumerator;

            if (scope == "farm")
            {
                enumerator = new SPEnumerator(SPFarm.Local);
            }
            else if (scope == "webapplication")
            {
                enumerator = new SPEnumerator(SPWebApplication.Lookup(new Uri(Params["url"].Value.TrimEnd('/'))));
            }
            else
            {
                // scope == "site"
                using (SPSite site = new SPSite(Params["url"].Value.TrimEnd('/')))
                {
                    Sync(site);
                }
                return((int)ErrorCodes.NoError);
            }

            enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated;
            enumerator.Enumerate();

            return((int)ErrorCodes.NoError);
        }
コード例 #7
0
        internal void ActivateDeactivateFeatureAtScope(SPFeatureDefinition feature, ActivationScope scope, bool activate, string url, bool force, bool ignoreNonActive)
        {
            m_IgnoreNonActive = ignoreNonActive;
            m_Activate        = activate;
            m_Force           = force;
            m_Url             = url;
            m_FeatureId       = feature.Id;

            if (feature.Scope == SPFeatureScope.Farm)
            {
                if (scope != ActivationScope.Farm)
                {
                    throw new SPSyntaxException("The Feature specified is scoped to the Farm.  The -scope parameter must be \"Farm\".");
                }
                ActivateDeactivateFeatureAtFarm(activate, m_FeatureId, m_Force, m_IgnoreNonActive);
            }
            else if (feature.Scope == SPFeatureScope.WebApplication)
            {
                if (scope != ActivationScope.Farm && scope != ActivationScope.WebApplication)
                {
                    throw new SPSyntaxException("The Feature specified is scoped to the Web Application.  The -scope parameter must be either \"Farm\" or \"WebApplication\".");
                }

                if (scope == ActivationScope.Farm)
                {
                    SPEnumerator enumerator = new SPEnumerator(SPFarm.Local);
                    enumerator.SPWebApplicationEnumerated += enumerator_SPWebApplicationEnumerated;
                    enumerator.Enumerate();
                }
                else
                {
                    if (string.IsNullOrEmpty(m_Url))
                    {
                        throw new SPSyntaxException("The -url parameter is required if the scope is \"WebApplication\".");
                    }
                    SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url));
                    ActivateDeactivateFeatureAtWebApplication(webApp, m_FeatureId, activate, m_Force, m_IgnoreNonActive);
                }
            }
            else if (feature.Scope == SPFeatureScope.Site)
            {
                if (scope == ActivationScope.Web)
                {
                    throw new SPSyntaxException("The Feature specified is scoped to Site.  The -scope parameter cannot be \"Web\".");
                }

                SPSite       site       = null;
                SPEnumerator enumerator = null;
                try
                {
                    if (scope == ActivationScope.Farm)
                    {
                        enumerator = new SPEnumerator(SPFarm.Local);
                    }
                    else if (scope == ActivationScope.WebApplication)
                    {
                        SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url));
                        enumerator = new SPEnumerator(webApp);
                    }
                    else if (scope == ActivationScope.Site)
                    {
                        site = new SPSite(m_Url);
                        ActivateDeactivateFeatureAtSite(site, activate, m_FeatureId, m_Force, m_IgnoreNonActive);
                    }
                    if (enumerator != null)
                    {
                        enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated;
                        enumerator.Enumerate();
                    }
                }
                finally
                {
                    if (site != null)
                    {
                        site.Dispose();
                    }
                }
            }
            else if (feature.Scope == SPFeatureScope.Web)
            {
                SPSite       site       = null;
                SPWeb        web        = null;
                SPEnumerator enumerator = null;
                try
                {
                    if (scope == ActivationScope.Farm)
                    {
                        enumerator = new SPEnumerator(SPFarm.Local);
                    }
                    else if (scope == ActivationScope.WebApplication)
                    {
                        SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url));
                        enumerator = new SPEnumerator(webApp);
                    }
                    else if (scope == ActivationScope.Site)
                    {
                        site       = new SPSite(m_Url);
                        enumerator = new SPEnumerator(site);
                    }
                    else if (scope == ActivationScope.Web)
                    {
                        site       = new SPSite(m_Url);
                        web        = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_Url)];
                        enumerator = new SPEnumerator(web);
                    }
                    if (enumerator != null)
                    {
                        enumerator.SPWebEnumerated += enumerator_SPWebEnumerated;
                        enumerator.Enumerate();
                    }
                }
                finally
                {
                    if (web != null)
                    {
                        web.Dispose();
                    }
                    if (site != null)
                    {
                        site.Dispose();
                    }
                }
            }
        }