How to tell if Flex is run in debug mode? - apache-flex

I want to declaratively turn on and off logger for my Flex application and it seems that my usual way of determining if it's debug mode or not works only sometimes. The code for it:
isDebugSWF = new Error().getStackTrace().search(/:[0-9]+]$/m) > -1;
Do you know a better way for it?
Edit:
I posted answer below.

The static property Capabilities.isDebugger in the flash.system.Capabilities class specifies if the Flash player installed is a debug version or not. It requires Flash Player 9 or AIR 1.0 as the minimum version.
Keep in mind though that debug Flash Player installers are publicly available, and that there is nothing stopping users from installing the debug version of Flash. If have something sensitive that you want to hide, using conditional compilation would be a better option.

The previous approach was based on great article . One of the comments suggested that in Release the stacktrace is null, so I modified it properly:
protected function configureLogger() : void
{
if(!isDebugPlayer()|| !isDebugBuild())
{
// stop logging
Logger.hide = true;
}
else
{
// resume logging
Logger.hide = false;
}
}
private function isDebugPlayer() : Boolean
{
return Capabilities.isDebugger;
}
/**
* Returns true if the swf is built in debug mode
**/
private function isDebugBuild() : Boolean
{
var stackTrace:String = new Error().getStackTrace();
if(stackTrace == null || stackTrace.length == 0)
{
//in Release the stackTrace is null
return false;
}
//The code searches for line numbers of errors in StackTrace result.
//Only StackTrace result of a debug SWF file contains line numbers.
return stackTrace.search(/:[0-9]+]$/m) > -1;
}
This way I can finally configure ThunderBoltAS3 logger depending on current build type.

Looks like you are looking for the same, as answered in another post. Look here: How can you tell programmatically if a Flex App is running in debug mode?

We are using conditional compilation at our project :
Adobe Documentation

Related

Unable to evaluate the expression Cannot find source class for java.util.List

I response this error when get JSON data by retrofit.
List<NewLicense> result = null;
Call<List<NewLicense>> serviceResult = ShahrdariApp.getShahrdariWebService().getLicenses(Configuration.getInstance().getString(SharedPrefs.MAC_ADDRESS), id);
try {
Response<List<NewLicense>> response = serviceResult.execute();
result = response.body();
Log.d("responseCode", String.valueOf(response.code()) );
} catch (Exception e) {
exceptionHandling(e);
Log.d("responseCode", String.valueOf(e.getMessage()) );
}
return result;
I had the same issue and forgot to set the Project SDK added this and it resolved the issue.
Simply restarting the IDE via File -> Invalidate caches can often solve this issue.
I faced the message
Unable to evaluate the expression Cannot find source class for
java.util.List
in hovering a List field while debugging in IntelliJ IDEA 2022.1.3 (UltimateEdition).
Even though an SDK was assigned to my Project, it helped to visit
IDEA ->File ->Project Structure -> Platform Settings ->SDKs and re-assign the SDK already visible in the list.
Namely I assigned openjdk-1.8.0.302-1, applied "OK", after that it was possible to debug a List foo.
IDE restart after that may additionally be necessary.

Chain Of Command (method wrapping) in D365FO results in 'Object is not set to an instance of an object'

I am trying to use the new 'Chain Of Command' feature in D365FO by extending CustTable.
We need to check if a value has changed on the update method, before we log it in a new table.
[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
void update(boolean _updateSmmBusRelTable = true, boolean _updateParty =
true)
{
CustTable custTable_Orig = this.orig();
boolean hasChanged = this.CreditMax != custTable_Orig.CreditMax;
next update(_updateSmmBusRelTable, _updateParty);
if(hasChanged)
{
//do something
}
}
}
However when running this code we get "Object is not set to an instance of an object" error. The error occurs because 'this' object is null. I also get the same error when calling "next update(_updateSmmBusRelTable, _updateParty);".
The documentation states: "This allows extending the logic of public and protected methods without the need to use event handlers. When you wrap a method, you can also access other public and protected methods and variables of the class."
Any ideas?
You have to (re-)compile package with CustTable - Application Suite with PU9 or newer.
See https://learn.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/get-started/whats-new-platform-update-9#supported-versions:
However, this functionality requires the class being augmented to be compiled on Platform update 9. Because the current releases of the Dynamics 365 for Finance and Operations, Enterprise editon applications have been compiled on Platform update 8 or earlier, you will need to recompile a base package (like Application Suite) on Platform update 9 or newer in order to wrap a method that is defined in that package
Try removing default parameters value from your wrapper method.
[ExtensionOf(tableStr(CustTable))]
final class CustTable_Extension
{
void update(boolean _updateSmmBusRelTable , boolean _updateParty )
{
CustTable custTable_Orig = this.orig();
boolean hasChanged = this.CreditMax != custTable_Orig.CreditMax;
next update(_updateSmmBusRelTable, _updateParty);
if(hasChanged)
{
//do something
}
}
}
I know that a long time passed on since the question was ask, but this one was a bug in Platform Updates lower than 13. This error fired in cases where a Form and a Table with the same name existed.
It was fixed with PU13.

