I am considering creating an async fork of ServiceStack.OrmLite. I can see that System.Data is referenced in version 2.0.0. I need to add a reference to the 4.0.0 version to get access to the async methods on DbCommand. My strategy would be to go through the code and add async versions of methods by using ExecuteNonQueryAsync, ExecuteReaderAsync and ExecuteScalarAsync instead of their sync counterparts. Because the async methods are defined on DbCommand instead of IDbCommand I would need to cast the IDbCommand to DbCommand.
Are anybody aware of any issues with this approach - is it ok to update reference to 4.0.0 version, any problmes with async in the native drivers for MySql, pgsql, firebird, ormlite?
If not then I will start the work and see how it turs out.
Related
I'm using MOQ to mock a durable entity, but seeing this error:
Extension methods (here: DurableContextExtensions.CallEntityAsync) may
not be used in setup / verification expressions.
Here's how I'm doing it:
mockContext.Setup(e => e.CallEntityAsync<List<string>>(It.IsAny<EntityId>(), "EntityFunctionName"))
.ReturnsAsync(new List<string>() {"one", "two", "three" });
Is there any way I can mock calls to my durable entity?
As of Durable Functions 2.3.0, all of our extension methods are now baked directly into the interface, so it should be substantially easier to use Moq with all of these methods and their overloads.
Edit: The previous answer below covers why the previous extension method approach made this dificult.
So this is an inherent limitation of how Moq works with extension methods.
Unfortunately, in the meantime, you will need to find out the core method on IDurableOrchestrationContext that is called by the extension method that provides the overload you are using.
For instance, in this case, DurableContextExtension.CallEntityAsync(EntityId entityId, string operationName) is calling IDurableOrchestrationContext.CallEntityAsync(EntityId entityId, string operationName, object operationInput), with a value of null for operationInput. You can find this by looking at the source code.
This is obviously not an ideal way for mocking, as without looking at our source code, it is difficult to tell if you are attempting to mock an extension method or not at the time of writing your tests. You can use a Moq analyzer to at least catch these errors at compile time, but it still won't tell you which method signature to mock to get rid of the error.
We are proposing getting rid of extension methods altogether for this reason, and just putting all of these signature overloads as interface methods directly, so you can mock any of them safely. This is a breaking change for customers who write their tests by directly implementing the interface, so we are trying to keep this change out of a patch release, and only in a minor release with clear guidance of how to fix those broken by these changes. Look for this to be fixed in version 2.3.0 of the extension.
Why is the Object.keys function on the global object not returning the process field?
> Object.keys(global)
[
'global',
'clearInterval',
'clearTimeout',
'setInterval',
'setTimeout',
'queueMicrotask',
'clearImmediate',
'setImmediate'
]
> global.process
process {
version: 'v13.7.0',
versions: {
node: '13.7.0',
v8: '7.9.317.25-node.28',
uv: '1.34.1',
process is not actually a key on the global object as of node version 12 (Described in the changelog https://nodejs.org/tr/blog/uncategorized/10-lts-to-12-lts/#notable-changes-in-node-js-12-0-0, implemented through PR https://github.com/nodejs/node/pull/26882). Instead it has a defined getter for it. E.g. try out global.__lookupGetter__('process') and you should see that you get a function back.
> Object.keys(global)
[
'global',
'clearInterval',
'clearTimeout',
'setInterval',
'setTimeout',
'queueMicrotask',
'clearImmediate',
'setImmediate'
]
> global.__lookupGetter__('process')
[Function: get]
> global.__lookupGetter__('process')()
process {
version: 'v13.7.0',
versions: {
node: '13.7.0',
...
The reason for the change as described in the PR:
This implements just the semver major breaking changes from #26334 Restrict process and Buffer globals to CommonJS, which is to make global.process and global.Buffer getters / setters over value properties.
...
The other referenced PR is https://github.com/nodejs/node/pull/26334 which is described as:
This PR deprecates access to global.process and global.Buffer access in ECMAScript modules only, while ensuring they continue to behave fine for all CommonJS modules and contexts providing comprehensive backwards compatibility.
This is done by making them getters which check the context in which they are called and throw when inside an ECMAScript module. To avoid this getter slowpath in accesses, process and Buffer are also added as a context to the compileFunction wrapper in CJS. In addition these getters are only defined as soon as there is a load of an ECMAScript module to avoid any slowdowns in these cases.
The benefits of this are that then ECMAScript modules don't by default have to assume access to all the root-level-security functions and properties on process allowing access control to be added in future, as well as helping towards browser compatibility by making process an import.
ECMAScript modules share the same realm global, so there isn't a way to do this otherwise. In addition once users start running and writing and publishing ECMAScript modules in Node.js that assume the process and Buffer globals exist, it becomes very difficult to change this then.
For these reasons I think it is quite important to land this with the ECMAScript modules implementation in Node.js to provide these properties, or risk never being able to provide them at all in Node.js due to ecosystem compatibility constraints.
With the new 3.0.0 version of Fabric JS we have to apply requestRenderAll() in order to see the handles when one objects is active.
My question is:
does requestRenderAll() replace some kind renderAll() method. Are there any important differences between both methods. When we have to use each of them and do we have to use them together?
I now that Canvas.renderall is a sync operation and requestRenderAll() method is regarded as improvemnt. But do we still need renderAll() and if "yes", when. And also - is renderAll() going to be deprecated in near future?
I started using a Web API cache which I add to particular methods by using an aspect [Cache]. Everything worked great. Later on I changed this method to be async, but since then the compiler started throwing following warnings:
The parameter 'region' of method 'GetTree(System.String,
System.String, System.String[])' has been optimized out by the
compiler and will not be available to the aspect. Disable compiler
optimizations to access the parameter.
Here you can see an example of how I am using Postsharp:
[Cache]
public async Task<IEnumerable<Node>> GetTree(
[FromUri] string region,
[FromUri] string language,
[FromUri] string[] networks)
{
...
await ...
}
What do I need to do in order to get rid of the warning?
The C# compiler optimizations remove the parameters from the state machine class if these parameters are not used anywhere inside the async method. This happens regardless of whether you use PostSharp or not. PostSharp shows you the warning to notify that the removed parameters cannot be accessed inside the aspect.
It's recommended to upgrade to the latest build of PostSharp - the newer versions can handle this issue by re-introducing the missing parameters back into the state machine.
If you cannot upgrade, then the workaround is to disable "Optimize code" in the build page of the project properties for release builds (it's disabled for debug builds by default).
I am using VS2012 and my project is 4.0, but I want to use the async/await keywords, so I install Microsoft.Bcl.Async.
I try to implement my async method in the following way:
public async Task<bool> myMethodAync(int paramInteger)
{
//my code, a simple code that return a bool. Is only an example
if(paramInteger == 2)
{
return true;
}
else return false;
}
I get an error and I get marked the name of the method and the error says something like this: it is not find all the types needed for the modify async. is it the target of the project a wrong version or is it missing the reference for some assembly?
I have the reference for the three assemblies Microsoft.Threading.Task, Microsoft.Threading.Task.Extensions and Microsoft.Threading.Task.Extensions.Desktop and I have the using in my class, System.Threading.task.
What else I need to do?
Thanks.
From http://michaelmairegger.wordpress.com/2012/09/19/cannot-find-all-types-required-by-the-async-modifier/:
The solution to this problem is to reference following nuGet package into all projects in which you want to use the ‘async’ and ‘await’ keyword.
Microsoft.CompilerServices.AsyncTargetingPack
So, right click on References, then select Manage NuGet Packages..., then search online. You may find the package under the name Async Targeting Pack for Visual Studio 11. Install it and the problem should be solved.