예제 #1
0
        private XmlNode GetFarmApplicationPoolsNode(SPWebServiceCollection webServices)
        {
            XmlNode farmApplicationPoolsNode = FarmXml.CreateElement("FarmApplicationPools");
            int     appPoolCount             = 0;

            foreach (SPWebService webService in webServices)
            {
                foreach (SPApplicationPool appPool in webService.ApplicationPools)
                {
                    appPoolCount++;
                    XmlNode AppPoolNode = FarmXml.CreateElement("FarmApplicationPool");

                    List <AttributeValuePair> appPoolAttributes = SPAttributes.GetSPApplicationPoolAttributes(appPool);
                    foreach (AttributeValuePair appPoolAttribute in appPoolAttributes)
                    {
                        AppPoolNode.Attributes.SetNamedItem(GetXmlAttribute(appPoolAttribute));
                    }

                    farmApplicationPoolsNode.AppendChild(AppPoolNode);
                }
            }
            XmlNode countAttribute = FarmXml.CreateAttribute("Count");

            countAttribute.Value = appPoolCount.ToString();
            farmApplicationPoolsNode.Attributes.SetNamedItem(countAttribute);

            return(farmApplicationPoolsNode);
        }
예제 #2
0
        // get all WebApplications availble on current WFE machine
        public List <string> getAvailableWebAppsOnMachine()
        {
            List <string> WebNames = new List <string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    // only include the data web apps not configuration (central admin)
                    if (!webApp.IsAdministrationWebApplication)
                    {
                        WebNames.Add(webApp.Name);
                    }
                    //url = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri);
                }
            }

            // sort + reverse so that sharepoint-80 is shown first
            WebNames.Sort();
            WebNames.Reverse();
            return(WebNames);
        }
        private void AddWebApplications(TreeNode farmnode, SPFarm farm)
        {
            SPWebServiceCollection ws = new SPWebServiceCollection(farm);

            // a node representing the web application
            TreeNode wanode = null;

            foreach (SPWebService webservice in ws)
            {
                foreach (SPWebApplication wa in webservice.WebApplications)
                {
                    if (!wa.IsAdministrationWebApplication)
                    {
                        wanode     = new TreeNode(wa.DisplayName, 6, 6);
                        wanode.Tag = wa;
                        farmnode.Nodes.Add(wanode);

                        AddFeaturesForWA(wa, wanode);

                        foreach (SPSite s in wa.Sites)
                        {
                            AddSiteCollections(s.RootWeb.Url, wanode);
                        }
                    }
                }
            }
        }
예제 #4
0
        public List <string> getSiteCollectionsInWebApp(string WebAppName)
        {
            List <string> SiteCollNames = new List <string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    if (webApp.Name == WebAppName)
                    {
                        SPSiteCollection sitecoll = webApp.Sites;
                        foreach (SPSite Site in sitecoll)
                        {
                            SiteCollNames.Add(Site.Url);
                            Site.Dispose();
                        }
                        return(SiteCollNames);
                    }
                }
            }
            return(SiteCollNames);
        }
 /// <summary>
 /// Get Web Application by ID
 /// </summary>
 public static SPWebApplication GetWebAppById(Guid webappId)
 {
     SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
     foreach (SPWebService webService in webServices)
     {
         foreach (SPWebApplication app in webService.WebApplications)
         {
             if (app.Id == webappId)
             {
                 return app;
             }
         }
     }
     return null;
 }
예제 #6
0
        /// <summary>
        /// Get Web Application by ID
        /// </summary>
        public static SPWebApplication GetWebAppById(Guid webappId)
        {
            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                foreach (SPWebApplication app in webService.WebApplications)
                {
                    if (app.Id == webappId)
                    {
                        return(app);
                    }
                }
            }
            return(null);
        }
