protected virtual void DoGenericAudit()
        {
            var auditFields = new HashSet <Field>();

            GetEditableFields(auditFields);

            var auditRequest = GetAuditRequest(auditFields);

            if (IsUpdate)
            {
                Row audit = null;
                if (auditRequest != null)
                {
                    audit = AuditLogService.PrepareAuditUpdate(RowRegistry.GetConnectionKey(Row), auditRequest);
                }

                if (audit != null)
                {
                    Connection.Insert(audit);
                }
            }
            else if (IsCreate)
            {
                if (auditRequest != null)
                {
                    AuditLogService.AuditInsert(Connection, RowRegistry.GetConnectionKey(Row), auditRequest);
                }
            }
        }
Exemple #2
0
        protected virtual void DoGenericAudit()
        {
            var auditRequest = GetAuditRequest();

            if (auditRequest != null)
            {
                AuditLogService.AuditUndelete(Connection, RowRegistry.GetConnectionKey(Row), auditRequest);
            }
        }
        public override void OnAudit(IDeleteRequestHandler handler)
        {
            var auditRequest = GetAuditDeleteRequest(handler);

            if (auditRequest != null)
            {
                AuditLogService.AuditDelete(handler.UnitOfWork.Connection, RowRegistry.GetConnectionKey(handler.Row), auditRequest);
            }
        }
Exemple #4
0
        static StaticInfo EnsureInfo()
        {
            var newInfo = info;

            if (newInfo != null)
            {
                return(newInfo);
            }

            var captureLogAttr = typeof(TRow).GetCustomAttribute <CaptureLogAttribute>(false);

            if (captureLogAttr == null || captureLogAttr.LogRow == null)
            {
                throw new InvalidOperationException(String.Format("{0} row type has no capture log attribute defined!", typeof(TRow).Name));
            }

            logConnectionKey = RowRegistry.GetConnectionKey(captureLogAttr.LogRow);
            var logRowInstance = (Row)Activator.CreateInstance(captureLogAttr.LogRow);

            var captureLogRow = logRowInstance as ICaptureLogRow;

            if (captureLogRow == null)
            {
                throw new InvalidOperationException(String.Format("Capture log table {0} doesn't implement ICaptureLogRow interface!",
                                                                  captureLogAttr.LogRow.FullName, logConnectionKey, typeof(TRow).Name));
            }

            newInfo = new StaticInfo();
            newInfo.logRowInstance       = logRowInstance;
            newInfo.captureLogInstance   = captureLogRow;
            newInfo.rowInstance          = new TRow();
            newInfo.rowFieldPrefixLength = PrefixHelper.DeterminePrefixLength(newInfo.rowInstance.EnumerateTableFields(), x => x.Name);
            newInfo.logFieldPrefixLength = PrefixHelper.DeterminePrefixLength(logRowInstance.EnumerateTableFields(), x => x.Name);
            var mappedIdField = captureLogAttr.MappedIdField ?? ((Field)newInfo.rowInstance.IdField).Name;

            newInfo.mappedIdField = ((Row)captureLogRow).FindField(mappedIdField) as IIdField;
            if (newInfo.mappedIdField == null)
            {
                throw new InvalidOperationException(String.Format("Can't locate capture log table mapped ID field for {0}!",
                                                                  ((Row)captureLogRow).Table));
            }

            info = newInfo;
            return(newInfo);
        }
