Ejemplo n.º 1
0
 public Bootstrap(IStartupContext startupContext)
 {
     _startupContext = startupContext;
     _container      = MainAppContainerBuilder.BuildContainer(startupContext);
     _container.Resolve <IAppFolderFactory>().Register();
     _container.Resolve <IPidFileProvider>().Write();
     _appMode = GetApplicationMode();
 }
Ejemplo n.º 2
0
        private static void SpinToExit(ApplicationModes applicationModes)
        {
            if (IsInUtilityMode(applicationModes))
            {
                return;
            }

            _container.Resolve <IWaitForExit>().Spin();
        }
Ejemplo n.º 3
0
        public void Route(ApplicationModes applicationModes)
        {
            _logger.Info("Application mode: {0}", applicationModes);

            switch (applicationModes)
            {
            case ApplicationModes.Service:
            {
                _logger.Debug("Service selected");
                _serviceProvider.Run(_nzbDroneServiceFactory.Build());
                break;
            }

            case ApplicationModes.Interactive:
            {
                _logger.Debug("Console selected");
                _nzbDroneServiceFactory.Start();
                break;
            }

            case ApplicationModes.InstallService:
            {
                _logger.Debug("Install Service selected");
                if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                {
                    _consoleService.PrintServiceAlreadyExist();
                }
                else
                {
                    _serviceProvider.Install(ServiceProvider.NZBDRONE_SERVICE_NAME);
                    _serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
                }
                break;
            }

            case ApplicationModes.UninstallService:
            {
                _logger.Debug("Uninstall Service selected");
                if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                {
                    _consoleService.PrintServiceDoesNotExist();
                }
                else
                {
                    _serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
                }

                break;
            }

            default:
            {
                _consoleService.PrintHelp();
                break;
            }
            }
        }
Ejemplo n.º 4
0
        private static void SpinToExit(ApplicationModes applicationModes)
        {
            if (IsInUtilityMode(applicationModes))
            {
                return;
            }

            _container.Resolve<IWaitForExit>().Spin();
        }
Ejemplo n.º 5
0
        public void Route(ApplicationModes applicationModes)
        {
            _logger.Info("Application mode: {0}", applicationModes);

            switch (applicationModes)
            {
            case ApplicationModes.InstallService:
            {
                _logger.Debug("Install Service selected");
                if (_serviceProvider.ServiceExist(ServiceProvider.SERVICE_NAME))
                {
                    _consoleService.PrintServiceAlreadyExist();
                }
                else
                {
                    _remoteAccessAdapter.MakeAccessible(true);
                    _serviceProvider.Install(ServiceProvider.SERVICE_NAME);
                    _serviceProvider.SetPermissions(ServiceProvider.SERVICE_NAME);

                    // Start the service and exit.
                    // Ensures that there isn't an instance of Readarr already running that the service account cannot stop.
                    _processProvider.SpawnNewProcess("sc.exe", $"start {ServiceProvider.SERVICE_NAME}", null, true);
                }

                break;
            }

            case ApplicationModes.UninstallService:
            {
                _logger.Debug("Uninstall Service selected");
                if (!_serviceProvider.ServiceExist(ServiceProvider.SERVICE_NAME))
                {
                    _consoleService.PrintServiceDoesNotExist();
                }
                else
                {
                    _serviceProvider.Uninstall(ServiceProvider.SERVICE_NAME);
                }

                break;
            }

            case ApplicationModes.RegisterUrl:
            {
                _logger.Debug("Regiser URL selected");
                _remoteAccessAdapter.MakeAccessible(false);

                break;
            }

            default:
            {
                _consoleService.PrintHelp();
                break;
            }
            }
        }
Ejemplo n.º 6
0
        private static void Start(ApplicationModes applicationModes, StartupContext startupContext)
        {
            if (!IsInUtilityMode(applicationModes))
            {
                EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext);
            }

            DbFactory.RegisterDatabase(_container);
            _container.Resolve<Router>().Route(applicationModes);
        }
Ejemplo n.º 7
0
        public void Route(ApplicationModes applicationModes)
        {
            _logger.Info("Application mode: {0}", applicationModes);

            switch (applicationModes)
            {
                case ApplicationModes.Service:
                    {
                        _logger.Trace("Service selected");
                        _serviceProvider.Run(_nzbDroneServiceFactory.Build());
                        break;
                    }

                case ApplicationModes.Interactive:
                    {
                        _logger.Trace("Console selected");
                        _nzbDroneServiceFactory.Start();
                        break;
                    }
                case ApplicationModes.InstallService:
                    {
                        _logger.Trace("Install Service selected");
                        if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                        {
                            _consoleService.PrintServiceAlreadyExist();
                        }
                        else
                        {
                            _serviceProvider.Install(ServiceProvider.NZBDRONE_SERVICE_NAME);
                            _serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
                        }
                        break;
                    }
                case ApplicationModes.UninstallService:
                    {
                        _logger.Trace("Uninstall Service selected");
                        if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                        {
                            _consoleService.PrintServiceDoesNotExist();
                        }
                        else
                        {
                            _serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
                        }

                        break;
                    }
                default:
                    {
                        _consoleService.PrintHelp();
                        break;
                    }
            }
        }
