public RunningQueryViewModel(SqlQuery baseModel)
        {
            Id = baseModel.Id;
            Sql = baseModel.Sql;
            Databases = baseModel.Databases;
            UserId = baseModel.UserId;
            DateStart = baseModel.DateStart;
            DateEnd = baseModel.DateEnd;
            SingleTable = baseModel.SingleTable;

            Done = DateEnd.HasValue && DateEnd > DateStart;

            var runningTime = Done
                ? DateEnd.Value - DateStart
                : DateTime.Now - DateStart;

            RunningTime = runningTime.ToString(@"dd\.hh\:mm\:ss");

            Results = new List<WorkerResult>();
            using (var dbContext = new OctopusDbContext())
            {
                var tmpResults = dbContext
                    .QueryResults
                    .Where(qr => qr.QueryId == Id)
                    .ToList();
                foreach (var tmpResult in tmpResults)
                    Results.Add(JsonConvert.DeserializeObject<WorkerResult>(tmpResult.Result));
            }
        }
Esempio n. 2
0
 public static bool IsAdmin(IIdentity identity)
 {
     if (!identity.IsAuthenticated)
         return false;
     else
         using (var context = new OctopusDbContext())
             return context.Accounts.Where(a => a.Name == identity.Name).First().IsAdmin;
 }
Esempio n. 3
0
 public static int GetUserId(IIdentity identity)
 {
     if (!identity.IsAuthenticated)
         return 0;
     else
         using (var context = new OctopusDbContext())
             return context.Accounts.Where(a => a.Name == identity.Name).First().Id;
 }
        /// <summary>
        /// Get script from script repository by id
        /// </summary>
        public static PreparedScript Get(int id)
        {
            var dbContext = new OctopusDbContext();

            return dbContext
                .PreparedScripts
                .Where(s => s.Id == id)
                .FirstOrDefault();
        }
        // GET: History
        public ActionResult Index()
        {
            var dbContext = new OctopusDbContext();

            int userId = UserHelper.GetUserId(User.Identity);

            return View(dbContext
                .Queries
                .Where(q => q.UserId == userId)
                .OrderByDescending(q => q.DateStart)
            );
        }
Esempio n. 6
0
 /// <summary>
 /// ctor -- init data sources collection
 /// </summary>
 static Worker()
 {
     _locker    = new object();
     _runners   = new List <QueryRunner>();
     _databases = new List <WorkerDb>();
     using (var dbContext = new OctopusDbContext())
     {
         var dataSources = dbContext.DataSources.ToArray();
         foreach (var source in dataSources)
         {
             _databases.AddRange(InitHelper.LoadDatabases(source));
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 /// ctor -- init data sources collection
 /// </summary>
 static Worker()
 {
     _locker = new object();
     _runners = new List<QueryRunner>();
     _databases = new List<WorkerDb>();
     using (var dbContext = new OctopusDbContext())
     {
         var dataSources = dbContext.DataSources.ToArray();
         foreach (var source in dataSources)
         {
             _databases.AddRange(InitHelper.LoadDatabases(source));
         }
     }
 }
Esempio n. 8
0
        public ActionResult Index(UserQueryViewModel model)
        {
            var dbContext = new OctopusDbContext();
            var script = PreparedScriptHelper.Get(model.PreparedScriptId);

            ModelState.Remove("Sql");
            if (script != null)
            {
                model.Sql = script.Sql;
                model.Params = PreparedScriptHelper.PrepareParams(script.Sql);
            }
            else
                model.Sql = string.Empty;

            return View(model);
        }
        /// <summary>
        /// Get prepared script for View
        /// </summary>
        /// <returns></returns>
        public static List<SelectListItem> GetScripts()
        {
            var dbContext = new OctopusDbContext();

            var result = new List<SelectListItem>();
            result.Add(new SelectListItem() { Value = "0", Text = "( none )" });

            result.AddRange(dbContext
                .PreparedScripts
                .Select(s => new SelectListItem()
                {
                    Text = s.Name,
                    Value = s.Id.ToString()
                }));

            return result;
        }
 public AccountController()
 {
     _dbContext = new OctopusDbContext();
 }