ricardo valls 3 lat temu
rodzic
commit
1a2b39b56e

+ 2 - 1
WorkerService1/WebApplication3/Clases/Constants.cs Wyświetl plik

@@ -24,7 +24,8 @@ namespace WebApplication3.Clases
24 24
             { "8", "#266A2E" }
25 25
         };
26 26
         public const string SVGFileName = "vector_image.svg";
27
+        public const string SVGGeoJson = "geoimage.svg";
27 28
         public const string PNGFileName = "color_map.png";
28
-        public const string GeoJsonFileName = "vector_image.geojson";
29
+        public const string GeoJsonFileName = "geoimage.geojson";
29 30
     }
30 31
 }

+ 21 - 1
WorkerService1/WebApplication3/Clases/Parser.cs Wyświetl plik

@@ -632,7 +632,7 @@ namespace WebApplication3.Clases
632 632
             return piezometria;
633 633
         }
634 634
 
635
-        public void GetGeolocalizationFromFile(string file,out string worldX,out string worldY)
635
+        public void GetGeolocalizationFromFile(string file,out string worldX,out string worldY, out string angle, out string length, out string heigth)
636 636
         {
637 637
 
638 638
             string text = File.ReadAllText(file);
@@ -644,10 +644,17 @@ namespace WebApplication3.Clases
644 644
             string[] geolocation_data = geolocation_line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
645 645
             string[] world_origin_x = geolocation_data[3].Split("World_Origin_X=", StringSplitOptions.RemoveEmptyEntries);
646 646
             string[] world_origin_y = geolocation_data[4].Split("World_Origin_Y=", StringSplitOptions.RemoveEmptyEntries);
647
+            string[] modelAngle = geolocation_data[5].Split("Angle=", StringSplitOptions.RemoveEmptyEntries);
648
+            string[] modelLength = geolocation_data[6].Split("Length=", StringSplitOptions.RemoveEmptyEntries);
649
+            string[] modelHeigth = geolocation_data[7].Split("Height=", StringSplitOptions.RemoveEmptyEntries);
647 650
 
648 651
 
649 652
             worldX = world_origin_x[0].Replace("\"", string.Empty);
650 653
             worldY = world_origin_y[0].Replace("\"", string.Empty);
654
+            angle = modelAngle[0].Replace("\"",string.Empty);
655
+            length = modelLength[0].Replace("\"", string.Empty);
656
+            heigth = modelHeigth[0].Replace("\"", string.Empty);
657
+
651 658
         }
652 659
 
653 660
         public WellData[] parseWellCSV(string file)
@@ -828,5 +835,18 @@ namespace WebApplication3.Clases
828 835
 
829 836
             return piezometerDatas.ToArray();
830 837
         }
838
+
839
+        public bool ModflowError(string file)
840
+        {
841
+            
842
+            string text = File.ReadAllText(file).ToLower();
843
+
844
+            if (!text.Contains("error"))
845
+            {
846
+                return false;
847
+            }
848
+
849
+            return true;
850
+        }
831 851
     }
832 852
 }

+ 29 - 0
WorkerService1/WebApplication3/Clases/Utilities.cs Wyświetl plik

@@ -69,5 +69,34 @@ namespace WebApplication3.Clases
69 69
                 }
70 70
             }
71 71
         }
72
+        public static bool ModifySVG(string fileOriginal, string x, string y, string length, string height, string destinationFile)
73
+        {
74
+            string text = File.ReadAllText(fileOriginal);
75
+            bool result = true;
76
+
77
+            List<string> textLines = text.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).ToList();
78
+
79
+            string aux = textLines.Find(x => x.Contains("metadata"));
80
+
81
+            if (aux != null)
82
+            {
83
+                try
84
+                {
85
+                    float latitude = float.Parse(x) + float.Parse(length);
86
+                    float longitude = float.Parse(y) + float.Parse(height);
87
+                    int index = textLines.IndexOf(aux);
88
+                    textLines[index] += "\r\n	<MetaInfo xmlns=\"http://www.prognoz.ru\">\r\n          < Geo >\r\n             < GeoItem X = \"" + 0 + "\" Y = \"" + 0 + "\" Latitude = \"" + x + "\" Longitude = \"" + y + "\" />                          < GeoItem X = \"" + x + "\" Y = \"" + y + "\" Latitude = \"" + latitude + "\" Longitude = \"" + longitude + "\" />\r\n          </ Geo >\r\n	</ MetaInfo > ";
89
+                    File.WriteAllLines(destinationFile, textLines);
90
+                }
91
+                catch(Exception ex)
92
+                {
93
+                    Logger.WriteLog(ex.Message);
94
+                    Logger.WriteLog(ex.InnerException.Message);
95
+                    result = false; ;
96
+                }
97
+            }
98
+
99
+            return result;
100
+        }
72 101
     }
