public StandaloneEnvironmentFixture() { StandaloneEnvironment.SetStandardLightBlueDataDirectory(); _containerPath = Path.Combine( StandaloneEnvironment.LightBlueDataDirectory, "dev", "blob", "testcontainer"); }
public void DoWork() { // makes an inner container, similar to the per-request container using (var standaloneEnvironment = new StandaloneEnvironment(_container)) { // resolve the manager and invoke it var manager = standaloneEnvironment.Resolve<IBackgroundService>(); manager.Sweep(); } }
public static IAzureBlockBlob Build(Uri blobUri) { if (blobUri.Scheme != "file") { return(new HostedAzureBlockBlob(blobUri)); } var locationParts = StandaloneEnvironment.SeparateBlobUri(blobUri); return(new StandaloneAzureBlockBlob(locationParts.ContainerPath, locationParts.BlobPath)); }
public void WillStripAccessToken() { var blobUri = new Uri(Path.Combine(_containerPath, "randomblob") + "?some=token"); var locationParts = StandaloneEnvironment.SeparateBlobUri(blobUri); new { ContainerPath = _containerPath, BlobPath = "randomblob" }.ToExpectedObject().ShouldMatch(locationParts); }
public void CanSplitBlobUri(string blobPath) { var blobUri = new Uri(Path.Combine(_containerPath, blobPath)); var locationParts = StandaloneEnvironment.SeparateBlobUri(blobUri); new { ContainerPath = _containerPath, BlobPath = blobPath }.ToExpectedObject().ShouldMatch(locationParts); }
public static string SetAsWindowsHost(string service, string cscfg, string csdef, string roleName) { StandaloneEnvironment.SetLightBlueDataDirectoryToProgramData(); var processId = string.Format("{0}-azurerole-{1}", service, Process.GetCurrentProcess().Id); var directory = Directory.CreateDirectory(Path.Combine(StandaloneEnvironment.LightBlueDataDirectory, processId)); Environment.SetEnvironmentVariable("TMP", directory.FullName); Environment.SetEnvironmentVariable("TEMP", directory.FullName); _context = new LightBlueAppDomainContext(cscfg, csdef, roleName, false); return(directory.FullName); }
public void Dispose() { StandaloneEnvironment.SetStandardLightBlueDataDirectory(); if (string.IsNullOrWhiteSpace(_appDataDirectory) || !Directory.Exists(_appDataDirectory)) { return; } var tries = 0; while (tries++ < 2) { try { Directory.Delete(_appDataDirectory, true); return; } catch (IOException) {} }
public IAzureBlockBlob GetBlockBlob(Uri blobUri, StorageCredentials storageCredentials) { var locationParts = StandaloneEnvironment.SeparateBlobUri(blobUri); return(new StandaloneAzureBlockBlob(locationParts.ContainerPath, locationParts.BlobPath)); }
public void ThrowsIfBlobUriIsNotInLightBlueDataDirectoru() { var blobUri = new Uri("file:///c:/temp/"); Assert.Throws <ArgumentException>(() => StandaloneEnvironment.SeparateBlobUri(blobUri)); }
public void ThrowsIfBlobUriIsNotAFileUri() { var blobUri = new Uri("http://www.abstractcode.com/"); Assert.Throws <ArgumentException>(() => StandaloneEnvironment.SeparateBlobUri(blobUri)); }
public ShellContext CreateShellContext(ShellSettings settings) { Logger.Debug("Creating shell context for tenant {0}", settings.Name); var knownDescriptor = _shellDescriptorCache.Fetch(settings.Name); if (knownDescriptor == null) { Logger.Information("No topology cached. Starting with minimum components."); knownDescriptor = MinimumTopologyDescriptor(); } var topology = _compositionStrategy.Compose(settings, knownDescriptor); var shellScope = _shellContainerFactory.CreateContainer(settings, topology); ShellDescriptor currentDescriptor; using (var standaloneEnvironment = new StandaloneEnvironment(shellScope)) { var topologyDescriptorProvider = standaloneEnvironment.Resolve<IShellDescriptorManager>(); currentDescriptor = topologyDescriptorProvider.GetShellDescriptor(); } if (currentDescriptor != null && knownDescriptor.SerialNumber != currentDescriptor.SerialNumber) { Logger.Information("Newer topology obtained. Rebuilding shell container."); _shellDescriptorCache.Store(settings.Name, currentDescriptor); topology = _compositionStrategy.Compose(settings, currentDescriptor); shellScope = _shellContainerFactory.CreateContainer(settings, topology); } return new ShellContext { Settings = settings, Descriptor = currentDescriptor, Topology = topology, LifetimeScope = shellScope, Shell = shellScope.Resolve<IOrchardShell>(), }; }
public void Setup(SetupContext context) { // The vanilla Orchard distibution has the following features enabled. if (context.EnabledFeatures == null || context.EnabledFeatures.Count() == 0) { string[] hardcoded = { "Orchard.Framework", "Common", "Dashboard", "Feeds", "HomePage", "Navigation", "Scheduling", "Settings", "XmlRpc", "Orchard.Users", "Orchard.Roles", "TinyMce", "Orchard.Modules", "Orchard.Themes", "Orchard.Pages", "Orchard.Blogs", "Orchard.Comments", "Orchard.Tags", "Orchard.Media", "Futures.Widgets"}; context.EnabledFeatures = hardcoded; } var shellSettings = new ShellSettings(_shellSettings); if (string.IsNullOrEmpty(shellSettings.DataProvider)) { shellSettings.DataProvider = context.DatabaseProvider; shellSettings.DataConnectionString = context.DatabaseConnectionString; shellSettings.DataTablePrefix = context.DatabaseTablePrefix; } var shellDescriptor = new ShellDescriptor { EnabledFeatures = context.EnabledFeatures.Select(name => new ShellFeature { Name = name }) }; var shellToplogy = _compositionStrategy.Compose(shellSettings, shellDescriptor); // initialize database explicitly, and store shell descriptor var bootstrapLifetimeScope = _shellContainerFactory.CreateContainer(shellSettings, shellToplogy); using (var environment = new StandaloneEnvironment(bootstrapLifetimeScope)) { environment.Resolve<ISessionFactoryHolder>().CreateDatabase(); environment.Resolve<IShellDescriptorManager>().UpdateShellDescriptor( 0, shellDescriptor.EnabledFeatures, shellDescriptor.Parameters); } // creating a standalone environment. // in theory this environment can be used to resolve any normal components by interface, and those // components will exist entirely in isolation - no crossover between the safemode container currently in effect // must mark state as Running - otherwise standalone enviro is created "for setup" shellSettings.State = new TenantState("Running"); using (var environment = _orchardHost.CreateStandaloneEnvironment(shellSettings)) { try { // create superuser var membershipService = environment.Resolve<IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // set site name and settings var siteService = environment.Resolve<ISiteService>(); var siteSettings = siteService.GetSiteSettings().As<SiteSettings>(); siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.Record.SiteName = context.SiteName; siteSettings.Record.SuperUser = context.AdminUsername; siteSettings.Record.PageTitleSeparator = " - "; // set site theme var themeService = environment.Resolve<IThemeService>(); themeService.SetSiteTheme("Classic"); var contentManager = environment.Resolve<IContentManager>(); // simulate installation-time module activation events var hackInstallationGenerator = environment.Resolve<IHackInstallationGenerator>(); hackInstallationGenerator.GenerateInstallEvents(); // create home page as a CMS page var page = contentManager.Create("page", VersionOptions.Draft); page.As<BodyAspect>().Text = "<p>Welcome to Orchard!</p><p>Congratulations, you've successfully set-up your Orchard site.</p><p>This is the home page of your new site. We've taken the liberty to write here about a few things you could look at next in order to get familiar with the application. Once you feel confident you don't need this anymore, just click <a href=\"Admin/Pages/Edit/3\">Edit</a> to go into edit mode and replace this with whatever you want on your home page to make it your own.</p><p>One thing you could do (but you don't have to) is go into <a href=\"Admin/Settings\">Manage Settings</a> (follow the <a href=\"Admin\">Admin</a> link and then look for it under \"Settings\" in the menu on the left) and check that everything is configured the way you want.</p><p>You probably want to make the site your own. One of the ways you can do that is by clicking <a href=\"Admin/Themes\">Manage Themes</a> in the admin menu. A theme is a packaged look and feel that affects the whole site.</p><p>Next, you can start playing with the content types that we installed. For example, go ahead and click <a href=\"Admin/Pages/Create\">Add New Page</a> in the admin menu and create an \"about\" page. Then, add it to the navigation menu by going to <a href=\"Admin/Navigation\">Manage Menu</a>. You can also click <a href=\"Admin/Blogs/Create\">Add New Blog</a> and start posting by clicking \"Add New Post\".</p><p>Finally, Orchard has been designed to be extended. It comes with a few built-in modules such as pages and blogs or themes. You can install new themes by going to <a href=\"Admin/Themes\">Manage Themes</a> and clicking <a href=\"Admin/Themes/Install\">Install a new Theme</a>. Like for themes, modules are created by other users of Orchard just like you so if you feel up to it, please <a href=\"http://www.orchardproject.net/\">consider participating</a>.</p><p>--The Orchard Crew</p>"; page.As<RoutableAspect>().Slug = "home"; page.As<RoutableAspect>().Title = T("Home").ToString(); page.As<CommonAspect>().Owner = user; if (page.Has<HasComments>()) { page.As<HasComments>().CommentsShown = false; } contentManager.Publish(page); siteSettings.Record.HomePage = "PageHomePageProvider;" + page.Id; // add a menu item for the shiny new home page var menuItem = contentManager.Create("menuitem"); menuItem.As<MenuPart>().MenuPosition = "1"; menuItem.As<MenuPart>().MenuText = T("Home").ToString(); menuItem.As<MenuPart>().OnMainMenu = true; menuItem.As<MenuItem>().Url = ""; //Temporary fix for running setup on command line if (HttpContext.Current != null) { var authenticationService = environment.Resolve<IAuthenticationService>(); authenticationService.SignIn(user, true); } //Add ContentType mappings var contentTypeService = environment.Resolve<IContentTypeService>(); //Add ContentTypePartNames to MetaData contentTypeService.AddContentTypePartNameToMetaData("HasComments"); contentTypeService.AddContentTypePartNameToMetaData("HasTags"); //Add mappings from ContentTypes to ContentParts to MetaData contentTypeService.MapContentTypeToContentPart("blogpost","HasComments"); contentTypeService.MapContentTypeToContentPart("page", "HasComments"); contentTypeService.MapContentTypeToContentPart("sandboxpage", "HasComments"); contentTypeService.MapContentTypeToContentPart("blogpost", "HasTags"); contentTypeService.MapContentTypeToContentPart("page", "HasTags"); contentTypeService.MapContentTypeToContentPart("sandboxpage", "HasTags"); } catch { environment.Resolve<ITransactionManager>().Cancel(); throw; } } _shellSettingsManager.SaveSettings(shellSettings); }