CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DataPortalContext.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortalContext.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Provides consistent context information between the client</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Security.Principal;
10using System.Collections.Specialized;
11using Csla.Core;
12
13namespace Csla.Server
14{
20 public class DataPortalContext : Csla.Serialization.Mobile.IMobileObject
21 {
22 private IPrincipal _principal;
23 private bool _remotePortal;
24 private string _clientCulture;
25 private string _clientUICulture;
26 private ContextDictionary _clientContext;
27 private ContextDictionary _globalContext;
28 [NonSerialized]
29 private TransactionalTypes _transactionalType;
30 [NonSerialized]
31 private ObjectFactoryAttribute _factoryInfo;
32
37 public IPrincipal Principal
38 {
39 get { return _principal; }
40 }
41
47 public bool IsRemotePortal
48 {
49 get { return _remotePortal; }
50 }
51
56 public string ClientCulture
57 {
58 get { return _clientCulture; }
59 }
60
65 public string ClientUICulture
66 {
67 get { return _clientUICulture; }
68 }
69 internal ContextDictionary ClientContext
70 {
71 get { return _clientContext; }
72 }
73
74 internal ContextDictionary GlobalContext
75 {
76 get { return _globalContext; }
77 }
78
85 {
86 get { return _transactionalType; }
87 internal set { _transactionalType = value; }
88 }
89
97 {
98 get { return _factoryInfo; }
99 internal set { _factoryInfo = value; }
100 }
101
107 public DataPortalContext(IPrincipal principal, bool isRemotePortal)
108 {
109 if (isRemotePortal)
110 {
111 _principal = principal;
112 _remotePortal = isRemotePortal;
113#if NETFX_CORE
114 _clientCulture = System.Globalization.CultureInfo.CurrentCulture.Name;
115 _clientUICulture = System.Globalization.CultureInfo.CurrentUICulture.Name;
116#else
117 _clientCulture =
118 System.Threading.Thread.CurrentThread.CurrentCulture.Name;
119 _clientUICulture =
120 System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
121#endif
122 _clientContext = Csla.ApplicationContext.ContextManager.GetClientContext();
123 _globalContext = Csla.ApplicationContext.ContextManager.GetGlobalContext();
124 }
125 else if (ApplicationContext.WebContextManager != null && ApplicationContext.WebContextManager.IsValid)
126 {
127 _clientContext = Csla.ApplicationContext.ContextManager.GetClientContext();
128 _globalContext = Csla.ApplicationContext.ContextManager.GetGlobalContext();
129 }
130 }
131
141 public DataPortalContext(IPrincipal principal, bool isRemotePortal, string clientCulture, string clientUICulture, ContextDictionary clientContext, ContextDictionary globalContext)
142 {
143 _principal = principal;
144 _clientContext = clientContext;
145 _clientCulture = clientCulture;
146 _clientUICulture = clientUICulture;
147 _globalContext = globalContext;
148 _remotePortal = isRemotePortal;
149 }
150
155 { }
156
157 void Serialization.Mobile.IMobileObject.GetState(Serialization.Mobile.SerializationInfo info)
158 {
159 info.AddValue("principal", Csla.Serialization.SerializationFormatterFactory.GetFormatter().Serialize(_principal));
160 info.AddValue("clientContext", Csla.Serialization.SerializationFormatterFactory.GetFormatter().Serialize(_clientContext));
161 info.AddValue("clientCulture", _clientCulture);
162 info.AddValue("clientUICulture", _clientUICulture);
163 info.AddValue("globalContext", Csla.Serialization.SerializationFormatterFactory.GetFormatter().Serialize(_globalContext));
164 info.AddValue("isRemotePortal", _remotePortal);
165 }
166
167 void Serialization.Mobile.IMobileObject.GetChildren(Serialization.Mobile.SerializationInfo info, Serialization.Mobile.MobileFormatter formatter)
168 {
169 }
170
171 void Serialization.Mobile.IMobileObject.SetState(Serialization.Mobile.SerializationInfo info)
172 {
173 _principal = (IPrincipal)Csla.Serialization.SerializationFormatterFactory.GetFormatter().Deserialize(info.GetValue<byte[]>("principal"));
174 _clientContext = (ContextDictionary)Csla.Serialization.SerializationFormatterFactory.GetFormatter().Deserialize(info.GetValue<byte[]>("clientContext"));
175 _clientCulture = info.GetValue<string>("clientCulture");
176 _clientUICulture = info.GetValue<string>("clientUICulture");
177 _globalContext = (ContextDictionary)Csla.Serialization.SerializationFormatterFactory.GetFormatter().Deserialize(info.GetValue<byte[]>("globalContext")); ;
178 _remotePortal = info.GetValue<bool>("isRemotePortal");
179 }
180
181 void Serialization.Mobile.IMobileObject.SetChildren(Serialization.Mobile.SerializationInfo info, Serialization.Mobile.MobileFormatter formatter)
182 {
183 }
184 }
185}
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Provides consistent context information between the client and server DataPortal objects.
string ClientCulture
The culture setting on the client workstation.
bool IsRemotePortal
Returns true if the server-side DataPortal is running on a remote server via remoting.
string ClientUICulture
The culture setting on the client workstation.
IPrincipal Principal
The current principal object if CSLA security is being used.
ObjectFactoryAttribute FactoryInfo
Gets the current ObjectFactory attribute value (if any).
DataPortalContext(IPrincipal principal, bool isRemotePortal)
Creates a new DataPortalContext object.
DataPortalContext()
Default constructor for use by SerializationFormatterFactory.GetFormatter().
TransactionalTypes TransactionalType
Gets the current transactional type.
DataPortalContext(IPrincipal principal, bool isRemotePortal, string clientCulture, string clientUICulture, ContextDictionary clientContext, ContextDictionary globalContext)
Creates a new DataPortalContext object.
Specifies that the data portal should invoke a factory object rather than the business object.
@ Serialization
The object is being serialized for a clone or data portal operation.
TransactionalTypes
Provides a list of possible transactional technologies to be used by the server-side DataPortal.
@ Serializable
Prevents updating or inserting until the transaction is complete.