Exemple #1
0
        public ActionResult GetChanges(
            [FromRoute(Name = "branch")] Branch updateBranch,
            [FromQuery(Name = "os")] OperatingSystem operatingSystem)
        {
            using (DogStatsd.StartTimer("controller.update.get_changes.time"))
            {
                DogStatsd.Increment("controller.update.get_changes.count");

                var updates = _database.UpdateEntities
                              .Include(x => x.UpdateFiles)
                              .Where(x => x.Branch == updateBranch && x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
                              .OrderByDescending(x => x.ReleaseDate)
                              .Take(5);

                var response = new List <UpdatePackage>();

                foreach (var update in updates)
                {
                    var updateFile = update.UpdateFiles.FirstOrDefault(u => u.OperatingSystem == operatingSystem);
                    if (updateFile == null)
                    {
                        continue;
                    }

                    UpdateChanges updateChanges = null;

                    if (update.New.Count != 0 || update.Fixed.Count != 0)
                    {
                        updateChanges = new UpdateChanges
                        {
                            New   = update.New,
                            Fixed = update.Fixed
                        };
                    }

                    response.Add(new UpdatePackage
                    {
                        Version     = update.Version,
                        ReleaseDate = update.ReleaseDate,
                        Filename    = updateFile.Filename,
                        Url         = updateFile.Url,
                        Changes     = updateChanges,
                        Hash        = updateFile.Hash,
                        Branch      = update.Branch.ToString().ToLower()
                    });
                }

                return(Ok(response));
            }
        }
Exemple #2
0
        public ActionResult GetUpdates(
            [FromRoute(Name = "branch")] Branch updateBranch,
            [FromQuery(Name = "os")] OperatingSystem operatingSystem,
            [FromQuery(Name = "version")] string urlVersion)
        {
            // Check given version
            if (!Version.TryParse(urlVersion, out var version))
            {
                return(BadRequest(new
                {
                    ErrorMessage = "Invalid version number specified."
                }));
            }

            using (DogStatsd.StartTimer("controller.update.get_updates.time"))
            {
                DogStatsd.Increment("controller.update.get_updates.count");

                // Grab latest update based on branch and operatingsystem
                var update = _database.UpdateEntities
                             .Include(x => x.UpdateFiles)
                             .Where(x => x.Branch == updateBranch && x.UpdateFiles.Any(u => u.OperatingSystem == operatingSystem))
                             .OrderByDescending(x => x.ReleaseDate)
                             .FirstOrDefault();

                if (update == null)
                {
                    return(NotFound(new
                    {
                        ErrorMessage = "Latest update not found."
                    }));
                }

                // Check if update file is present
                var updateFile = update.UpdateFiles.FirstOrDefault(u => u.OperatingSystem == operatingSystem);
                if (updateFile == null)
                {
                    return(NotFound(new
                    {
                        ErrorMessage = "Latest update file not found."
                    }));
                }

                // Compare given version and update version
                var updateVersion = new Version(update.Version);
                if (updateVersion.CompareTo(version) <= 0)
                {
                    return(Ok(new UpdatePackageContainer
                    {
                        Available = false
                    }));
                }

                // Get the update changes
                UpdateChanges updateChanges = null;

                if (update.New.Count != 0 || update.Fixed.Count != 0)
                {
                    updateChanges = new UpdateChanges
                    {
                        New   = update.New,
                        Fixed = update.Fixed
                    };
                }

                return(Ok(new UpdatePackageContainer
                {
                    Available = true,
                    UpdatePackage = new UpdatePackage
                    {
                        Version = update.Version,
                        ReleaseDate = update.ReleaseDate,
                        Filename = updateFile.Filename,
                        Url = updateFile.Url,
                        Changes = updateChanges,
                        Hash = updateFile.Hash,
                        Branch = update.Branch.ToString().ToLower()
                    }
                }));
            }
        }