Is it possible to get information about which advice has been caught in an adviceexecution pointcut? - aspectj

I have an aspect in my application that intercepts every advice execution on the system. I want to be able to identify which advice is being "intercepted" by my adviceexecution pointcut like this
//... some code in AdviceInspector.aj
before(): adviceexecution() && !within(AdviceInspector) {
System.out.println("advice execution being intercepted");
// TODO : get a way to know which advice execution has been intercepted
}
//... further code
Thanks in advance

You can get the Signature of the advice from the joinPoint. Signature has various methods to describe it. If it is just for debugging the toString() method describes it nicely
before(): adviceexecution() && !within(AdviceInspector) {
org.aspectj.lang.Signature sig = thisJoinPoint.getStaticPart().getSignature();
//It is also valid to do
//Signature sig = thisJoinPointStaticPart.getSignature();
System.out.println(sig);
}

Related

Bound variable in ViewModel is not updating the displayed value

I was trying to create an countdown timer in ViewModel but i didnt found any method to do that so i ve tried to do this with task delay and while loop but it ends after first task delay. Do u know any other way how to do that or how to repair that one.
public PageViewModel()
{
MethodName();
}
public async void MethodName()
{
CountSeconds = 10;
while (CountSeconds > 0)
{
await Task.Delay(1000);
CountSeconds--;
}
}
The reason why you can`t see others is related to context. You trying to run async code in non-async context.
To solve this problem you can do several ways, which way to choose is your choice and depends on your needs:
await MethodName();
async Task MethodName()
{
CountSeconds = 10;
while (CountSeconds > 0)
{
await Task.Delay(1000);
CountSeconds--;
}
}
Another way is to create various of tasks and execute them, here you can see methods, which can help you.
And as Rand Random metioned it's not about MAUI, it`s about understanding of async programming itself, so for you will be usefull read more about it.
You can use Dispatacher.StartTimer() (available in the DispatcherExtensions class) to create a function that will execute every x seconds/minutes/hours (depending of what you're setting) using the device's clock.
To access the Application's Dispatcher from any class, use the following line:
var dispatcher = Application.Current.Dispatcher;
Since there is no documentation available yet for MAUI, you can read the Device.StartTimer() documentation from Xamarin, which acts exactly the same.

Flutter & Dart: How to check/know which class has called a function?

I am trying to know which class has called a specific function. I've been looking through the docs for this, but without success. I already know how to get the name of a class, but that is something different of what I'm looking for. I found already something related for java but for dart I haven't. Maybe I'm missing something.
Let's say for example that I have a print function like so:
class A {
void printSomethingAndTellWhereYouDidIt() {
// Here I would also include the class where this function is
// being called. For instance:
print('you called the function at: ...');
//This dot-dot-dot is where maybe should go what I'm looking for.
}
}
class B {
A a = A();
void test() {
a.printSomethingAndTellWhereYouDidIt();
}
}
The output should be something like:
you called the function at: B
Please let me know if there are ways to achieve this. The idea behind is to then use this with a logger, for instance the logging package. Thank you in advance.
You can use StackTrace.current to obtain a stack trace at any time, which is the object that's printed when an exception occurs. This contains the line numbers of the chain of invocations leading up to the call, which should provide the information you need.
class A {
void printSomethingAndTellWhereYouDidIt() {
print(StackTrace.current);
}
}
class B {
A a = A();
void test() {
a.printSomethingAndTellWhereYouDidIt();
}
}
If you are doing this for debugging purposes, you can also set a breakpoint in printSomethingAndTellWhereYouDidIt to check where it was called from.

usage of copy_Path after stroke() or fill()

How is it possible to copy a path after a call to stroke() or fill() ?
I've setup a caching mecanism which looks like that
high end visual object class:
override void DrawDirect(canvas aCanvas)
{
aCanvas.Line(...)
aCanvas.Rectangle(...)
// etc.
MyCache = aCanvas.GetPath(); // = canvas.Context.copy_Path()
IsCached = true;
}
override void DrawCache(canvas aCanvas)
{
aCanvas.DrawPath(MyCache); // = canvas.Context.appendPath...
}
and the super class has this method:
voidDraw(canvas aCanvas)
{
if(IsCached) DrawCache();
else DrawDirect;
}
the canvas defines this kind of methods:
void Line(...)
{
Context.moveTo(...)
Context.lineTo(...)
Context.stroke();
}
when I call GetPath, MyCache.numData is equal to 0 unless I comment the calls to stroke() and to fill().
But as a side effect the DrawDirect methods do (visually) nothing.
One other subsequent question would be: is calling appendPath (really) faster than calling the basic "direct" methods ? (you can comment about this, I'll only accept answers about the copy_Path stuff).
Cairo has stroke() which deletes the path after stroking and stroke_preserve() which does not touch the path and leaves it as-is.
I don't really know if appendPath() is faster than re-creating the path directly, but I really cannot imagine that something like this should be a performance issue. It likely depends on your paths anyway and you should just benchmark this yourself.

Conditional exception raising in a flow block

While using Akka's data-flow DSL, I have twice encountered a need to throw an exception inside future, conditionally. This is how I am doing it:
flow {
// ...
if (someCond)
shiftUnit(throw new SomeException)
else
Future().apply()
// ...
}
Is this the correct way to do it? Or is there a better approach?
The approach seems correct (although my knowledge is a bit rusty), you can even leave out the other branch, the following works for me (Scala 2.10.1):
flow { if (x == 2) shiftUnit(throw new Exception) }
which results in a Future[Unit].

Entity Framework and Nested Lambda Expressions

I've just started using Lambda expressions, and really like the shortcut. I also like the fact that I have scope within the lambda of the encompassing method. One thing I am having trouble with is nesting lambdas. Here is what I am trying to do:
public void DoSomeWork()
{
MyContext context = new MyDomainContext();
context.GetDocumentTypeCount(ci.CustomerId, io =>
{
if (io.HasError)
{
// Handle error
}
// Do some work here
// ...
// make DB call to get data
EntityQuery<AppliedGlobalFilter> query =
from a in context.GetAppliedGlobalFiltersQuery()
where a.CustomerId == ci.CustomerId && a.FilterId == 1
select a;
context.Load<AppliedGlobalFilter>(query, lo =>
{
if (lo.HasError)
{
}
**// Do more work in this nested lambda.
// Get compile time error here**
}
}, null);
}, null);
}
The second lambda is where I get the following compile time error:
Cannot convert Lambda expression to type 'System.ServiceModel.DomainService.Client.LoadBehavior' because it is not a delegate type
The compiler is choosing the wrong overload for the Load method even though I am using the same override I did in the previous Lambda.
Is this because I am trying to nest? Or do I have something else wrong?
Thanks,
-Scott
Found the problem as described in my comment above. I'll head back to work now - red face and all....
I realize this is not the answer you want, but I suggest caution about lengthy and/or nested lambdas. They work, but they often make code harder to read / maintain by other developers. I try to limit my lambdas in length to three statements, with no nesting.