Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to CSLA #3636

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Source/Csla.Web.Mvc.Shared/CslaModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CslaModelBinder()
/// Bind the form data to a new instance of an IBusinessBase object.
/// </summary>
/// <param name="bindingContext">Binding context</param>
public Task BindModelAsync(ModelBindingContext bindingContext)
public async Task BindModelAsync(ModelBindingContext bindingContext)
{
ApplicationContext = (ApplicationContext)bindingContext.HttpContext.RequestServices.GetService(typeof(ApplicationContext));
if (bindingContext == null)
Expand All @@ -49,14 +49,13 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
}
else if (typeof(Core.IEditableBusinessObject).IsAssignableFrom(bindingContext.ModelType))
{
BindBusinessBase(bindingContext, result);
await BindBusinessBase(bindingContext, result);
bindingContext.Result = ModelBindingResult.Success(result);
}
}
return Task.CompletedTask;
}

private void BindBusinessBase(ModelBindingContext bindingContext, object result)
private async Task BindBusinessBase(ModelBindingContext bindingContext, object result)
{
var properties = Core.FieldManager.PropertyInfoManager.GetRegisteredProperties(bindingContext.ModelType);
foreach (var item in properties)
Expand All @@ -68,7 +67,7 @@ private void BindBusinessBase(ModelBindingContext bindingContext, object result)
index = $"{bindingContext.ModelName}.{item.Name}";
BindSingleProperty(bindingContext, result, item, index);
}
CheckRules(result);
await CheckRulesAsync(result);
}

private void BindBusinessListBase(ModelBindingContext bindingContext, object result)
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla.Xaml.Shared/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static CslaOptions AddXaml(this CslaOptions config, Action<XamlOptions> o
options?.Invoke(xamlOptions);

// use correct mode for raising PropertyChanged events
ApplicationContext.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml;
config.BindingOptions.PropertyChangedMode = ApplicationContext.PropertyChangedModes.Xaml;

return config;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/BusinessBindingListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ public override bool IsBusy
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{
this.MarkAsChild();
Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/BusinessListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,8 @@ void Core.IEditableCollection.SetParent(Core.IParent parent)
void IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void IDataPortalTarget.MarkAsChild()
{
this.MarkAsChild();
Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, E
void IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void IDataPortalTarget.MarkAsChild()
{ }

Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Configuration/Fluent/DataOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public int DefaultTransactionTimeoutInSeconds
/// </summary>
/// <param name="dbProvider"></param>
/// <returns></returns>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public DataOptions DbProvider(string dbProvider)
{
Data.ConnectionManager.DbProvider = dbProvider;
Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/Core/BusinessBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3429,6 +3429,8 @@ void Csla.Server.IDataPortalTarget.CheckRules()
BusinessRules.CheckRules();
}

async Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => await BusinessRules.CheckRulesAsync();

void Csla.Server.IDataPortalTarget.MarkAsChild()
{
this.MarkAsChild();
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Csla.Data
/// dispose the connection when the last consumer
/// has called Dispose."
/// </remarks>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class ConnectionManager : IDisposable, Core.IUseApplicationContext
{
private static object _lock = new object();
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/ConnectionManagerT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Csla.Data
/// dispose the connection when the last consumer
/// has called Dispose."
/// </remarks>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class ConnectionManager<C> : IDisposable, Core.IUseApplicationContext
where C : IDbConnection, new()
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/ContextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Csla.Data
/// dispose the object when the last consumer
/// has called Dispose."
/// </remarks>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class ContextManager<C> : IDisposable, Core.IUseApplicationContext
where C : DataContext
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/DataServiceContextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Csla.Data
/// <typeparam name="C">
/// Type of context object to use.
/// </typeparam>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class DataServiceContextManager<C> : Core.IUseApplicationContext
where C : System.Data.Services.Client.DataServiceContext
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/ServiceClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Csla.Data
/// <typeparam name="T">
/// Channel type for the ClientBase object.
/// </typeparam>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class ServiceClientManager<C, T> : Core.IUseApplicationContext
where C : System.ServiceModel.ClientBase<T>
where T : class
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla/Data/TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Csla.Data
/// dispose the transaction when the last consumer
/// has called Dispose."
/// </remarks>
[Obsolete("Use dependency injection", false)]
[Obsolete("Use dependency injection", true)]
public class TransactionManager<C, T> : IDisposable, Core.IUseApplicationContext
where C : IDbConnection, new()
where T : IDbTransaction
Expand Down
6 changes: 2 additions & 4 deletions Source/Csla/DataPortalClient/DataPortalCacheDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class DataPortalCacheDefault : IDataPortalCache
/// <param name="criteria">Criteria for domain type being added</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Data portal result to cache</param>
/// <returns></returns>
public Task AddObject(Type objectType, object criteria, DataPortalOperations operation, DataPortalResult result)
public Task AddDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation, DataPortalResult result)
=> throw new NotImplementedException();

/// <summary>
Expand All @@ -54,9 +53,8 @@ public bool IsCacheable(Type objectType, object criteria, DataPortalOperations o
/// <param name="objectType">Type of domain object to retrieve</param>
/// <param name="criteria">Criteria for domain type being retrieved</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Cached data portal result</param>
/// <returns>true if success, false if object isn't returned</returns>
public Task<bool> TryGetObject(Type objectType, object criteria, DataPortalOperations operation, out DataPortalResult result)
public Task<DataPortalResult> GetDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation)
=> throw new NotImplementedException();
}
}
9 changes: 4 additions & 5 deletions Source/Csla/DataPortalClient/IDataPortalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ namespace Csla.DataPortalClient
public interface IDataPortalCache
{
/// <summary>
/// Try to get object from cache.
/// Try to get result from cache.
/// </summary>
/// <param name="objectType">Type of domain object to retrieve</param>
/// <param name="criteria">Criteria for domain type being retrieved</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Cached data portal result</param>
/// <returns>true if success, false if object isn't returned</returns>
Task<bool> TryGetObject(Type objectType, object criteria, DataPortalOperations operation, out Server.DataPortalResult result);
/// <returns>null if not in cache</returns>
Task<Server.DataPortalResult?> GetDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation);
/// <summary>
/// Add object to cache.
/// </summary>
Expand All @@ -35,7 +34,7 @@ public interface IDataPortalCache
/// <param name="operation">Data portal operation</param>
/// <param name="result">Data portal result to cache</param>
/// <returns></returns>
Task AddObject(Type objectType, object criteria, DataPortalOperations operation, Server.DataPortalResult result);
Task AddDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation, Server.DataPortalResult result);
/// <summary>
/// Gets a value indicating whether the domain type
/// can be cached.
Expand Down
25 changes: 15 additions & 10 deletions Source/Csla/DataPortalT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ private async Task<object> DoCreateAsync(Type objectType, object criteria, bool
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Create, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Create);
if (result is null)
{
result = await proxy.Create(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Create, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Create, result);
}
}
finally
Expand Down Expand Up @@ -246,10 +247,11 @@ private async Task<object> DoFetchAsync(Type objectType, object criteria, bool i
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Fetch, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Fetch);
if (result is null)
{
result = await proxy.Fetch(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Fetch, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Fetch, result);
}
}
finally
Expand Down Expand Up @@ -310,10 +312,11 @@ private async Task<object> DoExecuteAsync(Type objectType, object criteria, bool
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Execute, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Execute);
if (result is null)
{
result = await proxy.Fetch(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Execute, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Execute, result);
}
}
finally
Expand Down Expand Up @@ -543,10 +546,11 @@ internal async Task<T> DoUpdateAsync(T obj, bool isSync)
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, obj, operation, out result))
result = await Cache.GetDataPortalResultAsync(objectType, obj, operation);
if (result is null)
{
result = await proxy.Update(obj, dpContext, isSync);
await Cache.AddObject(objectType, obj, operation, result);
await Cache.AddDataPortalResultAsync(objectType, obj, operation, result);
}
}
finally
Expand Down Expand Up @@ -651,10 +655,11 @@ internal async Task DoDeleteAsync(Type objectType, object criteria, bool isSync)
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Delete, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Delete);
if (result is null)
{
result = await proxy.Delete(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Delete, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Delete, result);
}
}
finally
Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/DynamicBindingListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ public T[] ToArray()
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/DynamicListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ public T[] ToArray()
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
3 changes: 3 additions & 0 deletions Source/Csla/NameValueListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Csla.Properties;
using Csla.Core;
using Csla.Serialization.Mobile;
using System.Threading.Tasks;

