private bool IsFeatureFaulty(SPFeature feature)
        {
            if (feature.Definition == null)
            {
                return(true);
            }
            FeatureChecker checker = new FeatureChecker();

            if (checker.CheckFeature(feature).Faulty)
            {
                return(true);
            }
            return(false);
        }
 private bool IsFeatureFaulty(SPFeature feature)
 {
     if (feature.Definition == null)
     {
         return true;
     }
     FeatureChecker checker = new FeatureChecker();
     if (checker.CheckFeature(feature).Faulty)
     {
         return true;
     }
     return false;
 }
Esempio n. 3
0
        /// <summary>searches for faulty features and provides the option to remove them</summary>
        /// <param name="features">SPFeatureCollection, the container for the features</param>
        /// <param name="scope">is needed, in case a feature is found, so that it can be deleted</param>
        /// <returns></returns>
        private bool findFaultyFeatureInCollection(SPFeatureCollection features, SPFeatureScope scope)
        {
            bool faultyFound = false;
            if (features == null)
            {
                logDateMsg("ERROR: Feature Collection was null!");
                return false;
            }
            if (features.Count == 0)
            {
                logDateMsg("ERROR: Feature Collection was empty!");
                return false;
            }

            // string DBName = string.Empty; // tbd: retrieve the database name of the featureCollection
            string featuresName = features.ToString();

            try
            {
                foreach (SPFeature feature in features)
                {
                    FeatureChecker checker = new FeatureChecker();
                    FeatureChecker.Status status = checker.CheckFeature(feature);
                    if (status.Faulty)
                    {
                        faultyFound = true;
                        string location = LocationInfo.SafeDescribeObject(feature.Parent);

                        string msgString = "Faulty Feature found! Id=" + feature.DefinitionId.ToString();
            #if SP2013
                        msgString += " Activation=" + feature.TimeActivated.ToString("yyyy-MM-dd");
            #endif
                        string solutionInfo = GetFeatureSolutionInfo(feature);
                        if (!string.IsNullOrEmpty(solutionInfo))
                        {
                            msgString += solutionInfo;
                        }
                        msgString += Environment.NewLine
                            + "Found in " + location + "." + Environment.NewLine
                            + " Should it be removed from the farm?";
                        logDateMsg(msgString);
                        string caption = "Found Faulty Feature";
                        DialogResult response = MessageBox.Show(msgString, caption,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (response == DialogResult.Yes)
                        {
                            removeFeaturesWithinFarm(feature.DefinitionId, scope);
                        }
                        if (response == DialogResult.Cancel)
                        {
                            return faultyFound;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is SqlException)
                {
                    string msgstring = string.Format("Cannot access a feature collection of scope '{0}'! Not enough access rights for a content DB on SQL Server! dbOwner rights are recommended. Please read the following error message:\n\n'{1}'", scope.ToString(), ex.ToString());
                    string MessageCaption = string.Format("FeatureCollection in a Content DB not accessible");
                    if(MessageBox.Show(msgstring, MessageCaption,MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return faultyFound;
                    }
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "An error has occured!", MessageBoxButtons.OK);
                }
                return faultyFound;
            }
            return faultyFound;
        }
Esempio n. 4
0
        /// <summary>searches for faulty features and provides the option to remove them</summary>
        /// <param name="features">SPFeatureCollection, the container for the features</param>
        /// <param name="scope">is needed, in case a feature is found, so that it can be deleted</param>
        /// <returns></returns>
        private bool findFaultyFeatureInCollection(SPFeatureCollection features, SPFeatureScope scope)
        {
            bool faultyFound = false;
            if (features == null)
            {
                logDateMsg("ERROR: Feature Collection was null!");
                return false;
            }
            if (features.Count == 0)
            {
                logDateMsg("ERROR: Feature Collection was empty!");
                return false;
            }

            // string DBName = string.Empty; // tbd: retrieve the database name of the featureCollection
            string featuresName = features.ToString();

            try
            {
                foreach (SPFeature feature in features)
                {
                    FeatureChecker checker = new FeatureChecker();
                    FeatureChecker.Status status = checker.CheckFeature(feature);
                    if (status.Faulty)
                    {
                        faultyFound = true;

                        string msgString = DescribeFeatureAndLocation(feature);
                        logDateMsg(msgString);
                        string caption = string.Format("Found Faulty {0} Feature", scope);
                        DialogResult response = MessageBox.Show(msgString, caption,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (response == DialogResult.Yes)
                        {
                            removeFeaturesWithinFarm(feature.DefinitionId, scope);
                        }
                        if (response == DialogResult.Cancel)
                        {
                            return faultyFound;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is SqlException)
                {
                    string msgstring = string.Format("Cannot access a feature collection of scope '{0}'! Not enough access rights for a content DB on SQL Server! dbOwner rights are recommended. Please read the following error message:\n\n'{1}'", scope.ToString(), ex.ToString());
                    string MessageCaption = string.Format("FeatureCollection in a Content DB not accessible");
                    if(MessageBox.Show(msgstring, MessageCaption,MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return faultyFound;
                    }
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "An error has occured!", MessageBoxButtons.OK);
                }
                return faultyFound;
            }
            return faultyFound;
        }