This commit is contained in:
2018-06-29 19:47:36 +00:00
commit be7f501333
3769 changed files with 1425961 additions and 0 deletions

View File

@@ -0,0 +1 @@
CSLA.Server.DataPortal.xml

View File

@@ -0,0 +1,38 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("CSLA.Server.DataPortal")>
<Assembly: AssemblyDescription("CSLA .NET framework MODIFIED FROM ORIGINAL SIGNIFICANTLY")>
<Assembly: AssemblyCompany("Rockford Lhotka MODIFIED FROM ORIGINAL SIGNIFICANTLY")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("Copyright 2003 Rockford Lhotka. All rights reserved.")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("1E5537B9-A381-4E20-8869-47FBAC978A2D")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
<Assembly: AssemblyVersion("7.5.0.0")>
' strong name
'<Assembly: AssemblyKeyFile("..\..\..\..\..\keys\AyaNova.snk")>
<Assembly: AssemblyFileVersionAttribute("7.5.0.0")>

View File

@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{80828E2C-E9FB-4E73-A27C-7F9CDB96FCDE}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>CSLA.Server.DataPortal</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\..\keys\AyaNova.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyMode>None</AssemblyOriginatorKeyMode>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<OptionCompare>Binary</OptionCompare>
<OptionExplicit>On</OptionExplicit>
<OptionStrict>Off</OptionStrict>
<RootNamespace>CSLA</RootNamespace>
<StartupObject>CSLA.%28None%29</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<MyType>Windows</MyType>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<SignAssembly>true</SignAssembly>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>CSLA.Server.DataPortal.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>
</DefineConstants>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>CSLA.Server.DataPortal.xml</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>
</DefineConstants>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>none</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'RELEASE AND DEPLOY BUILD|AnyCPU' ">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\RELEASE AND DEPLOY BUILD\</OutputPath>
<BaseAddress>285212672</BaseAddress>
<DocumentationFile>CSLA.Server.DataPortal.xml</DocumentationFile>
<Optimize>true</Optimize>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>
</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
</Reference>
<Reference Include="System.configuration" />
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
<Reference Include="System.Xml">
<Name>System.XML</Name>
</Reference>
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="CriteriaBase.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="DataPortal.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="DataPortalContext.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="ISerializationNotification.vb">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\keys\AyaNova.snk">
<Link>AyaNova.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastOpenVersion>7.10.3077</LastOpenVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ReferencePath>
</ReferencePath>
<CopyProjectDestinationFolder>
</CopyProjectDestinationFolder>
<CopyProjectUncPath>
</CopyProjectUncPath>
<CopyProjectOption>0</CopyProjectOption>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectTrust>0</ProjectTrust>
<PublishUrlHistory>
</PublishUrlHistory>
<InstallUrlHistory>
</InstallUrlHistory>
<SupportUrlHistory>
</SupportUrlHistory>
<UpdateUrlHistory>
</UpdateUrlHistory>
<BootstrapperUrlHistory>
</BootstrapperUrlHistory>
<ErrorReportUrlHistory>
</ErrorReportUrlHistory>
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<EnableASPDebugging>false</EnableASPDebugging>
<EnableASPXDebugging>false</EnableASPXDebugging>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
<EnableSQLServerDebugging>false</EnableSQLServerDebugging>
<RemoteDebugEnabled>false</RemoteDebugEnabled>
<RemoteDebugMachine>
</RemoteDebugMachine>
<StartAction>Project</StartAction>
<StartArguments>
</StartArguments>
<StartPage>
</StartPage>
<StartProgram>
</StartProgram>
<StartURL>
</StartURL>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartWithIE>false</StartWithIE>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<EnableASPDebugging>false</EnableASPDebugging>
<EnableASPXDebugging>false</EnableASPXDebugging>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
<EnableSQLServerDebugging>false</EnableSQLServerDebugging>
<RemoteDebugEnabled>false</RemoteDebugEnabled>
<RemoteDebugMachine>
</RemoteDebugMachine>
<StartAction>Project</StartAction>
<StartArguments>
</StartArguments>
<StartPage>
</StartPage>
<StartProgram>
</StartProgram>
<StartURL>
</StartURL>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartWithIE>false</StartWithIE>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,21 @@
''' <summary>
''' Base type from which Criteria classes can be
''' derived in a business class.
''' </summary>
<Serializable()> _
Public MustInherit Class CriteriaBase
''' <summary>
''' Type of the business object to be instantiated by
''' the server-side DataPortal.
''' </summary>
Public ObjectType As Type
''' <summary>
''' Initializes CriteriaBase with the type of
''' business object to be created by the DataPortal.
''' </summary>
Public Sub New(ByVal Type As Type)
ObjectType = Type
End Sub
End Class

