AutoCAD-Plugin : C# : (System.Data.SQlite + SpatialiteSharp) ERROR in AutoCAD 2016/2017 - system.data.sqlite

1) My Environment:
. Windows 10 Pro (licensed) - 64 bits - 8GB Ram;
. AutoCAD (licensed) 2014/2015/2016/2017 64 bits (all HOTFIX and SERVICEPACK installed);
. Visual Studio 2010 Express Edition (for AutoCAD 2014);
. Visual Studio 2013 (for AutoCAD 2015/2016/2017);
. Antivirus : only Windows Defender.
2) Visual Studio 2013 Solution
nuGet packages:
System.Data.SQLite
SpatialiteSharp
Target: .NET 4.5
3) Database used for this test
. Database name : 'dbtest.sqlite', download here and save to c:\temp
. Database table : 'tb_test'
. Database table tb_test fields:
featureName : TEXT
geometry : POLYGON
4) Code Running on AutoCAD 2015 : OK
In Visual Lisp, I call dbQuery .NET method (file MyCommands.cs):
(setq result_query (dbQuery))
and will return a list:
[0] "FeatureName=first test area , MinX=101.23 , MinY=101.5 , MaxX=215.7 , MaxY=201.953 , Area=5532.771185"
[1] "FeatureName=second test area , MinX=100 , MinY=50 , MaxX=200 , MaxY=100 , Area=5000"
5) P R O B L E M :: Code running on Autocad 2016/2017 ::
Error : "Autodesk application has stopped working"
My plugin run ok on AutoCAD 2014 (.NET 4.0) and AutoCAD 2015 (.NET 4.5), but don't running on AutoCAD 2016/2017.
The code is the same, but changed only AcMgd/AcCoreMgd/AcDbMgd and Target DotNet Framework.
When debug my plugin, crash occurs on
connection.LoadExtension("mod_spatialite");
Then I receive a AutoCAD crash message window, saying:
Autodesk applicaton has stopped working
6) My AutoCAD 2017 plugin code
clique here to download VisualStudio 2013 "AutoCAD2017SpatialiteTest" Solution
MyCommands.cs code
// Test (System.Data.SQLite + SpatialiteSharp) in AutoCAD 2017 plugin
// Date: March, 7, 2017.
//
//==============================================================
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using System.Data.SQLite;
using SpatialiteSharp;
using System.IO;
using System.Reflection;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass ( typeof ( AutoCAD2017SpatialiteTest.MyCommands ) )]
namespace AutoCAD2017SpatialiteTest
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class MyCommands
{
private static readonly object Lock = new object ();
private static bool _haveSetPath;
//*******************************************************************
// LispFunction is similar to CommandMethod but it creates a lisp
// callable function. Many return types are supported not just string
// or integer.
//
//
//
[LispFunction ( "dbQuery", "dbQuery" )]
public ResultBuffer dbQuery ( ResultBuffer args ) // This method can have any name
{
try
{
// Create Spatialite SQL Connection
//
string databaseName = #"c:\temp\dbtest.sqlite";
string connectString = #"Data Source=" + databaseName + ";Version=3;";
SQLiteConnection connection = new SQLiteConnection ( connectString );
/// Open the database and load in the Spatialite extension
connection.Open ();
/// Loads mod_spatialite.dll on the given connection
///
lock ( Lock )
{
//Need to work out where the file is and add it to the path so it can load all the other dlls too
if ( !_haveSetPath )
{
var spatialitePath = Path.Combine ( Path.GetDirectoryName ( Assembly.GetExecutingAssembly ().Location ), (Environment.Is64BitProcess ? "x64" : "x86"), "spatialite" );
Environment.SetEnvironmentVariable ( "PATH", spatialitePath + ";" + Environment.GetEnvironmentVariable ( "PATH" ) );
_haveSetPath = true;
}
}
connection.EnableExtensions ( true );
connection.LoadExtension ( "mod_spatialite" );
// Make some Spatialite function calls
string sql = "SELECT featureName, ST_MINX(geometry), ST_MINY(geometry), ST_MAXX(geometry), ST_MAXY(geometry), ST_AREA(geometry) FROM tb_test ";
double minX = 0.0, minY = 0.0, maxX = 0.0, maxY = 0.0, area = 0.0;
string featureName = "";
string result_query = "";
// initialize resBuf list
//
ResultBuffer resBufCatch = new ResultBuffer ();
resBufCatch.Add ( new TypedValue ( (int)LispDataType.ListBegin ) );
// execute sql query
//
using ( SQLiteCommand command = new SQLiteCommand ( sql, connection ) )
{
using ( SQLiteDataReader reader = command.ExecuteReader () )
{
while ( reader.Read () )
{
featureName = reader.GetString ( 0 );
minX = reader.GetDouble ( 1 );
minY = reader.GetDouble ( 2 );
maxX = reader.GetDouble ( 3 );
maxY = reader.GetDouble ( 4 );
area = reader.GetDouble ( 5 );
// define string with fields values from 'tb_test'
//
result_query = String.Format ( "FeatureName={0} , MinX={1} , MinY={2} , MaxX={3} , MaxY={4} , Area={5}", featureName, minX.ToString (), minY.ToString (), maxX.ToString (), maxY.ToString (), area );
// add result_query to buffer
//
resBufCatch.Add ( new TypedValue ( (int)LispDataType.Text, result_query ) );
}
}
}
// finalize resBuf list
//
resBufCatch.Add ( new TypedValue ( (int)LispDataType.ListEnd ) );
// Close and clean up the database connection
//
connection.Close ();
connection.Dispose ();
// return result_query value to lisp function...
//
return resBufCatch;
}
catch ( System.Exception ex )
{
string exception_message = String.Format ( "Error : {0}", ex.Message );
ResultBuffer resBufCatch = new ResultBuffer ();
resBufCatch.Add ( new TypedValue ( (int)LispDataType.Text, exception_message ) );
return resBufCatch;
}
}
}
}
7) Question
Anybody help me run this AutoCAD2017 plugin?
Thank you very much.

Do you have an error report dialog like this one after the crash?
If yes, don't close the dialog and go to the folder C:\Users\\AppData\Local\Temp (%temp%). There must be a file named dumpdata.zip. In the archive, there is an xml file which can give you more details on the error and a .dmp file you can open in Visual Studio.

Related

EMDK, Xamarin for Android: scan is possible only once

I'm developing an app for Android using Xamarin and EMDK for a Zebra TC51.
The problem is I'm able to trigger the barcode scanner (using the physical button) only once. After that, the scanner does not run anymore.
What can be the cause of that? What can I check to have a diagnostic?
Extract of the code:
Tracking of the status:
scanner.Status += ( s, e ) =>
{
try
{
StatusData statusData = e.P0;
StatusData.ScannerStates state = e.P0.State;
this.RunOnUiThread( () => StateMessage( "Scanner state : " + state.Name() ) );
}
catch ( System.Exception exc )
{
this.RunOnUiThread( () => StateMessage( "Scanner state exception : " + exc.Message ) );
}
};
and for received data:
scanner.Data += ( s, e ) =>
{
try
{
var statusData = e.P0;
var scanData = e.P0.GetScanData();
foreach ( var sd in scanData )
{
this.RunOnUiThread( () => StateMessage( "Scanned : " + sd.Data ) );
}
}
catch ( System.Exception exc )
{
this.RunOnUiThread( () => StateMessage( "Scanner data exception : " + exc.Message ) );
}
};
The state sequence I can trace is the following:
Before triggering: waiting, idle, waiting
After triggering: scanning, idle
After that nothing. The result is the same if I effectively read a barcode (and I can read it once) or not (just triggering the button).
you need to call read() again every time the scanner goes into the IDLE state to enable continuous scanning. There is a Xamarin sample app that you should be able to follow at https://github.com/Zebra/samples-emdkforxamarin-2_5/blob/BarcodeSample1/BarcodeSample1/BarcodeSample1/MainActivity.cs