예제 #7
0
        private XmlNode GetFarmWebApplicationsNode(SPWebServiceCollection webServices)
        {
            XmlNode farmWebApplicationsNode = FarmXml.CreateElement("FarmWebApplications");
            int     webAppCount             = 0;

            foreach (SPWebService webService in webServices)
            {
                foreach (SPWebApplication webApplication in webService.WebApplications)
                {
                    webAppCount++;
                    XmlNode WebAppNode = FarmXml.CreateElement("WebApplication");
                    List <AttributeValuePair> webAppAttributes = SPAttributes.GetSPWebApplicationAttributes(webApplication);
                    foreach (AttributeValuePair webAppAttribute in webAppAttributes)
                    {
                        WebAppNode.Attributes.SetNamedItem(GetXmlAttribute(webAppAttribute));
                    }

                    // Get the Application Pool for the Web Application
                    XmlNode           webAppApplicationPool = FarmXml.CreateElement("ApplicationPool");
                    SPApplicationPool appPool = webApplication.ApplicationPool;

                    List <AttributeValuePair> appPoolAttributes = SPAttributes.GetSPApplicationPoolAttributes(appPool);
                    foreach (AttributeValuePair appPoolAttribute in appPoolAttributes)
                    {
                        webAppApplicationPool.Attributes.SetNamedItem(GetXmlAttribute(appPoolAttribute));
                    }
                    WebAppNode.AppendChild(webAppApplicationPool);

                    // Get the site collections for the Web Application
                    XmlNode siteCollectionsNode = GetSiteCollectionsNode(webApplication.Sites, true);
                    WebAppNode.AppendChild(siteCollectionsNode);

                    // Get the content databases for the web application
                    XmlNode contentDatabasesNode = GetContentDatabasesNode(webApplication.ContentDatabases);
                    WebAppNode.AppendChild(contentDatabasesNode);

                    farmWebApplicationsNode.AppendChild(WebAppNode);
                }
            }
            XmlNode countAttribute = FarmXml.CreateAttribute("Count");

            countAttribute.Value = webAppCount.ToString();
            farmWebApplicationsNode.Attributes.SetNamedItem(countAttribute);

            return(farmWebApplicationsNode);
        }
