Ejemplo n.º 1
0
        public void SaveEmptySolution()
        {
            Solution solution = TestHelper.CreateSolution( );

            solution.Save( );
            long solutionId = solution.Id;

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, TestHelper.DefaultSolutionName);

            solution = Entity.Get <Solution>(solutionId);

            Assert.IsNotNull(solution);
            Assert.IsNotNull(solution.PackageId);

            if (solution.PackageId != null)
            {
                Guid packageId = solution.PackageId.Value;

                using (new GlobalAdministratorContext( ))
                {
                    AppPackage package = SystemHelper.GetPackageByVerId(packageId);

                    Assert.IsNotNull(package);
                    Assert.IsNotNull(package.AppVerId);
                    Assert.AreEqual("1.0.0.0", package.AppVersionString);
                    Assert.AreEqual(string.Format("{0} Application Package {1}", TestHelper.DefaultSolutionName, "1.0.0.0"), package.Name);
                    Assert.AreEqual(string.Format("Application Package for version {1} of {0}.", TestHelper.DefaultSolutionName, "1.0.0.0"), package.Description);

                    if (package.AppVerId != null)
                    {
                        var source = new LibraryAppSource
                        {
                            AppId = package.AppVerId.Value
                        };

                        IEnumerable <EntityEntry> entities = source.GetEntities(null);

                        Assert.IsFalse(entities.Any( ));

                        IEnumerable <RelationshipEntry> relationships = source.GetRelationships(null);

                        Assert.IsFalse(relationships.Any( ));

                        foreach (string fieldDataTable in Helpers.FieldDataTables)
                        {
                            IEnumerable <DataEntry> fieldData = source.GetFieldData(fieldDataTable, null);

                            Assert.IsFalse(fieldData.Any( ));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Imports the tenant.
        /// </summary>
        /// <returns>the tenant id</returns>
        public static void InstallGlobalTenant( )
        {
            IProcessingContext context = new ProcessingContext( );

            context.Report.Action = AppLibraryAction.InstallGlobal;
            context.Report.Arguments.Add(new KeyValuePair <string, string>("Tenant Id", "Global"));

            IDictionary <Guid, Guid> appToAppVer = new Dictionary <Guid, Guid>( );

            // Get application versions
            // It is assumed that if there is no global tenant, then there is only one version of each of the core apps
            using (IDatabaseContext dbContext = DatabaseContext.GetContext(false))
                using (IDbCommand command = dbContext.CreateCommand())
                {
                    command.CommandText = "select FromUid AppUid, AppVerUid from AppRelationship where ToUid = @solution and TypeUid = @isOfType";
                    command.AddParameterWithValue("@solution", Guids.Solution);
                    command.AddParameterWithValue("@isOfType", Guids.IsOfType);

                    using (IDataReader reader = command.ExecuteReader( ))
                    {
                        // Load appVerId for apps from app library
                        while (reader.Read( ))
                        {
                            Guid appId    = reader.GetGuid(0);
                            Guid appVerId = reader.GetGuid(1);
                            appToAppVer[appId] = appVerId;
                        }
                    }
                }

            // Install apps
            Guid[] coreApps = new[]
            {
                Guids.CoreSolution,
                Guids.ConsoleSolution,
                Guids.CoreDataSolution,
                Guids.SystemSolution
            };

            // Copy system application content from the app library into the global tenant
            foreach (Guid appId in coreApps)
            {
                // Get the AppVerId
                Guid appVerId;
                if (!appToAppVer.TryGetValue(appId, out appVerId))
                {
                    throw new Exception($"Aborting: System app {0} was not present in app library.");
                }

                context.WriteInfo($"Installing app {appId} package {appVerId} to global tenant.");

                IDataSource empty  = new EmptySource( );
                IDataSource source = new LibraryAppSource
                {
                    AppId    = appId,
                    AppVerId = appVerId,
                    AppName  = appId.ToString( )
                };
                TenantMergeTarget target = new TenantMergeTarget
                {
                    TenantId = 0
                };

                using (empty)
                    using (source)
                        using ( target )
                        {
                            MergeProcessor processor = new MergeProcessor(context)
                            {
                                OldVersion = empty,
                                NewVersion = source,
                                Target     = target
                            };
                            processor.MergeData( );

                            target.Commit( );
                        }
            }


            // Copy metadata from the tenant back into the application library
            foreach (Guid appId in coreApps)
            {
                Guid appVerId = appToAppVer[appId];

                long        solutionEntityId = Entity.GetIdFromUpgradeId(appId);
                IDataSource metadataSource   = new TenantAppSource
                {
                    SolutionId = solutionEntityId,
                    TenantId   = 0
                };
                LibraryAppTarget metadataTarget = new LibraryAppTarget
                {
                    ApplicationVersionId = appVerId
                };
                using (metadataSource)
                    using ( metadataTarget )
                    {
                        CopyProcessor processor = new CopyProcessor(metadataSource, metadataTarget, context);
                        processor.CopyMetadataOnly = true;
                        processor.MigrateData( );

                        metadataTarget.Commit( );
                    }

                context.WriteInfo($"Installed app {appId} to global tenant.");
            }
        }