using System.Collections.Generic; using System.IO; using System.Web.Services; using MathWorks.MATLAB.NET.Arrays; namespace BwnMatLab { /// /// Summary description for BwnFunctionsWrapper /// [WebService(Namespace = "http://viewer.openearth.nl/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class BwnFunctionsWrapper : WebService { private const string OutputDir = "/Output/"; private readonly string outputPath; private readonly BwnFunctions.BwnFunctions libraryInitializor = new BwnFunctions.BwnFunctions(); public BwnFunctionsWrapper() { outputPath = Server.MapPath("~") + OutputDir; libraryInitializor.Initialize(); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } } [WebMethod] public string InterpolateToLine(string ncFilePath, string ncVariableName, double centreLatitude, double centreLongitude, double vertexLatitude, double vertexLongitude) { var fullFilePath = libraryInitializor.InterpolateToLine( ncFilePath, ncVariableName, new MWNumericArray(new[] {centreLatitude, centreLongitude}), new MWNumericArray(new[] {vertexLatitude, vertexLongitude}), outputPath).ToString(); return OutputDir + Path.GetFileName(fullFilePath); } [WebMethod] public string PlotTimeSeries(string ncFilePath, string ncVariableName, string startDay, string startTime, string stopDay, string stopTime) { var fullFilePath =libraryInitializor.PlotTimeSeries( ncFilePath,ncVariableName,startDay,startTime,stopDay,stopTime,outputPath) .ToString(); return OutputDir + Path.GetFileName(fullFilePath); } [WebMethod] public string[] WaveTransformationTable(double lon, double lat,string startDay, string startTime,string stopDay, string stopTime) { var files = new List(); var filePaths = libraryInitializor.WaveTransformationTable(startDay, startTime, stopDay, stopTime, lon, lat, outputPath); for (var i = 1; i <= filePaths.NumberOfElements; i++) { files.Add(OutputDir + Path.GetFileName(filePaths[1,i].ToString())); } return files.ToArray(); } protected override void Dispose(bool disposing) { if (disposing) { libraryInitializor.Dispose(); } // todo: remove all temp files in output dir base.Dispose(disposing); } } }