コード例 #1
0
        private static void DeleteMissingFeature(MissingFeaturesInput missingFeature)
        {
            if (missingFeature == null)
            {
                return;
            }

            string featureId = missingFeature.FeatureId;
            string targetUrl = string.Empty;;

            if (missingFeature.Scope == "Site")
            {
                targetUrl = missingFeature.SiteCollection;
            }
            else
            {
                targetUrl = missingFeature.WebUrl;
            }

            if (targetUrl.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) < 0)
            {
                // ignore the header row in case it is still present
                return;
            }

            Guid featureDefinitionId = new Guid(featureId);

            try
            {
                Logger.LogInfoMessage(String.Format("Processing Feature {0} on {1} {2} ...", featureId, missingFeature.Scope, targetUrl), true);

                using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, targetUrl))
                {
                    //RemoveFeature(userContext, featureDefinitionId);
                    switch (missingFeature.Scope.ToLower())
                    {
                    case "site":
                        userContext.Load(userContext.Site);
                        userContext.ExecuteQuery();
                        if (RemoveFeatureFromSite(userContext, featureDefinitionId))
                        {
                            Logger.LogSuccessMessage(String.Format("Deleted Feature {0} from site {1}", featureDefinitionId.ToString(), userContext.Site.Url), false);
                        }
                        else
                        {
                            Logger.LogErrorMessage(String.Format("Could not delete site Feature {0}; feature not found", featureDefinitionId.ToString()), false);
                        }
                        break;

                    case "web":
                        userContext.Load(userContext.Web);
                        userContext.ExecuteQuery();
                        if (RemoveFeatureFromWeb(userContext, featureDefinitionId))
                        {
                            Logger.LogSuccessMessage(String.Format("Deleted Feature {0} from web {1}", featureDefinitionId.ToString(), userContext.Web.Url), false);
                        }
                        else
                        {
                            Logger.LogErrorMessage(String.Format("Could not delete web Feature {0}; feature not found", featureDefinitionId.ToString()), false);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("DeleteMissingFeature() failed for Feature {0} on {1} {2}; Error={3}", featureDefinitionId.ToString(), missingFeature.Scope, targetUrl, ex.Message), false);
            }
        }
コード例 #2
0
        private static void DeleteMissingFeature(MissingFeaturesInput missingFeature, string csvFile)
        {
            bool headerFeatureOP = false;
            MissingFeatureOutput objFeatureOP = new MissingFeatureOutput();

            if (missingFeature == null)
            {
                return;
            }

            string featureId = missingFeature.FeatureId;
            string targetUrl = string.Empty;

            objFeatureOP.FeatureId         = featureId;;
            objFeatureOP.Scope             = missingFeature.Scope;
            objFeatureOP.WebApplication    = missingFeature.WebApplication;
            objFeatureOP.ExecutionDateTime = DateTime.Now.ToString();

            if (missingFeature.Scope == "Site")
            {
                targetUrl = missingFeature.SiteCollection;
                objFeatureOP.SiteCollection = targetUrl;
                objFeatureOP.WebUrl         = Constants.NotApplicable;
            }
            else
            {
                targetUrl = missingFeature.WebUrl;
                objFeatureOP.SiteCollection = missingFeature.SiteCollection;
                objFeatureOP.WebUrl         = missingFeature.WebUrl;
            }

            if (targetUrl.IndexOf("http", StringComparison.InvariantCultureIgnoreCase) < 0)
            {
                // ignore the header row in case it is still present
                return;
            }

            Guid featureDefinitionId = new Guid(featureId);

            try
            {
                Logger.LogInfoMessage(String.Format("Processing Feature {0} on {1} {2} ...", featureId, missingFeature.Scope, targetUrl), true);

                using (ClientContext userContext = Helper.CreateAuthenticatedUserContext(Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, targetUrl))
                {
                    //RemoveFeature(userContext, featureDefinitionId);
                    switch (missingFeature.Scope.ToLower())
                    {
                    case "site":
                        userContext.Load(userContext.Site);
                        userContext.ExecuteQuery();
                        if (RemoveFeatureFromSite(userContext, featureDefinitionId))
                        {
                            Logger.LogSuccessMessage(String.Format("Deleted Feature {0} from site {1} and output file is present in the path: {2}", featureDefinitionId.ToString(), userContext.Site.Url, Environment.CurrentDirectory), true);
                            objFeatureOP.Status = Constants.Success;
                        }
                        else
                        {
                            Logger.LogErrorMessage(String.Format("[DeleteMissingFeatures: DeleteMissingFeature] Could not delete site Feature {0}; feature not found", featureDefinitionId.ToString()), true);
                            objFeatureOP.Status = Constants.Failure;
                        }
                        break;

                    case "web":
                        userContext.Load(userContext.Web);
                        userContext.ExecuteQuery();
                        if (RemoveFeatureFromWeb(userContext, featureDefinitionId))
                        {
                            Logger.LogSuccessMessage(String.Format("Deleted Feature {0} from web {1} and output file is present in the path: {2}", featureDefinitionId.ToString(), userContext.Web.Url, Environment.CurrentDirectory), true);
                            objFeatureOP.Status = Constants.Success;
                        }
                        else
                        {
                            Logger.LogErrorMessage(String.Format("[DeleteMissingFeatures: DeleteMissingFeature] Could not delete web Feature {0}; feature not found", featureDefinitionId.ToString()), true);
                            objFeatureOP.Status = Constants.Failure;
                        }
                        break;
                    }
                }
                if (System.IO.File.Exists(csvFile))
                {
                    headerFeatureOP = true;
                }
                FileUtility.WriteCsVintoFile(csvFile, objFeatureOP, ref headerFeatureOP);
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("[DeleteMissingFeatures: DeleteMissingFeature] failed for Feature {0} on {1} {2}; Error={3}", featureDefinitionId.ToString(), missingFeature.Scope, targetUrl, ex.Message), true);
                ExceptionCsv.WriteException(Constants.NotApplicable, targetUrl, targetUrl, "Feature", ex.Message, ex.ToString(), "DeleteMissingFeature",
                                            ex.GetType().ToString(), String.Format("DeleteMissingFeature() failed for Feature {0} on {1} {2}", featureDefinitionId.ToString(), missingFeature.Scope, targetUrl));
            }
        }