Drools .NET 3.0 - List<> C# - drools

I am using Drools. Net 3.0, but I can not use list structures as exists in Drools java version.
example:
//Code Drools - This code does not work in Drools. NET
rule 'ListC#'
when
Object1 ($list: listObjects)
Object2 (date> = '01/01/1992') from $list
then
mensagens.add ("132");
end
//C# Code
class Object1
{
public List < Object2> listObjects {get; sets;}
}
Does anyone have any idea how I can fix?

Drools in java is already in version 6, so the .NET port is really outdated by now. I wouldn't expect the new rule syntax to work with the old .NET port.. you can try to find out the drools 3.0 docs out there.. but there is no guarantee that it will work.

Related

Is there any way to make F# discriminated unions work in Unity?

I am experimenting with F# in Unity. I use compiled F# library and FSharp.Core.dll copied to Assets in Unity. Simple scripts work but when I add discriminated union type like
type A =
| AInt of int
| AString of string
then I get this error in Unity: "Unable to load attribute info on method fs.A:.ctor (). Are you missing a reference?".
What can be wrong and is there a way to make it work?
Ensure you are using F# 4.1 - 4.8 in order to be compatible with Unity. F# 5 and 6 are incompatible in exactly the same way as a C# project targeting beyond .NET Standard 2.1.
Tell me more
.NET profile support
https://en.wikipedia.org/wiki/F_Sharp_(programming_language)
.NET Standard Versions

Java 8: Spliterator, Iterator, Collection and "default" implemenations in Interfaces (Duplicate methods named spliterator)

