Beispiel #1
0
        public static ShouldDownloadStatus ShouldDownload(XML.indexDump dump)
        {
            string cnnStr = Devmasters.Core.Util.Config.GetConfigValue("CnnString");
            string sql    = @"select top 1 * from [DumpData] where mesic = @mesic and rok = @rok order by created desc";

            using (var p = new Devmasters.Core.PersistLib())
            {
                var ds = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, new IDataParameter[] {
                    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);
            }
        }
Beispiel #2
0
 public static void NoResult(string sql, System.Data.CommandType type, params IDataParameter[] param)
 {
     using (var p = new Devmasters.Core.PersistLib())
     {
         try
         {
             p.ExecuteNonQuery(cnnStr, type, sql, param);
         }
         catch (Exception e)
         {
             HlidacStatu.Util.Consts.Logger.Error("SQL error:" + sql, e);
             throw;
         }
     }
 }
Beispiel #3
0
        public static void SaveDumpProcessed(XML.indexDump dump, DateTime?processed, Exception ex = null)
        {
            string cnnStr = Devmasters.Core.Util.Config.GetConfigValue("CnnString");
            string sql    = @"INSERT INTO [dbo].[DumpData]
           ([Created]
           ,[Processed]
           ,[mesic]
           ,[rok]
           ,[hash]
           ,[velikost]
           ,[casGenerovani], exception)
     VALUES
           (@Created
           ,@Processed
           ,@mesic
           ,@rok
           ,@hash
           ,@velikost
           ,@casGenerovani
            ,@exception)
";

            try
            {
                using (var p = new Devmasters.Core.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("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);
            }
        }
        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.Core.PersistLib p = new Devmasters.Core.PersistLib())
                {
                    var res = p.ExecuteScalar(Devmasters.Core.Util.Config.GetConfigValue("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.Core.PersistLib.IsNull(res))
                    {
                        return(false);
                    }
                }

                return(db.AspNetUserRoles.Any(m => m.UserId == this.Id && m.RoleId == roleId));
            }
        }
Beispiel #5
0
        public ActionResult OCRStats(string type = "")
        {
            string cnnStr = Devmasters.Core.Util.Config.GetConfigValue("CnnString");
            string sql    = @"select 'Celkem' as 'type',
		                        (select count(*) from ItemToOcrQueue where started is null) as waiting,
		                        (select count(*) from ItemToOcrQueue where started is not null and done is null) as running,
		                        (select count(*) from ItemToOcrQueue where started is not null and done is not null and done > DATEADD(dy,-1,getdate())) as doneIn24H,
		                        (select count(*) from ItemToOcrQueue 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 where started is null and itemtype = t.itemtype) as waiting,
		                        (select count(*) from ItemToOcrQueue where started is not null and done is null and itemtype = t.itemtype) as running,
		                        (select count(*) from ItemToOcrQueue 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 where started is not null and done is null 
		                        and started< dateadd(hh,-24,getdate()) and itemtype = t.itemtype) as errors
		                        from ItemToOcrQueue t 
		                        order by type"        ;

            using (var p = new Devmasters.Core.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()));
            }
        }
Beispiel #6
0
 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.Core.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;
         }
     }
 }