Drools mode stream and containers

HI this is my code.
public static KieContainer createKieContainerForProject() {
KieServices ks = KieServices.Factory.get();
// Create a module model
KieModuleModel kieModuleModel = ks.newKieModuleModel();
// Base Model from the module model
KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel( "KBase" )
.setDefault( true )
.setEqualsBehavior( EqualityBehaviorOption.EQUALITY)
.setEventProcessingMode( EventProcessingOption.STREAM );
// Create session model for the Base Model
KieSessionModel ksessionModel = kieBaseModel.newKieSessionModel( "KSession" )
.setDefault( true )
.setType( KieSessionModel.KieSessionType.STATEFUL )
.setClockType( ClockTypeOption.get("realtime") );
// Create File System services
KieFileSystem kFileSystem = ks.newKieFileSystem();
File file = new File("src/main/resources/rules/Sample.drl");
Resource resource = ks.getResources().newFileSystemResource(file).setResourceType(ResourceType.DRL);
kFileSystem.write( resource );
KieBuilder kbuilder = ks.newKieBuilder( kFileSystem );
// kieModule is automatically deployed to KieRepository if successfully built.
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
throw new RuntimeException("Build time Errors: " + kbuilder.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
return kContainer;
}
}
it's dont work when I call the fucntion, and my rules no work too.
my rule is
rule "Sound the alarm in case temperature rises above threshold"
when
TemperatureThreshold( $max : max )
Number( doubleValue > $max ) from accumulate(
SensorReading( $temp : temperature ) over window:time( 10m ),
average( $temp ) )
then
// sound the alarm
end
when I run the program, He says it has error, mode not stream and the code dont work.
how do I put a program in stream mode?
REduce your code, and add -KieBase and KieSession creation:
KieServices ks = KieServices.Factory.get();
KieFileSystem kFileSystem = ks.newKieFileSystem();
FileInputStream fis = new FileInputStream( "...drl" );
kFileSystem.write("src/main/resources/somename.drl",
ks.getResources().newInputStreamResource( fis ) ); //XXX
KieBuilder kbuilder = ks.newKieBuilder( kFileSystem );
kbuilder.buildAll();
if (kbuilder.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
throw new RuntimeException("Build time Errors: " + kbuilder.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieBaseConfiguration config = ks.newKieBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KieBase kieBase = kContainer.newKieBase( config );
KieSession kieSession = kieBase.newKieSession();
This should give you a session that's capable of running your rule. (
According to the docs, it's as follows:
KieBaseConfiguration config = KieServices.Factory.get().newKieBaseConfiguration();
config.setOption( EventProcessingOption.STREAM );
But it's probably worth taking a look at this Drools test for a working example.

Tabris 0.11 iOS EXC_BAD_ACCESS Geolocation

First of all: Thanks that I got such a good and fast feedback from you guys a few days ago.
I'm still playing around in Tabris 0.11 and tried to implement a Geolocation like you guys did in the demo project.
Everything is working great on Android, but under iOS (IPhone 5) I get the error
EXC_BAD_ACCESS (code=1, address=0xbbadbeef)
Here is how my code looks like
public void create( Composite parent, UIContext context ) {
// creation of the layout types
createLayouts();
parent.setLayout( GridLayoutFactory.fillDefaults().margins( 0, 0 ).spacing( 0, 0 ).create() );
createContainer( parent );
createBrowser();
}
private void createLayouts() {
layoutGrid = new GridLayout();
layoutGrid.numColumns = 1;
layoutGridData = new GridData();
layoutGridData.horizontalAlignment = GridData.FILL;
}
private void createContainer( Composite parent ) {
[...]
containerBrowser = new Composite( parent, SWT.NONE );
containerBrowser.setLayout( layoutGrid );
containerBrowser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
[...]
}
private void createBrowser() {
browser = new Browser( containerBrowser, SWT.NONE );
browser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
lastLat = 48.775418;
lastLon = 9.181759;
setBrowserUrl( lastLat, lastLon);
}
private void setBrowserUrl( double lat, double lon) {
StringBuilder builder = new StringBuilder();
builder.append( "http://open.mapquestapi.com/staticmap/v4/getmap" );
builder.append( "?size=" + 200 + "," + 200 );
builder.append( "&zoom=16" );
lastLat = lat;
lastLon = lon;
builder.append( "&center=" + lat + "," + lon );
builder.append( "&imageType=png" );
if( lastLabel != null ) {
builder.append( "&pois=" + lastLabel + "," + lat + "," + lon + ",0,0" );
}
browser.setUrl( builder.toString() );
}
I'm not really experienced in iOS, I hope this information helps you guys.
Thanks in advance, Toby
With the example you've provided, I could not reproduce the problem. Maybe what you are seeing is an issue in the pre-release Tabris 0.11 client. The issue might be already fixed in the final Tabris 1.0 release.
I suggest you download Tabris 1.0 ( http://developer.eclipsesource.com/tabris/downloads/ ) and try again.
If you still have a problem, send my your "Device Log" of the crashed App using the "Xcode Organizer".

The errors of neo4j-manual-milestone.pdf

These codes are in neo4j-manual-milestone.pdf( version: 1.8M05):
TraversalDescription t = new TraversalDescription();
t.setOrder( TraversalDescription.DEPTH_FIRST );
t.setUniqueness( TraversalDescription.NODE );
t.setMaxDepth( 10 );
t.setReturnFilter( TraversalDescription.ALL );
t.setRelationships( new Relationship( "singer", Relationship.OUT ) );
// END SNIPPET: traversalDesc
// START SNIPPET: traverse
URI traverserUri = new URI( startNode.toString() + "/traverse/node" );
WebResource resource = Client.create()
.resource( traverserUri );
String jsonTraverserPayload = t.toJson();
ClientResponse response = resource.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON )
.entity( jsonTraverserPayload )
.post( ClientResponse.class );
System.out.println( String.format(
"POST [%s] to [%s], status code [%d], returned data: "
+ System.getProperty( "line.separator" ) + "%s",
jsonTraverserPayload, traverserUri, response.getStatus(),
response.getEntity( String.class ) ) );
response.close();
When I use them, the errors display.
If you go to the online version of the manual, at http://docs.neo4j.org/chunked/1.8.M05/tutorial-traversal-java-api.html at the bottom of the page there is a link to the full source, which is executed and tested together with the main neo4j build.
HTH

How to store a Lua function into C++ with SLB ( Simple Lua Binder )?

I need to store a Lua function using the library "Simple Lua Binder"
typedef ? TLuaFunction;
class Foo
{
public:
void SetCallback( TLuaFunction f )
{
mCallback = f;
}
void ExecuteCallback()
{
f(); // Calls Lua function
}
private:
TLuaFunction mCallback;
};
// Manager initialization
SLB::Manager scriptManager;
// SetCallback registration into lua
SLB::Class<Foo>( "Foo", &scriptManager )
.constructor()
.set( "SetCallback", &Foo::SetCallback )
.set( "ExecuteCallback", &Foo::ExecuteCallback )
;
char* luaCode =
"SLB.using( SLB )\n"
"o = Foo()\n"
"o:SetCallback( function() \n"
" print( 'Callback executed' ) \n"
" end \n"
") \n"
"o:ExecuteCallback() \n";
SLB::Script script( &scriptManager );
script.doString( luaCode );
// The result is
> "Callback executed"
I don't know if there is a type in SLB library that I can put instead of ? ( see the first line of code ).
Or if I have to do the things different.

Resources