Ejemplo n.º 8
0
        private static void SpinToExit(ApplicationModes applicationModes)
        {
            if (IsInUtilityMode(applicationModes))
            {
                return;
            }

            var runTimeInfo = _container.Resolve<IRuntimeInfo>();

            while (runTimeInfo.IsRunning)
            {
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 9
0
        private static void Start(ApplicationModes applicationModes, StartupContext startupContext)
        {
            if (!IsInUtilityMode(applicationModes))
            {
                if (startupContext.Flags.Contains(StartupContext.RESTART))
                {
                    Thread.Sleep(2000);
                }

                EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext);
            }

            DbFactory.RegisterDatabase(_container);
            _container.Resolve<Router>().Route(applicationModes);
        }
Ejemplo n.º 10
0
        private static void Start(ApplicationModes applicationModes, StartupContext startupContext)
        {
            if (!IsInUtilityMode(applicationModes))
            {
                if (startupContext.Flags.Contains(StartupContext.RESTART))
                {
                    Thread.Sleep(2000);
                }

                EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext);
            }

            DbFactory.RegisterDatabase(_container);
            _container.Resolve <Router>().Route(applicationModes);
        }
Ejemplo n.º 11
0
        private static void Start(ApplicationModes applicationModes, StartupContext startupContext)
        {
            _container.Resolve <ReconfigureLogging>().Reconfigure();

            if (!IsInUtilityMode(applicationModes))
            {
                if (startupContext.Flags.Contains(StartupContext.RESTART))
                {
                    Thread.Sleep(2000);
                }

                EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext);
            }

            _container.Resolve <Router>().Route(applicationModes);
        }
Ejemplo n.º 12
0
        private static bool IsInUtilityMode(ApplicationModes applicationMode)
        {
            switch (applicationMode)
            {
            case ApplicationModes.InstallService:
            case ApplicationModes.UninstallService:
            case ApplicationModes.Help:
            {
                return(true);
            }

            default:
            {
                return(false);
            }
            }
        }
Ejemplo n.º 13
0
 public async virtual Task <IList <ApplicationMode> > GetApplicationModesAsync()
 {
     return(await ApplicationModes
            .AsNoTracking()
            .ToListAsync());
 }
Ejemplo n.º 14
0
 private static bool IsInUtilityMode(ApplicationModes applicationMode)
 {
     switch (applicationMode)
     {
         case ApplicationModes.InstallService:
         case ApplicationModes.UninstallService:
         case ApplicationModes.Help:
             {
                 return true;
             }
         default:
             {
                 return false;
             }
     }
 }
Ejemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                var institutionalId = Context.Users.Single(u => u.Email.Equals(User.Identity.Name)).InstitutionId;
                var courses         = Context.Courses.Where(c => c.InstitutionId.Equals(institutionalId)).ToList();
                courses = courses.Prepend(new Course()
                {
                    Id         = 0,
                    CourseName = "Portal Only"
                }).ToList();
                ViewData["CourseId"]                              = new SelectList(courses, "Id", "CourseName");
                ViewData["LanguageId"]                            = new SelectList(Context.Languages, "Id", "Name");
                ViewData["FeedbackLevelOptionId"]                 = new SelectList(Context.FeedbackLevelOptions, "Id", "Name");
                ViewData["CoverageTypeLevelOptionId"]             = new SelectList(Context.CoverageTypeOptions, "Id", "Name");
                ViewData["TestingTypeOptionsId"]                  = new SelectList(Context.TestingTypeOptions, "Id", "Name");
                ViewData["AssignmentVisibilityProtectionLevelId"] = new SelectList(Context.AssignmentVisibilityProtectionLevels, "Id", "Name");
                ViewData["DifficultiesId"]                        = new SelectList(Context.Difficulties, "Id", "Value");
                ViewData["TagsId"] = new SelectList(Context.Tags, "Id", "Name");
                return(Page());
            }

            var assignmentToUpdate = await Context.GetAssignmentById(id);

            try
            {
                if (Assignment.CourseId == 0)
                {
                    Assignment.CourseId = null;
                }

                if (AssignmentSpecificationUpload != null)
                {
                    var file = FileHelpers.ProcessFormFile(AssignmentSpecificationUpload, ModelState);
                    var assignmentSpecification = new AssignmentSpecification
                    {
                        FileName  = file.FileName,
                        FileBytes = file.FileBytes
                    };

                    Context.AssignmentSpecifications.Add(assignmentSpecification);
                    await Context.SaveChangesAsync();

                    assignmentToUpdate.AssignmentSpecificationId = 0;
                    assignmentToUpdate.AssignmentSpecification   = assignmentSpecification;
                    await Context.SaveChangesAsync();
                }

                if (ReferenceSolutionUpload != null)
                {
                    var file = FileHelpers.ProcessFormFile(ReferenceSolutionUpload, ModelState);
                    var referenceSolution = new ReferenceSolution
                    {
                        FileName  = file.FileName,
                        FileBytes = file.FileBytes
                    };

                    Context.ReferenceSolutions.Add(referenceSolution);
                    await Context.SaveChangesAsync();

                    assignmentToUpdate.ReferenceSolutionId = 0;
                    assignmentToUpdate.ReferenceSolution   = referenceSolution;
                    await Context.SaveChangesAsync();
                }

                if (ReferenceTestCasesSolutionsUpload != null)
                {
                    var file = FileHelpers.ProcessFormFile(ReferenceTestCasesSolutionsUpload, ModelState);
                    var referenceTestCasesSolutions = new ReferenceTestCasesSolutions
                    {
                        FileName  = file.FileName,
                        FileBytes = file.FileBytes
                    };

                    Context.ReferenceTestCasesSolutions.Add(referenceTestCasesSolutions);
                    await Context.SaveChangesAsync();

                    assignmentToUpdate.ReferenceTestCasesSolutionsId = 0;
                    assignmentToUpdate.ReferenceTestCasesSolutions   = referenceTestCasesSolutions;
                    await Context.SaveChangesAsync();
                }

                assignmentToUpdate.Name = Assignment.Name;
                assignmentToUpdate.TestCoverageLevel     = Assignment.TestCoverageLevel;
                assignmentToUpdate.RedundantTestLevel    = Assignment.RedundantTestLevel;
                assignmentToUpdate.LanguageId            = Assignment.LanguageId;
                assignmentToUpdate.CourseId              = Assignment.CourseId;
                assignmentToUpdate.FeedbackLevelOptionId = Assignment.FeedbackLevelOptionId;
                assignmentToUpdate.TestingTypeOptionId   = Assignment.TestingTypeOptionId;
                assignmentToUpdate.AssignmentVisibilityProtectionLevelId =
                    Assignment.AssignmentVisibilityProtectionLevelId;

                ApplicationModes.ToList().ForEach(m =>
                {
                    if (assignmentToUpdate.AssignmentApplicationModes.ToList().Exists(x => x.ApplicationMode.Name.Equals(m.Name)))
                    {
                        assignmentToUpdate.AssignmentApplicationModes.First(x => x.ApplicationMode.Name.Equals(m.Name)).IsChecked =
                            m.IsChecked ? true : false;
                    }
                });

                CoverageTypeOptions.ToList().ForEach(o =>
                {
                    if (assignmentToUpdate.AssignmentCoverageTypeOptions.ToList().Exists(x => x.CoverageTypeOption.Name.Equals(o.Name)))
                    {
                        assignmentToUpdate.AssignmentCoverageTypeOptions.First(a => a.CoverageTypeOption.Name.Equals(o.Name)).IsChecked = o.IsChecked ? true : false;
                    }
                });


                await Context.SaveChangesAsync();

                foreach (var tag in AddedTags)
                {
                    if (await Context.Tags.FirstOrDefaultAsync(t => t.Name.Equals(tag)) == null)
                    {
                        Context.Tags.Add(new Tag()
                        {
                            Name = tag
                        });
                    }
                }

                await Context.SaveChangesAsync();

                assignmentToUpdate.Tags = new List <AssignmentTag>();
                foreach (var tag in Tags)
                {
                    if (tag < 0)
                    {
                        assignmentToUpdate.Tags.Add(new AssignmentTag()
                        {
                            Tag = Context.Tags.First(t => t.Name.Equals(AddedTags[tag * -1 - 1]))
                        });
                    }
                    else if (assignmentToUpdate.Tags.FirstOrDefault(t => t.TagId.Equals(tag)) == null)
                    {
                        assignmentToUpdate.Tags.Add(new AssignmentTag()
                        {
                            Tag = Context.Tags.First(t => t.Id.Equals(tag))
                        });
                    }
                }

                Context.Update(assignmentToUpdate);
                await Context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AssignmentExists(Assignment.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }