예제 #1
0
        public JsonResult Register()
        {
            string    toolfile = Server.MapPath(PANO_TOOL_EXE);
            PanoMaker maker    = new PanoMaker();
            bool      success  = maker.Register(toolfile);

            if (success)
            {
                return(Json(new { code = 0, message = "注册成功." }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { code = 101, message = "注册失败." }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public JsonResult Build(string uid, string name, string category, long date, int heading, double lat, double lng, string author, string remark)
        {
            try {
                //
                string imagefile = string.Format("{0}\\{1}.JPG", Server.MapPath(PANO_TEMP_PATH), uid);
                if (System.IO.File.Exists(imagefile) == false)
                {
                    throw new Exception("无效的UID: " + uid);
                }
                string toolfile = Server.MapPath(PANO_TOOL_EXE);
                // 切图
                string    message  = "";
                string    scenexml = "";
                string    root     = "";
                string[]  tiles    = new string[0];
                PanoMaker maker    = new PanoMaker();
                bool      success  = maker.MakeNormal(toolfile, imagefile, 100, out message, out scenexml, out tiles, out root);
                if (success == false)
                {
                    throw new Exception(message);
                }
                // 时间戳转换
                DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                DateTime time  = start.Add(new TimeSpan(date * 10000000));
                // epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000

                // 入库
                PanoItem panoItem = new PanoItem()
                {
                    uid      = uid,
                    name     = name,
                    category = category,
                    shottime = time,
                    heading  = heading,
                    lat      = lat,
                    lng      = lng,
                    author   = author,
                    remark   = remark,
                    maketime = DateTime.Now
                };
                SceneItem sceneItem = new SceneItem()
                {
                    uid   = uid,
                    scene = scenexml
                };

                string sql1 = "insert into PANOS(uid, name, category, shottime, heading, lat, lng, author, remark, maketime) " +
                              "values(@uid, @name, @category, @shottime, @heading, @lat, @lng, @author, @remark, @maketime)";
                string sql2 = "insert into PANOSSCENE(uid, scene) " +
                              "values(@uid, @scene)";
                SQLiteConnection conn = new SQLiteConnection(_connstr);
                conn.Open();
                int result1 = conn.Execute(sql1, panoItem);             // 插入
                int result2 = conn.Execute(sql2, sceneItem);            // 插入
                conn.Close();

                // 存储瓦片数据 碎片直接放磁盘上 放数据库访问起来会有点慢
                foreach (string tile in tiles)
                {
                    string tileroot = Server.MapPath(PANO_TILE_PATH);
                    string tilename = System.IO.Path.GetFileName(tile);
                    string tilepath = System.IO.Path.GetDirectoryName(tile).ToLower().Replace(root.ToLower(), "");
                    string tilesave = tileroot + "//" + tilepath;
                    string tilefile = tilesave + "//" + tilename;
                    if (System.IO.Directory.Exists(tilesave) == false)
                    {
                        System.IO.Directory.CreateDirectory(tilesave);
                    }
                    System.IO.File.Move(tile, tilefile);
                }

                // 保存图片 和 基本信息
                string imagesave = string.Format("{0}\\{1}.JPG", Server.MapPath(PANO_SAVE_PATH), uid);
                System.IO.File.Move(imagefile, imagesave);
                StreamWriter writer = new StreamWriter(string.Format("{0}\\{1}.TXT", Server.MapPath(PANO_SAVE_PATH), uid));
                writer.WriteLine("uid:" + panoItem.uid.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("name:" + panoItem.name.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("category:" + panoItem.category.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("shottime:" + panoItem.shottime.ToString("yyyy/MM/dd HH:mm:ss"));
                writer.WriteLine("heading:" + panoItem.heading.ToString());
                writer.WriteLine("lat:" + panoItem.lat.ToString());
                writer.WriteLine("lng:" + panoItem.lng);
                writer.WriteLine("author:" + panoItem.author.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("remark:" + panoItem.remark.Replace("\r\n", "\\r\\n"));
                writer.WriteLine("maketime:" + panoItem.maketime.ToString("yyyy/MM/dd HH:mm:ss"));
                writer.Flush();
                writer.Close();

                // 删除成图临时目录
                string outputdir = string.Format("{0}\\{1}", Server.MapPath(PANO_TEMP_PATH), uid);
                System.IO.Directory.Delete(outputdir, true);

                return(Json(new { code = 0, success = true, uid = uid, message = "" }));
            }
            catch (Exception ex) {
                return(Json(new { code = 101, success = false, uid = "", message = ex.Message }));
            }
        }