ROWLEX: Classes with the same property names not working:ROWLEX - rowlex

I have some complex classes which many of then have a class as a property. I have tried to mark up the class file with th ROWLEX attribute markers but when more than one class has the same property name, the Rowlex extractor gives an error.
I have produced a very simple set of classes Leg, Animal, Table. Both Table & Animal have Legs which is an Array of Leg....
The error message is:http://nc3a.nato.int/10/16/ZooOntology#Legs is assigned to more than one type.
Imports NC3A.SI.Rowlex
http://nc3a.nato.int/10/16/ZooOntology")>
Namespace Namespace1
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class Leg
End Class
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class House
<RdfProperty(False)> _
Public readonly Property Legs() As Leg()
Get
Return Nothing
End Get
End Property
End Class
<RdfSerializable(Ontology:="http://nc3a.nato.int/10/16/ZooOntology", HasResourceUri:=False)> _
Public Class Table
<RdfProperty(False)> _
Public ReadOnly Property Legs() As Leg()
Get
Return Nothing
End Get
End Property
End Class
End Namespace

ROWLEX2.1 solves the issue, you may download it from http://rowlex.nc3a.nato.int. For more detailed explanation and sample code, please look at this similar StackOverflow question.

Related

LiteDB - find data object via List.contains

A simplified version. I have two classes:
Public Class mSystem
Public Property ID as ObjectID
Public Property Name as string
End Class
Public Class mEmulator
Public Property ID as ObjectID
Public Property Name as string
<BsonRef("mSystems")>
Public Property AssociatedSystems as New List(Of mSystem)
End Class
Public Class Main
Public Sub EmaultorsLinkedToSystem
dim SelectedSystem as mSystem = db.Collections.mSystems.Find(Function(x) x.Name = "Sony Playstation").FirstOrDefault
test = db.Collections.mEmulators.Include(Function(x) x.AssociatedSystems).Find(Function(y) y.AssociatedSystems.Contains(SelectedSystem)).ToList
End sub
End Class
Now I know one mEmulator data object has "Sony Playstation" in its List(of mSystem). However, test returns null. Why isn't this finding it? I've tried a few permutations, but cant get this to work. Any ideas?
The Include method is used for resolving references to other collections, and you're not using BsonRef with AssociatedSystems (at least not in this example you provided). In your example, the instances of mSystem in AssociatedSystems are not being stored in a separate collection, but as an array of embedded documents in the emulators collection.
Try removing the Include call, it should work fine.

How do I access an object's eigenclass in Crystal?

In Ruby, it's possible to access the eigenclass (or "singleton class") of an object by reopening it. This is particularly useful for defining "private class methods":
class Foo
class << self
private
def declarative_method_name
end
end
declarative_method_name
end
# Foo.declarative_method_name => ERROR!
However, in Crystal this is not syntax:
Syntax error in ./test.cr:2: expecting token 'CONST', not '<<'
class << self
^
Is there another (or indeed any) way to achieve this in Crystal currently?
There's no eigenclass, or more commonly called singleton class in Ruby these days (given there's Object#singleton_class), in Crystal.
However defining class methods and calling them on the class level is supported:
class Foo
private def self.declarative_method_name
puts "hey"
end
declarative_method_name
end
https://carc.in/#/r/1316
The def self. construct here is specialized by the compiler and there's no more general concept beneath it, yet.
How would you make a super classes' new method private while still allowing it's subclasses' to be public?
class Foo
private self.new; end
end
class Bar < Foo
end
Bar.new #=> error: private method 'new' called for Foo:Class
It's also worth noting here that unlike in Ruby, class variables don't transcend inheritance. In Ruby the following code has a strange side effect...
class Foo
##var = 'foo'
def var
##var
end
end
class Bar < Foo
##var = 'bar'
end
puts Foo.new.var
It'll return 'bar' despite the fact that we modified the class variable on Bar. In crystal it returns 'foo' meaning that another reason we'd access the eiganclass, to store and read class level state safely, isn't necessary in crystal, we can just use class variables.

Return List from Lotusscript webservice

I have webservice on Lotusscript, and I want some function to return a list of elements.
As I know, Lotusscript functions can't return Lists of objects, you need to create a wrapper class to return lists (Can I return a List from a LotusScript Function?)
Here is the 1st version of code:
Class myClass
Public Function getList As Person
Dim pers As New Person
pers.info = "Iron Man"
Set getList = pers
End Function
End Class
Class Person
Public info As String
End Class
PortType class is set to myClass. This code works quite well and returns one object of class Person.
But when I try to return List of objects:
Class myClass
Public Function getList As PersonLst
Dim pers As New Person
Dim persLst As New PersonLst
pers.info = "Iron Man"
Set persLst.lst("Tony Stark") = pers
Set getList = persLst
End Function
End Class
Class Person
Public info As String
End Class
Class PersonLst
Public lst List As Person
End Class
I have the following error when i save my webservice:
The Web Service has been saved, but is not valid: Please specify which
class exposes your web service interface(s), using the
'PortType class' field of the Web Service properties panel
although PortType is still set to myClass.
Consider using a lotus script array as these will map to SOAP types.
See Web Service Mapping which explains how arrays are mapped, and special cases for different versions of Domino and empty arrays.

