AIR - NativeProcess With Sytem Profiler On Mac - apache-flex

I'm attempting to use Adobe AIR NativeProcess in a Flex application to generate an XML file that I can parse to get various system information on a Mac (I have the equivalent working on Windows and I'm not very familiar with the Mac). I need information mostly about the CPU.
I'm unable to call the system profiler and pass the proper parameters (or any parameters) to get the NativeProcess to execute properly.
If I set the NativeProcess executable to:
/Applications/Utilities/System Profiler.app/Contents/MacOS/System Profiler
it executes, but I see the results popup on screen (it ignores my arguments to save it to a file which I believe makes sense since it is the GUI version).
If I set the NativeProcess executable to:
user/sbin/system_profiler or just system_profiler
nothing executes and I receive an ArgumentError #2004 on the line where I assign the executable.
The parameters are something like this:
systemDataMac.npArgList = ["-xml",">", systemDataFileName,"-detailLevel","basic"];
How can I get this file generated properly (or is there any other way to get the CPU information directly into my Flex/AIR app?
Thank you!
Sample Code:
var nativeProcess:NativeProcess=new NativeProcess();
var startupInfo:NativeProcessStartupInfo=new NativeProcessStartupInfo();
var npArgs:Array = [];
var appDataDir:File = File.applicationStorageDirectory;
var nativeFilePath:String = appDataDir.nativePath.toString();
nativeFilePath+= File.separator + "systemInfoFile.xml";
nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExit);
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
nativeProcess.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onInputIOError);
nativeProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onOutputIOError);
try
{
// tried each of these three
startupInfo.executable=new File("system_profiler"); // throws error
startupInfo.executable=new File("/user/sbin/system_profiler"); // throws error
startupInfo.executable=new File("/Applications/Utilities/System Profiler.app/Contents/MacOS/System Profiler"); // works but doesn't handle args because it is the GUI version I believe
npArgs = ["-xml",">", nativeFilePath,"-detailLevel","basic"];
var args:Vector.<String>=new Vector.<String>();
for each(var item:String in npArgs)
{
args.push(item);
}
startupInfo.arguments=args;
nativeProcess.start(startupInfo);
}
catch (error:IllegalOperationError)
{
trace("Illegal Operator Error - " + error.toString());
}
catch (error:ArgumentError)
{
trace("Arg Error - " + error.toString());
}
catch (error:Error)
{
trace("Error - " + error.toString());
}

What kind of information do you need? Have you had a look at the Capabilities class?

Related

Xamarin Forms - Error in iOS Attempting to JIT compile

