コード例 #1
0
        public ActionResult AddTag(Guid id, string name, string value)
        {
            var apps = new Apps();
            var app = apps.GetApp(id);
            if (app.Tags.ContainsKey(name))
                throw new HttpException(406, "Tag name already exists");

            app.Tags.Add(name, value);
            apps.UpdateApp(app);
            if (Request.IsAjaxRequest())
                return Json(null);
            else
                return RedirectToAction("EditTags", new { id = id });
        }
コード例 #2
0
        public ActionResult Create(Guid aid, string comment, DateTime timestamp)
        {
            var apps = new Apps();
            var app = apps.GetApp(aid);

            var newVersion = new Version()
            {
                AppKey = aid,
                Comment = comment,
                Timestamp = timestamp,
                VersionNumber = string.Format("{0}.{1}", app.MajorVersion, app.Revision),
            };

            if (string.IsNullOrWhiteSpace(comment)) ModelState.AddModelError("comment", "Comment is required.");

            if (ModelState.IsValid)
            {
                try
                {
                    var versions = new Versions();
                    versions.CreateVersion(newVersion);

                    app.Revision += 1;
                    apps.UpdateApp(app);

                    return RedirectToAction("Details", new { id = newVersion.Key });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex);
                }
            }

            var groups = new Groups();

            var group = groups.GetGroup(app.GroupKey);

            var model = new VersionDetails()
            {
                Version = newVersion,
                App = app,
                Group = group,
            };

            return View(model);
        }
コード例 #3
0
        public ActionResult ConfirmDelete(Guid id)
        {
            var versions = new Versions();
            var apps = new Apps();
            var groups = new Groups();

            var version = versions.GetVersion(id);
            var app = apps.GetApp(version.AppKey);
            var group = groups.GetGroup(app.GroupKey);

            var model = new VersionDetails()
            {
                Version = version,
                App = app,
                Group = group,
            };
            return View(model);
        }
コード例 #4
0
        public ActionResult Create(Guid aid)
        {
            var apps = new Apps();
            var groups = new Groups();

            var app = apps.GetApp(aid);
            var group = groups.GetGroup(app.GroupKey);
            var version = new Version()
            {
                AppKey = aid,
                GroupKey = group.Key,
                VersionNumber = string.Format("{0}.{1}", app.MajorVersion, app.Revision)
            };

            var model = new VersionDetails()
            {
                Version = version,
                App = app,
                Group = group,
            };

            return View(model);
        }
コード例 #5
0
        public JsonResult UpdateTag(Guid id, string oldName, string name, string value)
        {
            var apps = new Apps();
            var app = apps.GetApp(id);
            if (!app.Tags.ContainsKey(oldName))
                throw new HttpException(404, "Tag not found");

            if (oldName == name)
            {
                app.Tags[name] = value;
            }
            else if (app.Tags.ContainsKey(name))
            {
                throw new HttpException(406, "Tag name already exists");
            }
            else
            {
                app.Tags.Remove(oldName);
                app.Tags.Add(name, value);
            }
            apps.UpdateApp(app);
            return Json(null);
        }
コード例 #6
0
        public JsonResult RemoveTag(Guid id, string name)
        {
            var apps = new Apps();
            var app = apps.GetApp(id);
            if (!app.Tags.ContainsKey(name))
                throw new HttpException(404, "Tag not found");

            app.Tags.Remove(name);
            apps.UpdateApp(app);
            return Json(null);
        }
コード例 #7
0
        public ActionResult Edit(Guid id, string name, string deploymentDirectory, string majorVersion, string revision)
        {
            var apps = new Apps();
            var app = apps.GetApp(id);
            int revisionNum;
            bool revisionValid = int.TryParse(revision, out revisionNum);

            app.Name = name;
            app.DeploymentDirectory = deploymentDirectory;
            app.MajorVersion = majorVersion;
            if (revisionValid)
                app.Revision = revisionNum;

            if (string.IsNullOrWhiteSpace(name)) ModelState.AddModelError("name", "Name is required.");
            if (string.IsNullOrWhiteSpace(deploymentDirectory)) ModelState.AddModelError("deploymentDirectory", "Deployment Directory is required.");
            if (string.IsNullOrWhiteSpace(majorVersion)) ModelState.AddModelError("majorVersion", "Major version is required.");
            if (!Plywood.Utils.Validation.IsMajorVersionValid(majorVersion)) ModelState.AddModelError("majorVersion", "Major version is not valid.");
            if (!revisionValid) ModelState.AddModelError("revision", "Revision must be a positive number.");
            if (revisionNum < 0) ModelState.AddModelError("revision", "Revision must be a positive number.");

            if (ModelState.IsValid)
            {
                try
                {
                    apps.UpdateApp(app);
                    return RedirectToAction("Details", new { id = app.Key });
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error", ex);
                }
            }

            var groups = new Groups();
            var group = groups.GetGroup(app.GroupKey);

            var model = new AppDetails()
            {
                App = app,
                Group = group,
            };

            return View(model);
        }
