예제 #1
0
        private void OverrideBrowserCaps(SPFeatureReceiverProperties properties)
        {
            if (webApp != null)
            {
                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                /*
                 * <browserCaps>
                 *  <result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                 *  <filter>isMobileDevice=false</filter>
                 * </browserCaps>
                 */
                SPWebConfigModification mod = new SPWebConfigModification("add[@type='System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a']", "configuration/system.web/browserCaps");
                mod.Owner    = properties.Feature.DefinitionId.ToString();
                mod.Sequence = 0;
                mod.Type     = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                mod.Value    = @"<result type=""System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"" /><filter>isMobileDevice=false</filter>";
                if (!webApp.WebConfigModifications.Contains(mod))
                {
                    webApp.WebConfigModifications.Add(mod);
                }
                try
                {
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                    ////webApp.WebService.ApplyWebConfigModifications();
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }
        }
        private void DeactivateHttpHandler_SiteMap(SPFeatureReceiverProperties properties)
        {
            if (webApp != null)
            {
                foreach (SPWebConfigModification mod in webApp.WebConfigModifications)
                {
                    if (mod.Owner == properties.Feature.DefinitionId.ToString())
                    {
                        webApp.WebConfigModifications.Remove(mod);
                        break;
                    }
                }

                try
                {
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                    ////webApp.WebService.ApplyWebConfigModifications();
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }
        }
        private void ActivateHttpHandler_Bing(SPFeatureReceiverProperties properties)
        {
            if (webApp != null)
            {
                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                SPWebConfigModification mod = new SPWebConfigModification("add[@type='Hemrika.SharePresence.WebSite.Bing.BingHandler, Hemrika.SharePresence.WebSite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11e6604a27f32a11']", "configuration/system.webServer/handlers");
                mod.Owner    = properties.Feature.DefinitionId.ToString();
                mod.Sequence = 0;
                mod.Type     = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
                mod.Value    = @"<add name=""BingHandler"" path=""BingSiteAuth.xml"" verb=""*"" type=""Hemrika.SharePresence.WebSite.Bing.BingHandler, Hemrika.SharePresence.WebSite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11e6604a27f32a11"" />";
                if (!webApp.WebConfigModifications.Contains(mod))
                {
                    webApp.WebConfigModifications.Add(mod);
                }


                try
                {
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                    ////webApp.WebService.ApplyWebConfigModifications();
                    webApp.Update();

                    webApp.BlockedFileExtensions.Remove("xml");
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }
        }
예제 #4
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

            WebSiteControllerWebConfigManager.ClearWebConfigModifications(webApp);
            SPWebConfigModification mod = WebSiteControllerWebConfigManager.GetHttpModuleEntry();

            if (!webApp.WebConfigModifications.Contains(mod))
            {
                webApp.WebConfigModifications.Add(mod);
            }

            mod = WebSiteControllerWebConfigManager.GetModuleEntry();
            if (!webApp.WebConfigModifications.Contains(mod))
            {
                webApp.WebConfigModifications.Add(mod);
            }

            try
            {
                webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                webApp.Update();
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
        private void EnableAnonumous(SPFeatureReceiverProperties properties)
        {
            try
            {
                if (webApp != null)
                {
                    SPUrlZone urlZone = SPUrlZone.Default;
                    //SPWebApplication specifiedWebApplication = specifiedSite.WebApplication;
                    SPIisSettings iisSettings = webApp.IisSettings[urlZone];
                    iisSettings.AuthenticationMode = AuthenticationMode.Windows;
                    iisSettings.AllowAnonymous     = true;

                    try
                    {
                        SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                        webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                        ////webApp.WebService.ApplyWebConfigModifications();
                        webApp.Update();
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                        //ex.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
예제 #6
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
            webApp.WebConfigModifications.Remove(WebSiteControllerWebConfigManager.GetHttpModuleEntry());
            webApp.WebConfigModifications.Remove(WebSiteControllerWebConfigManager.GetModuleEntry());
            webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
            webApp.Update();
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            FindWebApplication(properties);

            if (webApp != null)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    DeactivateHttpHandler_SiteMap(properties);
                });
            }
        }
        private void DeactivateHttpHandler_Robots(SPFeatureReceiverProperties properties)
        {
            if (webApp != null)
            {
                foreach (SPWebConfigModification mod in webApp.WebConfigModifications)
                {
                    if (mod.Owner == properties.Feature.DefinitionId.ToString())
                    {
                        webApp.WebConfigModifications.Remove(mod);
                        break;
                    }
                }
                try
                {
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                    //webApp.WebService.ApplyWebConfigModifications();
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }

                foreach (SPSite site in webApp.Sites)
                {
                    foreach (SPWeb allWeb in site.AllWebs)
                    {
                        SPWeb web = site.OpenWeb(allWeb.ID);
                        web.AllowUnsafeUpdates = true;
                        web.Update();
                        try
                        {
                            SPList robots = web.Lists["Robots"];
                            web.Lists.Delete(robots.ID);
                            web.Update();
                        }
                        catch (Exception ex)
                        {
                            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                            //ex.ToString();
                        }

                        web.Update();
                        web.AllowUnsafeUpdates = false;
                    }
                }
            }
        }
예제 #9
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            FindWebApplication(properties);

            Deactivate_WebSiteProvider(properties);

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

            try
            {
                webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                webApp.Update();
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
예제 #10
0
        /// <summary>
        /// Clears the web config modifications.
        /// </summary>
        /// <param name="webApp">The web app where the config changes will be cleared</param>
        internal static void ClearWebConfigModifications(SPWebApplication webApp)
        {
            Collection <SPWebConfigModification> collection = webApp.WebConfigModifications;
            int startCount = collection.Count;

            // Remove any modifications that were originally created by the owner.
            for (int i = startCount - 1; i >= 0; i--)
            {
                SPWebConfigModification configMod = collection[i];
                if (configMod.Owner.Equals(OWNERNAME))
                {
                    collection.Remove(configMod);
                }
            }

            // Apply changes only if any items were removed.
            if (startCount > collection.Count)
            {
                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                webApp.Update();
            }
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            FindWebApplication(properties);

            if (webApp != null)
            {
                CreateWebSiteConfig(properties);

                if (webApp != SPAdministrationWebApplication.Local)
                {
                    UpdateMimeMappings(properties);

                    ActivateModule_WebSiteModule(properties);

                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                    ActivateHttpModule_WebSiteModule(properties);

                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                    CreateJobs_WebSiteController(properties);

                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                    EnableAnonumous(properties);

                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                    //ActivateBrowserCaps(properties);

                    //SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                    /*
                     * ActivateHttpHandler_Robots(properties);
                     *
                     * SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                     *
                     * ActivateHttpHandler_Bing(properties);
                     *
                     * SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                     *
                     * ActivateHttpHandler_SiteMap(properties);
                     *
                     * SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                     *
                     * Activate_WebSiteProvider(properties);
                     */
                }
                else
                {
                    CreateDocIcons();
                }

                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

                try
                {
                    webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                    SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                    webApp.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }
        }
예제 #12
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            FindWebApplication(properties);

            SPFeatureScope scope = properties.Feature.Definition.Scope;

            if (scope == SPFeatureScope.Web)
            {
                SPWeb  web  = properties.Feature.Parent as SPWeb;
                SPList list = web.GetList("SiteMap");

                try
                {
                    ConsistantLookup(web, list);
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }

                try
                {
                    Navigation.SitemapDataContext context = new Navigation.SitemapDataContext(web.Url);

                    Navigation.SiteMapNavigationEntry root = new Navigation.SiteMapNavigationEntry();
                    root.Title = "root";
                    context.SiteMap.InsertOnSubmit(root);

                    Navigation.SiteMapNavigationEntry home = new Navigation.SiteMapNavigationEntry();
                    home.Title   = "Home";
                    home.URL     = web.Url;
                    home.Parent  = root;
                    home.Enabled = true;
                    context.SiteMap.InsertOnSubmit(home);

                    context.SubmitChanges(Microsoft.SharePoint.Linq.ConflictMode.ContinueOnConflict, true);
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }

            SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);

            Activate_WebSiteProvider(properties);

            try
            {
                webApp.Farm.Services.GetValue <SPWebService>().ApplyWebConfigModifications();
                SPWebConfigModificationExtensions.WaitForOnetimeJobToFinish(webApp.Farm, "job-webconfig-modification", 180);
                webApp.Update();
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }