private bool SaveBacterialClone(SequencingPostModel postModel)
        {
            ValidateBacterialClone(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobBacterialClone = new UserJobBacterialClone();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobBacterialClone);
                userJob.UserJobBacterialClone = userJobBacterialClone;
                userJob.User            = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                AddPlates(postModel.PlateNames, userJob, userJob.JobType);

                if (postModel.Strain != null && postModel.Strain.IsOther())
                {
                    var strain = new Strain()
                    {
                        Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false
                    };
                    userJob.UserJobBacterialClone.Strain = strain;
                }

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return(true);
            }

            return(false);
        }
        public IHttpActionResult PutUserJob(int id, UserJob userJob)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userJob.Id)
            {
                return(BadRequest());
            }

            try
            {
                repository.Put(userJob);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserJobExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private bool SaveSublibrarySubmission(SequencingPostModel postModel)
        {
            ValidateSublibrarySubmission(postModel);

            if (ModelState.IsValid)
            {
                var userJob           = new UserJob();
                var userJobSublibrary = new UserJobSublibrary();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobSublibrary);
                userJob.UserJobSublibrary = userJobSublibrary;
                userJob.User            = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                AddPlates(new List <string>()
                {
                    userJob.Name
                }, userJob, userJob.JobType);

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return(true);
            }

            return(false);
        }
Example #4
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            var progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                              Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();

            SyncTracksToAdd(progressUpdater);

            SyncTracksToUpdate(progressUpdater);

            SyncTracksToRemove(progressUpdater);

            SyncTracksToPlaylists();

            SyncDatabase(progressUpdater);

            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
Example #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserJob userJob = repo.GetJob(id);

            repo.DeleteJob(userJob);
            return(RedirectToAction("Index"));
        }
Example #6
0
        public bool DeleteUserFromJob(UserJob assigned)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand(@"DELETE FROM  (Id, title) VALUES(@id, @title);", connection);


                    command.Parameters.AddWithValue("@JobId", assigned.JobId);
                    command.Parameters.AddWithValue("@UserId", assigned.UserId);

                    command.ExecuteNonQuery();

                    if (assigned.JobId == null || assigned.UserId == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            catch (SqlException E)
            {
                Console.WriteLine(E.Message);
                return(false);
            }
        }
Example #7
0
        public ActionResult Create([Bind(Include = "JobTitle,JobDecription,JobType,Date,Latitude,Longitude")] JobViewModel _jobViewModel)
        {
            if (ModelState.IsValid)
            {
                //populate userJob object from database with viewmodel, add to database and redirect to index
                UserJob userJob = new UserJob
                {
                    JobTitle       = _jobViewModel.JobTitle,
                    JobDescription = _jobViewModel.JobDecription,
                    JobType        = _jobViewModel.JobType,
                    Date           = DateTime.Now,
                    Latitude       = _jobViewModel.Latitude,
                    Longitude      = _jobViewModel.Longitude,
                    AspNetUser_Id  = repo.GetUserId()
                };
                repo.PostJob(userJob);
                return(RedirectToAction("Index"));
            }

            //if text field is empty or location isn't set, set viewbag message to display in the view
            if (isNullOrEmpty(_jobViewModel.JobTitle) || isNullOrEmpty(_jobViewModel.JobDecription) ||
                isNullOrEmpty(_jobViewModel.JobType))
            {
                ViewBag.error = "empty";
                return(View(_jobViewModel));
            }
            else if (_jobViewModel.Latitude == 0.0 || _jobViewModel.Longitude == 0.0)
            {
                ViewBag.error = "location";
                return(View(_jobViewModel));
            }

            return(View(_jobViewModel));
        }
Example #8
0
        public bool AssignUserToJob(UserJob assigned)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand(@"INSERT INTO userJob (userID, job_Id) VALUES(@userId, @jobId);", connection);

                    command.Parameters.AddWithValue("@userId", assigned.UserId);
                    command.Parameters.AddWithValue("@jobId", assigned.JobId);

                    command.ExecuteNonQuery();

                    if (assigned.JobId == null || assigned.UserId == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            catch (SqlException E)
            {
                Console.WriteLine(E.Message);
                return(false);
            }
        }
