[DevExpress Support Team: CLONED FROM T683644: FAQ: XPO Async/Await Method Support]
I'm having a bit of a problem.
I'm using WCF, and connection pooling, and SQL server depen dency notifications (and SQL provider descendant for CTE support).
Basically, everything available :)
Connection is made thus (DbSqlServerProvider is the name of MSSqlProvider descendant with CTE):
C#public override IDataStore CreateDataStore(ConnectionInfo ci)
{
DbSqlServerProvider.Register();
var xpoConnectionString = ci.User.IsBlank()
? DbSqlServerProvider.GetConnectionString(ci.Server, ci.Database)
: DbSqlServerProvider.GetConnectionString(ci.Server, ci.User, ci.Password, ci.Database);
xpoConnectionString = String.Concat(xpoConnectionString, ";", "MultipleActiveResultSets=true");
var sqlParser = new ConnectionStringParser(xpoConnectionString);
sqlParser.RemovePartByName(DbSqlServerProvider.XpoProviderTypeParameterName);
var sqlConnectionString = sqlParser.GetConnectionString();
var sqlConnection = new SqlConnection(sqlConnectionString);
var sqlStore = new DbSqlServerProvider(sqlConnection, AutoCreateOption.DatabaseAndSchema);
DbEngine.FSPath = SqlClrAssembly.Check(sqlConnection);
var poolConnectionString = XpoDefault.GetConnectionPoolString(xpoConnectionString);
var poolStore = XpoDefault.GetConnectionProvider(poolConnectionString, AutoCreateOption.DatabaseAndSchema);
var cacheConfiguration = new DataCacheConfiguration(DataCacheConfigurationCaching.NotInList);
var objectsToDispose = new IDisposable[] { sqlConnection };
var root = MSSql2005SqlDependencyCacheRoot.CreateSqlDependencyCacheRoot(poolStore, sqlConnection, sqlStore, cacheConfiguration, out objectsToDispose);
var node = new DataCacheNodeLocal(root) { MaxCacheLatency = TimeSpan.Zero };
node.ProcessCookie(DataCacheCookie.Empty);
return node;
}
So far, so good …
On the client, on the other side of the WCF code is:
C# public override IDataStore CreateDataStore(ConnectionInfo ci)
...
var client = new CachedDataStoreClient(binding, new EndpointAddress(uri));
...
var root = client as ICachedDataStore;
var node = new DataCacheNode(root)
{
...
};
...
node.ProcessCookie(DataCacheCookie.Empty);
return node;
}
Actually, above is wrapped in 'XDataStoreWrapper' which just wrappes above node as IDataStore and adds some logging.
This worked until 19.1.
Now, under certain circumstances, I get the exception:
Your 'XDataStoreWrapper' Connection Provider does not support the 'DevExpress.Xpo.DB.IDataStoreAsync' interface. Please implement this interface, or use another compatible Connection Provider.
Now, I *cannot* forward implementation of IDataStoreAsync in wrapper as DataCacheNode (nor ICachedDataStore) do NOT implement it. So I basically wrote the following dummy wrappers:
C# public sealed class XDataStoreWrapper :
IDataStore,
IDataStoreSchemaExplorer,
ICommandChannel,
ICachedDataStore,
ICacheToCacheCommunicationCore,
IDataStoreAsync,
...
...
public IDataStore Store { get; }
public XDataStoreWrapper(IDataStore nested) => Store = nested;
...
...
public Task<ModificationResult> ModifyDataAsync(CancellationToken token, params ModificationStatement[] statements) => Store is IDataStoreAsync sa
? sa.ModifyDataAsync(token, statements)
: Task.Factory.StartNew(() => Store.ModifyData(statements), token);
public Task<SelectedData> SelectDataAsync(CancellationToken token, params SelectStatement[] statements) => Store is IDataStoreAsync sa
? sa.SelectDataAsync(token, statements)
: Task.Factory.StartNew(() => Store.SelectData(statements), token);
...
...
… but it doesn't feel quite right.
Basically what I'm asking is since you provide class CachedDataStoreService (which implements ICachedDataStoreService), shouldn't there also be (say) CachedDataStoreServiceAsync implementing ICachedDataStoreServiceAsync.
Or am I missing something obvious?
--------------------
Actually, it seems I'm overcomplicating it.
Basically, I try to avoid the exception:
Connection Provider does not support the 'DevExpress.Xpo.DB.IDataStoreAsync' interface. Please implement this interface, or use another compatible Connection Provider.
So, I change this
C#var client = new CachedDataStoreClient(binding, new EndpointAddress(uri));
var node = new DataCacheNode(client);
return node;
… to this …
C#var client = new CachedDataStoreClientAsync(binding, new EndpointAddress(uri));
var node = new DataCacheNode(client);
return node;
But that doesn't seem to help, as ICachedDataStoreAsync which client implements is 'lost' when chaining to DataCacheNode?
--------------------------
So, is there something like DataCacheNodeAsync planned for 19.1 or should fallback to Task.Run substitues in IDataStore wrapper classes via Task.Factory.Start as above in the first post?