Exemplo n.º 1
0
        public IEnumerable <string> FindChecksumErrors()
        {
            var output = new ConcurrentBag <string>();

            var models = this.UnitOfWork.GetDirect(
                "Security_getAllRecords",
                this.FetchRecordModel,
                ParametersBuilder.With("table", this.TableName)
                );

            const string errorFormat = "Dígito Verificador Horizontal Inválido. Tabla '{0}'. Id '{1}'.";

            Parallel.ForEach(models,
                             new ParallelOptions {
                MaxDegreeOfParallelism = ComicalConfiguration.ChecksumCheckByModelDOP
            },
                             model =>
            {
                var lazyVerify        = new Lazy <string>(() => this.CalculateHorizontalVerifier(model.Values));
                var verifierIsInvalid = String.IsNullOrWhiteSpace(model.Verifier) || lazyVerify.Value != model.Verifier;

                if (verifierIsInvalid)
                {
                    var message = String.Format(errorFormat, this.TableName, model.Id);
                    output.Add(message);
                }
            });

            return(output.ToList());
        }
Exemplo n.º 2
0
 public void KillAllConnections()
 {
     this.UnitOfWork.NonQueryDirect(
         "Database_killAll",
         ParametersBuilder.With("DBName", "Comical")
         );
 }
Exemplo n.º 3
0
        public void Update(RoleWithPermissionsViewModel role)
        {
            var permissionTableName = "RolePermission";

            this.UnitOfWork.Run(() =>
            {
                this.UnitOfWork.NonQuery(
                    "Role_update",
                    ParametersBuilder.With("Code", role.Code)
                    .And("Description", role.Description)
                    .And("Enabled", role.Enabled)
                    .And("Id", role.Id)
                    );

                this.UnitOfWork.NonQuery(
                    "Role_deletePermissions",
                    ParametersBuilder.With("roleId", role.Id)
                    );

                foreach (var permission in role.Permissions)
                {
                    var relationshipId = this.UnitOfWork.Scalar(
                        "Role_newPermission",
                        ParametersBuilder.With("roleId", role.Id)
                        .And("permissionId", permission.Key)
                        ).AsInt();

                    this.SetHorizontalVerifier(relationshipId, permissionTableName);
                }

                this.SetHorizontalVerifier(role.Id);
                this.SetVerticalVerifierClosure();
                this.SetVerticalVerifierClosure(permissionTableName);
            });
        }
Exemplo n.º 4
0
 public void SetUnderMaintenace(bool underMaintenance)
 {
     this.UnitOfWork.NonQueryDirect(
         "DatabaseStatus_setMaintenance",
         ParametersBuilder.With("DatabaseName", "Comical")
         .And("UnderMaintenance", underMaintenance)
         );
 }
Exemplo n.º 5
0
 public void SetHasChecksumError(bool hasChecksumError)
 {
     this.UnitOfWork.NonQueryDirect(
         "DatabaseStatus_setHasChecksumError",
         ParametersBuilder.With("DatabaseName", "Comical")
         .And("HasChecksumError", hasChecksumError)
         );
 }
Exemplo n.º 6
0
        public DatabaseStatus Get()
        {
            var model = this.UnitOfWork.GetDirect(
                "DatabaseStatus_get",
                this.Fetch,
                ParametersBuilder.With("DatabaseName", "Comical")
                ).First();

            return(model);
        }
Exemplo n.º 7
0
        public User GetByLogin(string login)
        {
            var output = this.UnitOfWork.GetDirect(
                "User_getByLogin",
                this.FetchUser,
                ParametersBuilder.With("Login", login)
                ).FirstOrDefault();

            return(output);
        }
Exemplo n.º 8
0
        public void DoBackup(string filepath, string createdBy)
        {
            this.UnitOfWork.NonQueryDirect("Database_doBackup_Comical_full",
                                           ParametersBuilder.With("filepath", filepath)
                                           );

            this.UnitOfWork.NonQueryDirect("Backup_new",
                                           ParametersBuilder.With("filepath", filepath)
                                           .And("CreatedBy", createdBy));
        }
Exemplo n.º 9
0
        public IEnumerable <Permission> GetByRole(int roleId)
        {
            var output = this.UnitOfWork.GetDirect(
                "Permission_getByRole",
                this.Fetch,
                ParametersBuilder.With("roleId", roleId)
                );

            return(output);
        }
Exemplo n.º 10
0
        public Role GetById(int roleId)
        {
            var output = this.UnitOfWork.GetDirect(
                "Role_getById",
                this.FetchRole,
                ParametersBuilder.With("Id", roleId)
                ).FirstOrDefault();

            return(output);
        }
