예제 #1
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);
        }
예제 #2
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);
        }