Example #9
0
        public async Task <ActionResult <UserJob> > PostUserJob(UserJob userJob)
        {
            if (userJob.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            _context.UsersJobs.Add(userJob);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (UserJobExists(userJob.UserId, userJob.JobId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetUserJob", new { id = userJob.UserId }, userJob));
        }
Example #10
0
        public async Task <IActionResult> PutUserJob(int id, UserJob userJob)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            if (id != userJob.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(userJob).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserJobExists(id, userJob.JobId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #11
0
        public async Task <ActionResult <UserJob> > PostUserJob(int userID, int jobID)
        {
            UserJob userJob = new UserJob
            {
                UserID = userID,
                JobID  = jobID
            };

            _context.UserJob.Add(userJob);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (UserJobExists(userJob.UserID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetUserJob", new { id = userJob.UserID }, userJob));
        }
Example #12
0
            public async Task <Unit> Handle(Command request,
                                            CancellationToken cancellationToken)
            {
                var job = new Job
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                };

                _context.Jobs.Add(job);

                var user = await _context.Users.SingleOrDefaultAsync(x =>
                                                                     x.UserName == _userAccessor.GetCurrentUsername());

                var applicant = new UserJob
                {
                    AppUser    = user,
                    Job        = job,
                    IsHost     = true,
                    DateJoined = DateTime.Now
                };

                _context.UserJobs.Add(applicant);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
Example #13
0
        void SyncTracksToAdd(UserJob progressUpdater)
        {
            string message = Catalog.GetString("Adding track {0} of {1}");
            int    total   = tracks_to_add.Count;
            int    i       = 0;

            while (tracks_to_add.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    total = tracks_to_add.Count + i;
                    track = tracks_to_add.Dequeue();
                }

                try {
                    UpdateProgress(progressUpdater, message, ++i, total);
                    track.CommitToIpod(MediaDatabase);
                    track.Save(false);
                    tracks_map[track.TrackId] = track;
                } catch (Exception e) {
                    Log.Error("Cannot save track to the Apple device", e);
                }
            }
            if (total > 0)
            {
                OnTracksAdded();
                OnUserNotifyUpdated();
            }
        }
Example #14
0
        void SyncTracksToRemove(UserJob progressUpdater)
        {
            string message = Catalog.GetString("Removing track {0} of {1}");
            int    total   = tracks_to_remove.Count;

            while (tracks_to_remove.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_remove.Dequeue();
                }

                if (tracks_map.ContainsKey(track.TrackId))
                {
                    tracks_map.Remove(track.TrackId);
                }

                try {
                    if (track.IpodTrack != null)
                    {
                        UpdateProgress(progressUpdater, message, total - tracks_to_remove.Count, total);

                        DeleteTrack(track.IpodTrack, true);
                    }
                    else
                    {
                        Log.Error("The ipod track was null");
                    }
                } catch (Exception e) {
                    Log.Error("Cannot remove track from iPod", e);
                }
            }

            SyncRemovalOfInvalidTracks(progressUpdater);
        }
Example #15
0
 private void DisposeSyncUserJob()
 {
     if (sync_user_job != null)
     {
         sync_user_job.Finish();
         sync_user_job = null;
     }
 }
Example #16
0
        private void OnIpodDatabaseSaveStarted(object o, EventArgs args)
        {
            DisposeSyncUserJob();

            sync_user_job = new UserJob(Catalog.GetString("Syncing iPod"),
                                        Catalog.GetString("Preparing to synchronize..."), GetIconNames());
            sync_user_job.Register();
        }
Example #17
0
 public UserJobModel(UserJob obj, bool isLoadJob = true)
 {
     ShareFunctions.CopyPropertiesTo <UserJob, UserJobModel>(obj, this);
     if (isLoadJob)
     {
         Post = new JobPostModel(this.JobId);
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            UserJob userJob = db.UserJobs.Find(id);

            db.UserJobs.Remove(userJob);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #19
0
 private void OnSubmissionEnd(object source, EventArgs args)
 {
     if (scrobble_job != null)
     {
         scrobble_job.Finish();
         scrobble_job = null;
     }
 }
Example #20
0
        public bool Update(UserJob data)
        {
            string id = $"{data.id_user_job}";

            data.id_user_job = string.Empty;
            data.ngay_sua    = XMedia.XUtil.TimeInEpoch(DateTime.Now);
            return(Update(_default_index, data, id));
        }
Example #21
0
 public ActionResult Edit([Bind(Include = "Id,JobTitle,JobDecription,JobType,Date,Latitude,Longitude,AspNetUser_Id")] UserJob userJob)
 {
     if (ModelState.IsValid)
     {
         repo.PutJob(userJob);
         return(RedirectToAction("Index"));
     }
     return(View(userJob));
 }
Example #22
0
        public bool UpdateThuocTinh(UserJob data)
        {
            string id = $"{data.id_user_job}";

            data.id_user_job = string.Empty;
            data.ngay_sua    = XMedia.XUtil.TimeInEpoch(DateTime.Now);
            var re = client.Update <UserJob, object>(id, u => u.Doc(new { ngay_sua = data.ngay_sua, thuoc_tinh = data.thuoc_tinh }));

            return(re.Result == Result.Updated || re.Result == Result.Noop);
        }
 public ActionResult Edit([Bind(Include = "UserJobID,JobID,UserID")] UserJob userJob)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userJob).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userJob));
 }
        public IHttpActionResult PostUserJob(UserJob userJob)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            repository.Post(userJob);

            return(CreatedAtRoute("DefaultApi", new { id = userJob.Id }, userJob));
        }
        public IHttpActionResult GetUserJob(int id)
        {
            UserJob userjob = repository.Get(id);

            if (userjob == null)
            {
                return(NotFound());
            }

            return(Ok(userjob));
        }
        public ActionResult Create([Bind(Include = "UserJobID,JobID,UserID")] UserJob userJob)
        {
            if (ModelState.IsValid)
            {
                db.UserJobs.Add(userJob);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userJob));
        }
Example #27
0
        private void OnFinished(object o, EventArgs args)
        {
            if (user_job != null)
            {
                user_job.CancelRequested -= OnCancelRequested;
                user_job.Finished        -= OnFinished;
                user_job = null;
            }

            source.UnlockAllTracks();
        }
Example #28
0
 public void UpdateUserJob(UserJob Entity)
 {
     try
     {
         _userJobRepository.Update(Entity);
     }
     catch (IntegratorException e)
     {
         throw e;
     }
 }
Example #29
0
        private bool SaveColonyPicking(QbotPostModel postModel)
        {
            ValidateColonyPicking(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobColonyPicking = new UserJobQbotColonyPicking();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobColonyPicking);
                userJob.UserJobQbotColonyPicking = userJobColonyPicking;
                userJob.User            = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                if (postModel.Strain.IsOther())
                {
                    var strain = new Strain()
                    {
                        Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false
                    };
                    userJob.UserJobQbotColonyPicking.Strain = strain;
                }

                if (postModel.Vector.IsOther())
                {
                    var vector = new Vector()
                    {
                        Name = postModel.NewVector, VectorType = postModel.VectorType, Antibiotic1 = postModel.Antibiotic1, Antibiotic2 = postModel.Antibiotic2
                    };
                    userJob.UserJobQbotColonyPicking.Vector = vector;
                }

                // add plate
                var stage   = _repositoryFactory.StageRepository.GetNullableById(StageIds.QpWebSubmittedPlates);
                var barcode = new Barcode()
                {
                    Stage = stage
                };
                var userJobPlate = new UserJobPlate()
                {
                    Name = userJob.Name
                };
                userJobPlate.AddBarcode(barcode);
                userJob.AddUserJobPlates(userJobPlate);

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return(true);
            }

            return(false);
        }
        public async Task StartMonitoring()
        {
            var users = await _userRepository.GetUsers().ConfigureAwait(false);

            foreach (var user in users)
            {
                var userJob = new UserJob(user, _twitchIntegration, _streamHealthLogger);
                userJob.Run();
                _userJobs.Add(userJob);
                _logger.LogInformation($"Started job for {user.Username}");
            }
        }
