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); } }
public ActionResult Telephone(string telephone) { try { AMS.Profile.Ini Ini = new AMS.Profile.Ini(AppDomain.CurrentDomain.BaseDirectory + "\\Callback.ini"); if (!Ini.HasSection("SMSC")) { Ini.SetValue("SMSC", "login", "mgerasim"); Ini.SetValue("SMSC", "psw", "zaq12wsx"); } string login = Ini.GetValue("SMSC", "login", "some-login"); string psw = Ini.GetValue("SMSC", "psw", "some-password"); string code = this.RandomString(4); string url = "http://smsc.ru/sys/send.php?login="******"&psw=" + psw + "&phones=" + telephone + "&mes=" + code; var request = (HttpWebRequest)WebRequest.Create(url); var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); var serializer = new JavaScriptSerializer(); // For simplicity just use Int32's max value. // You could always read the value from the config section mentioned above. serializer.MaxJsonLength = Int32.MaxValue; CallbackAspDotNetMvc.Models.User theUser = null; theUser = Models.User.GetByPhone(telephone); if (theUser == null) { theUser = new Models.User(); theUser.code = code; theUser.telephone = telephone; theUser.result = responseString; theUser.Save(); } else { theUser.code = code; theUser.result = responseString; theUser.Update(); } var resultData = new { telephone = telephone, result = responseString }; var result = new ContentResult { Content = serializer.Serialize(resultData), ContentType = "application/json" }; return(result); } catch (Exception ex) { var serializer = new JavaScriptSerializer(); // For simplicity just use Int32's max value. // You could always read the value from the config section mentioned above. serializer.MaxJsonLength = Int32.MaxValue; string err = ex.Message; if (ex.InnerException != null) { err += ex.InnerException.Message; } var resultData = new { telephone = telephone, error = err }; var result = new ContentResult { Content = serializer.Serialize(resultData), ContentType = "application/json" }; return(result); } return(View()); }