What is ScaffoldColumn and RegularExpression attributes

I am trying to learn MVC4 and i've come to this chapter called validation.
I came to know about DataAnnotations and they have pretty neat attributes to do some server side validation. In book they have only explained about [Required] and [Datatype] attribute. However in asp.net website i saw something called ScaffoldColumn and RegularExpression.
Can someone explain what they are, even though I know little what RegularExpression does.
Also are there any other important validation attributes I should know?
Scaffold Column dictates if when adding a view based on that datamodel it should/not scaffold the column. So forexample your model's id field is a good candidate for you to specify ScaffoldColumn(false), and other foreign key fields etc.
I you specify a regular expression, then if you scaffold a new view for that model,edit customer for example, a regex or regular expression on field will enforce that entered data must match that format.
You can read about ScaffoldColumnAttribute Class here
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
}
public class ProductMetadata
{
[ScaffoldColumn(true)]
public object ProductID;
[ScaffoldColumn(false)]
public object ThumbnailPhotoFileName;
}
And about RegularExpressionAttribute Class you can read here.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(#"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName;
// Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(#"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}

How to architect DAL for WebService exposure?

We have a highly specialized DAL which sits over our DB. Our apps need to use this DAL to correctly operate against this DB.
The generated DAL (which sits on some custom base classes) has various 'Rec' classes (Table1Rec, Table2Rec) each of which represents the record structure of a given table.
Here is a sample Pseudo-class...
Public Class SomeTableRec
Private mField1 As String
Private mField1isNull As Boolean
Private mField2 As Integer
Private mField2isNull As Boolean
Public Sub New()
mField1isNull = True
mField2isNull = True
End Sub
Public Property Field1() As String
Get
Return mField1
End Get
Set(ByVal value As String)
mField1 = value
mField1isNull = False
End Set
End Property
Public ReadOnly Property Field1isNull() As Boolean
Get
Return mField1isNull
End Get
End Property
Public Property Field2() As Integer
Get
Return mField2
End Get
Set(ByVal value As Integer)
mField2 = value
mField2isNull = False
End Set
End Property
Public ReadOnly Property Field2isNull() As Boolean
Get
Return mField2isNull
End Get
End Property
End Class
Each class has properties for each of the fields...
Thus I can write...
Dim Rec as New Table1Rec
Table1Rec.Field1 = "SomeString"
Table2Rec.Field2 = 500
Where a field can accept a NULL value, there is an additional property which indicates if the value is currently null.
Thus....
Dim Rec as New Table1Rec
Table1Rec.Field1 = "SomeString"
If Table1Rec.Field1Null then
' This clearly is not true
End If
If Table1Rec.Field2Null then
' This will be true
End If
This works because the constructor of the class sets all NULLproperties to True and the setting of any FieldProperty will cause the equivalent NullProperty to be set to false.
I have recently had the need to expose my DAL over the web through a web service (which I of course intend to secure) and have discovered that while the structure of the 'Rec' class remains intact over the web... All logic is lost..
If someone were to run the previous piece of code remotely they would notice that neither condition would prove true as there is no client side code which sets null to true.
I get the feeling I have architected this all wrong, but cannot see how I should improve it.
What is the correct way to architect this?
Not sure if I fully understand the question, but you can have nullable data types in XML.
So this...
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Testing
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetObjects() As Generic.List(Of TestObject)
Dim list As New Generic.List(Of TestObject)
list.Add(New TestObject(Nothing, "Empty ID Object"))
list.Add(New TestObject(1, "Full ID Object"))
list.Add(New TestObject(2, Nothing))
Return list
End Function
Public Class TestObject
Public Sub New()
_name = String.Empty
_id = Nothing
End Sub
Public Sub New(ByVal id As Nullable(Of Integer), ByVal name As String)
_name = name
_id = id
End Sub
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _id As Nullable(Of Integer)
Public Property ID() As Nullable(Of Integer)
Get
Return _id
End Get
Set(ByVal value As Nullable(Of Integer))
_id = value
End Set
End Property
End Class
End Class
outputs this (with nullable areas)
<?xml version="1.0" encoding="utf-8" ?>
<ArrayOfTestObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<TestObject>
<Name>Empty ID Object</Name>
<ID xsi:nil="true" />
</TestObject>
<TestObject>
<Name>Full ID Object</Name>
<ID>1</ID>
</TestObject>
<TestObject>
<ID>2</ID>
</TestObject>
</ArrayOfTestObject>
Web services are designed to expose operation(methods) & data contracts but not internal implementation logic. This is a "good thing" in the world of service-oriented architecture. The scenario you describe is a remote/distributed object architecture. Web services will not support what you are trying to do. Please see this post for more information.