コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public HttpResponseMessage Vsechny()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder(1024 * 500);
            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");

            using (Devmasters.PersistLib p = new Devmasters.PersistLib())
            {
                var reader = p.ExecuteReader(cnnStr, CommandType.Text, "select ico, jmeno from firma where ISNUMERIC(ico) = 1", null);
                while (reader.Read())
                {
                    string ico  = reader.GetString(0).Trim();
                    string name = reader.GetString(1).Trim();
                    if (!string.IsNullOrWhiteSpace(ico) &&
                        !string.IsNullOrWhiteSpace(name) &&
                        Devmasters.TextUtil.IsNumeric(ico))
                    {
                        ico = Util.ParseTools.NormalizeIco(ico);

                        sb.AppendLine(ico + "\t" + name);
                    }
                }
            }

            var res = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(sb.ToString())
            };

            return(res);
        }
コード例 #3
0
ファイル: DirectDB.cs プロジェクト: HlidacStatu/HlidacStatu
 public static void NoResult(string sql, System.Data.CommandType type, IDataParameter[] param = null, string cnnString = null)
 {
     using (var p = new Devmasters.PersistLib())
     {
         try
         {
             p.ExecuteNonQuery(defaultCnnStr, type, sql, param);
         }
         catch (Exception e)
         {
             HlidacStatu.Util.Consts.Logger.Error("SQL error:" + sql, e);
             throw;
         }
     }
 }
コード例 #4
0
        public static void SaveDumpProcessed(XML.indexDump dump, DateTime?processed, Exception ex = null)
        {
            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");
            string sql    = @"INSERT INTO [dbo].[DumpData]
           ([Created]
           ,[Processed]
           ,[den]
           ,[mesic]
           ,[rok]
           ,[hash]
           ,[velikost]
           ,[casGenerovani], exception)
     VALUES
           (@Created
           ,@Processed
           ,@den
           ,@mesic
           ,@rok
           ,@hash
           ,@velikost
           ,@casGenerovani
            ,@exception)
";

            try
            {
                using (var p = new Devmasters.PersistLib())
                {
                    p.ExecuteNonQuery(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] {
                        new System.Data.SqlClient.SqlParameter("created", DateTime.Now),
                        new System.Data.SqlClient.SqlParameter("processed", processed),
                        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),
                        new System.Data.SqlClient.SqlParameter("hash", dump.hashDumpu.Value),
                        new System.Data.SqlClient.SqlParameter("velikost", (long)dump.velikostDumpu),
                        new System.Data.SqlClient.SqlParameter("casGenerovani", dump.casGenerovani),
                        new System.Data.SqlClient.SqlParameter("exception", ex == null ? (string)null : ex.ToString()),
                    });
                }
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Error("SaveDumpProcessed error", e);
            }
        }
コード例 #5
0
        public bool IsInRole(string role)
        {
            using (DbEntities db = new DbEntities())
            {
                //var roleId = db.AspNetRoles.Where(m => m.Name == role).FirstOrDefault();
                string roleId = null;
                using (Devmasters.PersistLib p = new Devmasters.PersistLib())
                {
                    roleId = (string)p.ExecuteScalar(Devmasters.Config.GetWebConfigValue("CnnString"),
                                                     System.Data.CommandType.Text, "select id from aspnetroles  where name = @role",
                                                     new System.Data.IDataParameter[] { new System.Data.SqlClient.SqlParameter("role", role) });
                    if (Devmasters.PersistLib.IsNull(roleId))
                    {
                        return(false);
                    }
                }

                return(db.AspNetUserRoles.Any(m => m.UserId == this.Id && m.RoleId == roleId));
            }
        }
コード例 #6
0
ファイル: ApiV1Controller.cs プロジェクト: hosekp/HlidacStatu
        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()));
            }
        }
コード例 #7
0
ファイル: DirectDB.cs プロジェクト: HlidacStatu/HlidacStatu
 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;
         }
     }
 }
コード例 #8
0
        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();
        }
コード例 #9
0
        void AutoAddBlackList(Controllers.HomeController.ErrorPages errPage, HttpRequest req)
        {
            bool   add = false;
            var    dt  = DateTime.Now;
            string ip  = req.UserHostAddress;

            lock (_autoAddBlackList)
            {
                if (!attackers.ContainsKey(ip))
                {
                    attackers.Add(ip, new attack()
                    {
                        ip = ip, last = DateTime.Now, num = 0
                    });
                }
            }

            var att  = attackers[ip];
            var diff = (dt - att.last).TotalSeconds;

            if (diff >= 600)
            {
                att.num = 1;
            }
            else
            {
                att.num = att.num + 1;
            }

            switch (errPage)
            {
            case Controllers.HomeController.ErrorPages.Ok:
                break;

            case Controllers.HomeController.ErrorPages.NotFound:
                add = att.num > 20;
                break;

            case Controllers.HomeController.ErrorPages.Error:
                add = att.num > 15;
                break;

            case Controllers.HomeController.ErrorPages.ErrorHack:
                add = att.num > 10;
                break;

            default:
                break;
            }

            if (add)
            {
                HlidacStatu.Util.Consts.Logger.Warning($"added bannedIP {ip}");
                try
                {
                    using (Devmasters.PersistLib p = new Devmasters.PersistLib())
                    {
                        p.ExecuteNonQuery(Devmasters.Config.GetWebConfigValue("CnnString"),
                                          System.Data.CommandType.Text, "INSERT INTO [dbo].[BannedIPs] ([IP],[Expiration],[Created]) "
                                          + " VALUES(@ip,@dat,GetDate())", new System.Data.IDataParameter[] {
                            new System.Data.SqlClient.SqlParameter("ip", ip),
                            new System.Data.SqlClient.SqlParameter("dat", dt.AddHours(6))
                        });
                    }
                    BannedIPs.ForceRefreshCache();
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Warning($"added bannedIP {ip}", e);
                }
            }
        }