/// <summary>
        /// Installs all packages and builds the initial site from the import data (zip files) or from templates
        /// </summary>
        /// <remarks>
        /// This removes all data for all sites
        /// </remarks>
        public async Task InitAllAsync(QueryHelper qs, List <string> WantedPackages)
        {
            if (YetaWF.Core.Support.Startup.MultiInstance)
            {
                throw new InternalError("Installing packages is not possible when distributed caching is enabled");
            }

            InitialSiteLogging log = new InitialSiteLogging(LogFile);
            await Logging.RegisterLoggingAsync(log);

            Logging.AddLog("Site initialization starting");

            //ClearAll();
            List <Package> installedPackages = await InstallPackagesAsync(WantedPackages);

            if (qs["From"] == "Data")
            {
                await BuildSiteUsingDataAsync(false, installedPackages);
                await BuildSiteUsingTemplateAsync(Path.Combine(DataFolderName, "Add Site.txt"));
            }
            else     //if (qs["From"] == "Template") {
            {
                await BuildSiteUsingTemplateAsync("InitialSite.txt");

                //BuildSiteUsingTemplate("Custom Site (Initial Site).txt");
            }
            PermanentManager.ClearAll();// clear any cached objects
            await Package.SavePackageMapAsync();

            await SiteDefinition.RemoveInitialInstallAsync();

            Logging.UnregisterLogging(log);

            Logging.AddLog("Site initialization done");

            // Cache is now invalid so we'll just restart
#if MVC6
            //Manager.RestartSite(); // don't restart or redirect (can't)
            // tell user in browser what to do
#else
            // Cache is now invalid so we'll just restart
            Manager.RestartSite();
#endif
        }
Example #2
0
        /// <summary>
        /// Retrieve all roles except user and anonymous.
        /// </summary>
        /// <remarks>
        /// This method is cached and deliberately does not use async/await to simplify usage
        /// </remarks>
        public List <RoleDefinition> GetAllUserRoles(bool force = false)
        {
            bool isInstalled = YetaWFManager.Syncify <bool>(() => DataProvider.IsInstalledAsync()); // There's nothing really async about this

            if (!isInstalled)
            {
                return new List <RoleDefinition>()
                       {
                           MakeSuperuserRole()
                       }
            }
            ;

            List <RoleDefinition> roles;

            if (!force)
            {
                if (PermanentManager.TryGetObject <List <RoleDefinition> >(out roles))
                {
                    return(roles);
                }
            }

            lock (_lockObject) { // lock this to build cached roles list
                // See if we already have it as a permanent object
                if (!force)
                {
                    if (PermanentManager.TryGetObject <List <RoleDefinition> >(out roles))
                    {
                        return(roles);
                    }
                }
                // Load the roles
                DataProviderGetRecords <RoleDefinition> list = YetaWFManager.Syncify <DataProviderGetRecords <RoleDefinition> >(() => GetItemsAsync()); // Only done once during startup and never again, all cached

                roles = list.Data;

                PermanentManager.AddObject <List <RoleDefinition> >(roles);
            }
            return(roles);
        }