コード例 #8
0
        public ActionResult Delete(Guid id)
        {
            var apps = new Apps();
            var app = apps.GetApp(id);
            try
            {
                apps.DeleteApp(id);
                return RedirectToAction("Index", new { gid = app.GroupKey });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);

                var groups = new Groups();
                var group = groups.GetGroup(app.GroupKey);

                var model = new AppDetails()
                {
                    App = app,
                    Group = group,
                };

                return View("ConfirmDelete", model);
            }
        }
コード例 #9
0
        public void Install(Guid appKey, Guid versionKey)
        {
            var apps = new Apps(config);
            var app = apps.GetApp(appKey);
            string workingDirectory = String.Format("{0}\\{1}", config.DeploymentDirectory, app.DeploymentDirectory);

            if (app.Tags.ContainsKey("hook-install"))
            {
                // Run hook-install
                logWriter.Write("Running install hook.");
                RunHook(app.Tags["hook-install"], config.DeploymentDirectory);
            }

            PullFolders(appKey, versionKey, true, true);
            PutAppVersionIndexEntry(appKey, versionKey);

            var directory = new DirectoryInfo(workingDirectory);

            if (File.Exists(Path.Combine(workingDirectory, Plywood.IISDeployApi.IISDeployer.PLYWOOD_IIS_DEPLOYMENT_CONFIG_FILENAME)))
                Plywood.IISDeployApi.IISDeployer.Deploy(workingDirectory);

            if (app.Tags.ContainsKey("hook-installed"))
            {
                // Run hook-installed
                logWriter.Write("Running installed hook.");
                RunHook(app.Tags["hook-installed"], workingDirectory);
            }
            foreach (var hookFile in directory.EnumerateFiles("hook-installed.*"))
            {
                try
                {
                    RunCommand(hookFile.FullName);
                }
                catch (Exception ex)
                {
                    ElevateStatusTo(LogStatus.Warning);
                    WriteLog(string.Format("Failed running installed hook: {0}", ex.ToString()));
                }
            }
        }
コード例 #10
0
        private void RunUpdate(Guid appKey, Guid newVersionKey)
        {
            WriteLog(string.Format("Updating app {0} to version {1} ...", appKey, newVersionKey));
            try
            {
                var apps = new Apps(config);
                var versions = new Versions(config);
                var app = apps.GetApp(appKey);
                var version = versions.GetVersion(newVersionKey);
                string workingDirectory = String.Format("{0}\\{1}", config.DeploymentDirectory, app.DeploymentDirectory);
                var directory = new DirectoryInfo(workingDirectory);

                if (app.Tags.ContainsKey("hook-update"))
                {
                    // Run hook-install
                    WriteLog("Running app update hook.");
                    RunHook(app.Tags["hook-update"], workingDirectory);
                }
                if (version.Tags.ContainsKey("hook-update"))
                {
                    // Run hook-install
                    WriteLog("Running version update hook.");
                    RunHook(version.Tags["hook-update"], workingDirectory);
                }
                foreach (var hookFile in directory.EnumerateFiles("hook-update.*"))
                {
                    try
                    {
                        RunCommand(hookFile.FullName);
                    }
                    catch (Exception ex)
                    {
                        ElevateStatusTo(LogStatus.Warning);
                        WriteLog(string.Format("Failed running update hook: {0}", ex.ToString()));
                    }
                }

                PullFolders(appKey, newVersionKey);
                PutAppVersionIndexEntry(appKey, newVersionKey);

                directory.Refresh();

                if (File.Exists(Path.Combine(workingDirectory, Plywood.IISDeployApi.IISDeployer.PLYWOOD_IIS_DEPLOYMENT_CONFIG_FILENAME)))
                    Plywood.IISDeployApi.IISDeployer.Deploy(workingDirectory);

                if (version.Tags.ContainsKey("hook-updated"))
                {
                    // Run hook-install
                    WriteLog("Running version updated hook.");
                    RunHook(version.Tags["hook-updated"], workingDirectory);
                }
                if (app.Tags.ContainsKey("hook-updated"))
                {
                    // Run hook-install
                    WriteLog("Running app updated hook.");
                    RunHook(app.Tags["hook-updated"], workingDirectory);
                }
                foreach (var hookFile in directory.EnumerateFiles("hook-updated.*"))
                {
                    try
                    {
                        RunCommand(hookFile.FullName);
                    }
                    catch (Exception ex)
                    {
                        ElevateStatusTo(LogStatus.Warning);
                        WriteLog(string.Format("Failed running updated hook: {0}", ex.ToString()));
                    }
                }
                WriteLog(string.Format("Completed update of app {0} to version {1} ...", appKey, newVersionKey));
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("Failed update of app {0} to version {1} : {2}", appKey, newVersionKey, ex.ToString());
                WriteLog(errorMessage);
                System.Diagnostics.EventLog.WriteEntry("Plywood", errorMessage, System.Diagnostics.EventLogEntryType.Error, 3005);
            }
        }
