private void iInstallFeature(Guid gFeatureId, SPFeatureDefinition def, SPFeatureDefinitionScope scope, int ParentMessageId)
        {
            switch (def.Scope)
            {
            case SPFeatureScope.Site:
                if (!bVerifyOnly)
                {
                    oWeb.Site.Features.Add(gFeatureId, true, scope);
                }

                addMessage(ErrorLevels.NoError, def.DisplayName, string.Empty, ParentMessageId);

                break;

            case SPFeatureScope.Web:
                if (!bVerifyOnly)
                {
                    oWeb.Features.Add(gFeatureId, true, scope);
                }

                addMessage(ErrorLevels.NoError, def.DisplayName, string.Empty, ParentMessageId);

                break;

            default:
                addMessage(ErrorLevels.Warning, def.DisplayName, "Feature Not scoped for Site or Web", ParentMessageId);

                break;
            }
        }
Exemplo n.º 2
0
        private Control GetPackageControlForFeature(SPFeatureDefinition feature)
        {
            Control c           = new Control();
            string  name        = feature.Properties["SPSIN_ConfigPackage_Title"].Value;
            string  description = "No Description Available";

            if (feature.Properties["SPSIN_ConfigPackage_Description"] != null)
            {
                description = feature.Properties["SPSIN_ConfigPackage_Description"].Value;
            }

            string htmlString = string.Format(@"
<h2>{0}</h2>
<p>{1}</p>
", name, description);

            Button addButton = new Button();

            addButton.ID     = "add_" + feature.Id;
            addButton.Click += new EventHandler(addButton_Click);
            addButton.Text   = "Add " + name;

            Panel packagePanel = new Panel();

            packagePanel.Controls.Add(new LiteralControl(htmlString));
            packagePanel.Controls.Add(addButton);
            packagePanel.CssClass = "SPSIN-packagePanel";

            c.Controls.Add(packagePanel);

            return(c);
        }
Exemplo n.º 3
0
        public static FeatureDefinition ToFeatureDefinition(this SPFeatureDefinition spFeatureDefinition, string definitionInstallationScope)
        {
            var cultureInfo = new System.Globalization.CultureInfo(1033);

            if (spFeatureDefinition == null)
            {
                return(null);
            }

            var fd = FeatureDefinitionFactory.GetFeatureDefinition(
                spFeatureDefinition.Id,
                spFeatureDefinition.CompatibilityLevel,
                spFeatureDefinition.GetDescription(cultureInfo),
                spFeatureDefinition.DisplayName,
                spFeatureDefinition.Hidden,
                spFeatureDefinition.Name,
                spFeatureDefinition.Properties == null ? null :
                spFeatureDefinition.Properties.ToProperties(),
                spFeatureDefinition.Scope.ToScope(),
                spFeatureDefinition.GetTitle(cultureInfo),
                spFeatureDefinition.SolutionId,
                spFeatureDefinition.UIVersion,
                spFeatureDefinition.Version,
                definitionInstallationScope);

            return(fd);
        }
Exemplo n.º 4
0
        void InstallMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Explorer.Update();

            // Feature is not installed.
            string        path        = this.Tag as string;
            DirectoryInfo info        = new DirectoryInfo(path);
            string        featureName = info.Name + @"\feature.xml";

            SPFarm spFarm = Explorer.CurrentFarm;
            SPFeatureDefinition definition = spFarm.FeatureDefinitions.Add(featureName, Guid.Empty, true);
            SPFeatureDefinition dd         = new SPFeatureDefinition();

            this.Text = definition.DisplayName;
            this.Name = definition.Id.ToString();
            this.Tag  = definition;

            FeatureCollectionDefinitionNode nodeCollection = (FeatureCollectionDefinitionNode)this.Parent;

            this.ImageIndex         = nodeCollection.InstalledIndex;
            this.SelectedImageIndex = nodeCollection.InstalledIndex;

            IsInstalled = true;

            Explorer.EndUpdate();
            Explorer.Refresh();

            //Program.Window.propertyGrid.SelectedObject = this.Tag;

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 5
0
        public static string GetFeatureScript(string scriptName)
        {
            SPFeatureDefinition centralAdminFeature = SPFarm.Local.FeatureDefinitions[PowerWebPartConstants.CentralAdminFeatureId];
            string scriptPath = Path.Combine(centralAdminFeature.RootDirectory, "Scripts\\" + scriptName);

            return(File.ReadAllText(scriptPath));
        }
 /// <summary>
 /// Activates a feature on a given SharePoint Web site, if that feature is not yet active.
 /// </summary>
 ///
 /// <param name="webSiteUrl">The URL of the Web site.</param>
 ///
 /// <param name="featureName">The name of the feature.</param>
 ///
 static void ActivateFeatureOnWebSite(string webSiteUrl, string featureName)
 {
     Console.WriteLine("Activating feature \"{0}\" on Web site \"{1}\"", featureName,
                       webSiteUrl);
     using (SPSite spSite = new SPSite(webSiteUrl))
     {
         SPFeatureDefinition featureDefinition =
             spSite.WebApplication.Farm.FeatureDefinitions[featureName];
         if (featureDefinition == null)
         {
             throw new Exception(String.Format("Feature \"{0}\" not found", featureName));
         }
         using (SPWeb spWeb = spSite.OpenWeb())
         {
             SPFeature feature = spWeb.Features[featureDefinition.Id];
             if (feature != null)
             {
                 Console.WriteLine("...exists already");
             }
             else
             {
                 spWeb.Features.Add(featureDefinition.Id);
                 Console.WriteLine("...created");
             }
         }
     }
 }
Exemplo n.º 7
0
        public static List <AttributeValuePair> GetSPFeatureDefinitionAttributes(SPFeatureDefinition featureDef)
        {
            List <AttributeValuePair> featureDefAttributes = new List <AttributeValuePair>();

            try
            {
                featureDefAttributes.Add(new AttributeValuePair("DisplayName", featureDef.DisplayName));
                featureDefAttributes.Add(new AttributeValuePair("Id", featureDef.Id.ToString()));
                featureDefAttributes.Add(new AttributeValuePair("Scope", featureDef.Scope.ToString()));
                featureDefAttributes.Add(new AttributeValuePair("Hidden", featureDef.Hidden.ToString()));
                featureDefAttributes.Add(new AttributeValuePair("Name", featureDef.Name.ToString()));
                // suppress full feature path
                featureDefAttributes.Add(new AttributeValuePair("RootDirectory", featureDef.RootDirectory.Replace(SPUtility.GetGenericSetupPath(@"Template"), "")));
                featureDefAttributes.Add(new AttributeValuePair("Version", featureDef.Version.ToString()));
                featureDefAttributes.Add(new AttributeValuePair("Status", featureDef.Status.ToString()));
                featureDefAttributes.Add(new AttributeValuePair("SolutionId", featureDef.SolutionId.ToString()));
                if (featureDef.ReceiverAssembly != null)
                {
                    featureDefAttributes.Add(new AttributeValuePair("ReceiverAssembly", featureDef.ReceiverAssembly.ToString()));
                    featureDefAttributes.Add(new AttributeValuePair("ReceiverClass", featureDef.ReceiverClass.ToString()));
                }
            }
            catch (Exception e)
            {
                featureDefAttributes.Add(new AttributeValuePair("Exception", e.ToString()));
            }
            return(featureDefAttributes);
        }
        /// <summary>
        /// Activates or deactivates the feature at the specified scope.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="featureId">The feature id.</param>
        /// <param name="activate">if set to <c>true</c> [activate].</param>
        /// <param name="url">The URL.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        /// <param name="ignoreNonActive">if set to <c>true</c> [ignore non active].</param>
        internal void ActivateDeactivateFeatureAtScope(ActivationScope scope, Guid featureId, bool activate, string url, bool force, bool ignoreNonActive)
        {
            Logger.Verbose = true;

            m_FeatureId = featureId;

            if (m_FeatureId.Equals(Guid.Empty))
            {
                throw new SPException("Unable to locate Feature.");
            }

            SPFeatureDefinition feature = SPFarm.Local.FeatureDefinitions[m_FeatureId];

            if (feature == null)
            {
                throw new SPException("Unable to locate Feature.");
            }

            if (scope == ActivationScope.Feature)
            {
                scope = (ActivationScope)Enum.Parse(typeof(ActivationScope), feature.Scope.ToString().ToLowerInvariant(), true);
            }

            ActivateDeactivateFeatureAtScope(feature, scope, activate, url, force, ignoreNonActive);
        }
        protected override IEnumerable <SPFeature> RetrieveDataObjects()
        {
            List <SPFeature> features = new List <SPFeature>();

            switch (ParameterSetName)
            {
            case "SPFeature":
                foreach (SPFeatureDefinitionPipeBind fdpb in Identity)
                {
                    SPFeatureDefinition feature = fdpb.Read();
                    GetFeatureActivations(features, feature, NeedsUpgrade);
                }
                break;

            case "SPSolution":
                foreach (SPSolutionPipeBind spb in Solution)
                {
                    SPSolution solution = spb.Read();
                    List <SPFeatureDefinition> featureDefinitions = SPFarm.Local.FeatureDefinitions.Where(fd => fd.SolutionId == solution.Id).ToList();
                    foreach (SPFeatureDefinition feature in featureDefinitions)
                    {
                        GetFeatureActivations(features, feature, NeedsUpgrade);
                    }
                }
                break;
            }
            return(features);
        }
Exemplo n.º 10
0
 private void btnRemove_Click(object sender, RoutedEventArgs e)
 {
     if (lstSite.SelectedIndex != -1)
     {
         SPFeatureDefinition definition = lstSite.SelectedItem as SPFeatureDefinition;
         site.Features.Remove(definition.Id);
         ReadSource();
     }
 }
        public SPFeatureDefinitionInstance Construct(SPFeatureDefinition featureDefinition)
        {
            if (featureDefinition == null)
            {
                throw new ArgumentNullException("featureDefinition");
            }

            return(new SPFeatureDefinitionInstance(this.InstancePrototype, featureDefinition));
        }
Exemplo n.º 12
0
        public WebSiteZoneModifier(SPWebApplication application, Guid featureID, bool delete)
            : base("Zone Modifier for " + application.Name, application, null, SPJobLockType.None)
        {
            SPFeatureDefinition def = application.Features[featureID].Definition;
            string szone            = def.Properties[zoneKey].Value;

            this.Zone    = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), szone, true);
            this.Url     = def.Properties[urlKey].Value;
            this._delete = delete;
        }
