/// <summary>
        /// Get a deployer for the installed application.
        /// </summary>
        /// <param name="globalSettings">The global settings.</param>
        /// <param name="installedApplicationSettings">The installed application settings.</param>
        /// <param name="logger">The logger.</param>
        public ApplicationDeployer(
            EnvironmentSettings globalSettings,
            InstalledApplication installedApplicationSettings,
            ILoggerInterface logger)
        {
            this.GlobalSettings       = globalSettings;
            this.installedAppSettings = installedApplicationSettings;
            this.Logger = logger;

            if (this.GlobalSettings == null)
            {
                throw new InvalidDataException("settings argument cannot be null.");
            }

            if (this.installedAppSettings == null)
            {
                throw new Exception("installedApplicationSettings argument cannot be null.");
            }

            // Try to grab previous deployment...
            this.activeDeploymentPathStorage = UtilsSystem.CombinePaths(globalSettings.activeDeploymentDir, "active." + this.installedAppSettings.GetId() + ".json");

            if (File.Exists(this.activeDeploymentPathStorage))
            {
                this.DeploymentActive = Deployment.InstanceFromPath(this.activeDeploymentPathStorage, globalSettings);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="globalSettings"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Deployment GetActiveDeploymentById(EnvironmentSettings globalSettings, string id)
        {
            List <Deployment> result = new List <Deployment>();
            DirectoryInfo     dir    = new DirectoryInfo(globalSettings.activeDeploymentDir);

            foreach (var f in dir.EnumerateFiles("active." + id + ".json"))
            {
                return(Deployment.InstanceFromPath(f.FullName, globalSettings));
            }

            return(null);
        }
        /// <summary>
        /// Return a list of active deployments in the system.
        /// </summary>
        /// <returns></returns>
        public static List <Deployment> GetActiveDeployments(EnvironmentSettings globalSettings)
        {
            List <Deployment> result = new List <Deployment>();
            DirectoryInfo     dir    = new DirectoryInfo(globalSettings.activeDeploymentDir);

            foreach (var f in dir.EnumerateFiles("active.*.json"))
            {
                result.Add(Deployment.InstanceFromPath(f.FullName, globalSettings));
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Find the matching deployer of the parent application when
        /// inheritance is configured for this application.
        /// </summary>
        /// <typeparam name="TType"></typeparam>
        /// <returns></returns>
        public TType getDeployerFromParentApp <TType>()
            where TType : DeployerBase
        {
            // We need a parent application for this to work.
            if (this.ParentApp == null)
            {
                return(null);
            }

            // Try to grab parent deployment...
            Deployment parentDeployment;
            string     activeDeploymentPathStorage = UtilsSystem.CombinePaths(this.GlobalSettings.activeDeploymentDir, "active." + this.ParentApp.GetId() + ".json");

            if (File.Exists(activeDeploymentPathStorage))
            {
                parentDeployment = Deployment.InstanceFromPath(activeDeploymentPathStorage, this.GlobalSettings);
                DeployerSettingsBase      ourSettings          = this.DeployerSettings.castTo <DeployerSettingsBase>();
                List <IDeployerInterface> deployersAndServices = new List <IDeployerInterface>();
                deployersAndServices.AddRange(parentDeployment.GrabServices(this.Logger));
                deployersAndServices.AddRange(parentDeployment.GrabDeployers(this.Logger));

                // Only keep those that match our type
                deployersAndServices = deployersAndServices.Where(s => s.GetType() == typeof(TType)).ToList();

                // Filter by ID
                foreach (TType t in deployersAndServices)
                {
                    if (t.DeployerSettings.castTo <DeployerSettingsBase>().id == ourSettings.id)
                    {
                        return(t);
                    }
                }

                return(null);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        /// <summary>
        /// Store a serialized version of this in a path
        /// </summary>
        /// <param name="path"></param>
        public void StoreInPath(string path)
        {
            var temporaryPath = path + Guid.NewGuid() + ".tmp";
            var backupPath    = path + Guid.NewGuid() + ".bak";

            UtilsSystem.EnsureDirectoryExists(path);

            var serialized = JsonConvert.SerializeObject(
                this,
                Formatting.Indented,
                new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            File.WriteAllText(temporaryPath, serialized);

            try
            {
                Deployment.InstanceFromPath(temporaryPath, this.globalSettings);
            }
            catch (Exception e)
            {
                throw new Exception("Error while storing configuration file, corrupted file path: " + temporaryPath, e);
            }

            // Make this more robust, to avoid corrupted active configurations, we ensure that the active
            // configuration can be read before setting it as active. File.Move() is less error to corruption
            // than the actual writing to disk operation
            if (File.Exists(path))
            {
                File.Move(path, backupPath);
            }

            File.Move(temporaryPath, path);

            File.Delete(backupPath);
        }
Exemple #6
0
        /// <summary>
        /// Get a list of all currently installed applications.
        /// </summary>
        /// <returns></returns>
        public List <InstalledApplication> GetInstalledApps(string identifiers = null)
        {
            List <InstalledApplication> apps = new List <InstalledApplication>();

            string activeDeploymentPathStorage = this.GlobalSettings.activeDeploymentDir;

            if (!Directory.Exists(activeDeploymentPathStorage))
            {
                throw new Exception("Active deployment path not found: " + activeDeploymentPathStorage);
            }

            foreach (var f in (new DirectoryInfo(activeDeploymentPathStorage)).EnumerateFiles("active.*.json"))
            {
                Deployment deployment = Deployment.InstanceFromPath(f.FullName, this.GlobalSettings);

                if (string.IsNullOrWhiteSpace(identifiers) ||
                    this.ExplodeAndCleanList(identifiers, ",").Contains(deployment.installedApplicationSettings.GetId()))
                {
                    apps.Add(deployment.installedApplicationSettings);
                }
            }

            return(apps);
        }