Beispiel #1
0
        private static void ProvisionFeaturesImplementation <T>(T parent, IEnumerable <Feature> features, PnPMonitoredScope scope)
        {
            var  activeFeatures = new List <Microsoft.SharePoint.Client.Feature>();
            Web  web            = null;
            Site site           = null;

            if (parent is Site)
            {
                site = parent as Site;
                site.Context.Load(site.Features, fs => fs.Include(f => f.DefinitionId));
                site.Context.ExecuteQueryRetry();
                activeFeatures = site.Features.ToList();
            }
            else
            {
                web = parent as Web;
                web.Context.Load(web.Features, fs => fs.Include(f => f.DefinitionId));
                web.Context.ExecuteQueryRetry();
                activeFeatures = web.Features.ToList();
            }

            if (features != null)
            {
                foreach (var feature in features)
                {
                    if (!feature.Deactivate)
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) == null)
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Features_Activating__0__scoped_feature__1_, site != null ? "site" :"web", feature.Id);
                            if (site != null)
                            {
                                site.ActivateFeature(feature.Id);
                            }
                            else
                            {
                                web.ActivateFeature(feature.Id);
                            }
                        }
                    }
                    else
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) != null)
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Features_Deactivating__0__scoped_feature__1_, site != null ? "site" : "web", feature.Id);
                            if (site != null)
                            {
                                site.DeactivateFeature(feature.Id);
                            }
                            else
                            {
                                web.DeactivateFeature(feature.Id);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private static void ProvisionFeaturesImplementation <T>(T parent, List <Feature> features)
        {
            var  activeFeatures = new List <Microsoft.SharePoint.Client.Feature>();
            Web  web            = null;
            Site site           = null;

            if (parent is Site)
            {
                site = parent as Site;
                site.Context.Load(site.Features, fs => fs.Include(f => f.DefinitionId));
                site.Context.ExecuteQueryRetry();
                activeFeatures = site.Features.ToList();
            }
            else
            {
                web = parent as Web;
                web.Context.Load(web.Features, fs => fs.Include(f => f.DefinitionId));
                web.Context.ExecuteQueryRetry();
                activeFeatures = web.Features.ToList();
            }

            if (features != null)
            {
                foreach (var feature in features)
                {
                    if (!feature.Deactivate)
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) == null)
                        {
                            if (site != null)
                            {
                                site.ActivateFeature(feature.Id);
                            }
                            else
                            {
                                web.ActivateFeature(feature.Id);
                            }
                        }
                    }
                    else
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) != null)
                        {
                            if (site != null)
                            {
                                site.DeactivateFeature(feature.Id);
                            }
                            else
                            {
                                web.DeactivateFeature(feature.Id);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private static void ProvisionFeaturesImplementation(object parent, List <Feature> webFeatures)
        {
            Web  web  = null;
            Site site = null;

            if (parent is Site)
            {
                site = parent as Site;
            }
            else
            {
                web = parent as Web;
            }

            if (webFeatures != null)
            {
                foreach (var feature in webFeatures)
                {
                    if (!feature.Deactivate)
                    {
                        if (site != null)
                        {
                            if (!site.IsFeatureActive(feature.ID))
                            {
                                site.ActivateFeature(feature.ID);
                            }
                        }
                        else
                        {
                            if (!web.IsFeatureActive(feature.ID))
                            {
                                web.ActivateFeature(feature.ID);
                            }
                        }
                    }
                    else
                    {
                        if (site != null)
                        {
                            if (site.IsFeatureActive(feature.ID))
                            {
                                site.DeactivateFeature(feature.ID);
                            }
                        }
                        else
                        {
                            if (web.IsFeatureActive(feature.ID))
                            {
                                web.DeactivateFeature(feature.ID);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Unique ID for side loading feature
            Guid sideloadingFeature = new Guid("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D");
            // Prompt for URL
            string url = GetUserInput("Please provide URL for the site where app is being installed: \n");

            // Prompt for Credentials
            Console.WriteLine("Enter Credentials for {0}", url);
            string       userName = GetUserInput("SharePoint username: "******"Please provide full path to your app package: \n");

            // Create context for SharePoint online
            ClientContext ctx = new ClientContext(url);

            ctx.AuthenticationMode = ClientAuthenticationMode.Default;
            ctx.Credentials        = new SharePointOnlineCredentials(userName, pwd);

            // Get variables for the operations
            Site site = ctx.Site;
            Web  web  = ctx.Web;

            try
            {
                // Make sure we have side loading enabled.
                // Using PnP Nuget package extensions.
                site.ActivateFeature(sideloadingFeature);
                try
                {
                    // Load .app file and install that to site
                    var         appstream = System.IO.File.OpenRead(path);
                    AppInstance app       = web.LoadAndInstallApp(appstream);
                    ctx.Load(app);
                    ctx.ExecuteQuery();
                }
                catch
                {
                    throw;
                }
                // Disable side loading feature using
                // PnP Nuget package extensions.
                site.DeactivateFeature(sideloadingFeature);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(string.Format("Exception!"), ex.ToString());
                Console.WriteLine("Press any key to continue.");
                Console.Read();
            }
        }
Beispiel #5
0
        private static TokenParser ProvisionFeaturesImplementation <T>(T parent, IEnumerable <Feature> features, TokenParser parser, PnPMonitoredScope scope)
        {
            var  activeFeatures = new List <Microsoft.SharePoint.Client.Feature>();
            Web  web            = null;
            Site site           = null;

            if (parent is Site)
            {
                site = parent as Site;
                site.Context.Load(site.Features, fs => fs.Include(f => f.DefinitionId));
                site.Context.ExecuteQueryRetry();
                activeFeatures = site.Features.ToList();
            }
            else
            {
                web = parent as Web;
                web.Context.Load(web.Features, fs => fs.Include(f => f.DefinitionId));
                web.Context.ExecuteQueryRetry();
                activeFeatures = web.Features.ToList();
            }

            if (features != null)
            {
                foreach (var feature in features)
                {
                    if (!feature.Deactivate)
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) == null)
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Features_Activating__0__scoped_feature__1_, site != null ? "site" : "web", feature.Id);
                            if (site != null)
                            {
                                try
                                {
                                    site.ActivateFeature(feature.Id);
                                }
                                catch (ServerException ex)
                                {
                                    scope.LogError("Error activating feature {0}: {1}", feature.Id, ex.Message);
                                }
                            }
                            else
                            {
                                try
                                {
                                    web.ActivateFeature(feature.Id);
                                }
                                catch (ServerException ex)
                                {
                                    scope.LogError("Error activating feature {0}: {1}", feature.Id, ex.Message);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (activeFeatures.FirstOrDefault(f => f.DefinitionId == feature.Id) != null)
                        {
                            scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Features_Deactivating__0__scoped_feature__1_, site != null ? "site" : "web", feature.Id);
                            if (site != null)
                            {
                                try
                                {
                                    site.DeactivateFeature(feature.Id);
                                }
                                catch (ServerException ex)
                                {
                                    scope.LogError("Error deactivating feature {0}: {1}", feature.Id, ex.Message);
                                }
                            }
                            else
                            {
                                try
                                {
                                    web.DeactivateFeature(feature.Id);
                                }
                                catch (ServerException ex)
                                {
                                    scope.LogError("Error deactivating feature {0}: {1}", feature.Id, ex.Message);
                                }
                            }
                        }
                    }
                }
            }
            if (parent is Site)
            {
                parser.RebuildListTokens((parent as Site).RootWeb);
            }
            else
            {
                parser.RebuildListTokens(parent as Web);
            }
            return(parser);
        }
Beispiel #6
0
 /// <summary>
 /// Activate the in place records management feature
 /// </summary>
 /// <param name="site">Site collection to operate on</param>
 public static void ActivateInPlaceRecordsManagementFeature(this Site site)
 {
     site.ActivateFeature(new Guid(INPLACE_RECORDS_MANAGEMENT_FEATURE_ID));
 }