Exemplo n.º 13
0
        private void AddFeaturesInSolutionLVI(SPFeatureDefinition f)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.SubItems.Add(f.DisplayName);
            lvi.SubItems.Add(f.Scope.ToString());
            lvi.SubItems.Add(f.Hidden.ToString());
            lvi.SubItems.Add(f.Version.ToString());
            lvi.Tag = f;
            lvSolutions.Items.Add(lvi);
        }
        /// <summary>
        /// Activates or deactivates the feature.
        /// </summary>
        /// <param name="features">The features.</param>
        /// <param name="activate">if set to <c>true</c> [activate].</param>
        /// <param name="featureId">The feature id.</param>
        /// <param name="urlScope">The URL scope.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        /// <param name="ignoreNonActive">if set to <c>true</c> [ignore non active].</param>
        /// <returns></returns>
        private SPFeature ActivateDeactivateFeature(SPFeatureCollection features, bool activate, Guid featureId, string urlScope, bool force, bool ignoreNonActive)
        {
            if (features[featureId] == null && ignoreNonActive)
            {
                return(null);
            }

            if (!activate)
            {
                if (features[featureId] != null || force)
                {
                    Logger.Write("Progress: Deactivating Feature {0} from {1}.", featureId.ToString(), urlScope);
                    try
                    {
                        features.Remove(featureId, force);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteWarning("{0}", ex.Message);
                    }
                }
                else
                {
                    Logger.WriteWarning("" + SPResource.GetString("FeatureNotActivatedAtScope", new object[] { featureId }) + "  Use the -force parameter to force a deactivation.");
                }

                return(null);
            }
            if (features[featureId] == null)
            {
                Logger.Write("Progress: Activating Feature {0} on {1}.", featureId.ToString(), urlScope);
            }
            else
            {
                if (!force)
                {
                    SPFeatureDefinition fd = features[featureId].Definition;
                    Logger.WriteWarning("" + SPResource.GetString("FeatureAlreadyActivated", new object[] { fd.DisplayName, fd.Id, urlScope }) + "  Use the -force parameter to force a reactivation.");
                    return(features[featureId]);
                }

                Logger.Write("Progress: Re-Activating Feature {0} on {1}.", featureId.ToString(), urlScope);
            }
            try
            {
                return(features.Add(featureId, force));
            }
            catch (Exception ex)
            {
                Logger.WriteException(new System.Management.Automation.ErrorRecord(ex, null, System.Management.Automation.ErrorCategory.NotSpecified, features));
                return(null);
            }
        }