Exemple #5
0
        protected virtual List <TRow> GetItems()
        {
            var list   = new List <TRow>();
            var loader = new TRow();

            var query = new SqlQuery()
                        .From(loader);

            PrepareQuery(query);
            ApplyOrder(query);

            using (var connection = SqlConnections.NewByKey(RowRegistry.GetConnectionKey(loader)))
            {
                query.ForEach(connection, delegate()
                {
                    list.Add(loader.Clone());
                });
            }

            return(list);
        }
        public override void OnAudit(ISaveRequestHandler handler)
        {
            if (handler.Row == null)
            {
                return;
            }

            var auditRequest = GetAuditSaveRequest(handler);

            if (connectionKey == null)
            {
                connectionKey = RowRegistry.GetConnectionKey(handler.Row);
            }

            if (handler.IsCreate)
            {
                if (auditRequest != null)
                {
                    AuditLogService.AuditInsert(handler.UnitOfWork.Connection, connectionKey, auditRequest);
                }

                return;
            }

            Row audit = null;

            if (auditRequest != null)
            {
                audit = AuditLogService.PrepareAuditUpdate(connectionKey, auditRequest);
            }

            if (audit != null)
            {
                handler.UnitOfWork.Connection.Insert(audit);
            }
        }
Exemple #7
0
        public override void OnValidateRequest(ISaveRequestHandler handler)
        {
            base.OnValidateRequest(handler);

            var row      = handler.Row;
            var old      = handler.Old;
            var isUpdate = old == null;

            var parentIdRow = row as IParentIdRow;

            if (parentIdRow == null)
            {
                return;
            }

            var parentId = parentIdRow.ParentIdField[row];

            if (parentId == null)
            {
                return;
            }

            if (isUpdate && parentId == parentIdRow.ParentIdField[old])
            {
                return;
            }

            var parentIdField = (Field)parentIdRow.ParentIdField;

            if (parentIdField.ForeignTable.IsNullOrEmpty())
            {
                return;
            }

            var foreignRow = RowRegistry.GetConnectionRow(RowRegistry.GetConnectionKey(row),
                                                          parentIdField.ForeignTable);

            if (foreignRow == null)
            {
                return;
            }

            var idForeign = (IIdRow)foreignRow;

            if (idForeign == null)
            {
                return;
            }

            var isActiveForeign = (IIsActiveRow)foreignRow;

            if (isActiveForeign == null)
            {
                return;
            }

            ServiceHelper.CheckParentNotDeleted(handler.UnitOfWork.Connection, foreignRow.Table,
                                                query => query.Where(
                                                    new Criteria((Field)idForeign.IdField) == parentId.Value &
                                                    new Criteria(isActiveForeign.IsActiveField) < 0));
        }
Exemple #8
0
        public DbLookupScript(string name, string connectionKey = null, bool authorize = false, string right = null, bool nonCached = false,
                              Func <IDbConnection, IEnumerable <TItem> > getItems = null)
        {
            _lookupParams = new Dictionary <string, object>();

            Row row = null;

            if (typeof(TItem).IsSubclassOf(typeof(Row)))
            {
                row = (Row)(object)(new TItem());
            }

            if (name == null)
            {
                if (row == null)
                {
                    throw new ArgumentNullException("name");
                }

                name = row.Table;
            }

            if (row != null)
            {
                Field field;

                var idRow = row as IIdRow;
                if (idRow != null)
                {
                    field   = ((Field)idRow.IdField);
                    IdField = field.PropertyName ?? field.Name;
                }

                var nameRow = row as INameRow;
                if (nameRow != null)
                {
                    field     = ((Field)nameRow.NameField);
                    TextField = field.PropertyName ?? field.Name;
                }

                var treeRow = row as IParentIdRow;
                if (treeRow != null)
                {
                    field         = ((Field)treeRow.ParentIdField);
                    ParentIdField = field.PropertyName ?? field.Name;
                }
            }

            _scriptName = "Lookup." + name;

            if (connectionKey == null)
            {
                if (row != null)
                {
                    connectionKey = RowRegistry.GetConnectionKey(row);
                }
                else
                {
                    connectionKey = RowRegistry.DefaultConnectionKey;
                }
            }

            _schema = connectionKey;

            _lookup    = name;
            _getItems  = getItems;
            _authorize = authorize;
            _right     = right;
            _nonCached = nonCached;

            if (row != null)
            {
                GroupKey = row.GetFields().GenerationKey;
            }

            Expiration = _nonCached ? TimeSpan.FromDays(-1) : TimeSpan.Zero;

            DynamicScriptManager.Register(this);
        }