I have a xamarin forms app. When I compile and test on my Pixel3, everything seems to be working properly. When I load it up in my iOS device running iOS13.something, I get the following error when I try to make my second call to a web service in my app. The error is shown below.
Assertion at /Users/builder/jenkins/workspace/archive-mono/2019-08/ios/release/mono/mini/interp/interp.c:2160, condition `is_ok (error)' not met, function:do_jit_call, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (object&,single&,int&,intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information. assembly: type: member:(null)
The code is a bit of a mess, but has been working in the past.
var uri = String.Format("{0}//{1}/{2}?PlayerToken={3}", protocol, servername, tournamentsInClubUrl, userToken);
var httpC = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
requestMessage.Headers.Add("AppKey", AppKey);
var body = await httpC.SendAsync(requestMessage); <-- Error happens here.
var str = await body.Content.ReadAsStringAsync();
var res = JsonConvert.DeserializeObject<List<PicVideoApp.Models.TournamentInfo>>(str);
httpC.Dispose();
httpC = null;
return res;
I assume that I am doing something wrong, but danged if I can see it. Any ideas are appreciated.
It runs properly in the iOS Simulator.
TIA.
From shared error info , you need to use C# delegate to call native functions .
To call a native function through a C# delegate, the delegate's declaration must be decorated with one of the following attributes:
UnmanagedFunctionPointerAttribute (preferred, since it is cross-platform and compatible with .NET Standard 1.1+)
MonoNativeFunctionWrapperAttribute
For example :
[MonoNativeFunctionWrapper]
delegate void SomeDelegate (int a, int b);
//
// the ptrToFunc points to an unmanaged C function with the signature (int a, int b)
void Callback (IntPtr ptrToFunc)
{
var del = (SomeDelegate) Marshal.GetDelegateForFunctionPointer (ptrToFunc, typeof (SomeDelegate));
// invoke it
del (1, 2);
A similar error was thrown at me in iOS when I used dynamic types in my code. I was able to solve it by enabling the 'Mono Interpreter' in iOS build settings. Hope that helps in your case.

How to try catch block in Jmeter.Webdriver webdriver Sampler

I want to do the exception handling in Jmeter.Webdriver Webdriver Sampler
Please let me , How to use try/catch block in Jmeter.Webdriver webdriver Sampler ?
You can do this via normal JavaScript try block, here is an example of taking a screenshot when error occurs:
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, 5)
var exception = null
WDS.sampleResult.sampleStart()
try {
WDS.browser.get('http://example.com')
wait.until(conditions.presenceOfElementLocated(pkg.By.linkText('Not existing link')))
} catch (err) {
WDS.log.error(err.message)
var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
screenshot.renameTo(java.io.File('screenshot.png'))
exception = err
} finally {
throw (exception)
}
WDS.sampleResult.sampleEnd())
Don't forget to "throw" the error after you handle it otherwise it will be "swallowed" and you get a false positive result.
See The WebDriver Sampler: Your Top 10 Questions Answered article for more tips and tricks
Surround the code with try block and add catch block at the end by giving variable name to capture the exception. (in the example, it is exc)
try as follows:
try{
WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')
var pkg = JavaImporter(org.openqa.selenium)
WDS.browser.findElement(pkg.By.id('what')) // there is no such element with id what
WDS.sampleResult.sampleEnd()
}
catch(exc){ //exc variable name
WDS.log.error("element not found" + exc)
}
in the JMeter log, you can see the complete trace of NoSuchElementException, which is raised when trying to find the element by id with the values as what, which is not present in the HTML.
Note: use View Results in Table to see the Sampler response time.
Reference:
https://jmeter-plugins.org/wiki/WebDriverSampler/
Reference Image:
It is same as how do you do in other IDEs like eclipse.
you can see below code
//try block starts here
try{
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element"))).click();
}
catch(Exception e)
{
WDS.log.info("Exception is : " +e);//you can print the exception in jmeter log.
}
double quotes should be replaced with the single quote if you are using javascript Since the BeanShell is easy and it is similar to java use BeanShell as much as possible

asp.net app calling service says its not initialized?

So this code runs in an asp.net app on Linux. The code calls one of my services. (WCF doesn't work on mono currently, that is why I'm using asmx). This code works AS INTENDED when running from Windows (while debugging). As soon as I deploy to Linux, it stops working. I'm definitely baffled. I've tested the service thoroughly and the service is fine.
Here is the code producing an error: (NewVisitor is a void function taking 3 strings in)
//This does not work.
try
{
var client = new Service1SoapClient();
var results = client.NewVisitor(Request.UserHostAddress, Request.UrlReferrer == null ? String.Empty : Request.UrlReferrer.ToString(), Request.UserAgent);
Logger.Debug("Result of client: " + results);
}
Here is the error generated: Object reference not set to an instance of an object
Here is the code that works perfectly:
//This works (from the service)
[WebMethod(CacheDuration = _cacheTime, Description = "Returns a List of Dates", MessageName = "GetDates")]
public List<MySqlDateTime> GetDates()
{
return db.GetDates();
}
//Here is the code for the method above
var client = new Service1Soap12Client();
var dbDates = client.GetDates();
I'd love to figure out why it is saying that the object is not set.
Methods tried:
new soap client.
new soap client with binding and endpoint address specified
Used channel factory to create and open the channel.
If more info is needed I can give more. I'm out of ideas.
It looks like a bug in mono. You should file a bug with a reproducible test case so it can be fixed (and possibly find a workaround you can use).
Unfortunately, I don't have Linux to test it but I'd suggest you put the client variable in an using() statement:
using(var client = new Service1SoapClient())
{
var results = client.NewVisitor(Request.UserHostAddress, Request.UrlReferrer == null ?
String.Empty : Request.UrlReferrer.ToString(), Request.UserAgent);
Logger.Debug("Result of client: " + results);
}
I hope it helps.
RC.

Embedding metadata time limit for Flash Builder 4.5.1mobile project?

I am working on a project that requires me to embed metadata on the fly with a recorded stream from a webcam. I am utilizing Flash Builder 4.5.1 creating a mobile project. I am using a simple netStream.send function to set the metadata I want. This works just fine until my netstream time goes over around 10 seconds, then the function ceases to work or will not embed into the video. All my connections are correct and I can record to the Flash Media Server
The only thing I can think of is that my Flash Media Server 4 Developer is being over loaded and does not compute the metadata I send.
Any ideas would greatly help.
private function sendMetadata():void {
infotxt.text += 'called';
trace("sendMetaData() called")
myMetadata = new Object();
myMetadata.customProp = "This message is sent by #setDataFrame.";
myMetadata.customOther = cueHolder;
ns.send("#setDataFrame", "onMetaData", myMetadata);
}
And here is my onMetaData function
public function onMetaData(info:Object):void {
trace("caught");
infotxt.text = 'caught';
var key:String;
for (key in info){
outputWindow.text +=(key + ": " + info[key] + "\n");
}
//cueHolderReturn = info.customOther;
for (var i:int = 0; i < info.customOther.length; i++)
{
infotxt.text += info.customOther[i]
}
//infotxt.text = info.customOther[0];
}
Just wondering - is this problem occuring on both a real mobile device and a mobile emulator? If not, it could be the mobile connection - HTH

Is it possible to find the function and/or line number that caused an error in ActionScript 3.0 without using debug mode?

I'm currently trying to implement an automated bug reporter for a Flex application, and would like to return error messages to a server along with the function/line number that caused the error. Essentially, I'm trying to get the getStackTrace() information without going into debug mode, because most users of the app aren't likely to have the debug version of flash player.
My current method is using the UncaughtErrorEvent handler to catch errors that occur within the app, but the error message only returns the type of error that has occurred, and not the location (which means it's useless). I have tried implementing getStackTrace() myself using a function name-grabber such as
private function getFunctionName (callee:Function, parent:Object):String {
for each ( var m:XML in describeType(parent)..method) {
if ( this[m.#name] == callee) return m.#name;
}
return "private function!";
}
but that will only work because of arguments.callee, and so won't go through multiple levels of function calls (it would never get above my error event listener).
So! Anyone have any ideas on how to get informative error messages through the global
error event handler?
EDIT: There seems to be some misunderstanding. I'm explicitly avoiding getStackTrace() because it returns 'null' when not in debug mode. Any solution that uses this function is what I'm specifically trying to avoid.
Just noticed the part about "I don't want to use debug." Well, that's not an option, as the non-debug version of Flash does not have any concept of a stack trace at all. Sucks, don't it?
Not relevant but still cool.
The rest is just for with the debug player.
This is part of my personal debug class (strangely enough, it is added to every single project I work on). It returns a String which represents the index in the stack passed -- class and method name. Once you have those, line number is trivial.
/**
* Returns the function name of whatever called this function (and whatever called that)...
*/
public static function getCaller( index:int = 0 ):String
{
try
{
throw new Error('pass');
}
catch (e:Error)
{
var arr:Array = String(e.getStackTrace()).split("\t");
var value:String = arr[3 + index];
// This pattern matches a standard function.
var re:RegExp = /^at (.*?)\/(.*?)\(\)/ ;
var owner:Array = re.exec(value);
try
{
var cref:Array = owner[1].split('::');
return cref[ 1 ] + "." + owner[2];
}
catch( e:Error )
{
try
{
re = /^at (.*?)\(\)/; // constructor.
owner = re.exec(value);
var tmp:Array = owner[1].split('::');
var cName:String = tmp.join('.');
return cName;
}
catch( error:Error )
{
}
}
}
return "No caller could be found.";
}
As a side note: this is not set up properly to handle an event model -- sometimes events present themselves as either not having callers or as some very weird alternate syntax.
You don't have to throw an error to get the stack trace.
var myError:Error = new Error();
var theStack:String = myError.getStackTrace();
good reference on the Error class
[EDIT]
Nope after reading my own reference getStackTrace() is only available in debug versions of the flash player.
So it looks like you are stuck with what you are doing now.

Resources