Exemplo n.º 1
0
 public HttpResponseMessage DownloadStart()
 {
     try
     {
         //读取配置
         string              path        = System.AppDomain.CurrentDomain.BaseDirectory + "config\\fieldInfs.txt";
         string              c           = File.ReadAllText(path);
         List <R_FieldInf>   fieldInfs   = JsonConvert.DeserializeObject <List <R_FieldInf> >(c);
         string              path2       = System.AppDomain.CurrentDomain.BaseDirectory + "config\\mapping.txt";
         string              d           = File.ReadAllText(path2);
         Models.FieldMapping vitalFields = JsonConvert.DeserializeObject <Models.FieldMapping>(d);
         //
         CommonServices commonServices = new CommonServices();
         string         otherTypes     = commonServices.GetOtherType(fieldInfs, vitalFields);
         //
         ESServices    eSServices = new ESServices();
         ElasticClient client     = eSServices.Connect_ES();
         string[]      pointsJson = eSServices.GetAllPoints(client, vitalFields, otherTypes);
         //
         string       fguid  = Guid.NewGuid().ToString();
         string       path3  = System.AppDomain.CurrentDomain.BaseDirectory + "\\Download\\" + fguid;
         MemoryStream stream = commonServices.CreateShpZipStream(path3, pointsJson);
         commonServices.DeleteZipFile(path3);
         //下载文件
         HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
         response.Content = new StreamContent(stream);
         response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
         response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
         {
             FileName = "result.zip"
         };
         return(response);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message));
         //return new HttpResponseMessage(HttpStatusCode.NoContent);
     }
     finally
     {
     }
 }
Exemplo n.º 2
0
        public ActionResult CreateIndex(Models.FieldMapping _vitalFields)
        {
            VitalFields = _vitalFields;

            //将映射转为json存入config
            JsonSerializer serializer = new JsonSerializer();
            StringWriter   sw         = new StringWriter();

            serializer.Serialize(new JsonTextWriter(sw), VitalFields);
            string       mapping = sw.GetStringBuilder().ToString();
            string       path    = System.AppDomain.CurrentDomain.BaseDirectory + "config\\mapping.txt";
            FileStream   fs1     = new FileStream(path, FileMode.Create, FileAccess.Write);//创建写入文件
            StreamWriter Asss    = new StreamWriter(fs1);

            Asss.WriteLine(mapping);//开始写入值
            Asss.Close();
            fs1.Close();
            //将OtherTemplate保存进配置
            CommonServices common        = new CommonServices();
            string         OtherTemplate = common.GetOtherTemplate(FieldInfs, VitalFields);
            string         path2         = System.AppDomain.CurrentDomain.BaseDirectory + "config\\OtherTemplate.txt";
            FileStream     fs2           = new FileStream(path2, FileMode.Create, FileAccess.Write);//创建写入文件
            StreamWriter   Asss2         = new StreamWriter(fs2);

            Asss2.WriteLine(OtherTemplate);//开始写入值
            Asss2.Close();
            fs2.Close();
            //
            ESServices    eSServices = new ESServices();
            ElasticClient client     = eSServices.Connect_ES();

            eSServices.CreateIndex(client);
            ShpOperations      shpOperations = new ShpOperations();
            string             DbfPath       = "C:\\testdata\\Address_SpatialJoin2new.dbf";
            List <InputFields> inputFields   = new List <InputFields>();

            inputFields = shpOperations.GetFieldValues(FieldInfs, VitalFields, DbfPath);
            eSServices.PutDoc(inputFields, client);
            return(RedirectToAction("Index"));
        }