Exemplo n.º 11
0
 protected void SetHorizontalVerifierDirectly(int id, string verifier)
 {
     var where = this.CreateWhere(id);
     this.UnitOfWork.NonQueryDirect(
         "Security_setVerifier",
         ParametersBuilder.With("table", this.TableName)
         .And("verifier", verifier)
         .And("where", where)
         );
 }
Exemplo n.º 12
0
 protected void SetHorizontalVerifier(string verifier, string where, string table)
 {
     table = table ?? this.TableName;
     this.UnitOfWork.NonQuery(
         "Security_setVerifier",
         ParametersBuilder.With("table", table)
         .And("verifier", verifier)
         .And("where", where)
         );
 }
Exemplo n.º 13
0
        public IEnumerable <string> GetBy(int userId)
        {
            var output = this.UnitOfWork.GetDirect(
                "Permission_getByUser",
                this.FetchPermissionCodes,
                ParametersBuilder.With("userId", userId)
                );

            return(output);
        }
Exemplo n.º 14
0
        public bool IsGrantedTo(int userId, string permissionCode)
        {
            var output = this.UnitOfWork.ScalarDirect(
                "Permission_isGrantedToUser",
                ParametersBuilder.With("userId", userId)
                .And("permissionCode", permissionCode)
                ).AsBool();

            return(output);
        }
Exemplo n.º 15
0
        public void DoRestore(int backupId)
        {
            var model = this.UnitOfWork.GetOneDirect("Backup_getOne",
                                                     this.Fetch,
                                                     ParametersBuilder.With("id", backupId));

            this.UnitOfWork.NonQueryDirect("Security_doRestore",
                                           ParametersBuilder.With("filepath", model.FilePath)
                                           .And("dbname", "Comical")
                                           );
        }
Exemplo n.º 16
0
        public void Delete(int id)
        {
            this.UnitOfWork.Run(() =>
            {
                this.UnitOfWork.NonQuery(
                    "Role_delete",
                    ParametersBuilder.With("Id", id));

                this.SetVerticalVerifierClosure();
            });
        }
Exemplo n.º 17
0
        protected IEnumerable <string> GetRecordValues(string where, string table = null)
        {
            table = table ?? this.TableName;
            var values = this.UnitOfWork.Get(
                "Security_getRecord",
                this.FetchRecordValues,
                ParametersBuilder.With("table", table)
                .And("where", where)
                ).First();

            return(values);
        }
        public void ParametersBuilder_SetupDbCommand_SetsParametersProperly()
        {
            var dbCommandMock             = new Mock <IDbCommand>();
            var dbParameter1Mock          = new Mock <IDbDataParameter>();
            var dbParameter2Mock          = new Mock <IDbDataParameter>();
            var dbParameterCollectionMock = new Mock <IDataParameterCollection>();
            var myParameterList           = new List <IDbDataParameter>();
            var actualNames     = new HashSet <string>();
            var actualValues    = new HashSet <object>();
            var parametersQueue = new Queue <Mock <IDbDataParameter> >();

            void SetupIDbDataParameter(Mock <IDbDataParameter> mock)
            {
                mock
                .SetupSet(m => m.ParameterName = It.IsAny <string>())
                .Callback <string>(value => actualNames.Add(value));

                mock
                .SetupSet(m => m.Value = It.IsAny <object>())
                .Callback <object>(value => actualValues.Add(value));

                parametersQueue.Enqueue(mock);
            }

            dbCommandMock
            .Setup(m => m.CreateParameter())
            .Returns(() => parametersQueue.Dequeue().Object);

            dbCommandMock
            .SetupGet(m => m.Parameters)
            .Returns(() => dbParameterCollectionMock.Object);

            SetupIDbDataParameter(dbParameter1Mock);
            SetupIDbDataParameter(dbParameter2Mock);

            dbParameterCollectionMock
            .Setup(m => m.Add(It.IsAny <IDbDataParameter>()))
            .Callback <object>(parameter => myParameterList.Add(parameter as IDbDataParameter));

            var subject = ParametersBuilder.With("Param1", "string-value").And("Param2", 900);

            subject.SetupDbCommand(dbCommandMock.Object);

            Assert.AreEqual(2, myParameterList.Count);

            Assert.IsTrue(actualNames.Contains("@Param1"));
            Assert.IsTrue(actualNames.Contains("@Param2"));

            Assert.IsTrue(actualValues.Contains("string-value"));
            Assert.IsTrue(actualValues.Contains(900));
        }
Exemplo n.º 19
0
        public void ChangeEnabled(int id, bool value)
        {
            this.UnitOfWork.Run(() =>
            {
                this.UnitOfWork.NonQuery(
                    "User_changeEnabled",
                    ParametersBuilder.With("id", id)
                    .And("Enabled", value)
                    );

                this.SetHorizontalVerifier(id);
                this.SetVerticalVerifier();
            });
        }
        public void ParametersBuilder_With_WorksLikeAnd()
        {
            var subject = ParametersBuilder.With("Param1", 40).And("Param2", "string-value");

            var output = subject.GetProcedureParameters().ToArray();

            Assert.AreEqual(2, output.Count());

            Assert.AreEqual("Param1", output[0].Name);
            Assert.AreEqual("Param2", output[1].Name);

            Assert.AreEqual(40, output[0].GetValue());
            Assert.AreEqual("string-value", output[1].GetValue());
        }