How can I use INetwork in Xamarin Forms XLabs?

I am having a problem using INetwork from XLabs.Platform. I am getting System.NullReferenceException. I am not sure if the problem is similar to this where I need to initialize INetwork. However, because I am very new to Xamarin I have no idea how to set up the IOC container. I'd like to this in a completely cross-platform way (I'd like to avoid putting platform specific code if I can avoid it). Thanks!!
Code:
using XLabs.Ioc;
using XLabs.Platform;
...
namespace XXX
{
class XXX
{
public static bool isOnline()
{
var networkservice = DependencyService.Get<XLabs.Platform.Services.INetwork>();
var status = networkservice.InternetConnectionStatus();
return (
(status.Equals(XLabs.Platform.Services.NetworkStatus.ReachableViaCarrierDataNetwork))
|| (status.Equals(XLabs.Platform.Services.NetworkStatus.ReachableViaWiFiNetwork))
|| (status.Equals(XLabs.Platform.Services.NetworkStatus.ReachableViaUnknownNetwork)));
}
}
}
PS The documentation for using XLabs.Platform is out of date. The (apparently) previously functioning Reachability interface doesn't work anymore. Thinking about using this instead. This is an approach that requires cross platform code. Not going to use this as the author himself disses the approach.
If you want to check if there is any Internet Connection, I would suggest to use Connectivity Plugin (Xamarin Component). After adding the Xaamrin Component you can check if an internet connection is avaliable from PCL/Shared project like below
if (CrossConnectivity.Current.IsConnected)
{ // Make API call here
}
else
DisplayAlert("Connectivity Issue", "Please Connect to a Network", "OK") ;
You fill the ioc by adding this attribute:
[assembly: Xamarin.Forms.Dependency(typeof(NameOfClassImplementingAnInterface))]

Always run Unit Tests in Release mode

I've got a method that contains logic that varies between release mode and debug mode. It is not advanced at all, but i still want a unit test for it, since my application will be used in a bigger picture and i want to redirect the user to other sites if it is not used in release mode.
And now to my question, is there any way to force the unit test to run in Release Mode? I don't want to manually change build configuration for every time i want to run my unit tests.
Instead of running your unit tests in Release mode you can create a test seam so you can control which behavior you want to elicit. You might be able to something like this:
public class Foo {
public int Bar() {
if (IsDebugModeEnabled()) {
return 1;
} else {
return 0;
}
}
public boolean IsDebugModeEnabled() {
#if DEBUG
return true;
#else
return false;
#endif
}
}
This way you have a couple of options to test both paths of your logic. You can create a subclass Foo and override IsDebugModeEnabled or use a partial mock to directly set the return value.

Enqueue in Phonon no longer working

After a recent software update to the phonon libraries, I've noticed that a media playing application that I wrote is no longer able to loop tracks. The code in question is below. The first track is set, and once it nears completion it is set to play again.
void Alarm::Start(bool useCustom)
{
if(useCustom)
{
media->setCurrentSource(Phonon::MediaSource(this->_CustPath));
this->_UsingCustomPath=true;
}else{
FileIO::ExtractAudio();
media->setCurrentSource(Phonon::MediaSource(this->_DefaultPath));
this->_UsingCustomPath=false;
}
media->play();
connect(media,SIGNAL(aboutToFinish()),this,SLOT(RepeatAllTheThings()));
this->_isPlaying=true;
}
void Alarm::RepeatAllTheThings()
{
if(this->_UsingCustomPath)
{
media->enqueue(this->_CustPath);
}else{
media->enqueue(this->_DefaultPath);
}
}
After running through the debugger a few times I noticed this message:
"Ignoring source as no aboutToFinish handling is in progress"
A quick google search doesn't tell much about this message. It looks like a check for a private variable (that I dont have access to) has been added (a diff of the file)
Does anyone know if I just discovered a new bug in phonon, or am I some how using the enqueue method incorrectly?
EDIT:
The code above only fails about 1/2 the time. Very confused. Currently running phonon-gstreamer 4.6.3
Solved with this work-around:
media->play();
connect(media,SIGNAL(finished()),this,SLOT(RepeatAllTheThings()));
void Alarm::RepeatAllTheThings()
{
if(this->_UsingCustomPath)
{
media->setCurrentSource(Phonon::MediaSource(this->_CustPath));
}else{
media->setCurrentSource(Phonon::MediaSource(this->_DefaultPath));
}
media->play();
}

Resources