Exemplo n.º 15
0
        public static int GetFeatureCompatibilityLevel(SPFeatureDefinition definition)
        {
#if (SP2013)
            {
                return(definition.CompatibilityLevel);
            }
#else
            {
                return(Feature.COMPATINAPPLICABLE); // inapplicable
            }
#endif
        }
        public static string GetElementDefinition(ISharePointCommandContext context,
                                                  FeatureElementInfo elementInfo)
        {
            SPFeatureDefinition definition = SPFarm.Local.FeatureDefinitions[elementInfo.FeatureID];
            SPElementDefinition element    = definition.GetElementDefinitions(CultureInfo.CurrentCulture)
                                             .OfType <SPElementDefinition>()
                                             .Where(searchElement => searchElement.ElementType == elementInfo.ElementType)
                                             .Where(searchElement => GetNameFromNode(searchElement.XmlDefinition) == elementInfo.Name)
                                             .FirstOrDefault();

            return(element.XmlDefinition.OuterXml);
        }
Exemplo n.º 17
0
 private void GetFeatureScopeFromDefinition(SPFeatureDefinition fdef, ref Feature feature)
 {
     try
     {
         feature.Scope = fdef.Scope;
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
 }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="service"></param>
        /// <param name="featureID"></param>
        /// <param name="delete"></param>
        public WebSiteDocItemModifier(SPService service, Guid featureID, bool delete) : base("DocIcon Modifier for " + featureID.ToString(), service, null, SPJobLockType.None)
        {
            this._featureID = featureID;
            SPFeatureDefinition def = Farm.FeatureDefinitions[featureID];

            this.Key         = def.Properties[keyKey].Value;
            this.Value       = def.Properties[valueKey].Value;
            this.EditText    = def.Properties[textKey].Value;
            this.OpenControl = def.Properties[controlKey].Value;
            this.docIconType = def.Properties[typeKey].Value;
            this._delete     = delete;
        }
Exemplo n.º 19
0
 private void GetFeatureCompatibilityFromDefinition(SPFeatureDefinition fdef, ref Feature feature)
 {
     try
     {
         feature.CompatibilityLevel = FeatureManager.GetFeatureCompatibilityLevel(fdef);
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
 }
Exemplo n.º 20
0
        private string GetProvisioinerFilePath(SPFeatureDefinition featureDefinition)
        {
            string sharepointFeaturesDir = this.GetSharePointFeaturesDirectory();
            string filePath = String.Empty;
            if (featureDefinition != null && !String.IsNullOrEmpty(sharepointFeaturesDir))
            {
                string featureName = featureDefinition.DisplayName;
                string featureDir = Path.Combine(sharepointFeaturesDir, featureName);
                filePath = Path.Combine(featureDir, "SiteProvisioning.xml");
            }

            return filePath;
        }
Exemplo n.º 21
0
        void addButton_Click(object sender, EventArgs e)
        {
            SPContext context = SPContext.Current;

            if (context != null)
            {
                SPWeb web = context.Web;

                Control  b     = (Control)sender;
                string[] parts = b.ID.Split('_');
                if (parts.Length == 2 && parts[0] == "add")
                {
                    string featureID = parts[1];

                    SPFeatureDefinition def = SPFarm.Local.FeatureDefinitions[new Guid(featureID)];

                    if (def == null)
                    {
                        // Maybe sandbox...
                        if (SPFarm.Local.BuildVersion > new Version("14.0.0.0"))
                        {
                            //Load handler for sandbox solutions
                            try
                            {
                                ConfigurationPackageHandler handler = Utilities.GetConfigurationPackageHandlerForSandbox();
                                handler.AddConfigurationPackage(featureID, web);
                                SPSIN_Message.Text = "Configuration Added";
                            }
                            catch (Exception ex)
                            {
                                throw new SPException("Sorry, we cannot add that package. " + ex.Message);
                            }
                        }
                    }
                    else if (def.Scope == SPFeatureScope.Web)
                    {
                        if (web.Features[new Guid(featureID)] == null)
                        {
                            web.Features.Add(new Guid(featureID));
                            web.Features.Remove(new Guid(featureID));
                            SPSIN_Message.Text = "Configuration Added";
                        }
                    }
                    else
                    {
                        throw new SPException(string.Format("Sorry, the package with the feature ID {0} seems to be an invalid SP SIN configuration package. We even tried treating it as a sandbox solution. An SP SIN Configuration package needs to be web scoped (tell your developer) and you need to have permissions to activate the feature.", featureID));
                    }
                }
            }
        }
        private static string GetProvisioinerFilePath(SPFeatureDefinition featureDefinition)
        {
            string sharepointFeaturesDir = GetSharePointFeaturesDirectory();
            string filePath = String.Empty;

            if (featureDefinition != null && !String.IsNullOrEmpty(sharepointFeaturesDir))
            {
                string featureName = featureDefinition.DisplayName;
                string featureDir  = Path.Combine(sharepointFeaturesDir, featureName);
                filePath = Path.Combine(featureDir, "SiteProvisioning.xml");
            }

            return(filePath);
        }
Exemplo n.º 23
0
        public static string GetFeatureName(Guid?featureId)
        {
            if (featureId == null)
            {
                return("NULL feature ID");
            }
            SPFeatureDefinition fdef = SPFarm.Local.FeatureDefinitions[featureId.Value];

            if (fdef == null)
            {
                return(featureId.ToString());
            }
            return(fdef.DisplayName + " (" + featureId.ToString() + ")");
        }
Exemplo n.º 24
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (lstFarm.SelectedIndex != -1)
     {
         SPFeatureDefinition definition = lstFarm.SelectedItem as SPFeatureDefinition;
         if (definition.Scope == SPFeatureScope.Site)
         {
             site.Features.Add(definition.Id);
         }
         if (definition.Scope == SPFeatureScope.Web)
         {
             web.Features.Add(definition.Id);
         }
         ReadSource();
     }
 }
        /// <summary>
        /// Gets the feature activations.
        /// </summary>
        /// <param name="features">The features.</param>
        /// <param name="fd">The fd.</param>
        /// <param name="needsUpgrade">if set to <c>true</c> [needs upgrade].</param>
        private void GetFeatureActivations(List <SPFeature> features, SPFeatureDefinition fd, bool needsUpgrade)
        {
            switch (fd.Scope)
            {
            case SPFeatureScope.Farm:
                features.AddRange(SPWebService.AdministrationService.QueryFeatures(fd.Id, needsUpgrade));
                break;

            case SPFeatureScope.WebApplication:
                features.AddRange(SPWebService.QueryFeaturesInAllWebServices(fd.Id, needsUpgrade));
                break;

            case SPFeatureScope.Site:
                foreach (SPService svc in SPFarm.Local.Services)
                {
                    if (!(svc is SPWebService))
                    {
                        continue;
                    }

                    foreach (SPWebApplication webApp in ((SPWebService)svc).WebApplications)
                    {
                        features.AddRange(webApp.QueryFeatures(fd.Id, needsUpgrade));
                    }
                }
                break;

            case SPFeatureScope.Web:
                foreach (SPService svc in SPFarm.Local.Services)
                {
                    if (!(svc is SPWebService))
                    {
                        continue;
                    }

                    foreach (SPWebApplication webApp in ((SPWebService)svc).WebApplications)
                    {
                        foreach (SPSite site in webApp.Sites)
                        {
                            features.AddRange(site.QueryFeatures(fd.Id, needsUpgrade));
                            site.Dispose();
                        }
                    }
                }
                break;
            }
        }
        public static FeatureDependencyInfo[] GetFeatureDependencies(ISharePointCommandContext context, FeatureInfo featureID)
        {
            List <FeatureDependencyInfo> dependencies = new List <FeatureDependencyInfo>();
            SPFeatureDefinition          definition   = SPFarm.Local.FeatureDefinitions[featureID.FeatureID];

            foreach (SPFeatureDependency dependency in definition.ActivationDependencies)
            {
                SPFeatureDefinition dependencyDefinition = SPFarm.Local.FeatureDefinitions[dependency.FeatureId];
                dependencies.Add(new FeatureDependencyInfo()
                {
                    FeatureID      = dependency.FeatureId,
                    MinimumVersion = dependency.MinimumVersion.ToString(),
                    Title          = dependencyDefinition.GetTitle(CultureInfo.CurrentCulture)
                });
            }
            return(dependencies.ToArray());
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            featureDefinition = properties.Feature.Definition;

            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            webApp.WebConfigModifications.Add(GetModification());

            webApp.Update();
            webApp.WebService.ApplyWebConfigModifications();

            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IIncidentManagementRepository, IncidentManagementRepository>();
            typeMappings.RegisterTypeMapping <IPricingRepository, PricingRepository>();
            typeMappings.RegisterTypeMapping <IProductCatalogRepository, CachedBdcProductCatalogRepository>();
        }
Exemplo n.º 28
0
        public FeatureNode(object spParent, SPFeatureDefinition definition, int imageIndex, bool installed)
        {
            this.Tag = definition;
            this.SPParent = spParent;
            this.ImageIndex = imageIndex;
            this.SelectedImageIndex = imageIndex;
            this.IsInstalled = installed;

            try
            {
                if (definition.Hidden)
                {
                    _Text = definition.GetTitle(SPMConfig.Instance.CultureInfo) + " (Hidden)";
                    this.ForeColor = Color.DarkGray;
                }
                else
                {
                    _Text = definition.GetTitle(SPMConfig.Instance.CultureInfo);
                }

                _ToolTip = definition.GetDescription(SPMConfig.Instance.CultureInfo);
                _Name = definition.Id.ToString();

                this.Setup();

                this.Nodes.Add(new ExplorerNodeBase("Dummy"));
            }
            catch(Exception ex)
            {
                this.ForeColor = Color.DarkRed;
                if (definition != null)
                {
                    _Text = definition.RootDirectory.ToLower() + " (error)";
                    _ToolTip = ex.Message;
                    _Name = definition.Id.ToString();
                }
                else
                {
                    _Text = "(Error: Can not find feature definition)";
                    _ToolTip = ex.Message;
                    _Name = Guid.Empty.ToString();
                }

            }
        }
Exemplo n.º 29
0
        public FeatureNode(object spParent, SPFeatureDefinition definition, int imageIndex, bool installed)
        {
            this.Tag                = definition;
            this.SPParent           = spParent;
            this.ImageIndex         = imageIndex;
            this.SelectedImageIndex = imageIndex;
            this.IsInstalled        = installed;

            try
            {
                if (definition.Hidden)
                {
                    _Text          = definition.GetTitle(SPMConfig.Instance.CultureInfo) + " (Hidden)";
                    this.ForeColor = Color.DarkGray;
                }
                else
                {
                    _Text = definition.GetTitle(SPMConfig.Instance.CultureInfo);
                }

                _ToolTip = definition.GetDescription(SPMConfig.Instance.CultureInfo);
                _Name    = definition.Id.ToString();

                this.Setup();

                this.Nodes.Add(new ExplorerNodeBase("Dummy"));
            }
            catch (Exception ex)
            {
                this.ForeColor = Color.DarkRed;
                if (definition != null)
                {
                    _Text    = definition.RootDirectory.ToLower() + " (error)";
                    _ToolTip = ex.Message;
                    _Name    = definition.Id.ToString();
                }
                else
                {
                    _Text    = "(Error: Can not find feature definition)";
                    _ToolTip = ex.Message;
                    _Name    = Guid.Empty.ToString();
                }
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Get Feature Type
 /// </summary>
 public FeatureType GetFeatureType(SPFeatureDefinition featureDefinition)
 {
     if (sharePoint2007Features.Contains(featureDefinition.DisplayName))
     {
         return(FeatureType.SharePoint);
     }
     if (nintexFeatures.Contains(featureDefinition.DisplayName))
     {
         return(FeatureType.Nintex);
     }
     if (nextDocsFeatures.Contains(featureDefinition.DisplayName))
     {
         return(FeatureType.NextDocs);
     }
     else
     {
         return(FeatureType.Custom);
     }
 }
Exemplo n.º 31
0
 public static int GetFeatureCompatibilityLevel(SPFeatureDefinition definition)
 {
     #if (SP2013)
     {
         return(definition.CompatibilityLevel);
     }
     #endif
     #if (SP2010)
     {
         return(COMPATINAPPLICABLE); // inapplicable
     }
     #endif
     #if (SP2007)
     {
         return(Feature.COMPATINAPPLICABLE); // inapplicable
     }
     #endif
     throw new Exception("Unspecified SharePoint Version");
 }
Exemplo n.º 32
0
 public static int GetFeatureCompatibilityLevel(SPFeatureDefinition definition)
 {
     #if (SP2013)
     {
         return definition.CompatibilityLevel;
     }
     #endif
     #if (SP2010)
     {
         return COMPATINAPPLICABLE; // inapplicable
     }
     #endif
     #if (SP2007)
     {
         return Feature.COMPATINAPPLICABLE; // inapplicable
     }
     #endif
     throw new Exception("Unspecified SharePoint Version");
 }
Exemplo n.º 33
0
        private void FeatureSelected(object sender, EventArgs e)
        {
            if (lvSolutions.SelectedItems.Count > 0)
            {
                CurrentFeature = (SPFeatureDefinition)lvSolutions.SelectedItems[0].Tag;
                gbSites.Text   = "Sites using " + CurrentFeature.DisplayName;

                lvWebs.Items.Clear();
                List <SPWeb> sites = SPBroker.GetSitesUsingFeature(CurrentFeature.Id);
                foreach (SPWeb web in sites)
                {
                    AddFeaturesInWebLvi(web, UsageType.Direct);
                }
                foreach (SPWeb web in SPBroker.GetSitesUsingFeatureInDependency(CurrentFeature.Id))
                {
                    AddFeaturesInWebLvi(web, UsageType.Dependency);
                }
            }
        }
Exemplo n.º 34
0
        public FeatureDefinitionNode(object spParent, SPFeatureDefinition definition, int installedIndex, int unInstalledIndex)
        {
            this.Tag = definition;
            this.SPParent = spParent;
            this.InstalledIndex = installedIndex;
            this.UnInstalledIndex = unInstalledIndex;

            _Text = definition.GetTitle(SPMConfig.Instance.CultureInfo);
            _ToolTip = definition.GetDescription(SPMConfig.Instance.CultureInfo);
            _Name = definition.Id.ToString();

            if (definition.Status != SPObjectStatus.Online)
            {
                _Text += " (" + definition.Status.ToString() + ")";
            }

            this.ImageIndex = InstalledIndex;
            this.SelectedImageIndex = InstalledIndex;

            this.Setup();

            this.Nodes.Add(new ExplorerNodeBase("Dummy"));
        }
Exemplo n.º 35
0
        void InstallMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            Explorer.Update();

            // Feature is not installed.
            string path = this.Tag as string;
            DirectoryInfo info = new DirectoryInfo(path);
            string featureName = info.Name + @"\feature.xml";

            SPFarm spFarm = Explorer.CurrentFarm;
            SPFeatureDefinition definition = spFarm.FeatureDefinitions.Add(featureName, Guid.Empty, true);
            SPFeatureDefinition dd = new SPFeatureDefinition();
            this.Text = definition.DisplayName;
            this.Name = definition.Id.ToString();
            this.Tag = definition;

            FeatureCollectionDefinitionNode nodeCollection = (FeatureCollectionDefinitionNode)this.Parent;
            this.ImageIndex = nodeCollection.InstalledIndex;
            this.SelectedImageIndex = nodeCollection.InstalledIndex;

            IsInstalled = true;

            Explorer.EndUpdate();
            Explorer.Refresh();

            //Program.Window.propertyGrid.SelectedObject = this.Tag;

            Cursor.Current = Cursors.Default;
        }
        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();
                }
            }
        }
