Exemple #1
0
        public IHttpContext GetProjects(IHttpContext ctx)
        {
            Dictionary <int, MProject> projs = SqliteDb.GetProjects();

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(projs, Formatting.Indented));
            return(ctx);
        }
Exemple #2
0
        public IHttpContext UnloadProject(IHttpContext ctx)
        {
            if (ctx.Request.QueryString["sessionid"] == null)
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"not found\"}");
                return(ctx);
            }

            int sessionid = Int32.Parse(ctx.Request.QueryString["sessionid"]);

            if (sessions.ContainsKey(sessionid))
            {
                XBimParser parsomator;
                sessions.TryGetValue(sessionid, out parsomator);
                parsomator.Unload();
                sessions.Remove(sessionid);
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\"}");
            }
            else
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"session not found\"}");
            }

            return(ctx);
        }
Exemple #3
0
        public IHttpContext ReturnVersion(IHttpContext ctx)
        {
            Dictionary <string, string> versionInfo = new Dictionary <string, string>
            {
                { "Version", "0.1" }
            };

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(versionInfo, Formatting.Indented));
            return(ctx);
        }
Exemple #4
0
        public IHttpContext GetSessions(IHttpContext ctx)
        {
            Dictionary <int, string> filehandles = new Dictionary <int, string>();

            foreach (int key in sessions.Keys)
            {
                XBimParser parseme;
                sessions.TryGetValue(key, out parseme);
                filehandles.Add(key, parseme.GetFilename());
            }

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(filehandles, Formatting.Indented));
            return(ctx);
        }
Exemple #5
0
        public IHttpContext GetActors(IHttpContext ctx)
        {
            if (ctx.Request.QueryString["sessionid"] == null)
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"missing parameter\"}");
                return(ctx);
            }

            XBimParser parse  = GetSession(ctx.Request.QueryString["sessionid"]);
            var        actors = parse.GetActors();

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(actors, Formatting.Indented));

            return(ctx);
        }
Exemple #6
0
        public IHttpContext GetSILengthUnit(IHttpContext ctx)
        {
            if (ctx.Request.QueryString["sessionid"] == null)
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"missing parameter\"}");
                return(ctx);
            }

            XBimParser             parse    = GetSession(ctx.Request.QueryString["sessionid"]);
            string                 si       = parse.GetSILengthUnit();
            JsonSerializerSettings settings = new JsonSerializerSettings();

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\", \"unit\": \"" + si + "\"}");

            return(ctx);
        }
Exemple #7
0
        public IHttpContext GetShapesOfProduct(IHttpContext ctx)
        {
            if (ctx.Request.QueryString["sessionid"] == null || ctx.Request.QueryString["guid"] == null)
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"missing parameter\"}");
                return(ctx);
            }

            XBimParser             parse    = GetSession(ctx.Request.QueryString["sessionid"]);
            var                    objects  = parse.GetShapesOfProduct(ctx.Request.QueryString["guid"]);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(objects, Formatting.Indented, settings));

            return(ctx);
        }
Exemple #8
0
        public IHttpContext InsertTestProject(IHttpContext ctx)
        {
            MProject test = new MProject();

            test.ProjectVersion = 1337;
            test.Author         = "TestAuthor";
            test.ProjectName    = "A Testproject";
            test.Created        = DateTime.Now;
            test.LastChanged    = DateTime.Now;

            long id = SqliteDb.InsertProject(test);

            test.ProjectID = (int)id;

            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, JsonConvert.SerializeObject(test, Formatting.Indented));
            return(ctx);
        }
Exemple #9
0
        public IHttpContext LoadProject(IHttpContext ctx)
        {
            if (ctx.Request.QueryString["projectid"] == null)
            {
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"error\", \"reason\": \"not found\"}");
                return(ctx);
            }

            MProject   p        = SqliteDb.GetProject(Int32.Parse(ctx.Request.QueryString["projectid"]));
            XBimParser parsival = new XBimParser(p.FileName);

            parsival.LoadGeometry();
            if (parsival.HasLoaded())
            {
                sessions.Add(sessionCounter, parsival);
                HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\", \"session\": " + sessionCounter.ToString() + "}");
                sessionCounter++;
            }

            return(ctx);
        }
Exemple #10
0
        public IHttpContext PostProject(IHttpContext ctx)
        {
            if (ctx.Request.HasEntityBody)
            {
                int chunksize = 1024;
                using (Stream input = ((HttpRequest)ctx.Request).Advanced.InputStream)
                {
                    var parser = MultipartFormDataParser.Parse(input);

                    foreach (FilePart file in parser.Files)
                    {
                        using (BinaryReader reader = new BinaryReader(file.Data, ctx.Request.ContentEncoding))
                        {
                            string filename    = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + ".ifc";
                            string storagefile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Storage", filename);
                            using (BinaryWriter output = new BinaryWriter(File.Open(storagefile, FileMode.Create)))
                            {
                                byte[] chunk = reader.ReadBytes(chunksize);
                                while (chunk.Length > 0)
                                {
                                    output.Write(chunk);
                                    chunk = reader.ReadBytes(chunksize);
                                }
                            }

                            //ifc file available here
                            XBimParser xbparse = new XBimParser(storagefile);
                            MProject   mp      = xbparse.GetProject();
                            SqliteDb.InsertProject(mp);
                            HttpResponseExtensions.SendResponse(ctx.Response, HttpStatusCode.Ok, "{\"status\": \"success\"}");
                        }
                    }
                }
            }
            return(ctx);
        }