Have an interesting situation following the release of Java 1.8.0_25 into the wilds... I believe the root of my issue is related primarily to the new (to 1.8) features of "default" implementations within Interfaces.
The application I am working on is currently targeted at 1.7, which until now has been working well. Until users started updating to 1.8. Now that our users have started updating to 1.8, our hand is forced somewhat into moving to 1.8 support.
We have fixed most of the issues (mainly relating to changes to the JavaFX packages between 1.7 and 1.8) but have one vexing issue remaining.
In my wisdom, or lack thereof, I, some time ago, decided to create a SortedList<T> which extends from AbstractList<T>. Until now, this class has worked fine, however when running on a 1.8 runtime, I get:
Duplicate methods named spliterator with the parameters () and () are inherited
from the types Collection<T> and Iterable<T>
This, to me, appears to be caused by the "default" implementations in some of the Interfaces that are implemented by AbstractList<T> (my SortedList<T> class does not implement any additional Interfaces other than Serializable). Implementing Serializable is another problem for us, as we need to support deserialisation of SortedList<T> objects, there's no way around that!).
I can get rid of the error by providing an override implementation of spliterator() in my SortedList<T> class. However, if this is built, it no longer runs on a Java 1.7 environment. If I attempt to use SortedList<T> with a 1.7 runtime, I get:
Problem:
Error: Unresolved compilation problems:
The import java.util.Spliterator cannot be resolved
Spliterator cannot be resolved to a type
com.xxxx.xxxx.util.SortedList.<init>(SortedList.java:13)
This error is pretty obvious, since we've now overridden the spliterator() method in SortedList<T> it needs to include java.util.Spliterator, but that doesn't exist in 1.7.
Ideally we would like to NOT require our customers to update to Java 1.8 if they don't want to.
Is our hand being forced here? Do we need to force users to update to 1.8 and also roll out a new version to any users who have updated to 1.8 by themselves?
Does anyone know a way around this issue?
On a more philosophical note, why has Interface been corrupted with with implementation :-(. Might be a nifty new feature, but they really should have avoided doing anything that would result in breaking changes to existing code, particularly in something so fundamental as lists/collections etc.
Any help or suggestions regarding this predicament would be greatly appreciated.
Cheers,
Mark
The whole point of default methods is to avoid the situation you describe. The code below compiles and runs as expected with Java 7 and 8:
public class SortedList<T> extends AbstractList<T> implements Serializable {
#Override public T get(int index) { return null; }
#Override public int size() { return 0; }
public static void main(String[] args) {
SortedList<String> s = new SortedList<> ();
System.out.println(s.size());
}
}
Ok, so both of you (#Holger and #assylias) were correct... But, our situation is a little more complicated.
The environment we're working in is Eclipse 3.8.1 which doesn't support Java 8 (and won't in the future to my knowelege). So we can't just change to a Java 8
compiler to fix the issues.
Our product is a sizeable Eclipse RCP application. Upgrading our IDE is not currently an option, as there would be major rework involved. We will need to continue
to develop under a Java 1.7 environment for this reason.
If anyone is interested, we have resolved the issue by:
Creating fragments (one per Java version that causes issues, so three in our case) for our main plugin. These fragments are configured as patch fragments.
Added the Java FX JARs into the fragments (This was done to resolve some issues with Java FX in an earlier release and again for the 1.8.0_25 release).
Also in the fragments, in the same namespace as the main plugin, we added the implementation of the SortedList class. The code is identical for each case, but
the fragment for Java 8 is compiled specifically with a Java 8 compiler. Overriding the spliterator() method wasn't necessary in the end (when compiled with the Java 8
compiler, it works ok and still compiles with the 1.7 compiler as there is no reference to the Spliterator class anymore).
This is probably not an ideal solution, but it will work we think :-).
Thanks for your input & suggestions, much appreciated.
try Creating an abstract class that overrides the spliterator() with the prefered behaviour definition i.e.
abstract class Java8_AbstractCollection<E> extends AbstractCollection<E> {
/* (non-Javadoc)
* #see java.util.Collection#spliterator()
*/
public Spliterator<E> spliterator() {
return (Spliterator<E>) super.spliterator();
}
}

PHPUnit Mock of MongoCollection class creating a _PHP_Incomplete_Class object

Today I came back to a project I have not touched for a while. It is a Zend Framework 2 project using MongoDB as its database.
I decided since it had been a while to update MongoDB to the latest version (2.4) from (2.0), and the driver to the latest (1.4.2?).
Now when running my PHPUnit tests I get errors due to a mocked MongoCollection class failing a "is_a()" test.
Instead of the new mocked class being an instance of MongoCollection, it turns out to be a _PHP_Incomplete_Class instance instead. I have been searching high and low and I cannot find anyone with the same issue. I can only assume something has changed to the MongoDB classes that PHPUnit doesn't like.
$collection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor()
->getMock();
When inspecting $collection I see:
_PHP_Incomplete_Class Object {
_PHP_Incomplete_Class_Name => (string) Mock_MongoCollection_2798b1f7"
}
Does anyone know a way around this or do I need to bash out my own MongoCollection mock/test class to test with?
OK, after a few days of doing other things I came back to this issue and have solved it.
I updated PHPUnit to the latest version (as of today, 1 August 2013) via PEAR and the issue has gone away.
The lesson: try updating everything and not just one component!

How do I conviniently consume OData service from .NET code

Is there any best-practice approach/library for consuming OData services from .NET code? So that I do not have to mess with building query string and parse the response manually?
I envision something like this:
class Person
{
public string Name {get; set;}
public int Age {get; set;}
}
void Main()
{
Person person =
new ODataRequest<Person>()
.EndPoint("http://server.com/personservice")
.AddHeader("header", "value")
.AsJson()
.Where(p => p.Name.EndsWith("y") && p.Age > 21)
.Skip(10)
.Take(5)
.Send();
}
Please ignore the syntax (and that I'm mixing endpoint related stuff with query related stuff), this is just to convey the idea.
The code above would be supposed to automatically build proper OData query string with $filter, $skip, etc expressions as well as parse the response.
Has a library of this kind been already built? Or I'm on my own here?:)
Thanks!
As per Padrus' answer, the library you're looking for is definitely WCF Data Services. It has a solid code-gen experience as well as a reasonably complete LINQ provider. If you want to play with it up front with minimal investment, try out the latest betas of LINQPad (http://www.linqpad.net/Beta.aspx), which has the WCF DS client built in. To the best of my knowledge, there isn't anything else comparable out there for .NET.
Note: WCF DS is built into Visual Studio. If you use the Add Service Reference wizard to add a reference to an OData service, you will get our DLLs. Note that if you are using VS 2012, you will get references to our NuGet packages, which you can then maintain the way you maintain all of your other NuGet dependencies. If you are using VS 2010 you should still consider adding references to the NuGet packages and using NuGet to update dependencies going forward.

Is newest version of MS Enterprise Library compatible with older versions like 3.1

This current project I've been assigned uses the Version 3.1 levels of:
Microsoft.Practices.EnterpriseLibrary.Common;
Microsoft.Practices.EnterpriseLibrary.Data;
As I try to get to know more about the capabilities of the Ent Lib, I am running into lots of articles and doc about various versions (3.1, 4.0, and 5.0 I think).
In general do the newer versions work with application code written for an earlier release of the Ent Lib? I haven't surveyed all of the source code in this app I've inherited but I think only the "basics" of the Data Access Application Block are being used. Here is a typical piece of code:
public override List<Erx.Action> GetAll(bool bIsActive)
{
Database db = null;
DbCommand cmd = null;
List<Erx.Action> lst = null;
IDataReader iRdr = null;
try
{
db = DatabaseFactory.CreateDatabase();
cmd = db.GetStoredProcCommand("Mst_GetAllCorrectiveAction");
db.AddInParameter(cmd, "#CorrectiveActionID", DbType.Int32, -1);
db.AddInParameter(cmd, "#IsActive", DbType.Boolean, bIsActive);
iRdr = db.ExecuteReader(cmd);
lst = new List<Erx.Action>();
while (iRdr.Read())
{
Action objAction = new Action();
objAction.CorrectiveAction = iRdr["CorrectiveAction"].ToString();
objAction.CorrectiveActionID = int.Parse(iRdr["CorrectiveActionID"].ToString());
objAction.IsActive = (bool)iRdr["IsActive"];
lst.Add(objAction);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
db = null;
iRdr.Close();
if (cmd != null)
{
cmd.Dispose(); cmd = null;
}
}
return lst;
}
Frankly, this does not seem to offer much beyond regular ADO.Net but maybe the newer versions make things simpler (I've heard some very good stuff about Unity).
I just installed Ent Lib 4.1 and dug closely into the doc and found this in the "Introduction to the Data Access Application Block":
Changed Features, Version 3.1 and Later
In general, applications built using earlier releases of the Data Access Application Block will function with this release without the need for any code changes. It may be necessary to update the references to refer to the new assemblies and to update the configuration files to reference the correct version of the assemblies. However, some changes were made to the Data Access Application Block in version 3.1 (May 2007), which may affect applications written for earlier versions if you upgrade to the current version of Enterprise Library. The following sections describe these changes.
The .NET Framework 2.0 TransactionScope Class
To take advantage of the .NET Framework 2.0 TransactionScope class, there have been changes to some of the Database class methods in version of Enterprise Library from version 3.1 onwards. These methods, such as ExecuteNonQuery, have been modified to recognize when a TransactionScope instance is active by replacing the GetConnection method with the GetOpenConnection method. If you have written a class that inherits from the Database class, you will need to rewrite your code to take these changes into account. If you continue to use the GetConnection method, you will receive a compiler warning. In addition, if your application uses the ExecuteXmlReader method, you may need to rewrite your code to test to see whether a TransactionScope instance is active before closing a connection.
For more information, see Using the TransactionScope Class. For an example of how to use the ExecuteXMLReader method, see Retrieving Multiple Rows As XML.
strong text
SQL Server Compact Edition
Enterprise Library 3.1 – May 2007 and later supports SQL Server Compact Edition (CE). SQL Server CE provides the essential features of a relational database and is intended for desktop and mobile applications that need a local data store but do not require the full functionality of SQL Server. For more information, see the section "Using SQL Server CE" in Creating a Database Object.
I am still trying to get a sense of how truly useful this DAAB is. It seems like a tremendous amount of reading of doc is required to end up writing just a little less code than otherwise required with ADO.NET un-aided by the DAAB. I guess if one wanted to provide for an easier switch to say, Oracle [from MS SQL Server), this is a useful way to configure things.
If you have unit tests,port to new and run and see,if you have Resharper it can analyse your solution in VStudio and point out the errors.It will take you time.