Esempio n. 1
0
        public Deployment(Session session, string ipAddress)
        {
            // Store ip address for logging later.
            IPAddress = ipAddress;

            // Store the session.
            Session = session;

            // Create the temporary directory if it doesn't exist.
            CreateDirectoryIfNotExist(TempPath);

            // Identify package zips.
            List <string> packageZips = IdentifyPackages();

            // Create install jobs.
            List <InstallJob> installJobs = new List <InstallJob>();
            List <PackageJob> packageJobs = new List <PackageJob>();

            foreach (string packageZip in packageZips)
            {
                InstallJob installJob = new InstallJob(packageZip);
                installJobs.Add(installJob);
                packageJobs.AddRange(installJob.Packages);
            }

            // Are package dependencies fulfulled?
            foreach (InstallJob installJob in installJobs)
            {
                installJob.CheckDependencies(packageJobs);
            }

            // Order jobs.
            OrderedInstall = OrderInstallJobs(installJobs);
        }
Esempio n. 2
0
        private void AddInstallJob(InstallJob installJob, SortedList <int, InstallJob> orderedInstall, List <InstallJob> installJobs, List <InstallJob> dependencyStack = null)
        {
            // Initialise dependency stack if needed.
            if (dependencyStack == null)
            {
                dependencyStack = new List <InstallJob>();
            }

            // Is this job already in the dependency stack?
            if (dependencyStack.Contains(installJob))
            {
                // Yes, that's a circular dependency detection then.
                throw new Exception("Circular package dependency!");
            }

            // Add this job to the dependency stack.
            dependencyStack.Add(installJob);

            // Loop packages in this install job.
            foreach (PackageJob pj in installJob.Packages)
            {
                // Loop dependencies in this package.
                foreach (PackageDependency pd in pj.Dependencies)
                {
                    // Is this dependency met by our deployment and is it a package dependency?
                    if (pd.DeployMet && pd.Type.Equals("package"))
                    {
                        // Try and find the install job that provides this dependency.
                        InstallJob foundInstallDependency = FindInstallJobWithPackage(pd.Value, installJobs);

                        // Did we find it?
                        if (foundInstallDependency == null)
                        {
                            // No, unfulfilled dependency.
                            throw new Exception("Unfulfilled package dependency.");
                        }

                        // Is it already in the ordered jobs?
                        if (!orderedInstall.ContainsValue(foundInstallDependency))
                        {
                            // No, add that install job first.
                            AddInstallJob(foundInstallDependency, orderedInstall, installJobs, dependencyStack);
                        }
                    }
                }
            }

            // Add ourself.
            orderedInstall.Add(orderedInstall.Count, installJob);
        }
Esempio n. 3
0
        public void Deploy()
        {
            // Do the install.
            JavaScriptSerializer  jsonSer = new JavaScriptSerializer();
            SessionDataController dc      = new SessionDataController();

            // Set as started.
            Session.Status = SessionStatus.InProgess;
            dc.Update(Session);

            // Install in order.
            foreach (KeyValuePair <int, InstallJob> keyPair in OrderedInstall)
            {
                // Get install job.
                InstallJob job = keyPair.Value;

                // Attempt install.
                job.Install();

                // Log package installs.
                foreach (PackageJob package in job.Packages)
                {
                    string log = string.Format("Package successfully installed: {0} @ {1}, session: {2}.", package.Name, package.VersionStr, Session.Guid);

                    EventLogManager.Log("PACKAGE_INSTALLED", EventLogSeverity.Info, log);
                }

                // Make sorted list serialisable.
                SortedList <string, InstallJob> serOrderedInstall = new SortedList <string, InstallJob>();

                foreach (KeyValuePair <int, InstallJob> pair in OrderedInstall)
                {
                    serOrderedInstall.Add(pair.Key.ToString(), pair.Value);
                }

                // After each install job, update response.
                Session.Response = jsonSer.Serialize(serOrderedInstall);
                dc.Update(Session);
            }

            // Done.
            Session.Status = SessionStatus.Complete;
            dc.Update(Session);
        }