Exemplo n.º 21
0
        protected void InsertUserRoles(User model)
        {
            foreach (var role in model.Roles)
            {
                var id = this.UnitOfWork.Scalar(
                    "UserRole_new",
                    ParametersBuilder.With("UserId", model.Id)
                    .And("RoleId", role.Id)
                    ).AsInt();

                this.SetHorizontalVerifier(id, "UserRole");
            }

            this.SetVerticalVerifier("UserRole");
        }
Exemplo n.º 22
0
        public int IncrementRetry(int id)
        {
            var output = this.UnitOfWork.Run(() =>
            {
                var retries = this.UnitOfWork.Scalar(
                    "User_incrementRetry",
                    ParametersBuilder.With("id", id)
                    ).AsInt();

                this.SetHorizontalVerifier(id);
                this.SetVerticalVerifier();

                return(retries);
            });

            return(output);
        }
Exemplo n.º 23
0
        public void SetVerticalVerifierClosure(string table = null)
        {
            table = table ?? this.TableName;

            var verifiers = this.UnitOfWork.Get(
                "Security_getHorizontalVerifiers",
                this.FetchHorizontalVerifier,
                ParametersBuilder.With("TableName", table)
                );

            var verticalChecksum = Crypto3DES.obj.GetChecksum(verifiers);

            this.UnitOfWork.NonQuery(
                "VerticalVerifier_update",
                ParametersBuilder.With("TableName", table)
                .And("VerticalVerifier", verticalChecksum)
                );
        }
Exemplo n.º 24
0
        public void ResetHorizontalVerifiers()
        {
            var models = this.UnitOfWork.GetDirect(
                "Security_getAllRecords",
                this.FetchRecordModel,
                ParametersBuilder.With("table", this.TableName)
                );

            Parallel.ForEach(models,
                             new ParallelOptions {
                MaxDegreeOfParallelism = ComicalConfiguration.ChecksumResetDOP
            },
                             model =>
            {
                var verifier = this.CalculateHorizontalVerifier(model.Values);
                this.SetHorizontalVerifierDirectly(model.Id, verifier);
            }
                             );
        }
Exemplo n.º 25
0
        public int New(HistoryEvent model)
        {
            var output = this.UnitOfWork.Run(() =>
            {
                var id = this.UnitOfWork.Scalar(
                    "HistoryEvent_new",
                    ParametersBuilder.With("Section", model.Section)
                    .And("Message", model.Message)
                    .And("UserId", model.UserId)
                    ).AsInt();

                this.SetHorizontalVerifier(id);
                this.SetVerticalVerifierClosure();

                return(id);
            });

            return(output);
        }
Exemplo n.º 26
0
        public int New(User model)
        {
            var output = this.UnitOfWork.Run(() =>
            {
                model.Id = this.UnitOfWork.Scalar(
                    "User_new",
                    ParametersBuilder.With("Login", model.Login)
                    .And("Password", model.Password)
                    ).AsInt();

                this.SetHorizontalVerifier(model.Id);
                this.SetVerticalVerifier();

                this.InsertUserRoles(model);

                return(model.Id);
            }).AsInt();

            return(output);
        }
Exemplo n.º 27
0
        public User Get(int id)
        {
            var roleRepository = new RoleRepository();

            var output = this.UnitOfWork.Run(() =>
            {
                var model = this.UnitOfWork.Get(
                    "User_getById",
                    this.FetchUser,
                    ParametersBuilder.With("id", id)
                    ).First();

                model.Roles = this.UnitOfWork.Get(
                    "User_getRoles",
                    roleRepository.FetchRole,
                    ParametersBuilder.With("userId", id)
                    ).ToList();

                return(model);
            });

            return(output);
        }
Exemplo n.º 28
0
        public void Update(User model)
        {
            this.UnitOfWork.Run(() =>
            {
                this.UnitOfWork.NonQuery(
                    "UserRole_delete",
                    ParametersBuilder.With("userId", model.Id)
                    );

                this.InsertUserRoles(model);

                this.UnitOfWork.NonQuery(
                    "User_update",
                    ParametersBuilder.With("id", model.Id)
                    .And("Login", model.Login)
                    .And("Password", model.Password)
                    .And("Enabled", model.Enabled)
                    .And("Blocked", model.Blocked)
                    );

                this.SetHorizontalVerifier(model.Id);
                this.SetVerticalVerifier();
            });
        }