View File

@@ -0,0 +1,274 @@
Imports System.Reflection
Imports System.Security.Principal
'case 1012
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO.Compression
Imports System.IO
'Imports System.Configuration
Namespace Server
''' <summary>
''' Implements the server-side DataPortal as discussed
''' in Chapter 5.
''' </summary>
Public Class DataPortal
Inherits MarshalByRefObject
#Region " Data Access "
''' <summary>
''' Called by the client-side DataPortal to create a new object.
''' </summary>
''' <param name="Criteria">Object-specific criteria.</param>
''' <param name="context">The user's principal object (if using CSLA .NET security).</param>
''' <returns>A populated business object.</returns>
Public Function Create(ByVal Criteria As Object, ByVal context As DataPortalContext) As Object
SetPrincipal(context.Principal)
' create an instance of the business object
Dim obj As Object = CreateBusinessObject(Criteria)
' tell the business object to fetch its data
CallMethod(obj, "DataPortal_Create", Criteria)
' return the populated business object as a result
If context.IsRemotePortal Then
Serialization.SerializationNotification.OnSerializing(obj)
End If
Return obj
End Function
''' <summary>
''' Called by the client-side DataProtal to retrieve an object.
''' </summary>
''' <param name="Criteria">Object-specific criteria.</param>
''' <param name="context">The user's principal object (if using CSLA .NET security).</param>
''' <returns>A populated business object.</returns>
Public Function Fetch(ByVal Criteria As Object, ByVal context As DataPortalContext) As Object
SetPrincipal(context.Principal)
' create an instance of the business object
Dim obj As Object = CreateBusinessObject(Criteria)
' tell the business object to fetch its data
CallMethod(obj, "DataPortal_Fetch", Criteria)
' return the populated business object as a result
'If context.IsRemotePortal Then
' Serialization.SerializationNotification.OnSerializing(obj)
'End If
'case 1012
If context.IsRemotePortal Then
Return Compress(obj)
Else
Return obj
End If
'Return obj
End Function
''' <summary>
''' Called by the client-side DataPortal to update an object.
''' </summary>
''' <param name="obj">A reference to the object being updated.</param>
''' <param name="context">The user's principal object (if using CSLA .NET security).</param>
''' <returns>A reference to the newly updated object.</returns>
Public Function Update(ByVal obj As Object, ByVal context As DataPortalContext) As Object
SetPrincipal(context.Principal)
Dim canCompress As Boolean = True
'case 1012
If context.IsRemotePortal AndAlso canCompress Then
'it's coming from the client compressed so decompress first
'Note servicebank can't be compressed due to transaction object not being serializable
If (obj.GetType().ToString() <> "GZTW.AyaNova.BLL.ServiceBank") Then
obj = Decompress(DirectCast(obj, Byte()))
Else
canCompress = False
End If
End If
' tell the business object to update itself
CallMethod(obj, "DataPortal_Update")
'case 1012
If context.IsRemotePortal AndAlso canCompress Then
'It's going back to the client remotely so compress it first
Return Compress(obj)
Else
Return obj
End If
'Return obj
End Function
''' <summary>
''' Called by the client-side DataPortal to delete an object.
''' </summary>
''' <param name="Criteria">Object-specific criteria.</param>
''' <param name="context">The user's principal object (if using CSLA .NET security).</param>
Public Sub Delete(ByVal Criteria As Object, ByVal context As DataPortalContext)
SetPrincipal(context.Principal)
' create an instance of the business object
Dim obj As Object = CreateBusinessObject(Criteria)
' tell the business object to delete itself
CallMethod(obj, "DataPortal_Delete", Criteria)
End Sub
#End Region
#Region "Compression" 'case 1012
Private Shared bSerializer As New BinaryFormatter
Public Shared Function Compress(ByVal obj As Object) As Byte()
Dim ms3 As New MemoryStream
Dim cmp3 As New GZipStream(ms3, CompressionMode.Compress, False)
bSerializer.Serialize(cmp3, obj)
cmp3.Flush()
cmp3.Close()
Return ms3.ToArray()
End Function
Public Shared Function Decompress(ByVal bytes() As Byte) As Object
Dim ms4 As New MemoryStream(bytes)
Dim cmp4 As New GZipStream(ms4, CompressionMode.Decompress)
Dim o As Object = bSerializer.Deserialize(cmp4)
Return o
End Function
#End Region
#Region " Security "
Private Function AUTHENTICATION() As String
Return "CSLA" 'System.CoXXXnfiguration.ConfigurationManager.AppSettings("Authentication")
End Function
Private Sub SetPrincipal(ByVal Principal As Object)
Dim objPrincipal As IPrincipal
Dim objIdentity As IIdentity
If AUTHENTICATION() = "Windows" Then
' When using integrated security, Principal must be Nothing
If Principal Is Nothing Then
' Set .NET to use integrated security
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
Exit Sub
Else
Throw New Security.SecurityException( _
"No principal object should be passed to DataPortal when using Windows integrated security")
End If
End If
' We expect the Principal to be of the type BusinessPrincipal, but we can't enforce
' that since it causes a circular reference with the business library.
' Instead we must use type Object for the parameter, so here we do a check
' on the type of the parameter.
objPrincipal = CType(Principal, IPrincipal)
If Not (objPrincipal Is Nothing) Then
objIdentity = objPrincipal.Identity
If Not (objIdentity Is Nothing) Then
If objIdentity.AuthenticationType = "CSLA" Then
' See if our current principal is different from the caller's principal
If Not ReferenceEquals(Principal, _
System.Threading.Thread.CurrentPrincipal) Then
' The caller had a different principal, so change ours to match the
' caller's, so all our objects use the caller's security.
System.Threading.Thread.CurrentPrincipal = CType(Principal, _
IPrincipal)
End If
Else
Throw New Security.SecurityException( _
"Principal must be of type BusinessPrincipal, not " & Principal.ToString())
End If
End If
Else
Throw New Security.SecurityException( _
"Principal must be of type BusinessPrincipal, not Nothing")
End If
End Sub
#End Region
#Region " Creating the business object "
Private Function CreateBusinessObject(ByVal Criteria As Object) As Object
Dim businessType As Type
If Criteria.GetType.IsSubclassOf(GetType(CriteriaBase)) Then
' get the type of the actual business object
' from CriteriaBase (using the new scheme)
businessType = CType(Criteria, CriteriaBase).ObjectType
Else
' get the type of the actual business object
' based on the nested class scheme in the book
businessType = Criteria.GetType.DeclaringType
End If
' create an instance of the business object
Return Activator.CreateInstance(businessType, True)
End Function
#End Region
#Region " Calling a method "
Private Function CallMethod(ByVal obj As Object, ByVal method As String, ByVal ParamArray params() As Object) As Object
' call a private method on the object
Dim info As MethodInfo = GetMethod(obj.GetType, method)
Dim result As Object
Try
result = info.Invoke(obj, params)
Catch e As Exception
Throw 'e.InnerException
End Try
Return result
End Function
Private Function GetMethod(ByVal ObjectType As Type, ByVal method As String) As MethodInfo
Return ObjectType.GetMethod(method, _
BindingFlags.FlattenHierarchy Or _
BindingFlags.Instance Or _
BindingFlags.Public Or _
BindingFlags.NonPublic)
End Function
#End Region
End Class
End Namespace

View File

@@ -0,0 +1,64 @@
Imports System.Security.Principal
Namespace Server
''' <summary>
''' Provides consistent context information between the client
''' and server DataPortal objects.
''' </summary>
''' <remarks>
''' The context includes the current
''' <see cref="T:CSLA.Security.BusinessPrincipal" />
''' object if CSLA security is being used. It also includes a
''' flag indicating whether the server-side DataPortal is running
''' locally or remotely.
''' </remarks>
<Serializable()> _
Public Class DataPortalContext
Private mPrincipal As IPrincipal
Private mRemotePortal As Boolean
''' <summary>
''' The current <see cref="T:CSLA.Security.BusinessPrincipal" />
''' if CSLA security is being used.
''' </summary>
Public ReadOnly Property Principal() As IPrincipal
Get
Return mPrincipal
End Get
End Property
''' <summary>
''' Returns True if the server-side DataPortal is running
''' on a remote server via remoting.
''' </summary>
Public ReadOnly Property IsRemotePortal() As Boolean
Get
Return mRemotePortal
End Get
End Property
''' <summary>
''' Creates a new DataPortalContext object.
''' </summary>
''' <param name="isRemotePortal">Indicates whether the DataPortal is remote.</param>
Public Sub New(ByVal isRemotePortal As Boolean)
mPrincipal = Nothing
mRemotePortal = isRemotePortal
End Sub
''' <summary>
''' Creates a new DataPortalContext object.
''' </summary>
''' <param name="principal">The current Principal object.</param>
''' <param name="isRemotePortal">Indicates whether the DataPortal is remote.</param>
Public Sub New(ByVal principal As IPrincipal, ByVal isRemotePortal As Boolean)
mPrincipal = principal
mRemotePortal = isRemotePortal
End Sub
End Class
End Namespace

View File

@@ -0,0 +1,83 @@
Namespace Serialization
''' <summary>
''' Objects can implement this interface if they wish to be
''' notified of serialization events.
''' </summary>
''' <remarks>
''' <para>
''' Note that .NET serialization does NOT call these methods. Only
''' code that checks for the ISerializationNotification interface
''' when serializating and deserializing objects will invoke these
''' methods.
''' </para><para>
''' The CSLA .NET framework's DataPortal processing and the Clone
''' method in BusinessBase automatically make these calls.
''' </para>
''' </remarks>
Public Interface ISerializationNotification
''' <summary>
''' This method is called before an object is serialized.
''' </summary>
Sub Serializing()
''' <summary>
''' This method is called on the original instance of the
''' object after it has been serialized.
''' </summary>
Sub Serialized()
''' <summary>
''' This method is called on a newly deserialized object
''' after deserialization is complete.
''' </summary>
Sub Deserialized()
End Interface
''' <summary>
''' Helper methods for invoking the ISerializatoinNotification
''' methods.
''' </summary>
Public Class SerializationNotification
''' <summary>
''' Invokes the Serializing method on the target object
''' if it has implemented ISerializationNotification.
''' </summary>
''' <param name="target">Object on which the method should be invoked.</param>
Public Shared Sub OnSerializing(ByVal target As Object)
If TypeOf target Is ISerializationNotification Then
DirectCast(target, ISerializationNotification).Serializing()
End If
End Sub
''' <summary>
''' Invokes the Serialized method on the target object
''' if it has implemented ISerializationNotification.
''' </summary>
''' <param name="target">Object on which the method should be invoked.</param>
Public Shared Sub OnSerialized(ByVal target As Object)
If TypeOf target Is ISerializationNotification Then
DirectCast(target, ISerializationNotification).Serialized()
End If
End Sub
''' <summary>
''' Invokes the Deserialized method on the target object
''' if it has implemented ISerializationNotification.
''' </summary>
''' <param name="target">Object on which the method should be invoked.</param>
Public Shared Sub OnDeserialized(ByVal target As Object)
If TypeOf target Is ISerializationNotification Then
DirectCast(target, ISerializationNotification).Deserialized()
End If
End Sub
End Class
End Namespace