Example #31
0
        public void AdvanceAllBarcodes(IRepositoryFactory repositoryFactory, UserJob userJob, Stage stage)
        {
            var barcodes = userJob.UserJobPlates.SelectMany(a => a.Barcodes).Where(a => a.Stage == stage && !a.Done);

            if (barcodes.Any())
            {
                foreach(var bc in barcodes)
                {
                    AdvanceStage(repositoryFactory, bc, userJob);
                }
            }
        }
        /// <summary>
        /// Adds the plates necessary for the original submission
        /// </summary>
        /// <param name="plateNames"></param>
        /// <param name="userJob"></param>
        private void AddPlates(List<string> plateNames, UserJob userJob, JobType jobType)
        {
            // figure out the stage
            Stage stage = null;

            switch(jobType.Id)
            {
                case (int)JobTypeIds.BacterialClone:
                    stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.BcWebSubmittedPlates);
                    break;
                case (int)JobTypeIds.PCRProduct:
                    stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.PcrWebSubmittedPlates);
                    break;
                case (int)JobTypeIds.UserRunSequencing:
                    stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.UrsWebSubmittedPlates);
                    break;
                case (int)JobTypeIds.PurifiedDna:
                    stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.PdWebSubmittedPlates);
                    break;
                case (int)JobTypeIds.Sublibrary:
                    stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.SlWebSubmittedPlates);
                    break;
            }

            if (stage == null)
            {
                throw new ArgumentException("JobType");
            }

            foreach(var name in plateNames)
            {
                var plate = new UserJobPlate() {Name = name};
                var barcode = new Barcode() {Stage = stage};

                plate.AddBarcode(barcode);
                userJob.AddUserJobPlates(plate);
            }
        }
        private bool SaveBacterialClone(SequencingPostModel postModel)
        {
            ValidateBacterialClone(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobBacterialClone = new UserJobBacterialClone();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobBacterialClone);
                userJob.UserJobBacterialClone = userJobBacterialClone;
                userJob.User = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                AddPlates(postModel.PlateNames, userJob, userJob.JobType);

                if (postModel.Strain != null && postModel.Strain.IsOther())
                {
                    var strain = new Strain() { Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false };
                    userJob.UserJobBacterialClone.Strain = strain;
                }

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return true;
            }

            return false;
        }
        private bool SaveSublibrarySubmission(SequencingPostModel postModel)
        {
            ValidateSublibrarySubmission(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobSublibrary = new UserJobSublibrary();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobSublibrary);
                userJob.UserJobSublibrary = userJobSublibrary;
                userJob.User = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                AddPlates(new List<string>() {userJob.Name}, userJob, userJob.JobType);

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return true;
            }

            return false;
        }
        private bool SaveUserRunSubmission(SequencingPostModel postModel)
        {
            ValidateUserRunSubmission(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobUserRun = new UserJobUserRun();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobUserRun);
                userJob.UserJobUserRun = userJobUserRun;
                userJob.User = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                AddPlates(postModel.PlateNames, userJob, userJob.JobType);

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return true;
            }

            return false;
        }
