void IExport.Run() { try { this.theLogger.Log("Export:Run"); AMS.Profile.Ini Ini = new AMS.Profile.Ini(AppDomain.CurrentDomain.BaseDirectory + "AgkExportSettings.ini"); if (!Ini.HasSection("COMMON")) { Ini.SetValue("COMMON", "AgkDataFolder", "C:\\Данные_АГК"); Ini.SetValue("COMMON", "CountPrevMonth", "1"); } string strAgkDataFolder = Ini.GetValue("COMMON", "AgkDataFolder", "C:\\Данные_АГК"); int countPrevMonth = Ini.GetValue("COMMON", "CountPrevMonth", 1); strAgkDataFolder.TrimEnd(new char[] { '\\' }); if (!Directory.Exists(strAgkDataFolder)) { Directory.CreateDirectory(strAgkDataFolder); } Hydro.HydroServiceClient theHydro = new Hydro.HydroServiceClient("BasicHttpBinding_IHydroService"); const int TYPE_AGK = 6; foreach (var Site in theHydro.GetSiteList(TYPE_AGK)) { string strSiteFolder = strAgkDataFolder + "\\" + Site.SiteCode.ToString(); if (!Directory.Exists(strSiteFolder)) { Directory.CreateDirectory(strSiteFolder); theLogger.Log(strSiteFolder); } strSiteFolder = strSiteFolder + "\\уровни"; if (!Directory.Exists(strSiteFolder)) { Directory.CreateDirectory(strSiteFolder); theLogger.Log(strSiteFolder); } DateTime bgnDate = new DateTime(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month, countPrevMonth); DateTime endDate = new DateTime(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month, DateTime.DaysInMonth(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month)); const int WATER_LEVEL = 2; string strFileName = strSiteFolder + "\\" + Site.SiteCode.ToString() + "_" + bgnDate.ToString("yyyy_MM") + ".asc"; theLogger.Log(strFileName); var fileHandle = File.CreateText(strFileName); var DataValueList = theHydro.GetDataValues(Site.SiteId, bgnDate, endDate, WATER_LEVEL, null, null, null); if (DataValueList != null) { foreach (var item in DataValueList) { string line = item.Date.ToString("dd.MM.yyyy hh:mm:ss") + "\t" + item.Value.ToString() + "\tсм"; fileHandle.WriteLine(line); } } fileHandle.Close(); //for (DateTime currDate = bgnDate; currDate <= endDate; currDate.AddDays(1)) //{ // var DataValueList = theHydro.GetDataValues(Site.SiteId, TYPE_AGK, currDate, WATER_LEVEL, null, null); // foreach (var item in DataValueList) // { // } //} } this.theLogger.Log(strAgkDataFolder); } catch (Exception ex) { this.theLogger.Error(ex.Message); this.theLogger.Error(ex.Source); this.theLogger.Error(ex.StackTrace); } }
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { eventLog1.WriteEntry("timer1_Elapsed"); eventLog1.WriteEntry(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); string setting = ConfigurationManager.AppSettings["DataExport"]; if (setting == null) { setting = "Setting not found"; } eventLog1.WriteEntry(setting); string strAgkDataFolder = setting; strAgkDataFolder.TrimEnd(new char[] { '\\' }); Hydro.HydroServiceClient theClient = new Hydro.HydroServiceClient(); const int TYPE_AGK = 6; foreach (var Site in theClient.GetSiteList(TYPE_AGK)) { string strSiteFolder = strAgkDataFolder + "\\" + Convert.ToInt32(Site.SiteCode).ToString(("00000")); if (!Directory.Exists(strSiteFolder)) { Directory.CreateDirectory(strSiteFolder); } strSiteFolder += "\\уровни"; if (!Directory.Exists(strSiteFolder)) { Directory.CreateDirectory(strSiteFolder); } int countPrevMonth = 12; for ( ; countPrevMonth > 0; countPrevMonth--) { DateTime bgnDate = new DateTime(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month, countPrevMonth); DateTime endDate = new DateTime(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month, DateTime.DaysInMonth(DateTime.Now.AddMonths(-countPrevMonth).Year, DateTime.Now.AddMonths(-countPrevMonth).Month)); const int WATER_LEVEL = 2; string strFileName = strSiteFolder + "\\" + Convert.ToInt32(Site.SiteCode).ToString(("00000")) + "_" + bgnDate.ToString("yyyy_MM") + ".asc"; if (File.Exists(strFileName)) { continue; } var fileHandle = File.CreateText(strFileName); var DataValueList = theClient.GetDataValues(Site.SiteId, bgnDate, endDate, WATER_LEVEL, null, null, null); if (DataValueList != null) { foreach (var item in DataValueList) { string line = item.Date.ToString("dd.MM.yyyy ") + item.Date.ToLongTimeString() + "\t" + item.Value.ToString() + "\tcм"; fileHandle.WriteLine(line); } } fileHandle.Close(); } } } catch (Exception ex) { eventLog1.WriteEntry(ex.Message); eventLog1.WriteEntry(ex.StackTrace); } }
public ActionResult Months(int SiteCode = -1, int YYYY = -1, int MM = -1, int DD = 1) { DateTime currDate; try { currDate = new DateTime(YYYY, MM, DD); } catch { currDate = DateTime.Now; } ViewBag.currDate = currDate; Hydro.HydroServiceClient theHydro = new Hydro.HydroServiceClient(); ViewLevel theView = new ViewLevel(); const int TYPE_AGK = 6; theView.theSiteList = ViewSite.GetAll(TYPE_AGK); theView.SelectedSiteCode = SiteCode; if (theView.SelectedSiteCode == -1) { theView.SelectedSiteCode = theView.theSiteList[0].Code; } int SiteID = theView.theSiteList.Where(x => x.Code == theView.SelectedSiteCode).Single().ID; DateTime dateBgn = new DateTime(currDate.Year, currDate.Month, 1); DateTime dateEnd = new DateTime(currDate.Year, currDate.Month, DateTime.DaysInMonth(currDate.Year, currDate.Month)); const int LEVEL_CODE = 2; var ValueCollection = theHydro.GetDataValues(SiteID, dateBgn, dateEnd, LEVEL_CODE, null, null, null); if (ValueCollection == null) { return(View(theView)); } foreach (var item in ValueCollection) { if (item.Value > -9000) { ViewLevel.Level theLevel = new ViewLevel.Level(); theLevel.Value = item.Value; theLevel.YYYY = item.Date.Year; theLevel.MM = item.Date.Month; theLevel.DD = item.Date.Day; theLevel.HH = item.Date.Hour; theLevel.MI = 0; theLevel.SS = 0; theLevel.ID = item.Id; theView.theLevelList.Add(theLevel); } } const int HydroPostType = 2; var HydroPost = theHydro.GetSite(theView.SelectedSiteCode.ToString(), HydroPostType); var HydroPostValueCollection = theHydro.GetDataValues(HydroPost.SiteId, dateBgn, dateEnd, LEVEL_CODE, null, null, null); if (HydroPostValueCollection == null) { return(View(theView)); } foreach (var item in HydroPostValueCollection) { if (item.Value > -9000) { ViewLevel.Level theLevel = new ViewLevel.Level(); theLevel.Value = item.Value; theLevel.YYYY = item.Date.Year; theLevel.MM = item.Date.Month; theLevel.DD = item.Date.Day; theLevel.HH = item.Date.Hour; theLevel.MI = 0; theLevel.SS = 0; theLevel.ID = item.Id; theView.theHydroPostLevelList.Add(theLevel); } } return(View(theView)); }