/// <summary>
        /// Update an existing route package record using the specified <see cref="RoutePackage"/> instance.
        /// </summary>
        /// <param name="package">Instance of <see cref="RoutePackage"/> used to update database record.</param>
        /// <returns>The updated <see cref="RoutePackage"/> record.</returns>
        public async Task <RoutePackage> UpdateRoutePackageAsync(RoutePackage package)
        {
            using (var db = new SubrouteContext())
            {
                // Try to get the user ID for auditing purposes.
                var userId = Thread.CurrentPrincipal.GetUserId();

                var existingPackage = await db.RoutePackages.FirstOrDefaultAsync(rs => rs.Id == package.Id);

                if (existingPackage == null)
                {
                    throw new NotFoundException($"No route package exists with ID '{package.Id}'.");
                }

                existingPackage.Version       = package.Version;
                existingPackage.UserSpecified = package.UserSpecified;
                existingPackage.UpdatedOn     = DateTimeOffset.Now;
                existingPackage.UpdatedBy     = userId;

                await db.SaveChangesAsync();

                // Detach entry so its changes won't be tracked.
                db.Entry(existingPackage).State = EntityState.Detached;

                return(existingPackage);
            }
        }
Example #2
0
        public Route GetRouteSubgraph(RoutePackage task)
        {
            StochasticTask worker = new StochasticTask(task);

            worker.Run(1000);
            return(worker.route);
        }
Example #3
0
 public static Dependency FromRoutePackage(RoutePackage package)
 {
     return(new Dependency
     {
         Id = package.Id,
         Version = package.Version,
         Type = package.Type
     });
 }
        /// <summary>
        /// Delete the route package record using the passed instance.
        /// </summary>
        /// <param name="package">Instance of <see cref="RoutePackage"/> that represents the record to delete.</param>
        /// <returns>Returns a Task, essentially void when using async syntax.</returns>
        public async Task DeleteRoutePackageAsync(RoutePackage package)
        {
            using (var db = new SubrouteContext())
            {
                // Mark route for deletion so the context knowns to delete it.
                db.Entry(package).State = EntityState.Deleted;

                await db.SaveChangesAsync();
            }
        }
        /// <summary>
        /// Uses the specified <see cref="RoutePackage"/> instance to create a new route package record in the database.
        /// </summary>
        /// <param name="setting">Instance of <see cref="RoutePackage"/> used to create the database record.</param>
        /// <returns>Returns instance of <see cref="RoutePackage"/>.</returns>
        public async Task <RoutePackage> CreateRoutePackageAsync(RoutePackage package)
        {
            using (var db = new SubrouteContext())
            {
                // Try to get the user ID for auditing purposes.
                var userId = Thread.CurrentPrincipal.GetUserId();

                // Set auto property values.
                package.CreatedOn = DateTimeOffset.Now;
                package.CreatedBy = userId;
                package.UpdatedOn = package.CreatedOn;
                package.UpdatedBy = userId;

                db.RoutePackages.Add(package);
                await db.SaveChangesAsync();

                // Detach entry so its changes won't be tracked.
                db.Entry(package).State = EntityState.Detached;

                return(package);
            }
        }
Example #6
0
 public StochasticTask(RoutePackage task)
 {
     matrix = task.matrix;
     route  = task.reference;
     size   = route.nodes.Length;
 }
Example #7
0
        /// <summary>
        /// Downloads and extracts the specified package to the NuGet package folder.
        /// </summary>
        /// <param name="package">Package indicating the specific Id and Version of the dependency to download.</param>
        public async Task DownloadPackageAsync(RoutePackage package)
        {
            var dependency = Dependency.FromRoutePackage(package);

            await DownloadPackageAsync(dependency);
        }