示例#1
0
        public async Task <IHttpActionResult> Average(AverageProjectsModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (!AllProjectsExist(model.Projects))
            {
                return(NotFound());
            }

            var now     = DateTime.UtcNow;
            var project = new Project
            {
                UserId            = User.Identity.GetUserId(),
                TraceId           = Guid.NewGuid(),
                Name              = model.Name,
                FileName          = FormatStitchedFrom(model.Projects),
                TestName          = model.TestName,
                TestType          = model.TestType,
                Channel           = model.Channel,
                Tag               = model.Tag,
                Mass              = model.Mass,
                Area              = model.Area,
                Comments          = $"{model.Comments} {FormatStitchedFromNames(model.Projects)}",
                IsAveragePlot     = true,
                CreatedAt         = now,
                UpdatedAt         = now,
                StitchedFromNames = FormatStitchedFromNames(model.Projects),
            };

            _db.Projects.Add(project);
            await _db.SaveChangesAsync();

            var traceId = project.TraceId.ToString();

            project.JobId = _jobClient.Enqueue <IBackgroundProcessor>(
                p => p.PrepareAverageProject(
                    traceId,
                    project.Id,
                    model.Projects,
                    JobCancellationToken.Null));

            await _db.SaveChangesAsync();

            var timeoutJobId = _jobClient.Schedule <IBackgroundProcessor>(
                p => p.HandleTimeout(traceId, project.Id),
                _options.ProjectPrepareTimeout);

            _jobClient.ContinueWith <IBackgroundProcessor>(project.JobId,
                                                           p => p.CancelTimeout(traceId, project.Id, timeoutJobId),
                                                           JobContinuationOptions.OnAnyFinishedState);

            return(Ok());
        }
示例#2
0
        ////////////////////////////////////////////////////////////
        // Public Methods/Atributes
        ////////////////////////////////////////////////////////////

        /// <summary>
        /// Create a new project
        /// </summary>
        /// <param name="project">Project to be created</param>
        /// <returns></returns>
        public async Task CreateProject(Project project)
        {
            var dateTime = DateTime.UtcNow;

            project.CreatedAt = dateTime;
            project.UpdatedAt = dateTime;

            _db.Projects.Add(project);
            await _db.SaveChangesAsync();

            await StartProjectProcessingJobAsync(project);
        }
示例#3
0
        public async Task <IHttpActionResult> SavePreferences(UserPreferencesModel model)
        {
            var entity = await _db.UserPreferences.FindAsync(User.Identity.GetUserId()) ?? new AppUserPreferences();

            entity.Id = User.Identity.GetUserId();
            entity.ChartPreferences = new ChartPreferences
            {
                LegendShowen   = model.ChartPreferences.ShowLegend,
                XLineVisible   = model.ChartPreferences.XLineVisible,
                YLineVisible   = model.ChartPreferences.YLineVisible,
                PointSize      = model.ChartPreferences.PointSize,
                FontSize       = model.ChartPreferences.FontSize,
                FontFamilyName = model.ChartPreferences.FontFamilyName,
                PaletteColors  = model.ChartPreferences.PaletteColors.Select(item => item.Color).ToArray()
            };

            if (_db.Entry(entity).State == EntityState.Detached)
            {
                _db.UserPreferences.Add(entity);
            }

            await _db.SaveChangesAsync();

            _cacheProvider.Clear();
            return(Ok());
        }