73 102
 }

+ 16 - 13
WorkerService1/WebApplication3/Controllers/AcuiferoController.cs Wyświetl plik

@@ -159,17 +159,17 @@ namespace WebApplication3.Controllers
159 159
         [HttpPost("TestBinary")]
160 160
         public bool TestBinario([FromBody] DatosPostAcuifero datos)
161 161
         {
162
-            string file = Constants.PathZip + "test.zip";
163
-            Utilities.BinaryToFile(datos.Fichero.Test, file);
164
-
165
-            if (System.IO.File.Exists(file)) 
166
-            {
167
-                return true;
168
-            }
169
-            else
170
-            {
171
-                return false;
172
-            }
162
+            //string file = Constants.PathZip + "test.zip";
163
+            //Utilities.BinaryToFile(datos.Fichero.Test, file);
164
+            return true;
165
+            //if (System.IO.File.Exists(file)) 
166
+            //{
167
+            //    return true;
168
+            //}
169
+            //else
170
+            //{
171
+            //    return false;
172
+            //}
173 173
 
174 174
         }
175 175
         // POST: api/Acuifero
@@ -210,12 +210,15 @@ namespace WebApplication3.Controllers
210 210
                 //1.2 - Obtencion de coordenadas de origen (en el mundo) del modelo
211 211
                 string geoFile = files.Find(x => x.Contains(".vmf"));
212 212
                 Logger.WriteLog("geofile " + geoFile);
213
-                string world_origin_x, world_origin_y;
213
+                string world_origin_x, world_origin_y, angle, length, height;
214 214
 
215
-                parser.GetGeolocalizationFromFile(geoFile, out world_origin_x, out world_origin_y);
215
+                parser.GetGeolocalizationFromFile(geoFile, out world_origin_x, out world_origin_y, out angle, out length, out height);
216 216
 
217 217
                 acuifero.WorldOriginX = world_origin_x;
218 218
                 acuifero.WorldOriginY = world_origin_y;
219
+                acuifero.Angle = angle;
220
+                acuifero.Length = length;
221
+                acuifero.Height = height;
219 222
 
220 223
                 _context.Acuiferos.Add(acuifero);
221 224
                 await _context.SaveChangesAsync();

+ 31 - 0
WorkerService1/WebApplication3/Controllers/ServiceQueueController.cs Wyświetl plik

@@ -120,6 +120,37 @@ namespace WebApplication3.Controllers
120 120
             return CreatedAtAction("GetQueueItem", new { id = serviceQueueItem.Id }, serviceQueueItem);
121 121
         }
122 122
 
123
+        [NonAction]
124
+        public async Task<ActionResult<ServiceQueue>> SetError(uint id)
125
+        {
126
+            var serviceQueueItem = await _context.ServiceQueue.FindAsync(id);
127
+
128
+            serviceQueueItem.Error = 1;
129
+            serviceQueueItem.Corriendo = 0;
130
+            serviceQueueItem.Terminado = 1;
131
+            serviceQueueItem.Fin = DateTime.Now.ToString();
132
+
133
+            _context.Entry(serviceQueueItem).State = EntityState.Modified;
134
+
135
+            try
136
+            {
137
+                await _context.SaveChangesAsync();
138
+            }
139
+            catch (DbUpdateConcurrencyException)
140
+            {
141
+                if (!ServiceQueueExists(id))
142
+                {
143
+                    return NotFound();
144
+                }
145
+                else
146
+                {
147
+                    throw;
148
+                }
149
+            }
150
+
151
+            return CreatedAtAction("GetQueueItem", new { id = serviceQueueItem.Id }, serviceQueueItem);
152
+        }
153
+
123 154
 