예제 #8
0
        private IList <Guid> getSubWebSiteIds()
        {
            List <Guid> ids = new List <Guid>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                foreach (SPWebApplication webApp in webService.WebApplications)
                {
                    if (!webApp.IsAdministrationWebApplication)
                    {
                        foreach (SPSite item in webApp.Sites)
                        {
                            ids.Add(item.ID);
                        }
                    }
                }
            }

            return(ids);
        }
        private void UpdateWebConfig(SPFeatureReceiverProperties properties, bool remove)
        {
            try
            {
                SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
                foreach (SPWebService webService in webServices)
                {
                    foreach (SPWebApplication webApp in webService.WebApplications)
                    {
                        if (webApp.IsAdministrationWebApplication)
                            continue;       // don't install on central administration
                        if(!remove)
                            TraceProvider.TraceWarning("NGCCustomActivities", "Adding 'authorizedType' for NGCCustomActivities to " + webApp.Name);
                        else
                            TraceProvider.TraceWarning("NGCCustomActivities", "Removing 'authorizedType' for NGCCustomActivities to " + webApp.Name);

                        SPWebConfigModification authorizedTypeActivity = GetAuthorizedTypeConfigNode(
                            "NGCCustomActivities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=55285224b77190ba",
                            "NGCCustomActivities");
                        if (authorizedTypeActivity != null)
                        {
                            if (remove)
                                webApp.WebConfigModifications.Remove(authorizedTypeActivity);   // Remove from web.config
                            else
                                webApp.WebConfigModifications.Add(authorizedTypeActivity);      // Add to web.config
                            webApp.Update(true);
                            webApp.WebService.ApplyWebConfigModifications();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceProvider.TraceException("NGCActivities", "Exception Updating web.config: " + ex.Message);
                throw ex;
            }
        }
예제 #10
0
        public static List <SPWeb> GetAllWebs()
        {
            List <SPWeb> result = new List <SPWeb>();

            SPWebServiceCollection ws = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webservice in ws)
            {
                foreach (SPWebApplication wa in webservice.WebApplications)
                {
                    if (!wa.IsAdministrationWebApplication)
                    {
                        foreach (SPSite s in wa.Sites)
                        {
                            foreach (SPWeb w in s.AllWebs)
                            {
                                result.Add(w);
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #11
0
        public void BuildFarmXml()
        {
            // Start with the Farm
            Farm = SPFarm.Local;
            XmlElement farmNode = FarmXml.CreateElement("Farm");

            FarmXml.AppendChild(farmNode);

            // StartTime
            XmlNode startTimeAttribute = FarmXml.CreateAttribute("StartTime");

            startTimeAttribute.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
            farmNode.Attributes.SetNamedItem(startTimeAttribute);

            // FarmVersion
            // TODO config file to store the description of SharePoint versions for lookup
            XmlNode versionNode = FarmXml.CreateElement("FarmVersion");
            Version farmVersion = Farm.BuildVersion;

            versionNode.InnerText = farmVersion.ToString();
            farmNode.AppendChild(versionNode);

            // FarmName
            XmlNode farmNameNode = FarmXml.CreateElement("FarmName");
            string  farmName     = Farm.DisplayName;

            farmNameNode.InnerText = farmName;
            farmNode.AppendChild(farmNameNode);

            // FarmId
            XmlNode farmIdNode = FarmXml.CreateElement("FarmId");
            Guid    farmId     = Farm.Id;

            farmIdNode.InnerText = farmId.ToString();
            farmNode.AppendChild(farmIdNode);

            // FarmStatus
            XmlNode        farmStatusNode = FarmXml.CreateElement("FarmStatus");
            SPObjectStatus farmStatus     = Farm.Status;

            farmStatusNode.InnerText = farmStatus.ToString();
            farmNode.AppendChild(farmStatusNode);

            // FarmServers
            farmNode.AppendChild(GetServersNode(Farm.Servers, "FarmServers"));

            // FarmServices
            XmlNode farmServicesNode = FarmXml.CreateElement("FarmServices");

            farmServicesNode = GetFarmServicesNode(Farm.Services, farmServicesNode);
            farmNode.AppendChild(farmServicesNode);

            // FarmSolutions
            XmlNode farmSolutionsNode = GetFarmSolutionsNode(Farm.Solutions);

            farmNode.AppendChild(farmSolutionsNode);

            // FarmFeatureDefinitions
            XmlNode farmFeatureDefinitionsNode = FarmXml.CreateElement("FarmFeatureDefinitions");

            farmFeatureDefinitionsNode = GetFarmFeatureDefinitionsNode(Farm.FeatureDefinitions, farmFeatureDefinitionsNode);
            farmNode.AppendChild(farmFeatureDefinitionsNode);

            // FarmSiteCollections
            farmSiteCollectionsNode = FarmXml.CreateElement("FarmSiteCollections");

            // WebApplications
            SPWebServiceCollection webServices = new SPWebServiceCollection(Farm);
            // note this also populates the FarmSiteCollections
            XmlNode farmWebApplicationsNode = GetFarmWebApplicationsNode(webServices);

            farmNode.AppendChild(farmWebApplicationsNode);
            farmNode.AppendChild(farmSiteCollectionsNode);

            //ApplicationPools
            XmlNode farmApplicationPoolsNode = GetFarmApplicationPoolsNode(webServices);

            farmNode.AppendChild(farmApplicationPoolsNode);

            // FinishTime
            XmlNode  finishTimeAttribute = FarmXml.CreateAttribute("FinishTime");
            DateTime finishTime          = DateTime.Now;

            finishTimeAttribute.Value = finishTime.ToString("yyyy-MM-dd HH:mm:ss:fff");
            farmNode.Attributes.SetNamedItem(finishTimeAttribute);

            // A nicer GenerationTime format
            XmlNode generationTimeAttribute = FarmXml.CreateAttribute("GenerationTime");

            generationTimeAttribute.Value = finishTime.ToLongDateString() + " " + finishTime.ToLongTimeString();
            farmNode.Attributes.SetNamedItem(generationTimeAttribute);
        }
예제 #12
0
        public List<string> getSiteCollectionsInWebApp(string WebAppName)
        {
            List<string> SiteCollNames = new List<string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    if (webApp.Name == WebAppName)
                    {
                        SPSiteCollection sitecoll = webApp.Sites;
                        foreach (SPSite Site in sitecoll)
                        {
                            SiteCollNames.Add(Site.Url);
                            Site.Dispose();
                        }
                        return (SiteCollNames);
                    }
                }
            }
               return (SiteCollNames);
        }
예제 #13
0
        // get all WebApplications availble on current WFE machine
        public List<string> getAvailableWebAppsOnMachine()
        {
            List<string> WebNames = new List<string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    // only include the data web apps not configuration (central admin)
                    if (!webApp.IsAdministrationWebApplication)
                        WebNames.Add(webApp.Name);
                    //url = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri);
                }
            }

            // sort + reverse so that sharepoint-80 is shown first
            WebNames.Sort();
            WebNames.Reverse();
            return (WebNames);
        }
        /// <summary>
        /// Gets the default webapp when siteURL property is not set.
        /// - Get all webapps (that are not admin) that are on port 80. Use the one with least number of dots (segments). When there are
        /// multiple with same number of dots, use the one starting with www. Otherwise fail.
        /// - If there are no webapps on port 80, do same as above for 443.
        /// </summary>
        /// <returns>WebApp URL</returns>
        private string GetDefaultWebAppUrl()
        {
            Uri result = null;
            var conflict = true;
            var webServices = new SPWebServiceCollection(parentFarm);
            foreach (var webService in webServices)
            {
                foreach (var webApp in webService.WebApplications)
                {
                    var uri = webApp.GetResponseUri(SPUrlZone.Default);
                    if (webApp.IsAdministrationWebApplication ||
                        ((uri.Port != 80 || !uri.Scheme.ToUpperInvariant().Equals("HTTP")) &&
                         (uri.Port != 443 || !uri.Scheme.ToUpperInvariant().Equals("HTTPS")))) continue;
                    if (result == null)
                    {
                        conflict = false;
                        result = uri;
                    }
                    else
                    {
                        var uriSegments = uri.Host.Split('.');
                        var resultSegments = result.Host.Split('.');

                        //Give preference to port 80.
                        if (result.Port == 80 && uri.Port == 443)
                        {
                            continue;
                        }
                        if (result.Port == 443 && uri.Port == 80)
                        {
                            result = uri;
                            continue;
                        }

                        if (resultSegments.Length > uriSegments.Length)
                        {
                            conflict = false;
                            result = uri;
                        }
                        else if (resultSegments.Length == uriSegments.Length)
                        {
                            bool uriIsWww = uri.Segments[0].ToUpperInvariant().Equals("WWW");
                            bool resultIsWww = result.Segments[0].ToUpperInvariant().Equals("WWW");

                            if (uriIsWww && !resultIsWww)
                            {
                                conflict = false;
                                result = uri;
                            }
                            else if (!uriIsWww && resultIsWww)
                            {
                                conflict = false;
                            }
                            else
                            {
                                conflict = true;
                            }
                        }
                    }
                }
            }

            if (conflict)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                    "Feature {0} definition is missing 'SiteUrl' property and it cannot be determined.", this.featureName), "properties");
            }

            return result.OriginalString;
        }
예제 #15
0
        private static void CleanOldHandlers()
        {
            var webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                foreach (SPWebApplication webApp in webService.WebApplications)
                {
                    if (!webApp.IsAdministrationWebApplication)
                    {
                        try
                        {
                            // Get the filepath location for the web.config
                            SPIisSettings settings = webApp.GetIisSettingsWithFallback(SPUrlZone.Default);
                            DirectoryInfo iisPath  = settings.Path;

                            string webConfigpath = iisPath.FullName + "\\web.config";

                            // start reading the web.config in order to add appropriate text
                            var    configReader   = new StreamReader(webConfigpath);
                            string configContents = configReader.ReadToEnd();
                            configReader.Close();

                            string moduleText = "<add name=\"AlphaMosaikTranslation\" type=\"TranslatorHttpHandler.TranslatorModule, TranslatorHttpHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a65beeb1a6acb37a\" />" + Environment.NewLine;
                            if (configContents.IndexOf(moduleText) != -1)
                            {
                                // remove old handler
                                configContents = configContents.Replace(moduleText, string.Empty);

                                var configWriter = new StreamWriter(webConfigpath);
                                configWriter.Write(configContents);
                                configWriter.Flush();
                                configWriter.Close();

                                foreach (SPSite site in webApp.Sites)
                                {
                                    var list = new List(site.Url, "/", "LanguagesVisibility");

                                    // Remove Old Assembly
                                    list.UnlinkEventHandlerToList("CheckDefaultLangEvent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b49392f9e06d3f3", "CheckDefaultLangEvent.ItemEvent", "ItemUpdated");
                                    list.UnlinkEventHandlerToList("CreateGUIDEvent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4a041d2cfd549304", "CreateGUIDEvent.GenerateId", "ItemAdded");

                                    const string OldAssemblyName = "ReloadCacheEvent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=45fd9f0eaea17ba9";
                                    const string ClassName       = "ReloadCacheEvent.CacheEvent";

                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemAdded");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemDeleting");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemUpdated");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemUpdated");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemUpdated");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemDeleting");
                                    list.UnlinkEventHandlerToList(OldAssemblyName, ClassName, "ItemAdded");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Feature Search
        /// </summary>
        private void fm_search_Click(object sender, EventArgs e)
        {
            featuresToDisplay.Clear();
            fm_grid.Rows.Clear();
            featuresDisplayed = 0;

            SPWebApplication webApp = GetSelectedWebApplication();

            if (webApp == null)
            {
                return;
            }

            try
            {
                if (fm_search_textbox.Text == "<GUID / Feature Name>")
                {
                    fm_search_textbox.Clear();
                }
                progressBar1.Value   = 0;
                collectionLabel.Text = "Feature Occurences: Loading...Please Wait";
                this.Invalidate();
                this.Update();

                // Farm Features
                if (fm_scope_Farm.Checked)
                {
                    SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
                    foreach (SPWebService webService in webServices)
                    {
                        foreach (SPFeature feature in webService.Features)
                        {
                            AddFeature(fm_search_textbox.Text, feature, FeatureScope.Farm, "N/A", fm_type_Custom.Checked);
                        }
                    }
                }

                // Web Application Features
                if (fm_scope_WebApplication.Checked)
                {
                    foreach (SPFeature feature in webApp.Features)
                    {
                        AddFeature(fm_search_textbox.Text, feature, FeatureScope.WebApplication, webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri, fm_type_Custom.Checked);
                    }
                }

                foreach (SPSite site in webApp.Sites)
                {
                    // Site Collection features..
                    if (fm_scope_SiteCollection.Checked)
                    {
                        foreach (SPFeature feature in site.Features)
                        {
                            AddFeature(fm_search_textbox.Text, feature, FeatureScope.SiteCollection, site.Url, fm_type_Custom.Checked);
                        }
                    }

                    // Site features..
                    if (fm_scope_Site.Checked)
                    {
                        foreach (SPWeb web in site.AllWebs)
                        {
                            foreach (SPFeature feature in web.Features)
                            {
                                AddFeature(fm_search_textbox.Text, feature, FeatureScope.Site, web.Url, fm_type_Custom.Checked);
                            }
                            web.Dispose();
                        }
                    }
                    site.Dispose();
                }
                DisplayFeatures();
                collectionLabel.Text = "Feature Occurences: " + (fm_grid.Rows.Count - 1);
                progressBar1.Value   = 0;
            }
            catch (Exception ex) { if (DEBUG_MODE.Checked)
                                   {
                                       MessageBox.Show(ex.ToString());
                                   }
            }
        }