public static ShouldDownloadStatus ShouldDownload(XML.indexDump dump) { string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString"); string sql = @"select top 1 * from [DumpData] where mesic = @mesic and rok = @rok and den = @den order by created desc"; using (var p = new Devmasters.PersistLib()) { var ds = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] { new System.Data.SqlClient.SqlParameter("den", (int)dump.den), new System.Data.SqlClient.SqlParameter("mesic", (int)dump.mesic), new System.Data.SqlClient.SqlParameter("rok", (int)dump.rok), }); if (ds.Tables[0].Rows.Count == 0) { return(ShouldDownloadStatus.Yes); } DataRow dr = ds.Tables[0].Rows[0]; string oldHash = (string)dr["hash"]; if (string.IsNullOrEmpty(oldHash)) { return(ShouldDownloadStatus.Yes); } if (oldHash != dump.hashDumpu.Value) { //if (dump.casGenerovani < DateTime.Now.Date) // return ShouldDownloadStatus.WaitForData; //else return(ShouldDownloadStatus.Yes); } return(ShouldDownloadStatus.No); } }
public ActionResult OCRStats(string type = "") { string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString"); string sql = @"select 'Celkem' as 'type', (select count(*) from ItemToOcrQueue with (nolock) where started is null) as waiting, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is null) as running, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is not null and done > DATEADD(dy,-1,getdate())) as doneIn24H, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is null and started< dateadd(hh,-24,getdate())) as errors union select distinct t.itemtype as 'type', (select count(*) from ItemToOcrQueue with (nolock) where started is null and itemtype = t.itemtype) as waiting, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is null and itemtype = t.itemtype) as running, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is not null and done > DATEADD(dy,-1,getdate()) and itemtype = t.itemtype) as doneIn24H, (select count(*) from ItemToOcrQueue with (nolock) where started is not null and done is null and started< dateadd(hh,-24,getdate()) and itemtype = t.itemtype) as errors from ItemToOcrQueue t with (nolock) order by type" ; using (var p = new Devmasters.PersistLib()) { var ds = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, null); System.Text.StringBuilder sb = new System.Text.StringBuilder(1024); sb.AppendLine("Typ\tVe frontě\tZpracovavane\tHotovo za 24hod\tChyby pri zpracovani"); foreach (System.Data.DataRow dr in ds.Tables[0].Rows) { sb.Append((string)dr[0]); sb.Append("\t"); sb.Append((int)dr[1]); sb.Append("\t"); sb.Append((int)dr[2]); sb.Append("\t"); sb.Append((int)dr[3]); sb.Append("\t"); sb.Append((int)dr[4]); sb.AppendLine(); } return(Content(sb.ToString())); } }
private static IEnumerable <T> GetList <T>(Func <DataRow, T> fillFnc, string sql, System.Data.CommandType type, IDataParameter[] param, string cnnString) { //bool isStruct = typeof(T).IsValueType && !typeof(T).IsEnum; using (var p = new Devmasters.PersistLib()) { var res = new List <T>(); try { var ds = p.ExecuteDataset(cnnString ?? defaultCnnStr, type, sql, param); foreach (DataRow dr in ds.Tables[0].Rows) { res.Add(fillFnc(dr)); //GetRowValue<T>(dr, 0) } return(res); } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("SQL error:" + sql, e); throw; } } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configure(WebApiConfig.Register); BannedIPs = new Devmasters.Cache.LocalMemory.AutoUpdatedLocalMemoryCache <string[]>( TimeSpan.FromSeconds(30), "BannedIPs", (obj) => { var ret = new System.Collections.Generic.List <string>(); try { using (Devmasters.PersistLib p = new Devmasters.PersistLib()) { //p.ExecuteNonQuery(Devmasters.Config.GetWebConfigValue("CnnString"), // System.Data.CommandType.Text, "delete from BannedIPs where expiration < GetDate()", null); var ds = p.ExecuteDataset(Devmasters.Config.GetWebConfigValue("CnnString"), System.Data.CommandType.Text, "select IP from BannedIPs where Expiration is null or expiration > GetDate()", null); foreach (System.Data.DataRow dr in ds.Tables[0].Rows) { ret.Add(((string)dr[0]).ToLower()); } } } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("Global.asax BannedIP db query", e); } return(ret.ToArray()); } ); //if (ValueProviderFactories.Factories.Any(m => m.GetType() == typeof(System.Web.Mvc.JsonValueProviderFactory))) //{ // var f = ValueProviderFactories.Factories.Where(m => m.GetType() == typeof(System.Web.Mvc.JsonValueProviderFactory)).FirstOrDefault(); // if (f != null) // ValueProviderFactories.Factories.Remove(f); //} var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter; formatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore, //ContractResolver = new HlidacStatu.Util.FirstCaseLowercaseContractResolver() }; formatter.MediaTypeMappings .Add(new System.Net.Http.Formatting.RequestHeaderMapping("Accept", "text/html", StringComparison.InvariantCultureIgnoreCase, true, "application/json")); //System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new Framework.DataSetsVirtualPathProvider()); HlidacStatu.Lib.Init.Initialise(); }