Пример #1
0
 private static void SetColumns(IList <object> items, CommitActionType actionType, int _userID)
 {
     foreach (object item in items)
     {
         setProperty(item, AuditInfo.ActionUserID, _userID);
         setProperty(item, AuditInfo.ActionTime, DateTime.Now);
     }
 }
Пример #2
0
        private static void ProcessUpdateItems(DataContext _dataContext, DataContext _historyDataContext, int _userID)
        {
            ChangeSet CurrentChangeSet = _dataContext.GetChangeSet();

            foreach (object item in CurrentChangeSet.Updates)
            {
                ITable table        = _dataContext.GetTable(item.GetType());
                object originalItem = table.GetOriginalEntityState(item);

                CommitActionType actionType = CommitActionType.Update;

                CopyTableColumns(originalItem, actionType, _historyDataContext, _userID);
            }
        }
Пример #3
0
        private static void CopyTableColumns(object item, CommitActionType actionType, DataContext _targetDataContext, int _userID)
        {
            string typeName = item.GetType().AssemblyQualifiedName.Replace(item.GetType().FullName, item.GetType().FullName + "_History");

            Type historyType = Type.GetType(typeName);

            if (historyType != null)
            {
                ObjectHandle instance = Activator.CreateInstance(historyType.Assembly.FullName, item.GetType().FullName + "_History");

                string tableName            = item.GetType().Name;
                List <PropertyInfo> columns = new List <PropertyInfo>();

                foreach (PropertyInfo column in item.GetType().GetProperties())
                {
                    if (AllowedTypes.Contains(column.PropertyType.BaseType.FullName))
                    {
                        columns.Add(column);
                    }
                }

                foreach (var column in instance.Unwrap().GetType().GetProperties())
                {
                    if (columns.FirstOrDefault(q => q.Name == column.Name) != null)
                    {
                        string colName = columns.FirstOrDefault(q => q.Name == column.Name).Name;
                        object val     = item.GetType().GetProperty(colName).GetValue(item, null);
                        column.SetValue(instance.Unwrap(), val, null);
                    }
                }

                setProperty(instance.Unwrap(), AuditInfo.ActionTime, DateTime.UtcNow);
                setProperty(instance.Unwrap(), AuditInfo.ActionUserID, _userID);
                setProperty(instance.Unwrap(), AuditInfo.Action, Convert.ToInt32(actionType));

                _targetDataContext.GetTable(instance.Unwrap().GetType()).InsertOnSubmit(instance.Unwrap());
            }
        }
        private static void CopyTableColumns(object item, CommitActionType actionType, DataContext _targetDataContext, int _userID)
        {
            string typeName = item.GetType().AssemblyQualifiedName.Replace(item.GetType().FullName, item.GetType().FullName + "_History");

            Type historyType = Type.GetType(typeName);

            if (historyType != null)
            {
                ObjectHandle instance = Activator.CreateInstance(historyType.Assembly.FullName, item.GetType().FullName + "_History");

                string tableName = item.GetType().Name;
                List<PropertyInfo> columns = new List<PropertyInfo>();

                foreach (PropertyInfo column in item.GetType().GetProperties())
                {
                    if (AllowedTypes.Contains(column.PropertyType.BaseType.FullName))
                        columns.Add(column);
                }

                foreach (var column in instance.Unwrap().GetType().GetProperties())
                {
                    if (columns.FirstOrDefault(q => q.Name == column.Name) != null)
                    {
                        string colName = columns.FirstOrDefault(q => q.Name == column.Name).Name;
                        object val = item.GetType().GetProperty(colName).GetValue(item, null);
                        column.SetValue(instance.Unwrap(), val, null);
                    }
                }

                setProperty(instance.Unwrap(), AuditInfo.ActionTime, DateTime.UtcNow);
                setProperty(instance.Unwrap(), AuditInfo.ActionUserID, _userID); 
                setProperty(instance.Unwrap(), AuditInfo.Action, Convert.ToInt32(actionType));

                _targetDataContext.GetTable(instance.Unwrap().GetType()).InsertOnSubmit(instance.Unwrap());
            }
        }
 private static void SetColumns(IList<object> items, CommitActionType actionType, int _userID)
 {
     foreach (object item in items)
     {
         setProperty(item, AuditInfo.ActionUserID, _userID);
         setProperty(item, AuditInfo.ActionTime, DateTime.Now);
     }
 }