Beispiel #1
0
        public int AssociateSyncedFileToBackupPlan(Models.BackupPlan plan, string path, bool ignoreCase = false)
        {
            Assert.IsNotNull(plan);
            Assert.IsNotNull(plan.Id);
            Assert.That(path, Is.Not.Null.Or.Empty);

            string modelName = typeof(Models.BackupPlanFile).Name;
            string backupPlanPropertyName     = this.GetPropertyName((Models.BackupPlanFile x) => x.BackupPlan);
            string storageAccountPropertyName = this.GetPropertyName((Models.BackupPlanFile x) => x.StorageAccount);
            string pathPropertyName           = this.GetPropertyName((Models.BackupPlanFile x) => x.Path);

            string queryString = string.Format(
                "UPDATE {0}"
                + "   SET {1} = :backupPlanId"
                + " WHERE"
                + "   {1} IS NULL"
                + "   AND {2} = :storageAccountId"
                + (ignoreCase ? "   AND lower({3}) = lower(:path)" : "   AND {3} = :path")
                , modelName, backupPlanPropertyName, storageAccountPropertyName, pathPropertyName
                );

            IQuery query = Session.CreateQuery(queryString)
                           .SetParameter("backupPlanId", plan.Id)
                           .SetParameter("storageAccountId", plan.StorageAccount.Id)
                           .SetParameter("path", path)
            ;

            return(query.ExecuteUpdate());
        }
Beispiel #2
0
        public Models.Backup GetLatestByPlan(Models.BackupPlan plan)
        {
            Assert.IsNotNull(plan);
            ICriteria crit = Session.CreateCriteria(PersistentType);
            string    backupPlanPropertyName = this.GetPropertyName((Models.Backup x) => x.BackupPlan);

            crit.Add(Restrictions.Eq(backupPlanPropertyName, plan));
            string idPropertyName = this.GetPropertyName((Models.Backup x) => x.Id);

            crit.AddOrder(Order.Desc(idPropertyName));
            crit.SetMaxResults(1);
            return(crit.UniqueResult <Models.Backup>());
        }
Beispiel #3
0
        public IList <Models.BackupPlanFile> GetAllByBackupPlan(Models.BackupPlan plan)
        {
            ICriteria crit = Session.CreateCriteria(PersistentType);
            string    backupPlanPropertyName = this.GetPropertyName((Models.BackupPlanFile x) => x.BackupPlan);

            if (plan == null)
            {
                crit.Add(Restrictions.IsNull(backupPlanPropertyName));
            }
            else
            {
                crit.Add(Restrictions.Eq(backupPlanPropertyName, plan));
            }
            return(crit.List <Models.BackupPlanFile>());
        }
Beispiel #4
0
        public IList <Models.BackupedFile> GetCompleteByPlanAndPath(Models.BackupPlan plan, string path, bool ignoreCase = false)
        {
            Assert.IsNotNull(plan);
            Assert.That(path, Is.Not.Null.Or.Empty);
            ICriteria crit = Session.CreateCriteria(PersistentType);

            // By status
            string transferStatusPropertyName = this.GetPropertyName((Models.BackupedFile x) => x.TransferStatus);

            crit.Add(Restrictions.Eq(transferStatusPropertyName, TransferStatus.COMPLETED));

            // By plan
            string backupPlanPropertyName = this.GetPropertyName((Models.Backup x) => x.BackupPlan);
            string backupPropertyName     = this.GetPropertyName((Models.BackupedFile x) => x.Backup);

            crit.CreateAlias(backupPropertyName, "bp");
            crit.Add(Restrictions.Eq("bp." + backupPlanPropertyName, plan));

            // By path
            string filePropertyName     = this.GetPropertyName((Models.BackupedFile x) => x.File);
            string filePathPropertyName = this.GetPropertyName((Models.BackupPlanFile x) => x.Path);

            crit.CreateAlias(filePropertyName, "f");
            SimpleExpression expr = Restrictions.Eq("f." + filePathPropertyName, path);

            if (ignoreCase)
            {
                expr = expr.IgnoreCase();
            }
            crit.Add(expr);

            // Order
            string idPropertyName = this.GetPropertyName((Models.BackupedFile x) => x.Id);

            crit.AddOrder(Order.Desc(idPropertyName));

            return(crit.List <Models.BackupedFile>());
        }