124 155
         // POST: api/ServiceQueue
125 156
         // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754

+ 25 - 6
WorkerService1/WebApplication3/Controllers/SimulacionController.cs Wyświetl plik

@@ -221,6 +221,7 @@ namespace WebApplication3.Controllers
221 221
 
222 222
             uint simulacionId = (uint)serviceQueue.IdSimulacion;
223 223
             Simulacion simulacion = _context.Simulaciones.Find(simulacionId);
224
+            Acuifero aquifer = _context.Acuiferos.Find(simulacion.IdAcuifero);
224 225
 
225 226
             //Obtenemos el nombre de fichero original del acuifero
226 227
             string zip = acuiferoController.GetFicheroZip((uint)simulacion.IdAcuifero);
@@ -363,6 +364,15 @@ namespace WebApplication3.Controllers
363 364
                 Thread.Sleep(5000);
364 365
                 Logger.WriteLog("fin modflow");
365 366
 
367
+                string modelResultsFile = files.Find(x => x.Contains(".LST"));
368
+
369
+                if (parser.ModflowError(modelResultsFile))
370
+                {
371
+                    Logger.WriteLog("El fichero LST para la simulacion con id interno "+simulacion.Id+" tiene error");
372
+                    await serviceQueueController.SetError(serviceQueue.Id);
373
+                    return true;
374
+                }
375
+
366 376
                 //6.Ejecucion Zonebudget
367 377
                 //Seguidamente miramos el fichero de resultado de zonas (si existe)
368 378
                 if (zoneFile != null && System.IO.File.Exists(zoneFile))
@@ -382,7 +392,6 @@ namespace WebApplication3.Controllers
382 392
                 files = Directory.GetFiles(workingDirectory).ToList<string>();
383 393
 
384 394
                 string zoneResultsFile = files.Find(x => x.Contains(".zblst"));
385
-                string modelResultsFile = files.Find(x => x.Contains(".LST"));
386 395
                 string piezometryFile = files.Find(x => x.Contains(".HDS"));
387 396
 
388 397
                 //Parseo del fichero de balance hidrico por zonas
@@ -477,16 +486,26 @@ namespace WebApplication3.Controllers
477 486
                 /*
478 487
                  * se transforma la imagen vectorial obtenida anteriormente para transformarla en un geojson
479 488
                  */
480
-                string svgFile = workingDirectory + Constants.SVGFileName;
481
-                await serviceController.GetGeoJsonFromSVG(workingDirectory, svgFile);
482
-
483
-                await SetGeoJson(simulacionId, workingDirectory+Constants.GeoJsonFileName);
489
+                string svgFileOriginal = workingDirectory + Constants.SVGFileName;
490
+                string svgModifiedFile = workingDirectory + Constants.SVGGeoJson;
491
+                string geoJsonFile = workingDirectory + Constants.GeoJsonFileName;
492
+                if (System.IO.File.Exists(svgFileOriginal))
493
+                {
494
+                    if (Utilities.ModifySVG(svgFileOriginal, aquifer.WorldOriginX, aquifer.WorldOriginY, aquifer.Length, aquifer.Height, svgModifiedFile))
495
+                    {
496
+                        await serviceController.GetGeoJsonFromSVG(workingDirectory, svgModifiedFile);
497
+                        if (System.IO.File.Exists(geoJsonFile))
498
+                        {
499
+                            await SetGeoJson(simulacionId, geoJsonFile);
500
+                        }
501
+                    }
502
+                }
484 503
                 
485 504
                 await serviceQueueController.SetTerminado(serviceQueue.Id);
486 505
                 Logger.WriteLog("terminado");
487 506
                 try
488 507
                 {
489
-                    System.IO.Directory.Delete(workingDirectory);
508
+                    Directory.Delete(workingDirectory);
490 509
                 }catch(Exception ex)
