예제 #1
0
 private void Execute(IModelDatabaseMaintanance databaseMaintanance, Action <Session, string> action)
 {
     using (var objectSpace = Application.CreateObjectSpace()){
         var isObjectFitForCriteria = IsObjectFitForCriteria(databaseMaintanance, objectSpace);
         if ((isObjectFitForCriteria.HasValue && isObjectFitForCriteria.Value))
         {
             var parser   = new ConnectionStringParser(Application.ConnectionString);
             var database = parser.GetPartByName("Initial Catalog");
             action(objectSpace.Session(), database);
         }
     }
 }
예제 #2
0
 private Task BackupTask(string database, IModelDatabaseMaintanance databaseMaintanance)
 {
     return(Task.Factory.StartNew(() => {
         try{
             var dateTime = DateTime.Now.ToString("yyyy.MMMM.dd-HH.mm.ss");
             string text = $@"BACKUP DATABASE [{database}] TO  DISK = N'{databaseMaintanance.BackupDirectory}\{database}-{dateTime
                     }.bak' WITH NOFORMAT, NOINIT,  NAME = N'{database}-Full Database Backup on {dateTime}', SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
             ExecuteNonQuery(text, databaseMaintanance.BackupTimeout);
         }
         catch (Exception e) {
             Tracing.Tracer.LogError(e);
         }
     }, TaskCreationOptions.LongRunning | TaskCreationOptions.AttachedToParent));
 }
예제 #3
0
        private bool?IsObjectFitForCriteria(IModelDatabaseMaintanance databaseMaintanance, IObjectSpace objectSpace)
        {
            var user = objectSpace.GetObject(SecuritySystem.CurrentUser);
            CriteriaOperator criteriaOperator;
            var typeInfo         = databaseMaintanance.UserModelClass?.TypeInfo;
            var targetObjectType = typeInfo?.Type;

            using (objectSpace.CreateParseCriteriaScope()){
                criteriaOperator = CriteriaWrapper.ParseCriteriaWithReadOnlyParameters(databaseMaintanance.UserCriteria, targetObjectType);
            }

            var fit = objectSpace.GetExpressionEvaluator(new EvaluatorContextDescriptorDefault(typeInfo == null?typeof(object):targetObjectType), criteriaOperator).Fit(typeInfo == null?new object():user);

            return(fit);
        }
예제 #4
0
 public static IModelList <IModelClass> Get_UserClasses(IModelDatabaseMaintanance databaseMaintanance)
 {
     return(databaseMaintanance.ModelClasses(typeof(ISecurityUser)));
 }
예제 #5
0
 public static IModelClass Get_UserModelClass(IModelDatabaseMaintanance databaseMaintanance)
 {
     return(databaseMaintanance.ModelClasses(typeof(ISecurityUser)).FirstOrDefault());
 }