Пример #1
0
        public IActionResult Post([FromBody] PipelineViewModel value)
        {
            var             _id             = Guid.Parse(userManager.GetUserId(User));
            Profile         profile         = dataCenterContext.Profiles.Where(x => x.Id == _id).First();
            Algorithm       algorithm       = dataCenterContext.Algorithms.Find(Guid.Parse(value.AlgorithmId));
            CompleteDataSet completeDataSet = dataCenterContext.CompleteDataSets.Find(Guid.Parse(value.DataSetId));
            Pipeline        pipeline        = new Pipeline
            {
                Algorithm          = algorithm,
                Id                 = Guid.NewGuid(),
                Name               = value.Name,
                Description        = value.Description,
                NumberOfContainers = value.NumberOfContainers,
                GetCompleteDataSet = completeDataSet
            };
            List <PipelineParameter> parameters = new List <PipelineParameter>();

            foreach (var parameter in value.Parameters)
            {
                AlgorithmParameters algorithmParameter = dataCenterContext.AlgorithmParameters.Find(Guid.Parse(parameter.Id));
                parameters.Add(new PipelineParameter
                {
                    Id                 = Guid.NewGuid(),
                    Pipeline           = pipeline,
                    Value              = parameter.Value,
                    AlgorithmParameter = algorithmParameter
                });
            }
            pipeline.PipelineParameters = parameters;
            ProfilePipeline profilePipeline = new ProfilePipeline
            {
                Pipeline = pipeline,
                Profile  = profile
            };

            dataCenterContext.ProfilePipeline.Add(profilePipeline);
            dataCenterContext.SaveChanges();

            RabbitMqService rabbitMqService = new RabbitMqService();

            rabbitMqService.SendMessage(pipeline.Id + "~" + algorithm.MasterImage);
            for (int i = 0; i < pipeline.NumberOfContainers - 1; i++)
            {
                rabbitMqService.SendMessage(pipeline.Id + "~" + algorithm.SlaveImage);
            }

            return(Ok());
        }
Пример #2
0
 public IActionResult Post([FromBody] AlgorithmViewModel value)
 {
     dataCenterContext.Algorithms.Add(new Algorithm
     {
         Id          = Guid.NewGuid(),
         Cover       = value.Cover,
         Description = value.Description,
         MasterImage = value.Master,
         SlaveImage  = value.Slave,
         Name        = value.Name
     });
     dataCenterContext.SaveChanges();
     return(Ok());
 }
Пример #3
0
        public IActionResult Post([FromBody] AlgorithmParameterViewModel value)
        {
            Algorithm           algorithm  = dataCenterContext.Algorithms.Find(Guid.Parse(value.Algorithm));
            AlgorithmParameters parameters = new AlgorithmParameters
            {
                Algorithm   = algorithm,
                DataType    = value.DataType,
                Description = value.Description,
                Id          = Guid.NewGuid(),
                Name        = value.Name
            };

            dataCenterContext.AlgorithmParameters.Add(parameters);
            dataCenterContext.SaveChanges();
            return(Ok());
        }
Пример #4
0
        public async Task <object> Register([FromBody] RegistrationViewModel register)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser
                {
                    UserName = register.Email,
                    Email    = register.Email
                };

                var result = await userManager.CreateAsync(user, register.Password);

                if (result.Succeeded)
                {
                    user = await userManager.FindByEmailAsync(register.Email);

                    dataCenterContext.Profiles.Add(new Models.Profile
                    {
                        FirstName      = register.FirstName,
                        LastName       = register.LastName,
                        Email          = register.Email,
                        Id             = Guid.Parse(user.Id),
                        CoverPicture   = "URL",
                        ProfilePicture = "URL"
                    });
                    dataCenterContext.SaveChanges();
                    await userManager.AddToRoleAsync(user, "User");

                    return(Ok());
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }

            return(BadRequest(ModelState));
        }
