An abreviated form of the ApplicationCatalog that allows us to override the base directory and relative search paths.
Inheritance: AggregateCatalog
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var siteurl = this.ClientContext.Url.EnsureTrailingSlashLowered();

            LogVerbose($"Check if app sideLoading is enabled for {siteurl}");


            try
            {
                var sideLoadingEnabled = AppCatalog.IsAppSideloadingEnabled(this.ClientContext);
                this.ClientContext.ExecuteQuery();

                if (!sideLoadingEnabled.Value)
                {
                    LogWarning("SideLoading feature is not enabled on the site: {0}", siteurl);
                }
                else
                {
                    LogVerbose("SideLoading feature is already enabled on site {0}", siteurl);
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Error encountered when trying to enable SideLoading feature {0} with message {1}", siteurl, ex.Message.ToString());
            }
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            try
            {
                var ctx    = this.ClientContext;
                var apps   = AppCatalog.GetAppInstances(ctx, this.ClientContext.Web);
                var result = ctx.LoadQuery(apps.Where(a => a.Status == AppInstanceStatus.Installed));
                this.ClientContext.ExecuteQueryRetry();
                foreach (AppInstance res in result)
                {
                    LogVerbose($"AppCatalog => App {res.Id} instance id {res.Title} and catalog {res.RemoteAppUrl} w/ SvcPri {res.AppPrincipalId}");
                }


                if (AppInstanceId != Guid.Empty)
                {
                    var appPermissions = ctx.Web.GetAppInstanceById(AppInstanceId);
                    ctx.Load(appPermissions);
                    ctx.ExecuteQuery();

                    var appd = AppCatalog.GetAppPermissionDescriptions(ctx, ctx.Web, appPermissions);
                    this.ClientContext.ExecuteQueryRetry();
                }
            }
            catch (Exception ex)
            {
                LogError(ex, $"Failed in EPAAppInstances for {ex.Message}");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns all app instances
        /// </summary>
        /// <param name="web">The site to process</param>
        /// <returns></returns>
        public static ClientObjectList <AppInstance> GetAppInstances(this Web web)
        {
            var instances = AppCatalog.GetAppInstances(web.Context, web);

            web.Context.Load(instances);
            web.Context.ExecuteQueryRetry();

            return(instances);
        }
Beispiel #4
0
        public void When_GetBand_is_called_without_an_Id_and_the_current_Band_is_not_Known_then_an_InvalidOperationException_is_thrown()
        {
            AppCatalog
            .Expect(catalog => catalog.CurrentBand)
            .Return(null)
            .Repeat.Once();
            AppCatalog.Replay();

            Repository.GetBand();
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();


            var sideLoadingGuid = OfficeDevPnP.Core.Constants.FeatureId_Site_AppSideLoading;
            var siteurl         = this.ClientContext.Url.EnsureTrailingSlashLowered();

            LogVerbose($"Enables SharePoint app sideLoading for {siteurl}");


            try
            {
                var site = this.ClientContext.Site;
                this.ClientContext.Load(site);

                var sideLoadingEnabled = AppCatalog.IsAppSideloadingEnabled(this.ClientContext);
                this.ClientContext.ExecuteQueryRetry();

                if (!sideLoadingEnabled.Value)
                {
                    LogVerbose("SideLoading feature is not enabled on the site: {0}", siteurl);

                    var siteFeatures = ClientContext.LoadQuery(ClientContext.Site.Features.Include(fctx => fctx.DefinitionId, fctx => fctx.DisplayName));
                    ClientContext.ExecuteQueryRetry();
                    var sideLoadingFeature = siteFeatures.FirstOrDefault(f => f.DefinitionId == sideLoadingGuid);


                    var siteFeature = site.Features.GetById(sideLoadingGuid);
                    this.ClientContext.Load(siteFeature);
                    this.ClientContext.ExecuteQueryRetry();


                    if (!siteFeature.ServerObjectIsNull())
                    {
                        LogWarning("Side loading feature is found.");
                    }

                    site.ActivateFeature(sideLoadingGuid, pollingIntervalSeconds: 20);
                    this.ClientContext.ExecuteQueryRetry();
                    LogVerbose("SideLoading feature enabled on site {0}", siteurl);
                }
                else
                {
                    LogVerbose("SideLoading feature is already enabled on site {0}", siteurl);
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Error encountered when trying to enable SideLoading feature {0} with message {1}", siteurl, ex.Message.ToString());
            }
        }
Beispiel #6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="AppModule"/> class.
            /// </summary>
            /// <param name="app">The underlying application.</param>
            private AppModule(CompositeApp app)
            {
                this.app = app;

                IEnumerable <ComposablePartDefinition> parts = app.Parts;

                if (parts == null)
                {
                    throw Error.ReturnsNull(nameof(Parts));
                }

                catalog = new AppCatalog(parts);
            }
Beispiel #7
0
        public void When_GetLoginAccountByLoginName_is_called_with_an_invalid_loginName_then_a_InvalidOperationException_is_thrown()
        {
            var          loginAccounts = LoginAccountCreator.CreateCollection();
            const string loginName     = "Invalid loginName";

            AppCatalog
            .Expect(catalog => catalog.LoginAccounts)
            .Return(loginAccounts)
            .Repeat.Once();
            AppCatalog.Replay();

            Repository.GetLoginAccountByLoginName(loginName);
        }
Beispiel #8
0
        public void When_GetBand_is_called_with_an_Id_and_there_is_no_Band_in_the_collection_with_that_Id_then_an_InvalidOperationException_is_thrown()
        {
            var bands  = BandCreator.CreateCollection();
            var bandId = Guid.NewGuid();

            AppCatalog
            .Expect(catalog => catalog.Bands)
            .Return(bands)
            .Repeat.Once();
            AppCatalog.Replay();

            Repository.GetBand(bandId);
        }
Beispiel #9
0
        public void When_UpdateBand_is_called_with_a_null_value_for_Band_then_an_ArgumentNullException_is_thrown()
        {
            AppCatalog
            .Expect(catalog =>
                    catalog.Update(Arg <Band> .Is.Anything))
            .Return(null)
            .Repeat.Once();
            AppCatalog.Replay();

            Repository.UpdateBand(null);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #10
0
        public void When_AddBand_is_called_with_a_valid_Band_then_the_Band_is_added_to_the_collection()
        {
            var band = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.Add(band))
            .Return(band)
            .Repeat.Once();
            AppCatalog.Replay();

            band = Repository.AddBand(band);

            Assert.IsNotNull(band);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #11
0
        public void Cleanup()
        {
            // Deactivate sideloading
            clientContext.Load(clientContext.Site);
            clientContext.ExecuteQuery();
            clientContext.Site.DeactivateFeature(OfficeDevPnP.Core.Constants.APPSIDELOADINGFEATUREID);

            var props = clientContext.Web.AllProperties;

            clientContext.Load(props);
            clientContext.ExecuteQuery();

            if (props.FieldValues.ContainsKey(_key))
            {
                props[_key] = null;
                props.FieldValues.Remove(_key);
            }
            if (props.FieldValues.ContainsKey(INDEXED_PROPERTY_KEY))
            {
                props[INDEXED_PROPERTY_KEY] = null;
                props.FieldValues.Remove(INDEXED_PROPERTY_KEY);
            }
            clientContext.Web.Update();
            clientContext.ExecuteQuery();

            var instances = AppCatalog.GetAppInstances(clientContext, clientContext.Web);

            clientContext.Load(instances);
            clientContext.ExecuteQuery();

            string appToRemove = APPNAME;

            #if CLIENTSDKV15
            appToRemove += "15";
            #endif

            foreach (var instance in instances)
            {
                if (string.Equals(instance.Title, appToRemove, StringComparison.OrdinalIgnoreCase))
                {
                    instance.Uninstall();
                    clientContext.ExecuteQuery();
                    break;
                }
            }
            clientContext.Dispose();
        }
Beispiel #12
0
        public void When_GetBand_is_called_without_an_Id_then_the_current_Band_is_retrieved_from_the_collection()
        {
            var band = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.CurrentBand)
            .Return(band)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetBand();

            Assert.IsNotNull(result);
            Assert.AreEqual(band, result);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #13
0
        public void When_UpdateBand_is_called_with_a_valid_Band_then_the_Band_is_updated_in_the_collection()
        {
            var entity = BandCreator.CreateSingle();

            AppCatalog
            .Expect(catalog => catalog.Update(entity))
            .Return(entity)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.UpdateBand(entity);

            Assert.IsNotNull(result);
            Assert.AreEqual(entity.Id, result.Id);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #14
0
        public void When_GetBand_is_called_with_an_Id_then_the_Band_with_the_corresponding_Id_is_retrieved_from_the_collection()
        {
            var bands  = BandCreator.CreateCollection();
            var bandId = bands.ElementAt(2).Id;

            AppCatalog
            .Expect(catalog => catalog.Bands)
            .Return(bands)
            .Repeat.Once();
            AppCatalog.Replay();

            var band = Repository.GetBand(bandId);

            Assert.IsNotNull(band);
            Assert.AreEqual(bandId, band.Id);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #15
0
        public void When_GetLoginAccountByLoginName_is_called_with_a_loginName_then_the_LoginAccount_with_that_loginName_is_retrieved_from_the_collection()
        {
            var loginAccounts = LoginAccountCreator.CreateCollection();
            var loginName     = loginAccounts.ElementAt(2).LoginName;

            AppCatalog
            .Expect(catalog => catalog.LoginAccounts)
            .Return(loginAccounts)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetLoginAccountByLoginName(loginName);

            Assert.IsNotNull(result);
            Assert.AreEqual(loginName, result.LoginName);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #16
0
        public void When_GetUsersByEmailAddress_is_called_with_an_invalid_emailAddress_then_no_Users_with_that_emailAddress_are_retrieved_from_the_collection()
        {
            var          users        = UserCreator.CreateCollection();
            const string emailAddress = "*****@*****.**";

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetUsersByEmailAddress(emailAddress);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #17
0
        public void When_GetUsersByLoginName_is_called_with_an_invalid_loginName_then_no_Users_with_that_loginName_are_retrieved_from_the_collection()
        {
            var          users     = UserCreator.CreateCollection();
            const string loginName = "Invalid loginName";

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetUsersByLoginName(loginName);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #18
0
        public void When_GetUsersByLoginAccount_is_called_with_an_invalid_id_then_no_Users_are_retrieved_from_the_collection()
        {
            var users = UserCreator.CreateCollection();
            var id    = Guid.NewGuid();

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetUsersByLoginAccount(id);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #19
0
        public void When_GetAllUsers_is_called_then_all_Users_are_retrieved_from_the_collection()
        {
            var users = UserCreator.CreateCollection();

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetAllUsers();

            Assert.IsNotNull(result);
            Assert.AreEqual(users.Count(), result.Count());
            Assert.AreEqual(users, result);

            AppCatalog.VerifyAllExpectations();
        }
        public object Resolve(object source, Dictionary <String, IResolver> resolvers = null, Boolean recursive = false)
        {
            var result = new AppCatalog();

            var appCatalogPackages = source.GetPublicInstancePropertyValue("AppCatalog");

            if (null != appCatalogPackages)
            {
                foreach (var p in ((IEnumerable)appCatalogPackages))
                {
                    var targetItem = new Model.Package();
                    PnPObjectsMapper.MapProperties(p, targetItem, resolvers, recursive);
                    result.Packages.Add(targetItem);
                }
            }

            return(result);
        }
Beispiel #21
0
        public void When_GetUsersByEmailAddress_is_called_with_a_emailAddress_then_all_Users_with_that_emailAddress_are_retrieved_from_the_collection()
        {
            var users        = UserCreator.CreateCollection();
            var emailAddress = users.ElementAt(2).Login.EmailAddress;

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetUsersByEmailAddress(emailAddress);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(emailAddress, result.First().Login.EmailAddress);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #22
0
        public void When_GetUsersByLoginAccount_is_called_with_a_valid_id_then_all_Users_with_that_LoginAccount_are_retrieved_from_the_collection()
        {
            var users = UserCreator.CreateCollection();
            var id    = users.ElementAt(2).Login.Id;

            AppCatalog
            .Expect(catalog => catalog.Users)
            .Return(users)
            .Repeat.Once();
            AppCatalog.Replay();

            var result = Repository.GetUsersByLoginAccount(id);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(id, result.First().Login.Id);

            AppCatalog.VerifyAllExpectations();
        }
Beispiel #23
0
        /// <summary>
        /// Removes the app instance with the specified title.
        /// </summary>
        /// <param name="web">Web to remove the app instance from</param>
        /// <param name="appTitle">Title of the app instance to remove</param>
        /// <returns>true if the the app instance was removed; false if it does not exist</returns>
        public static bool RemoveAppInstanceByTitle(this Web web, string appTitle)
        {
            // Removes the association between the App and the Web
            bool removed   = false;
            var  instances = AppCatalog.GetAppInstances(web.Context, web);

            web.Context.Load(instances);
            web.Context.ExecuteQueryRetry();
            foreach (var app in instances)
            {
                if (string.Equals(app.Title, appTitle, StringComparison.OrdinalIgnoreCase))
                {
                    removed = true;
                    LoggingUtility.Internal.TraceInformation((int)EventId.RemoveAppInstance, CoreResources.WebExtensions_RemoveAppInstance, appTitle, app.Id);
                    app.Uninstall();
                    web.Context.ExecuteQueryRetry();
                }
            }
            if (!removed)
            {
                LoggingUtility.Internal.TraceVerbose("Requested to remove app '{0}', but no instances found; nothing to remove.", appTitle);
            }
            return(removed);
        }
        public void Cleanup()
        {
            // Deactivate sideloading
            clientContext.Load(clientContext.Site);
            clientContext.ExecuteQueryRetry();
            clientContext.Site.DeactivateFeature(OfficeDevPnP.Core.Constants.APPSIDELOADINGFEATUREID);

            var props = clientContext.Web.AllProperties;

            clientContext.Load(props);
            clientContext.ExecuteQueryRetry();

            // Implement cleanup mechanism that cleans test stranglers + also cleans up the NoMobileMapping key that's generated per created sub site
            List <string> keysToDelete = new List <string>(10);

            foreach (var prop in props.FieldValues)
            {
                if (prop.Key.StartsWith("TEST_KEY_", StringComparison.InvariantCultureIgnoreCase) ||
                    prop.Key.StartsWith("TEST_VALUE_", StringComparison.InvariantCultureIgnoreCase) ||
                    prop.Key.StartsWith("__NoMobileMapping", StringComparison.InvariantCultureIgnoreCase))
                {
                    keysToDelete.Add(prop.Key);
                }
            }

            int batch = 0;

            foreach (string key in keysToDelete)
            {
                props[key] = null;
                props.FieldValues.Remove(key);
                batch++;

                // send cleanup in batches of 50 to the server
                if (batch >= 50)
                {
                    clientContext.Web.Update();
                    clientContext.ExecuteQueryRetry();
                    batch = 0;
                }
            }
            clientContext.Web.Update();
            clientContext.ExecuteQueryRetry();

            var instances = AppCatalog.GetAppInstances(clientContext, clientContext.Web);

            clientContext.Load(instances);
            clientContext.ExecuteQueryRetry();

            string appToRemove = APPNAME;

#if ONPREMISES
            appToRemove += "15";
#endif

            foreach (var instance in instances)
            {
                if (string.Equals(instance.Title, appToRemove, StringComparison.OrdinalIgnoreCase))
                {
                    instance.Uninstall();
                    clientContext.ExecuteQueryRetry();
                    break;
                }
            }
            clientContext.Dispose();
        }
        public void Cleanup()
        {
            // Deactivate sideloading
            clientContext.Load(clientContext.Site);
            clientContext.ExecuteQueryRetry();
            clientContext.Site.DeactivateFeature(Constants.FeatureId_Site_AppSideLoading);

            var props = clientContext.Web.AllProperties;

            clientContext.Load(props);
            clientContext.ExecuteQueryRetry();

            // Implement cleanup mechanism that cleans test stranglers + also cleans up the NoMobileMapping key that's generated per created sub site
            List <string> keysToDelete = new List <string>(10);

            foreach (var prop in props.FieldValues)
            {
                if (prop.Key.StartsWith("TEST_KEY_", StringComparison.InvariantCultureIgnoreCase) ||
                    prop.Key.StartsWith("TEST_VALUE_", StringComparison.InvariantCultureIgnoreCase) ||
                    prop.Key.StartsWith("__NoMobileMapping", StringComparison.InvariantCultureIgnoreCase))
                {
                    keysToDelete.Add(prop.Key);
                }
            }

            int batch = 0;

            foreach (string key in keysToDelete)
            {
                props[key] = null;
                props.FieldValues.Remove(key);
                batch++;

                // send cleanup in batches of 50 to the server
                if (batch >= 50)
                {
                    clientContext.Web.Update();
                    clientContext.ExecuteQueryRetry();
                    batch = 0;
                }
            }
            clientContext.Web.Update();
            clientContext.ExecuteQueryRetry();

            var instances = AppCatalog.GetAppInstances(clientContext, clientContext.Web);

            clientContext.Load(instances);
            clientContext.ExecuteQueryRetry();

            string appToRemove = APPNAME;

#if ONPREMISES
            appToRemove += "15";
#endif

            foreach (var instance in instances)
            {
                if (string.Equals(instance.Title, appToRemove, StringComparison.OrdinalIgnoreCase))
                {
                    instance.Uninstall();
                    clientContext.ExecuteQueryRetry();
                    break;
                }
            }

            var ct = clientContext.Web.GetContentTypeByName(contentTypeName);
            if (ct != null)
            {
                ct.DeleteObject();
                clientContext.ExecuteQueryRetry();
            }

            bool dirty = false;
            clientContext.Load(clientContext.Web.Webs, wc => wc.Include(w => w.Title, w => w.ServerRelativeUrl));
            clientContext.ExecuteQueryRetry();
            foreach (Web subWeb in clientContext.Web.Webs.ToList())
            {
                if (subWeb.Title.StartsWith("Test_") || subWeb.ServerRelativeUrl.Contains("Test_"))
                {
                    subWeb.DeleteObject();
                    dirty = true;
                }
            }
            if (dirty)
            {
                clientContext.ExecuteQueryRetry();
            }

            clientContext.Dispose();
        }
Beispiel #26
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            LogVerbose("To enable SharePoint app sideLoading, enter Site Url, username and password");

            var sideLoadingGuid = OfficeDevPnP.Core.Constants.FeatureId_Site_AppSideLoading;
            var siteurl         = this.ClientContext.Url;
            var outfilepath     = siteurl.Replace(':', '_').Replace('/', '_');

            try
            {
                var web  = this.ClientContext.Web;
                var site = this.ClientContext.Site;
                this.ClientContext.Load(web);
                this.ClientContext.Load(site);
                this.ClientContext.ExecuteQuery();

                var siteFeatures = site.Features;
                this.ClientContext.Load(siteFeatures, fcol => fcol.Include(f => f.DisplayName, f => f.DefinitionId));
                var webFeatures = web.Features;
                this.ClientContext.Load(webFeatures, wf => wf.Include(f => f.DisplayName, f => f.DefinitionId));
                this.ClientContext.ExecuteQuery();

                LogWarning("Now parsing site features.");

                siteFeatures.ToList().ForEach(a =>
                {
                    var status = FeatureExtensions.IsFeatureActive(site, a.DefinitionId);

                    LogVerbose("Site Feature {0} with Id {1} and status {2}", a.DisplayName, a.DefinitionId, status);
                });

                LogWarning("Now parsing web features.");

                webFeatures.ToList().ForEach(a =>
                {
                    var status = FeatureExtensions.IsFeatureActive(web, a.DefinitionId);

                    LogVerbose("Web Feature {0} with Id {1} and status {2}", a.DisplayName, a.DefinitionId, status);
                });


                var sideLoadingEnabled = AppCatalog.IsAppSideloadingEnabled(this.ClientContext);
                this.ClientContext.ExecuteQuery();

                var sideLoadingFeature = siteFeatures.FirstOrDefault(f => f.DefinitionId == sideLoadingGuid);

                if (!sideLoadingEnabled.Value)
                {
                    LogVerbose("SideLoading feature is not enabled on the site: {0}", siteurl);
                    var siteFeature = site.Features.GetById(sideLoadingGuid);
                    this.ClientContext.Load(siteFeature);
                    this.ClientContext.ExecuteQuery();

                    if (siteFeature != null)
                    {
                        LogWarning("Side loading feature is found.");
                    }

                    site.Features.Add(sideLoadingGuid, true, Microsoft.SharePoint.Client.FeatureDefinitionScope.Site);
                    this.ClientContext.ExecuteQuery();
                    LogVerbose("SideLoading feature enabled on site {0}", siteurl);
                }
                else
                {
                    LogVerbose("SideLoading feature is already enabled on site {0}", siteurl);
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Error encountered when trying to enable SideLoading feature {0} with message {1}", siteurl, ex.Message.ToString());
            }
        }
 /// <summary>
 /// Initializes the AppEngine.
 /// </summary>
 private AppEngine()
 {
     _applicationModel = new ApplicationModel();
     _catalog          = new AppCatalog();
     InitializeAppCatalog();
 }