491 510
                 {
492 511
                     Logger.WriteLog(ex.Message);

+ 3 - 0
WorkerService1/WebApplication3/Models/Acuifero.cs Wyświetl plik

@@ -12,6 +12,9 @@ namespace WebApplication3.Models
12 12
         public string Fichero { get; set; }
13 13
         public string WorldOriginX { get; set; }
14 14
         public string WorldOriginY { get; set; }
15
+        public string Angle { get; set; }
16
+        public string Length { get; set; }
17
+        public string Height { get; set; }
15 18
         public string RechargeGeometry { get; set; }
16 19
         public string RechargeColorMap { get; set; }
17 20
 

+ 3 - 0
WorkerService1/WebApplication3/Models/AquiferContext.cs Wyświetl plik

@@ -74,6 +74,9 @@ namespace WebApplication3.Models
74 74
 
75 75
                 entity.Property(e => e.WorldOriginX).HasColumnName("world_origin_x");
76 76
                 entity.Property(e => e.WorldOriginY).HasColumnName("world_origin_y");
77
+                entity.Property(e => e.Angle).HasColumnName("angle");
78
+                entity.Property(e => e.Length).HasColumnName("length");
79
+                entity.Property(e => e.Height).HasColumnName("height");
77 80
                 entity.Property(e => e.RechargeGeometry).HasColumnName("recharge_geometry");
78 81
                 entity.Property(e => e.RechargeColorMap).HasColumnName("recharge_color_map");
79 82
 

+ 6 - 0
WorkerService1/WebApplication3/Program.cs Wyświetl plik

@@ -32,15 +32,21 @@ namespace WebApplication3
32 32
                     services.AddLogging();
33 33
                     services.AddHostedService<Worker>();
34 34
                     services.AddHostedService<QueueWorker>();
35
+
35 36
                 })
36 37
                 .ConfigureWebHostDefaults( webBuilder =>
37 38
                 {
38 39
                     webBuilder.UseStartup<Startup>();
40
+                    webBuilder.UseHttpSys(options =>
41
+                    {
42
+                        options.MaxRequestBodySize = 300_000_000;
43
+                    });
39 44
 
40 45
                 } ).ConfigureWebHost( config =>
41 46
                 {
42 47
                     config.UseUrls( "http://*:5050" );
43 48
 
49
+
44 50
                 } ).UseWindowsService();
45 51
 
46 52
     }

+ 5 - 1
WorkerService1/WebApplication3/Startup.cs Wyświetl plik

@@ -13,7 +13,7 @@ using System.Linq;
13 13
 using System.Threading.Tasks;
14 14
 using Microsoft.EntityFrameworkCore;
15 15
 using WebApplication3.Models;
16
-
16
+using Microsoft.AspNetCore.Http.Features;
17 17
 
18 18
 namespace WebApplication3
19 19
 {
@@ -32,6 +32,7 @@ namespace WebApplication3
32 32
         // This method gets called by the runtime. Use this method to add services to the container.
33 33
         public void ConfigureServices( IServiceCollection services )
34 34
         {
35
+                     
35 36
             services.AddDbContext<AquiferContext>(opt =>
36 37
                        opt.UseMySql(Configuration.GetConnectionString("AquiferDatabase"), Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.24-mysql"))
37 38
             );
@@ -41,11 +42,13 @@ namespace WebApplication3
41 42
              {
42 43
                  c.SwaggerDoc( "v1", new OpenApiInfo { Title = "WebApplication3", Version = "v1" } );
43 44
              } );
45
+
44 46
         }
45 47
 
46 48
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
47 49
         public void Configure( IApplicationBuilder app, IWebHostEnvironment env )
48 50
         {
51
+            
49 52
             if( env.IsDevelopment() )
50 53
             {
51 54
                 app.UseDeveloperExceptionPage();
@@ -63,6 +66,7 @@ namespace WebApplication3
63 66
              {
64 67
                  endpoints.MapControllers();
65 68
              } );
69
+
66 70
         }
67 71
     }
68 72
 }