Пример #5
0
        public IActionResult Post([FromBody] CompleteDataSetViewModel value)
        {
            var             _id             = Guid.Parse(userManager.GetUserId(User));
            Profile         profile         = dataCenterContext.Profiles.Where(x => x.Id == _id).First();
            CompleteDataSet completeDataSet = new CompleteDataSet
            {
                Id                = Guid.NewGuid(),
                Description       = value.Description,
                Name              = value.Name,
                XComponentDataSet = dataCenterContext.DataSets.Find(Guid.Parse(value.XComponentId)),
                YComponentDataSet = dataCenterContext.DataSets.Find(Guid.Parse(value.YComponentId))
            };
            ProfileCompleteDataSet profileCompleteDataSet = new ProfileCompleteDataSet
            {
                CompleteDataSet = completeDataSet,
                Profile         = profile
            };

            dataCenterContext.ProfilesCompleteDataSets.Add(profileCompleteDataSet);
            dataCenterContext.SaveChanges();
            return(Ok());
        }
Пример #6
0
        public async Task <IActionResult> Post()
        {
            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                return(BadRequest("Did not get multipart data"));
            }

            var    formAccumulator = new KeyValueAccumulator();
            string targetFilePath  = null;
            string fileName        = Guid.NewGuid().ToString().Trim();
            string fileExtension   = "";

            var boundry = MultipartRequestHelper.GetBoundry(MediaTypeHeaderValue.Parse(Request.ContentType),
                                                            defaultFormOptions.MultipartBoundaryLengthLimit);
            var reader = new MultipartReader(boundry, HttpContext.Request.Body);

            var section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                ContentDispositionHeaderValue contentDisposition;
                var hasContentDisposition = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out contentDisposition);

                if (hasContentDisposition)
                {
                    if (MultipartRequestHelper.HasFileContentDispostion(contentDisposition))
                    {
                        fileExtension  = Path.GetExtension(HeaderUtilities.RemoveQuotes(contentDisposition.FileName) + "").Trim();
                        targetFilePath = Path.Combine("DataSets", fileName) + fileExtension;
                        using (var targetStream = System.IO.File.Create(targetFilePath))
                        {
                            await section.Body.CopyToAsync(targetStream);
                        }
                    }
                    else if (MultipartRequestHelper.HasFormDataContentDispostion(contentDisposition))
                    {
                        var key      = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
                        var encoding = GetEncoding(section);
                        using (var streamReader = new StreamReader(
                                   section.Body,
                                   encoding,
                                   detectEncodingFromByteOrderMarks: true,
                                   bufferSize: 1024,
                                   leaveOpen: true))
                        {
                            var value = await streamReader.ReadToEndAsync();

                            if (string.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase))
                            {
                                value = string.Empty;
                            }
                            formAccumulator.Append(key + "", value);

                            if (formAccumulator.ValueCount > defaultFormOptions.ValueCountLimit)
                            {
                                throw new InvalidDataException("Form key limit exceeded");
                            }
                        }
                    }
                }

                section = await reader.ReadNextSectionAsync();
            }

            var dataSet           = new DataSetViewModel();
            var formValueProvider = new FormValueProvider(BindingSource.Form,
                                                          new FormCollection(formAccumulator.GetResults()),
                                                          CultureInfo.CurrentCulture);
            var bindingSuccessful = await TryUpdateModelAsync(dataSet, prefix : "", valueProvider : formValueProvider);

            if (bindingSuccessful)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                else
                {
                    var     _id       = Guid.Parse(userManager.GetUserId(User));
                    Profile profile   = dataCenterContext.Profiles.Where(x => x.Id == _id).First();
                    DataSet myDataSet = new DataSet
                    {
                        Id          = Guid.Parse(fileName),
                        Name        = dataSet.Name,
                        Description = dataSet.Description,
                        URL         = "/DataSets/" + fileName + fileExtension
                    };
                    ProfileDataSet profileDataSet = new ProfileDataSet
                    {
                        DataSet = myDataSet,
                        Profile = profile
                    };
                    dataCenterContext.Add(profileDataSet);
                    dataCenterContext.SaveChanges();
                }
            }

            return(Ok("/DataSets/" + fileName + fileExtension));
        }