Example #36
0
        public void AdvanceStage(IRepositoryFactory repositoryFactory, Barcode barcode, UserJob userJob)
        {
            // barcode is complete and cannot be advanced
            if (barcode.Stage.IsComplete) return;

            var jobType = userJob.JobType;
            var stage = barcode.Stage;
            var plate = barcode.UserJobPlate;

            // by default only insert one new barcode
            var subPlates = 1;

            // jobs with large plate, gets broken down to 4 barcodes
            if (_largeplateJobs.Contains(jobType.Id) && userJob.PlateType == PlateTypes.ThreeEightyFour && stage.Order == 2)
            {
                subPlates = 4;
            }

            Primer primer1 = barcode.Primer;
            Primer primer2 = null;
            var directional = false;

            // if it's directional, you need a forward and back for each sub plate to generate
            if (_directionalJobs.Contains(jobType.Id))
            {
                // bacterial clone, 2nd stage, take the direction
                if (jobType.Id == (int)JobTypeIds.BacterialClone && stage.Order == 3 && userJob.UserJobBacterialClone.SequenceDirection == SequenceDirection.Backward)
                {
                    directional = true;
                    primer1 = userJob.UserJobBacterialClone.Primer1;
                    primer2 = userJob.UserJobBacterialClone.Primer2;
                }

                // frankly, I think this was old code that isn't used any more
                // pcr and purified dna take the direction at 1st stage
                if ((jobType.Id == (int)JobTypeIds.PCRProduct || jobType.Id == (int)JobTypeIds.PurifiedDna) && stage.Order == 2 && userJob.UserJobDna.SequenceDirection == SequenceDirection.Backward)
                {
                    directional = true;
                    primer1 = userJob.UserJobDna.Primer1;
                    primer2 = userJob.UserJobDna.Primer2;
                }
            }

            // load the next stage
            var nextStage = jobType.Stages.First(a => a.Order == stage.Order + 1);

            for (var i = 0; i < subPlates; i++)
            {
                // write the first plate
                var newBarcode1 = new Barcode() { SourceBarcode = barcode, Stage = nextStage, Primer = primer1, SubPlateId = i + 1};
                plate.AddBarcode(newBarcode1);

                if (directional)
                {
                    var newBarcode2 = new Barcode() { SourceBarcode = barcode, Stage = nextStage, Primer = primer2, SubPlateId = i + 1 };
                    plate.AddBarcode(newBarcode2);
                }
            }

            barcode.Done = true;

            repositoryFactory.UserJobPlateRepository.EnsurePersistent(plate);

            userJob.LastUpdate = DateTime.Now;
            repositoryFactory.UserJobRepository.EnsurePersistent(userJob);
        }