Exemplo n.º 37
0
 private void GetFeatureCompatibilityFromDefinition(SPFeatureDefinition fdef, ref Feature feature)
 {
     try
     {
         feature.CompatibilityLevel = FeatureManager.GetFeatureCompatibilityLevel(fdef);
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
 }
Exemplo n.º 38
0
 private void GetFeatureNameFromDefinition(SPFeatureDefinition fdef, ref Feature feature)
 {
     try
     {
         feature.Name = fdef.GetTitle(System.Threading.Thread.CurrentThread.CurrentCulture);
         return;
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
     try
     {
         feature.Name = fdef.DisplayName;
         return;
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
 }
Exemplo n.º 39
0
 private void GetFeatureScopeFromDefinition(SPFeatureDefinition fdef, ref Feature feature)
 {
     try
     {
         feature.Scope = fdef.Scope;
     }
     catch (Exception exc)
     {
         feature.AppendExceptionMsg(exc);
         feature.IsFaulty = true;
     }
 }
        /// <summary>
        /// Returns the full path of the Feature folder.
        /// </summary>
        /// <param name="featureDefinition">Feature definition object.</param>
        /// <returns>Full path of the feature folder.</returns>
        private static string GetFeatureFolder(SPFeatureDefinition featureDefinition)
        {
            if (featureDefinition == null)
            {
                throw new ArgumentNullException("featureDefinition");
            }

            string featureFolder = Path.Combine(SPUtility.GetGenericSetupPath(@"Template\Features"), featureDefinition.DisplayName);
            if (Directory.Exists(featureFolder) == false)
            {
                throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture,
                    "Feature folder '{0}' does not exists.", featureFolder));
            }
            return featureFolder;
        }
Exemplo n.º 41
0
 private static XmlDocument GetXmlDocument(SPFeatureDefinition definition, String path, CultureInfo info)
 {
     return (XmlDocument)(Type.GetType(SPXmlDocCacheAssembly).InvokeMember("GetLocalizedXmlDocument",
         BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static,
         null, null, new object[] { definition, GetRelativePath(path, definition.RootDirectory), info }));
 }
        private static CachedElementDefinition? GetElementInfoFromElementDefinition(SPFeatureDefinition featureDefinition, string elementType, string idAttributeName, object id)
        {
            var elementCollection = featureDefinition.GetElementDefinitions(CultureInfo.InvariantCulture);
            CachedElementDefinition? ret = null;

            foreach (SPElementDefinition e in elementCollection)
            {
                if (e.ElementType == "ContentType" ||
                    e.ElementType == "Field" ||
                    e.ElementType == "ListInstance" ||
                    e.ElementType == "ListTemplate")
                {
                    string elementId;
                    if (e.ElementType == "ContentType" || e.ElementType == "Field")
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "ID");
                    }
                    else if (e.ElementType == "ListInstance")
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "Url");
                    }
                    else
                    {
                        elementId = SPGENCommon.GetElementDefinitionAttribute(e.XmlDefinition.Attributes, "Type");
                    }

                    string key = CreateKey(e.ElementType, elementId);

                    if (_cache.Exists(key))
                        continue;

                    var elementInfo = new CachedElementDefinition();
                    elementInfo.ElementXml = e.XmlDefinition.Clone();
                    elementInfo.FeatureId = featureDefinition.Id;

                    bool equals = false;

                    if (e.ElementType == elementType)
                    {
                        if (id is Guid)
                        {
                            if ((Guid)id == new Guid(elementId))
                                equals = true;
                        }
                        else if (id is SPContentTypeId)
                        {
                            if ((SPContentTypeId)id == new SPContentTypeId(elementId))
                                equals = true;
                        }
                        else
                        {
                            if ((string)id == elementId)
                                equals = true;
                        }
                    }

                    if (!equals)
                    {
                        if (e.ElementType == "ListTemplate")
                        {
                            key += "_" + e.FeatureDefinition.Id.ToString("N").ToUpper();
                        }

                        _cache.Insert(key, elementInfo, true);
                    }
                    else
                    {
                        ret = elementInfo;
                    }
                }
            }

            return ret;
        }
        private static void PreloadDefinitionIntoCache(SPFeatureDefinition featureDefinition, string idAttributeName)
        {
            var coll = featureDefinition.GetElementDefinitions(CultureInfo.InvariantCulture);

            foreach (SPElementDefinition element in coll)
            {
                string elementId = (element.XmlDefinition as XmlElement).GetAttribute(idAttributeName);

                string key = CreateKey(element.ElementType, elementId);
                if (_cache.Exists(key))
                    continue;

                var elementInfo = new CachedElementDefinition();
                elementInfo.ElementXml = element.XmlDefinition.Clone();
                elementInfo.FeatureId = featureDefinition.Id;

                if (element.ElementType == "ListTemplate")
                {
                    key += "_" + element.FeatureDefinition.Id.ToString("N").ToUpper();
                }

                _cache.Insert(key, elementInfo, false);
            }
        }