コード例 #11
0
        public ActionResult Delete(Guid id)
        {
            var versions = new Versions();
            var version = versions.GetVersion(id);

            try
            {
                versions.DeleteVersion(id);
                return RedirectToAction("Index", new { aid = version.AppKey });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);

                var apps = new Apps();
                var app = apps.GetApp(version.AppKey);

                var groups = new Groups();
                var group = groups.GetGroup(version.GroupKey);

                var model = new VersionDetails()
                {
                    Version = version,
                    App = app,
                    Group = group,
                };

                return View("ConfirmDelete", model);
            }
        }
コード例 #12
0
        public void PullApp(Guid appKey)
        {
            var appsController = new Apps(config);
            var versionsController = new Versions(config);
            var localAppVersions = GetLocalAppVersionsIndex();

            var app = appsController.GetApp(appKey);
            var latestVersion = versionsController.SearchAppVersions(appKey, pageSize: 1);
            if (latestVersion.TotalCount < 1 && !latestVersion.Versions.Any()) throw new VersionNotFoundException("No versions available for installation.");
            Guid versionKey = latestVersion.Versions.First().Key;

            if (localAppVersions.ContainsKey(appKey))
            {
                if (localAppVersions[appKey] != versionKey)
                {
                    RunUpdate(appKey, versionKey);
                }
            }
            else
            {
                Install(appKey, versionKey);
            }
        }
コード例 #13
0
        //
        // GET: /Versions/
        public ActionResult Index(Guid aid, string q = null, DateTime? f = null, DateTime? t = null, int o = 0, int c = 50)
        {
            if (o < 0) o = 0;
            if (c < 1) o = 1;
            if (c > 100) o = 100;

            var versions = new Versions();
            var apps = new Apps();
            var groups = new Groups();

            var versionList = versions.SearchAppVersions(aid, f, t, q, o, c);
            var app = apps.GetApp(aid);
            var group = groups.GetGroup(app.GroupKey);

            var model = new VersionIndex()
            {
                VersionList = versionList,
                App = app,
                Group = group,
            };
            return View(model);
        }
コード例 #14
0
        public ActionResult Edit(Guid id, string comment)
        {
            Version version = null;
            try
            {
                var versions = new Versions();
                version = versions.GetVersion(id);
                version.Comment = comment;
                versions.UpdateVersion(version);
                return RedirectToAction("Details", new { id = version.Key });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex);
            }

            var groups = new Groups();
            var apps = new Apps();
            Group group = null;
            App app = null;
            if (version != null)
            {
                group = groups.GetGroup(version.GroupKey);
                app = apps.GetApp(version.AppKey);
            }

            var model = new VersionDetails()
            {
                Version = version,
                App = app,
                Group = group,
            };

            return View(model);
        }
コード例 #15
0
 private void PullFolders(Guid appKey, Guid newVersionKey, bool create = false, bool clean = true)
 {
     var appsController = new Apps(config);
     var app = appsController.GetApp(appKey);
     var targetDirectory = new DirectoryInfo(config.DeploymentDirectory + "\\" + app.DeploymentDirectory);
     if (!targetDirectory.Exists)
     {
         if (create)
         {
             targetDirectory.Create();
             targetDirectory.Refresh();
         }
         else
         {
             throw new AppDeploymentException(string.Format("Failed pulling version \"{0}\" for app \"{1}\".", newVersionKey, appKey));
         }
     }
     var folderContent = targetDirectory.EnumerateFileSystemInfos();
     if (folderContent.Count() > 0)
     {
         foreach (var item in folderContent)
         {
             if (item.GetType() == typeof(DirectoryInfo))
             {
                 (item as DirectoryInfo).Delete(true);
             }
             else
             {
                 item.Delete();
             }
         }
     }
     var versionsController = new Versions(config);
     versionsController.PullVersion(newVersionKey, targetDirectory);
 }
コード例 #16
0
        public ActionResult ConfirmDelete(Guid id)
        {
            var apps = new Apps();
            var groups = new Groups();

            var app = apps.GetApp(id);
            var group = groups.GetGroup(app.GroupKey);

            var model = new AppDetails()
            {
                App = app,
                Group = group,
            };

            return View(model);
        }
コード例 #17
0
        public ActionResult Version(Guid tid, Guid aid)
        {
            var targetAppVersions = new TargetAppVersions();
            var versions = new Versions();
            var apps = new Apps();
            var targets = new Targets();
            var groups = new Groups();

            Version version;
            var versionKey = targetAppVersions.GetTargetAppVersion(tid, aid);
            if (versionKey.HasValue)
            {
                try
                {
                    version = versions.GetVersion(versionKey.Value);
                }
                catch (Exception)
                {
                    version = null;
                }
            }
            else
            {
                version = null;
            }

            var app = apps.GetApp(aid);
            var target = targets.GetTarget(tid);
            var group = groups.GetGroup(target.GroupKey);

            var model = new TargetAppVersionDetails()
            {
                Version = version,
                App = app,
                Target = target,
                Group = group,
            };
            return View(model);
        }