コード例 #1
0
        /// <summary>
        /// Gets the package dependencies recursive.
        /// </summary>
        /// <param name="packageId">The package identifier.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="results">The results.</param>
        /// <param name="discoveredPackageIds">The discovered package ids.</param>
        /// <exception cref="ApplicationDependencyException">
        /// </exception>
        private void GetPackageDependenciesRecursive(long packageId, long tenantId, List <MissingDependencyData> results, ISet <Guid> discoveredPackageIds)
        {
            IList <DependencyFailure> applicationDependencies = SolutionHelper.GetMissingPackageDependencies(packageId, tenantId);

            if (applicationDependencies != null && applicationDependencies.Count > 0)
            {
                foreach (DependencyFailure dependency in applicationDependencies)
                {
                    if (dependency.Reason == DependencyFailureReason.BelowMinVersion)
                    {
                        SolutionHelper.EnsureUpgradePath(tenantId, dependency);
                    }

                    string dependencyPackageAppVersionString = null;

                    var dependencyPackageId = SystemHelper.GetPackageIdByGuid(dependency.ApplicationId, dependency.MinVersion, dependency.MaxVersion);

                    if (dependencyPackageId >= 0)
                    {
                        AppPackage dependencyPackage = ReadiNow.Model.Entity.Get <AppPackage>(dependencyPackageId);

                        if (dependencyPackage != null)
                        {
                            dependencyPackageAppVersionString = dependencyPackage.AppVersionString;
                        }
                    }

                    if (!discoveredPackageIds.Contains(dependency.ApplicationId))
                    {
                        discoveredPackageIds.Add(dependency.ApplicationId);

                        if (dependencyPackageId >= 0)
                        {
                            GetPackageDependenciesRecursive(dependencyPackageId, tenantId, results, discoveredPackageIds);
                        }

                        results.Add(new MissingDependencyData(dependency, dependencyPackageId, dependencyPackageAppVersionString));
                    }
                }
            }
        }
コード例 #2
0
        public void TestGetMissingDependencies_NoUpgradePath( )
        {
            Solution appA = new Solution
            {
                Name = "appA",
                SolutionVersionString = "1.0.0.0"
            };
            Solution appB = new Solution
            {
                Name = "appB",
                SolutionVersionString = "1.0.0.0"
            };
            Solution appC = new Solution
            {
                Name = "appC",
                SolutionVersionString = "1.0.0.0"
            };

            ApplicationDependency aDependsOnB = new ApplicationDependency
            {
                Name = "appA depends on appB",
                DependentApplication  = appA,
                DependencyApplication = appB
            };

            appA.DependentApplicationDetails.Add(aDependsOnB);

            appA.Save( );

            ApplicationDependency bDependsOnC = new ApplicationDependency
            {
                Name = "appB depends on appC",
                DependentApplication  = appB,
                DependencyApplication = appC
            };

            appB.DependentApplicationDetails.Add(bDependsOnC);

            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appA");
            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB");
            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appC");

            Guid appAUpgradeId = Entity.GetUpgradeId(appA.Id);
            Guid appBUpgradeId = Entity.GetUpgradeId(appB.Id);

            long tenantId = TenantHelper.CreateTenant("ABC");

            AppManager.DeployApp("ABC", Applications.CoreApplicationId.ToString("B"));
            AppManager.DeployApp("ABC", appAUpgradeId.ToString("B"));

            bDependsOnC.ApplicationMinimumVersion = "2.0.0.0";
            bDependsOnC.Save( );
            appB.SolutionVersionString = "2.0.0.0";
            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB");

            using (new GlobalAdministratorContext( ))
            {
                AppPackage appPackage = SystemHelper.GetLatestPackageByGuid(appBUpgradeId);

                var applicationDependencies = SolutionHelper.GetMissingPackageDependencies(appPackage.Id, tenantId);

                if (applicationDependencies != null && applicationDependencies.Count > 0)
                {
                    Assert.AreEqual(1, applicationDependencies.Count);

                    DependencyFailure dependency = applicationDependencies[0];

                    if (dependency.Reason == DependencyFailureReason.BelowMinVersion)
                    {
                        SolutionHelper.EnsureUpgradePath(tenantId, dependency);
                    }

                    Assert.AreEqual(DependencyFailureReason.NoUpgradePathAvailable, dependency.Reason);
                }
            }
        }