Geode native client deserialise PdxInstanceImpl - gemfire

I have a REST client that populates a Geode region with Json data which the Geode REST API automatically converts to a PdxInstance type.
The region triggers a C# native client listener AfterCreate(EntryEvent<TKey, TVal> ev) in which the TVal type ev.NewValue is seen as type PdxInstanceImpl and looks like:
PDX[7534066,__GEMFIRE_JSON]{#type=MyClass, Field1=Value1, Field2=Value2}
I've seen from here that the following code can get at the individual Pdx fields
IPdxInstance pdx = (IPdxInstance)ev.NewValue;
pdx.GetField("Field1");
and that works on a Field level, but I want to convert the PdxInstanceImpl that is received to PdxInstance so it can be put into another region directly, or I want to convert all the fields back to Json (as a string) in 1 go and put a Json string into another region, or use it as I like.
So there is apparently a way to autoserialize a PdxInstance to MyClass but if I try
MyClass c = (MyClass)pdx;
then I get System.InvalidCastException: Unable to cast object of type 'Apache.Geode.Client.Internal.PdxInstanceImpl' to type 'MyClass'
I've seen from some Java client examples you can use type PdxInstanceImpl to get at the data but in the C# native client that gives an error: PdxInstanceImpl is inaccessible due to its protection level.
I've added the autoserializer and the results are the same.
Any idea what I am missing here? Thanks

In the end I've used a field by field approach:
IPdxInstance pdx = (IPdxInstance)ev.NewValue;
pdx.GetField("Field1");
pdx.GetField("Field2");
pdx.GetField("Field3");
etc...
Outside of the event handlers, to create a PDX instance I used:
IPdxInstanceFactory writer = Setup.g.GetCache().CreatePdxInstanceFactory("myType");
writer.WriteString("String", "s");
writer.WriteChar("Char", 'c');
writer.WriteDouble("Double", Convert.ToDouble(1000));
IPdxInstance pdx = writer.Create();
To read a PDX instance its:
IPdxInstance pdx = Setup.gpg.GeodeGetPdx("myType", key);
MyType t = new MyType();
t.String1 = (string)pdx.GetField("String1");
t.Int1 = (int)pdx.GetField("Int1");
t.Date1 = (DateTime)pdx.GetField("Date1");
etc...

Related

Type name 'serializeObject' does not exist in the type 'JsonConvert'

I am trying to convert some data to Json to send to the CloudFlare API. I am attempting to use Newtonsoft.Json.JsonConvert.SeriablizeObject() to accomplish this but I am getting the Intellisense error that the type name 'serializeObject' does not exist in the type 'JsonConvert'. I have the NuGet package Newtonsoft.Json installed but it does not recognize the SerializeObject() method. I am not sure what I am missing.
Its because you're calling the method wrong, remove the new operator from the line
var json = new JsonConvert.SerializeObject(updateDnsRecord);
to
var json = JsonConvert.SerializeObject(updateDnsRecord);

Processing Event Hub Capture AVRO files with Azure Data Lake Analytics

I'm attempting to extract data from AVRO files produced by Event Hub Capture. In most cases this works flawlessly. But certain files are causing me problems. When I run the following U-SQL job, I get the error:
USE DATABASE Metrics;
USE SCHEMA dbo;
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
REFERENCE ASSEMBLY [Avro];
REFERENCE ASSEMBLY [log4net];
USING Microsoft.Analytics.Samples.Formats.ApacheAvro;
USING Microsoft.Analytics.Samples.Formats.Json;
USING System.Text;
//DECLARE #input string = "adl://mydatalakestore.azuredatalakestore.net/event-hub-capture/v3/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}/{filename}";
DECLARE #input string = "adl://mydatalakestore.azuredatalakestore.net/event-hub-capture/v3/2018/01/16/19/rcpt-metrics-us-es-eh-metrics-v3-us-0-35-36.avro";
#eventHubArchiveRecords =
EXTRACT Body byte[],
date DateTime,
filename System.String
FROM #input
USING new AvroExtractor(#"
{
""type"":""record"",
""name"":""EventData"",
""namespace"":""Microsoft.ServiceBus.Messaging"",
""fields"":[
{""name"":""SequenceNumber"",""type"":""long""},
{""name"":""Offset"",""type"":""string""},
{""name"":""EnqueuedTimeUtc"",""type"":""string""},
{""name"":""SystemProperties"",""type"":{""type"":""map"",""values"":[""long"",""double"",""string"",""bytes""]}},
{""name"":""Properties"",""type"":{""type"":""map"",""values"":[""long"",""double"",""string"",""bytes""]}},
{""name"":""Body"",""type"":[""null"",""bytes""]}
]
}
");
#json =
SELECT Encoding.UTF8.GetString(Body) AS json
FROM #eventHubArchiveRecords;
OUTPUT #json
TO "/outputs/Avro/testjson.csv"
USING Outputters.Csv(outputHeader : true, quoting : true);
I get the following error:
Unhandled exception from user code: "The given key was not present in the dictionary."
An unhandled exception from user code has been reported when invoking the method 'Extract' on the user type 'Microsoft.Analytics.Samples.Formats.ApacheAvro.AvroExtractor'
Am I correct in assuming the problem is within the AVRO file produced by Event Hub Capture, or is there something wrong with my code?
The Key Not Present error is referring to the fields in your extract statement. It's not finding the data and filename fields. I removed those fields and your script runs correctly in my ADLA instance.
The current implementation only supports primitive types, not complex types of the Avro specification at the moment.
You have to build and use an extractor based on apache avro and not use the sample extractor provided by MS.
We went the same path

wsdl2java code generation for lists of custom objects

I would like to know if the tool "wsdl2java" (Axis2) is able to generate stubs that support getting list of custom ojects.
For instance, if I have a WS that have the following method:
public List<Device> getDevices(){
//...
}
Where Device is a custom class...
This tool can do that?
I changed the return data type of my Web Service to an array because of that:
http://www.ibm.com/developerworks/webservices/library/ws-tip-coding/index.html
And I had to do some changes (some namespaces) to the generated stub (I used ADB)...
I changed that because it was giving me an ADBException: Unexpected subelement ...

Can I reference a DataContract and its proxy version from same class

I'm dipping my foot into WCF and am trying to make a simple test project that can both consume the service as a service and also directly instantiate it's classes and work with them.
I had an earlier working version where data passed was just primitive types. However, when I attempted to convert to using data contracts, I'm getting conflicts in whether it's referencing the proxy-declared version of the contract or the version from the project itself.
Question: Is it possible to do this and if so, how would I resolve the data contract references?
private void Test()
{
MyService fssDirect = new MyService(); // direct instantiation
MyServiceClient fssService = new MyServiceClient(); // Service proxy
ClientCredentialsContract Client = new ClientCredentialsContract();
ResponseDataContract Result = new ResponseDataContract();
if (CallAsService)
{
Result = fssService.Create(Client, Request);
}
else
{
Result = fssDirect.Create(Client, Request);
}
}
In the above, any reference to the RequestDataContract and ClientCredentialsContract types indicates
Warning: The type 'MyContracts.RequestDataContract' in 'C:...\Test\MyServiceProxy.cs' conflicts with the imported type 'MyContracts.RequestDataContract' in 'C:...\MyService\bin\Debug\Contracts.dll'. Using the type defined in 'C:...\Test\MyServiceProxy.cs'.
(Names changed and paths shortened to protect the innocent)
Thanks,
John
When you create the proxy for your service, try referencing the assembly which contains the data contracts (if using "Add Service Reference", go to the advanced options, select "reuse types in referenced assemblies"; if using svcutil, use the /r argument). This way the tool won't generate the data contracts and you won't have the conflicts.

Unity Container Type Registration Quirk

I'm trying to automatically register all reports in a unity container.
All reports implement IReport and also have a Report() attribute which defines the title, description and unique key (so I can read these without instantiating a concrete class).
So...
I get the report types like this
Public Shared Function GetClassesWhichimplementInterface(Of T)() As IEnumerable(Of Type)
Dim InterfaceType = GetType(T)
Dim Types As IEnumerable(Of Type)
Types = Reflection.Assembly.GetCallingAssembly.GetTypes()
Return Types.Where(Function(x) InterfaceType.IsAssignableFrom(x))
End Function
And register them like this:
Public Sub RegisterReports()
Dim ReportTypes = ReflectionHelper.GetClassesWhichimplementInterface(Of IReport)()
For Each ReportType In ReportTypes
''Previously I was reading the report attribute here and using the defined unique key. I've stopped using this code to remove possible problems while debugging.
Container.RegisterType(GetType(IReport), ReportType, ReportType.Name)
Next
End Sub
There are types being returned by the call to GetClassesWhichimplementInterface() and the Container.RegisterType() call is made without errors. If I call Container.Resolve(of Interfaces.IReport) immediately after the register call, I get the following exception:
Resolution of the dependency failed, type = "MyProject.Interfaces.IReport", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, MyProject.Interfaces.IReport, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving MyProject.Interfaces.IReport,(none)
Can anyone tell me why the container isn't preserving the registration?
The registration is in the container. The thing is that you are calling resolve without passing a named registration as a parameter.
As all your registrations were performed using the following code:
Container.RegisterType(GetType(IReport), ReportType, ReportType.Name)
Then all of them have a name. You must provide the name along with the type to be able to resolve the dependency from the container.
The error you are getting is because there is no type mapping registered without a name.