protected void Page_Load(object sender, EventArgs e) { //Path Settings if (Request.QueryString.Count == 0) { //W00ds1de337 //woodside Response.Redirect("RunModel.aspx?CaseName=SAMPLE2&ClientKey=OilWebDemo17&ModelType=OILSPILL&StartDate=20180911T22:00:00&simLength=24&WaterTemp=72.6F&IncLat=33.856999&IncLon=-118.541794&Winds=390&Currents=765&EcopWinds=GFS_WINDS&EcopCurrents=HYCOM_global_Navy_currents&Duration=6&Location=WORLD&&Volume=1000&group=7f22adb83ed7431f824df84a41a7f038&every1share=true&OilType=Heavy%20Crude%20Oil&OilUnits=5&FullPath=true&scriptid=Model2Shape&description=test&WNEID=Wanaea_Okha_FPSO&CMTID=Wanaea_Okha_FPSO");//&WNEID=Wanaea_Okha_FPSO&CMTID=Wanaea_Okha_FPSO } _sWebPath = Path.GetDirectoryName(Server.MapPath("ModelRunMapPath.txt")); _OutputFile = "ERROR: an unknown error has occured in Page_Load"; double timeout = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["ProccessTimeout"]); //Parse the Query String string qsProcessed = processQueryString(); if (qsProcessed != "") { Response.Write(qsProcessed); return; } if (!(Directory.Exists(_sWebPath + "\\ModelData\\LogFile"))) { Directory.CreateDirectory(_sWebPath + "\\ModelData\\LogFile"); } using (StreamWriter sw = new StreamWriter(_sWebPath + "\\ModelData\\LogFile\\LogFile.txt", true)) { sw.WriteLine(String.Format("{0},{1},{2}", DateTime.Now.ToString(), HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"], Request.QueryString.ToString())); } string sOutputPath = "\\ModelData\\" + _sLocation; CheckOutputPath(_sWebPath + sOutputPath); string sPrefixFile = _sWebPath + sOutputPath + "\\Winds\\Prefix.txt"; _sWindsPrefix = ""; if (File.Exists(sPrefixFile)) { _sWindsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["WindFilePrefix"]; } sPrefixFile = _sWebPath + sOutputPath + "\\Currents\\CurrentsPrefix.txt"; _sCurrentsPrefix = ""; if (File.Exists(sPrefixFile)) { _sCurrentsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["CurrentFilePrefix"]; } if (_bIsRivers) { sPrefixFile = _sWebPath + sOutputPath + "\\Currents\\RiverPrefix.txt"; if (File.Exists(sPrefixFile)) { _sCurrentsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["RiverCurrentFilePrefix"]; } } //Set up the aggregator EDSProcessor myProcessor = new EDSProcessor(); string windsStat = ""; //For WNE Winds if (_WNEWinds != "") { string sOutFilename = _sWebPath + sOutputPath + "\\winds\\" + _FileName + ".WNE"; string sDate = _StartDate.ToString("yyyy-MM-ddTHH:mm:ssZ"); string eDate = _EndDate.ToString("yyyy-MM-ddTHH:mm:ssZ"); string source_loc = "woodside_private"; string station_list_bom = "Truscott, Onslow_Airport,Barrow_Island_Airport,Lombadina_Airport,Kalumburu,Port_Keats_Aero,Browse_Island,Broome_Airport"; if (station_list_bom.Contains(_WNEWinds)) { source_loc = "woodside_bom"; } string wneURL = "https://data.oceansmap.com/model_data_service/get_data?start_time=" + sDate + "&end_time=" + eDate + "&station_id=" + _WNEWinds + "&type=WNE&token=gen_model_data&source_id=" + source_loc; using (var client = new WebClient()) { //"http://data.oceansmap.com/model_data_service/get_data?start_time=2018-09-08T00:00:00Z&end_time=2018-09-10T00:00:00Z&station_id=Kalumburu&type=WNE&source_id=woodside_bom&token=gen_model_data" client.DownloadFile(wneURL, sOutFilename); } windsStat = sOutFilename; string sWNLFile = Path.ChangeExtension(sOutFilename, ".WNL"); using (StreamWriter outfile = new StreamWriter(sWNLFile)) { outfile.WriteLine(_IncidentSite.lon.ToString() + " " + _IncidentSite.lat.ToString()); outfile.WriteLine(""); } } else if (_Winds == m_cLocal) { //Process the winds _AggEngine = new AggregatorEngine(_Winds, _StartDate, _EndDate, _AOI, _sWebPath, _sWebPath + sOutputPath + "\\WINDS\\", _bIsRivers); windsStat = _AggEngine.getWinds(_sWindsPrefix, _FileName); if (windsStat.Contains("ERROR")) { Response.Write(windsStat + " WINDS"); return; } } else if (_Winds == m_cConstant) { windsStat = _sWebPath + sOutputPath + "\\WINDS\\" + _FileName + ".WNE"; CreateWNEFile(windsStat, _WindMag, _WindDir); } else if (_Winds != m_cNoData) //EDS Winds { string sFilename = myProcessor.GetDataFile(_ClientKey, _Winds, _StartDate, _EndDate, _AOI); string sResult = myProcessor.GetStatus(sFilename); if (sResult == "COMPLETE") { string sOutFilename = _sWebPath + sOutputPath + "\\winds\\" + _FileName + ".NC"; myProcessor.DownloadDataFile(sOutFilename, sFilename); windsStat = sOutFilename; } else { windsStat = sResult; } if (!(File.Exists(windsStat))) { windsStat = ""; } } _AggEngine = null; //Process the currents string currStat = ""; //For CMT Currents if (_CMTCurrents != "") { string sOutFilename = _sWebPath + sOutputPath + "\\currents\\" + _FileName + ".CMT"; string sDate = _StartDate.ToString("yyyy-MM-ddTHH:mm:ssZ"); string eDate = _EndDate.ToString("yyyy-MM-ddTHH:mm:ssZ"); string cmtURL = "https://data.oceansmap.com/model_data_service/get_data?start_time=" + sDate + "&end_time=" + eDate + "&station_id=" + _CMTCurrents + "&type=CMT&source_id=woodside_private&token=gen_model_data"; using (var client = new WebClient()) { //"http://data.oceansmap.com/model_data_service/get_data?start_time=2018-03-04T00:00:00Z&end_time=2018-03-10T00:00:00Z&station_id=46088&type=CMT&source_id=ndbc" client.DownloadFile(cmtURL, sOutFilename); } currStat = sOutFilename; } else if (_Currents == m_cLocal) { if (_sCurrentsPrefix.ToUpper().Contains("STATIC")) { string[] sSplit = _sCurrentsPrefix.Split(new char[] { '-' }); currStat = _sWebPath + sOutputPath + "\\Currents\\" + sSplit[1]; } else { string currentsDataPath = _sWebPath; _AggEngine = new AggregatorEngine(_Currents, _StartDate, _EndDate, _AOI, _sWebPath, _sWebPath + sOutputPath + "\\Currents\\", _bIsRivers); currStat = _AggEngine.getCurrents(_sCurrentsPrefix, _FileName); if (currStat.Contains("ERROR")) { Response.Write(currStat + " CURRENTS"); return; } } } else if (_Currents == m_cConstant) { currStat = _sWebPath + sOutputPath + "\\Currents\\" + _FileName + ".CMT"; CreateCMTFile(currStat, _CurrMag, _CurrDir); } else if (_Currents != m_cNoData)//EDS { string sFilename = myProcessor.GetDataFile(_ClientKey, _Currents, _StartDate, _EndDate, _AOI); string sResult = myProcessor.GetStatus(sFilename); if (sResult == "COMPLETE") { string sOutFilename = _sWebPath + sOutputPath + "\\currents\\" + _FileName + ".NC"; myProcessor.DownloadDataFile(sOutFilename, sFilename); currStat = sOutFilename; } else { currStat = sResult; } if (!(File.Exists(currStat))) { currStat = ""; } } //Run the model _ModelProcessor = new ModelProcessor(_eModelType, timeout); if (_eModelType == ModelType.OilModel) { OilInputData oilInput = new OilInputData(_sWebPath, _sLocation); oilInput.bBox = _AOI; oilInput.caseName = _sCaseName; oilInput.incidentSite = _IncidentSite; oilInput.start = _StartDate; oilInput.end = _EndDate; oilInput.currentFile = currStat; oilInput.windsFile = windsStat; oilInput.ecopCurrents = _EcopCurrents; oilInput.ecopWinds = _EcopWinds; oilInput.fileName = _FileName; oilInput.spillDuration = _Duration; oilInput.SpillAmount = _SpillAmount; oilInput.SpillUnits = _OilUnits; oilInput.WaterTemp = _WaterTemp; oilInput.evaporationOn = _EvapOn ? 0 : -1; oilInput.entrainOn = _EntrainOn ? 0 : -1; // xp added oilInput.outputInterval = _OutputInterval; oilInput.modelStep = _ModelStep; oilInput.groupID = _groupIDShare; oilInput.every1 = _ShareEveryone; oilInput.description = _description; if (_ModelMethod) //fast { oilInput.timeStep = 60; } else //comprehensive { oilInput.timeStep = 10; } /*if (_Currents == m_cConstant) * { * oilInput.CurrMag = _CurrMag; * oilInput.CurrDir = _CurrDir; * } * else * { * oilInput.CurrMag = -999; * oilInput.CurrDir = -999; * }*/ oilInput.oilType = _OilType; /*if ((_Currents > 0) || (_Winds > 0)) * { * oilInput.coastLineFile = Path.GetDirectoryName(oilInput.coastLineFile) + "\\LANDPOLY.BDM"; * }*/ _OutputFile = _ModelProcessor.runOilModel(oilInput); } if (_eModelType == ModelType.ChemModel) { ChemInputData chemInput = new ChemInputData(_sWebPath, _sLocation); chemInput.bBox = _AOI; chemInput.caseName = _sCaseName; chemInput.incidentSite = _IncidentSite; chemInput.start = _StartDate; chemInput.end = _EndDate; chemInput.currentFile = currStat; chemInput.windsFile = windsStat; chemInput.fileName = _FileName; chemInput.chemType = _ChemType; chemInput.spillDuration = _Duration; chemInput.ModelMethod = _ModelMethod; /*if ((_Currents > 0) || (_Winds > 0)) * chemInput.coastLineFile = Path.GetDirectoryName(chemInput.coastLineFile) + "\\LANDPOLY.BDM";*/ _OutputFile = _ModelProcessor.runChemModel(chemInput); } //Rout the output to the user if (_OutputFile == "") { Response.Write("ERROR: An error occurred while running the model."); } else if (_OutputFile.Contains("ERROR:")) { Response.Write(_OutputFile); } else { if (Request.QueryString["FullPath"] != null) { if (Request.QueryString["FullPath"] == "true") { Response.Write("\\\\" + Environment.MachineName + "\\" + _sWebPath.Remove(0, 3) + sOutputPath + "\\Outdata\\" + _FileName + ".INP"); } else { Response.Write(_OutputFile); } } else { //Response.Write("\\\\" + Environment.MachineName + "\\" + _sWebPath.Remove(0, 3) + sOutputPath + "\\Outdata\\" + _OutputFile + ".INP"); Response.Write(_OutputFile); } //if (_AddToDB) // AddScenarioToDatabase(); } //testing with hardcoded version //string testCommand = @"F:\groups\rps_data\code\ds_oilmapweb\SyncModelRun\Push2ESRI\Model2Shape_v6.py " + @"F:\groups\rps_data\code\ds_oilmapweb\SyncModelRun\ModelData\WORLD\Outdata\SAMPLE_TEST_109_87799.inp F:\groups\rps_data\code\ds_oilmapweb\SyncModelRun\ModelData"; //convert the oilmap format to geodatabase string fileNameINP = _sWebPath + "\\" + sOutputPath + "\\Outdata\\" + _FileName + ".INP"; //_sCaseName //_StartDate //_SpillAmount //_OilType //_OilUnits //_SimLength TimeSpan t = _StartDate - new DateTime(1970, 1, 1); int secondsSinceEpoch = (int)t.TotalSeconds; string pyCommandInput = _sWebPath + @"\Push2ESRI\" + _scriptID + ".py " + fileNameINP + " " + _sCaseName + " " + secondsSinceEpoch + " " + _SimLength + " " + _SpillAmount + " " + _OilUnits + " \"" + _OilType + "\"" + " \"" + _description + "\""; string sPythonPath = ""; string sArcVersion = "10.3"; Platform myPlatform = GetPlatform(); switch (myPlatform) { case Platform.X64: sPythonPath = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\ESRI\\Python" + sArcVersion, "PythonDir", ""); break; default: sPythonPath = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ESRI\\Python" + sArcVersion, "PythonDir", ""); break; } //this may be in a different location so best to check all enviormental variables are correct //string pyLoc = "\"" + sPythonPath + "ArcGIS" + sArcVersion + "\\python.exe\""; string pyLoc = @"C:\Python27\ArcGISx6410.5\python.exe"; //for deploy on server Push2ESRI(pyLoc, pyCommandInput); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Count != 0) { Response.Redirect("RunModel.aspx?" + Request.QueryString.ToString()); } //Path Settings else { //W00ds1de337 Response.Redirect("RunModel.aspx?CaseName=SAMPLE_TEST3&ClientKey=OilWebDemo17&ModelType=OILSPILL&StartDate=20170501T12:00:00&simLength=24&WaterTemp=72.6F&IncLat=33.856999&IncLon=-118.541794&Winds=390&Currents=765&EcopWinds=GFS_WINDS&EcopCurrents=HYCOM_global_Navy_currents&Duration=6&Location=WORLD&&Volume=1000&group=7f22adb83ed7431f824df84a41a7f038&every1share=true&OilType=Heavy%20Crude%20Oil&OilUnits=5&FullPath=true&scriptid=Model2Shape&description=test"); } _sWebPath = Path.GetDirectoryName(Server.MapPath("ModelRunMapPath.txt")); _OutputFile = "ERROR: an unknown error has occured in Page_Load"; double timeout = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["ProccessTimeout"]); //Parse the Query String string qsProcessed = processQueryString(); if (qsProcessed != "") { Response.Write(qsProcessed); return; } if (!(Directory.Exists(_sWebPath + "\\ModelData\\LogFile"))) { Directory.CreateDirectory(_sWebPath + "\\ModelData\\LogFile"); } using (StreamWriter sw = new StreamWriter(_sWebPath + "\\ModelData\\LogFile\\LogFile.txt", true)) { sw.WriteLine(String.Format("{0},{1},{2}", DateTime.Now.ToString(), HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"], Request.QueryString.ToString())); } string sOutputPath = "\\ModelData\\" + _sLocation; CheckOutputPath(_sWebPath + sOutputPath); string sPrefixFile = _sWebPath + sOutputPath + "\\Winds\\Prefix.txt"; if (File.Exists(sPrefixFile)) { _sWindsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["WindFilePrefix"]; } sPrefixFile = _sWebPath + sOutputPath + "\\Currents\\CurrentsPrefix.txt"; if (File.Exists(sPrefixFile)) { _sCurrentsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["CurrentFilePrefix"]; } //if (_bIsRivers) //{ // sPrefixFile = _sWebPath + sOutputPath + "\\Currents\\RiverPrefix.txt"; //if (File.Exists(sPrefixFile)) // _sCurrentsPrefix = File.ReadAllText(sPrefixFile); //System.Configuration.ConfigurationManager.AppSettings["RiverCurrentFilePrefix"]; //} //Set up the aggregator EDSProcessor myProcessor = new EDSProcessor(); string windsStat = ""; if (_Winds == m_cLocal) { //Process the winds _AggEngine = new AggregatorEngine(_Winds, _StartDate, _EndDate, _AOI, _sWebPath, _sWebPath + sOutputPath + "\\WINDS\\", _bIsRivers); windsStat = _AggEngine.getWinds(_sWindsPrefix, _FileName); if (windsStat.Contains("ERROR")) { Response.Write(windsStat + " WINDS"); return; } } else if (_Winds == m_cConstant) { windsStat = _sWebPath + sOutputPath + "\\WINDS\\" + _FileName + ".WNE"; CreateWNEFile(windsStat, _WindMag, _WindDir); } else if (_Winds != m_cNoData) //EDS Winds { string sFilename = myProcessor.GetDataFile(_ClientKey, _Winds, _StartDate, _EndDate, _AOI); string sResult = myProcessor.GetStatus(sFilename); if (sResult == "COMPLETE") { string sOutFilename = _sWebPath + sOutputPath + "\\winds\\" + _FileName + ".NC"; myProcessor.DownloadDataFile(sOutFilename, sFilename); windsStat = sFilename; } else { windsStat = sResult; } } _AggEngine = null; //Process the currents string currStat = ""; if (_Currents == m_cLocal) { string currentsDataPath = _sWebPath; _AggEngine = new AggregatorEngine(_Currents, _StartDate, _EndDate, _AOI, _sWebPath, _sWebPath + sOutputPath + "\\Currents\\", _bIsRivers); currStat = _AggEngine.getCurrents(_sCurrentsPrefix, _FileName); if (currStat.Contains("ERROR")) { Response.Write(currStat + " CURRENTS"); return; } } else if (_Currents == m_cConstant) { currStat = ""; } else if (_Currents != m_cNoData) { string sFilename = myProcessor.GetDataFile(_ClientKey, _Currents, _StartDate, _EndDate, _AOI); string sResult = myProcessor.GetStatus(sFilename); if (sResult == "COMPLETE") { string sOutFilename = _sWebPath + sOutputPath + "\\currents\\" + _FileName + ".NC"; myProcessor.DownloadDataFile(sOutFilename, sFilename); currStat = sFilename; } else { currStat = sResult; } } //Run the model _ModelProcessor = new ModelProcessor(_eModelType, timeout); if (_eModelType == ModelType.OilModel) { OilInputData oilInput = new OilInputData(_sWebPath, _sLocation); oilInput.bBox = _AOI; oilInput.caseName = _sCaseName; oilInput.incidentSite = _IncidentSite; oilInput.start = _StartDate; oilInput.end = _EndDate; oilInput.currentFile = currStat; oilInput.windsFile = windsStat; oilInput.ecopCurrents = _EcopCurrents; oilInput.ecopWinds = _EcopWinds; oilInput.fileName = _FileName; oilInput.spillDuration = _Duration; oilInput.SpillAmount = _SpillAmount; oilInput.SpillUnits = _OilUnits; oilInput.WaterTemp = _WaterTemp; oilInput.groupID = _groupIDShare; oilInput.every1 = _ShareEveryone; if (_ModelMethod) //fast { oilInput.timeStep = 60; } else //comprehensive { oilInput.timeStep = 10; } if (_Currents == m_cConstant) { oilInput.CurrMag = _CurrMag; oilInput.CurrDir = _CurrDir; } else { oilInput.CurrMag = -999; oilInput.CurrDir = -999; } oilInput.oilType = _OilType; /*if ((_Currents > 0) || (_Winds > 0)) * { * oilInput.coastLineFile = Path.GetDirectoryName(oilInput.coastLineFile) + "\\LANDPOLY.BDM"; * }*/ _OutputFile = _ModelProcessor.runOilModel(oilInput); } if (_eModelType == ModelType.ChemModel) { ChemInputData chemInput = new ChemInputData(_sWebPath, _sLocation); chemInput.bBox = _AOI; chemInput.caseName = _sCaseName; chemInput.incidentSite = _IncidentSite; chemInput.start = _StartDate; chemInput.end = _EndDate; chemInput.currentFile = currStat; chemInput.windsFile = windsStat; chemInput.fileName = _FileName; chemInput.chemType = _ChemType; chemInput.spillDuration = _Duration; chemInput.ModelMethod = _ModelMethod; /*if ((_Currents > 0) || (_Winds > 0)) * chemInput.coastLineFile = Path.GetDirectoryName(chemInput.coastLineFile) + "\\LANDPOLY.BDM";*/ _OutputFile = _ModelProcessor.runChemModel(chemInput); } //Rout the output to the user if (_OutputFile != "") { if (Request.QueryString["FullPath"] != null) { if (Request.QueryString["FullPath"] == "true") { Response.Write("\\\\" + Environment.MachineName + "\\" + _sWebPath.Remove(0, 3) + sOutputPath + "\\Outdata\\" + _OutputFile + ".INP"); } else { Response.Write(_OutputFile); } } else { //Response.Write("\\\\" + Environment.MachineName + "\\" + _sWebPath.Remove(0, 3) + sOutputPath + "\\Outdata\\" + _OutputFile + ".INP"); Response.Write(_OutputFile); } } else { Response.Write("ERROR: An error occurred while running the model."); } }