public void LoadCheck() { var path = @"..\..\Sample\sample.dll.zip"; if(!File.Exists(path)) { // special casing the integration server path = @"..\..\Test\Lokad.Cloud.Framework.Test\Sample\sample.dll.zip"; } byte[] buffer; using (var dllFile = new FileStream(path, FileMode.Open)) { buffer = new byte[dllFile.Length]; dllFile.Read(buffer, 0, buffer.Length); } var provider = GlobalSetup.Container.Resolve<IBlobStorageProvider>(); provider.CreateContainer(AssemblyLoader.ContainerName); // put the sample assembly provider.PutBlob(AssemblyLoader.ContainerName, AssemblyLoader.PackageBlobName, buffer); var loader = new AssemblyLoader(provider); loader.LoadPackage(); loader.LoadConfiguration(); // validate that 'sample.dll' has been loaded var assemblies = AppDomain.CurrentDomain.GetAssemblies(); Assert.That(assemblies.Any(a => a.FullName.StartsWith("sample"))); // validate using management class var cloudAssemblies = new CloudAssemblies(provider, NullLog.Instance); Assert.That(cloudAssemblies.GetAssemblies().Any(a => a.AssemblyName.StartsWith("sample"))); // no update, checking try { loader.CheckUpdate(false); } catch (TriggerRestartException) { Assert.Fail("Package has not been updated yet."); } // forcing update, this time using the management class cloudAssemblies.UploadAssemblyZipContainer(buffer); // update, re-checking try { loader.CheckUpdate(false); Assert.Fail("Update should have been detected."); } catch (TriggerRestartException) { // do nothing } }
public AssemblyConfigurationUpdateService(IBlobStorageProvider blobStorage) { // NOTE: we can't use the BlobStorage as provided by the base class // as this is not available at constructur time, but we want to reset // the status as soon as possible to avoid missing any changes _assemblyLoader = new AssemblyLoader(blobStorage); _assemblyLoader.ResetUpdateStatus(); }
/// <summary> /// Load and get all initialized service instances using the provided IoC container. /// </summary> IContainer LoadAndBuildApplication(out List<CloudService> services) { var applicationBuilder = new ContainerBuilder(); applicationBuilder.RegisterModule(new CloudModule()); applicationBuilder.RegisterInstance(_settings); // Load Application Assemblies into the AppDomain var loader = new AssemblyLoader(_runtimeProviders); loader.LoadPackage(); // Load Application IoC Configuration and apply it to the builder var config = loader.LoadConfiguration(); if (config.HasValue) { // HACK: need to copy settings locally first // HACK: hard-code string for local storage name const string fileName = "lokad.cloud.clientapp.config"; const string resourceName = "LokadCloudStorage"; var pathToFile = Path.Combine(CloudEnvironment.GetLocalStoragePath(resourceName), fileName); File.WriteAllBytes(pathToFile, config.Value); applicationBuilder.RegisterModule(new ConfigurationSettingsReader("autofac", pathToFile)); } // Look for all cloud services currently loaded in the AppDomain var serviceTypes = AppDomain.CurrentDomain.GetAssemblies() .Select(a => a.GetExportedTypes()).SelectMany(x => x) .Where(t => t.IsSubclassOf(typeof (CloudService)) && !t.IsAbstract && !t.IsGenericType) .ToList(); // Register the cloud services in the IoC Builder so we can support dependencies foreach (var type in serviceTypes) { applicationBuilder.RegisterType(type) .OnActivating(e => { e.Context.InjectUnsetProperties(e.Instance); var initializable = e.Instance as IInitializable; if (initializable != null) { initializable.Initialize(); } }) .InstancePerDependency() .ExternallyOwned(); // ExternallyOwned: to prevent the container from disposing the // cloud services - we manage their lifetime on our own using // e.g. RuntimeFinalizer } var applicationContainer = applicationBuilder.Build(); // Instanciate and return all the cloud services services = serviceTypes.Select(type => (CloudService)applicationContainer.Resolve(type)).ToList(); return applicationContainer; }
/// <summary> /// Load and get all initialized service instances using the provided IoC container. /// </summary> IContainer LoadAndBuildApplication(out List <CloudService> services) { var applicationBuilder = new ContainerBuilder(); applicationBuilder.RegisterModule(new CloudModule()); applicationBuilder.RegisterInstance(_settings); // Load Application Assemblies into the AppDomain var loader = new AssemblyLoader(_storage.BlobStorage); loader.LoadPackage(); // Load Application IoC Configuration and apply it to the builder var config = loader.LoadConfiguration(); if (config.HasValue) { // HACK: need to copy settings locally first // HACK: hard-code string for local storage name const string fileName = "lokad.cloud.clientapp.config"; const string resourceName = "LokadCloudStorage"; var pathToFile = Path.Combine(_environment.GetLocalResourcePath(resourceName), fileName); File.WriteAllBytes(pathToFile, config.Value); applicationBuilder.RegisterModule(new ConfigurationSettingsReader("autofac", pathToFile)); } // Look for all cloud services currently loaded in the AppDomain var serviceTypes = AppDomain.CurrentDomain.GetAssemblies() .Select(a => a.GetExportedTypes()).SelectMany(x => x) .Where(t => t.IsSubclassOf(typeof(CloudService)) && !t.IsAbstract && !t.IsGenericType) .ToList(); // Register the cloud services in the IoC Builder so we can support dependencies foreach (var type in serviceTypes) { applicationBuilder.RegisterType(type) .OnActivating(e => { e.Context.InjectUnsetProperties(e.Instance); var initializable = e.Instance as IInitializable; if (initializable != null) { initializable.Initialize(); } }) .InstancePerDependency() .ExternallyOwned(); // ExternallyOwned: to prevent the container from disposing the // cloud services - we manage their lifetime on our own using // e.g. RuntimeFinalizer } var applicationContainer = applicationBuilder.Build(); // Instanciate and return all the cloud services services = serviceTypes.Select(type => (CloudService)applicationContainer.Resolve(type)).ToList(); return(applicationContainer); }