namespace Csla
{
Expand Down Expand Up @@ -328,6 +329,8 @@ protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, E
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/ReadOnlyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,8 @@ protected virtual void OnBusyChanged(BusyChangedEventArgs args)
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
3 changes: 3 additions & 0 deletions Source/Csla/ReadOnlyBindingListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class ReadOnlyBindingListBase<T, C> : ReadOnlyListBase<T, C>
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Csla.Properties;

namespace Csla
Expand Down Expand Up @@ -211,6 +212,8 @@ public C[] ToArray()
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
3 changes: 3 additions & 0 deletions Source/Csla/ReadOnlyListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics.CodeAnalysis;
using Csla.Properties;
using System;
using System.Threading.Tasks;

namespace Csla
{
Expand Down Expand Up @@ -205,6 +206,8 @@ protected virtual void Child_OnDataPortalException(DataPortalEventArgs e, Except
void Csla.Server.IDataPortalTarget.CheckRules()
{ }

Task Csla.Server.IDataPortalTarget.CheckRulesAsync() => Task.CompletedTask;

void Csla.Server.IDataPortalTarget.MarkAsChild()
{ }

Expand Down
2 changes: 2 additions & 0 deletions Source/Csla/Server/IDataPortalTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// <summary>no summary</summary>
//-----------------------------------------------------------------------
using System;
using System.Threading.Tasks;

namespace Csla.Server
{
Expand All @@ -15,6 +16,7 @@ internal interface IDataPortalTarget
void MarkNew();
void MarkOld();
void CheckRules();
Task CheckRulesAsync();
void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e);
void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e);
void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex);
Expand Down
17 changes: 17 additions & 0 deletions Source/Csla/Server/ObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// <summary>Base class to be used when creating a data portal</summary>
//-----------------------------------------------------------------------
using System;
using System.Threading.Tasks;
using Csla.Core;
using Csla.Properties;
using Csla.Reflection;
Expand Down Expand Up @@ -61,6 +62,22 @@ protected void CheckRules(object obj)
MethodCaller.CallMethodIfImplemented(obj, "CheckRules", null);
}

/// <summary>
/// Calls the ValidationRules.CheckRules() method
/// on the specified object, if possible.
/// </summary>
/// <param name="obj">
/// Object on which to call the method.
/// </param>
protected async Task CheckRulesAsync(object obj)
{
var target = obj as IDataPortalTarget;
if (target != null)
await target.CheckRulesAsync();
else
MethodCaller.CallMethodIfImplemented(obj, "CheckRules", null);
}

/// <summary>
/// Calls the MarkOld method on the specified
/// object, if possible.
Expand Down
Loading
Loading