Пример #1
0
        /// <summary>
        /// Starts the application and modules
        /// </summary>
        public void Start()
        {
            if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
            //Load configuration
            ConfigFile configurationFile = new ConfigFile("config.json");
            BaseConfiguration config = configurationFile.Load();
            this.config = config;
            //Set up context
            this.serverContext = new ServerContext(config);
            //Set up ctrl + c handling
                Console.CancelKeyPress += Console_CancelKeyPress;
            //We do a query to sql lite here, give it a chance to connect and cache without
            //having to do it on the first request
            Console.WriteLine("Loading Sql Lite");
            using (var context = new PersistanceContext())
            {
                context.Projects.Any();
                //we dont care about the result
            }
            //Start Subsystems
            StartSubsystem(new HTTPModule());
            StartSubsystem(new SimulationModule());
            StartSubsystem(new WebsocketModule());

            Console.WriteLine("Press any key to close");
            Console.ReadKey();
            this.StopModules();
        }
Пример #2
0
 public override void IndexAction()
 {
     using (var context = new PersistanceContext())
     {
         this.SetSuccessfulContent(context.Projects, HttpStatusCode.OK);
     }
 }
Пример #3
0
        public override void PostAction()
        {
            string postData = GetTextData(Request);
            ProjectData projectData = JsonConvert.DeserializeObject<ProjectData>(postData);
            //Check if a project with this name already exists
            using (var context = new PersistanceContext())
            {
                ProjectData data = context.Projects.FirstOrDefault(x=> x.ProjectName == projectData.ProjectName);
                if (data != null)
                {
                    this.Response.AppendHeader("location", "/project/" + data.Id);
                    throw new HTTPException(HttpStatusCode.SeeOther);
                }
            }
            Workspace workspace = ServerContext.Workspace;
            workspace.CreateProject(projectData);

            //Just for testing
            this.SetSuccessfulContent(projectData, HttpStatusCode.Created);
        }
Пример #4
0
 private ProjectData GetById(string id)
 {
     using (var context = new PersistanceContext())
     {
         int projId = int.Parse(id);
         var project = context.Projects.FirstOrDefault(x => x.Id == projId);
         if (project == null)
         {
             throw new HTTPException(HttpStatusCode.NotFound);
         }
         return project;
     }
 }
Пример #5
0
 private ProjectData GetByName(string name)
 {
     using (var context = new PersistanceContext())
     {
         var project = context.Projects.FirstOrDefault(x => x.ProjectName == name);
         if (project == null)
         {
             throw new HTTPException(HttpStatusCode.NotFound);
         }
         return project;
     }
 }