private Guid GetInstallVersion(Guid appKey)
        {
            var targetAppVersionController = new TargetAppVersions(config);
            System.Guid? updatedVersionKey = targetAppVersionController.GetTargetAppVersion(config.TargetKey, appKey);
            if (updatedVersionKey.HasValue)
                return updatedVersionKey.Value;

            var versionController = new Versions(config);
            var res = versionController.SearchAppVersions(appKey, pageSize: 1);
            if (res.Versions.Count() > 0)
                return res.Versions.First().Key;

            throw new AppDeploymentException(string.Format("Failed updating application \"{0}\", no versions found.", appKey));
        }
 public void Update(Guid appKey, Guid versionKey)
 {
     var targetAppVersionController = new TargetAppVersions(config);
     VersionCheckResult changeResult = targetAppVersionController.TargetAppVersionChanged(config.TargetKey, appKey, versionKey);
     if (changeResult == VersionCheckResult.Changed)
     {
         System.Guid? updatedVersionKey = targetAppVersionController.GetTargetAppVersion(config.TargetKey, appKey);
         if (updatedVersionKey.HasValue)
             RunUpdate(appKey, updatedVersionKey.Value);
     }
     else if (changeResult == VersionCheckResult.NotSet)
     {
         // Check for latest version
         var versionController = new Versions(config);
         var res = versionController.SearchAppVersions(appKey, pageSize: 1);
         if (res.Versions.Count() != 1)
         {
             throw new AppDeploymentException(string.Format("Failed updating application \"{0}\", no versions found.", appKey));
         }
         if (res.Versions.Single().Key != versionKey)
         {
             RunUpdate(appKey, res.Versions.Single().Key);
         }
     }
 }
 public ActionResult Autocomplete(Guid aid, string query, int offset = 0, int count = 10)
 {
     var versions = new Versions();
     var versionList = versions.SearchAppVersions(aid, null, null, query, offset, count);
     return Json(versionList);
 }
        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);
            }
        }
        //
        // 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);
        }