I'm using Apache Ignite on Azure Kubernetes service.
I need to get the registered devices list from Ignite in lately.
But the scan query is not working.
Here is my device object;
public class Device
{
[Required]
public string Id { get; set; }
public bool IsActive { get; set; }
public DateTime FirstRegisterDateTime { get; set; }
public Guid FirstRegisterUserId { get; set; }
}
Filter class is like below;
class RegisterDateFilter : ICacheEntryFilter<string, Device>
{
public DateTime LastSyncDateTime { get; set; }
public bool Invoke(ICacheEntry<string, Device> entry)
{
return entry.Value.FirstRegisterDateTime >= LastSyncDateTime;
}
}
and finally when I tried to call Scan Query in my method like below;
DateTime lastSyncDateTime = engineManager.GetLastSuccededJobTime(JobConstants.DEVICE_JOB);
using (var cursor = cacheManager.DeviceCache.Query(new ScanQuery<string, Device>(new RegisterDateFilter { LastSyncDateTime = lastSyncDateTime })))
{
foreach (var entry in cursor)
{
//logic
}
}
When the Scan query is executed, it gives the below error.
Platforms are not available [nodeId=*****-c534-48ae-a5a8-ceb2fff52c72]
(Use Apache.Ignite.Core.Ignition.Start() or Apache.Ignite.exe to start
Ignite.NET nodes; ignite::Ignition::Start() or ignite.exe to start
Ignite C++ nodes).
I also share the apache official sample. I didn't find the what is the problem?
Looks like your server nodes are Java-only, started with ignite.sh. Please make sure that all server nodes are started from .NET so that .NET-based filters can be evaluated.
https://ignite.apache.org/docs/latest/net-specific/net-platform-interoperability#mixed-platform-clusters
Related
I have the following data model
public class Profile : Entity
{
public virtual string Name { get; set; }
public virtual int Sequence { get; set; }
public virtual string Description { get; set; }
public virtual IList<MapService> MapServices { get; set; }
}
public class MapService : Entity
{
public virtual string Name { get; set; }
public virtual string Url { get; set; }
public virtual int MaximumResolution { get; set; }
}
As you can see , a profile has many MapService(s).
And the relation is many to many.
I am building an ASP.NET Web API rest service that return profile data.
I have two calls, one to return all the profiles, and the second filtered by ID, with the following URL
http://myapp/api/profiles
http://myapp/api/profiles/:id
I am using NHibernate for data access in the API Controller.
the Web API controller looks like this
public class ProfilesController : ApiController
{
public ProfilesController()
{
}
public IEnumerator<Profile> GetAllProfiles()
{
using (Session = .. create nhibernate session )
{
return Session.Query<Profile>().GetEnumerator();
}
}
}
When I return the whole list, I don't want the details of the MapService(s), just the Name and Id
so, I thought I will do lazy loading.
So, I configured the nhibernate mapping using fluent nhibernate as follows
public class ProfileMapping : ClassMap<Profile>
{
public ProfileMapping()
{
Table("PROFILE");
Id(x => x.Id, "OBJECT_ID");
Map(x => x.Name, "PROFILE_NAME");
Map(x => x.Sequence, "SEQUENCE_NO");
Map(x => x.Description, "DESCR");
HasManyToMany<MapService>(x => x.MapServices).LazyLoad().
Table("PROFILE_MAP_SERVICE").ParentKeyColumn("PROFILE_ID").ChildKeyColumn("MAP_SERVICE_ID");
}
}
I thought by doing this, I will return only the profile data without the details of MapService List
But when I call the rest service to return the whole data like this
http://myapp/api/profiles
I get this error
"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json
"Message":"An error has occurred.","ExceptionMessage":"Initializing[Domain.Profile#2]-failed to lazily initialize a collection of role: Domain.Profile.MapServices, no session or session was closed","ExceptionType":"NHibernate.LazyInitializationException","StackTrace":"
It seems that the nhibernate is returning the list of profiles without mapservices, and close the session.
But them somehow the web api service is trying to access the list of map service during serialization.
how to tell the web api service to ignore the map service list?
The simple approach here would be to introduce the DTO object:
public class ProfileDto
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Sequence { get; set; } // or Guid...
public virtual string Description { get; set; }
... // if more needed
}
and then adjust the API Controller method
public IEnumerable<ProfileDto> GetAllProfiles()
{
using (var session = ...)
{
return session.Query<Profile>()
.Select(entity => new ProfileDto
{
Id = entity.ID,
Name = entity.Name,
Sequence = entity.Sequence,
Description = entity.Description,
})
.ToList();
}
}
The most important here is the call .ToList() which will assure, that all the loads from DB server are done during the session life time (using clause). Automapper maybe could be next step to make it more easy (less code)...
I am using Hot towel template and extended functionality of it by using breeze. I have used breeze.partial-entities.js file to conver breeze entities to proper dtos that can be used by knockout observables as shown below.
function dtoToEntityMapper(dto) {
var keyValue = dto[keyName];
var entity = manager.getEntityByKey(entityName, keyValue);
if (!entity) {
// We don't have it, so create it as a partial
extendWith = $.extend({ }, extendWith || defaultExtension);
extendWith[keyName] = keyValue;
entity = manager.createEntity(entityName, extendWith);
}
mapToEntity(entity, dto);
entity.entityAspect.setUnchanged();
return entity;
}
For few of the entities it is working properly and getting breeze data converted to entities but for one of the entity implementation is failing. Model for the same is given as below.
public class StandardResourceProperty
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int StandardResourceId{ get; set; }
public int InputTypeId{ get; set; }
public int ListGroupId{ get; set; }
public string Format{ get; set; }
public string Calculation{ get; set; }
public bool Required{ get; set; }
public int MinSize{ get; set; }
public int MaxSize{ get; set; }
public string DefaultValue{ get; set; }
public string Comment { get; set; }
public virtual StandardResource AssociatedStandardResource { get; set; }
public virtual List AssociatedList { get; set; }
}
The error i am getting is
TypeError: this[propertyName] is not a function
[Break On This Error]
thispropertyName;
breeze.debug.js (line 13157)
]
with code
proto.setProperty = function(propertyName, value) {
this[propertyName](value);
// allow set property chaining.
return this;
};
Please let me know . What can be possible issue with the implementation also , it would be great if i can get more suggestion on how to debug and trace such issues.
Let's back up. I do not understand what you mean by "convert breeze entities to proper dtos that can be used by knockout observables". Breeze entities are already configured as KO observables (assuming you are using the default Breeze model library configuration). What are you trying to do?
I suspect you are following along with the Code Camper Jumpstart course where it does a getSessionPartials projection query. That query (like all projections) returns DTOs - not entities - and maps them with the dtoToEntityMapper method into Session entities.
The CCJS dtoToEntityMapper method cannot be used with entities. It is for converting from a DTO to an Entity and takes DTOs - not entities - as input.
Goodbye to dtoEntityMapper
The dtoToEntityMapper method pre-dates the ability of Breeze to automate projection-to-entity mapping by adding .toType('StandardResourceProperty') to your projection query.
Here is what the CCJS getSessionPartials query could look like now:
var query = EntityQuery
.from('Sessions')
.select('id, title, code, speakerId, trackId, timeSlotId, roomId, level, tags')
.orderBy(orderBy.session)
.toType('Session');
If you go this way, be sure to set the default state of the isPartial flag to true in the custom constructor (see model.js)
metadataStore.registerEntityTypeCtor(
'Session', function () { this.isPartial = true; }, sessionInitializer);
Note that this.isPartial = true is the reverse of the CCJS example where the default was false.
Make sure that you set isPartial(false) when you query or create a full entity. In CCJS there are two places to do that: in the success-callback of getSessionById AND in createSession which would become:
var createSession = function () {
return manager.createEntity(entityNames.session, {isPartial: false});
};
This is my model on the server side. I don't want to use Entity Framework, how would I generate BreezeJS metadata from the server. Breeze Metadata Format found here http://www.breezejs.com/documentation/breeze-metadata-format doesn't work.
public class User
{
public string Id { get; set; }
public string Name { get; set; }
public List<App> Apps { get; set; }
}
public class App
{
public string Id { get; set; }
public string Name { get; set; }
public Dictionary<string, string> Info { get; set; }
}
Did anyone try complex objects (nested object) similar to above one without using EF.
Using Breeze Metdata API or OData ?
Look at this example http://www.breezejs.com/samples/nodb it should give you a clue.
I am using MVC3 and Entity Framework. I have a class called User with 20 different properties. I have already created a database and filled it with some data. I want to break out the Addresses property and make it it's own class.
namespace NameSpace.Domain.Entities
{
public class User
{
public int UserId { get; set; }
...
...
public string AddressOne { get; set; }
public string AddressTwo { get; set; }
}
}
I want to break out both Addresses like so
namespace NameSpace.Domain.Entities
{
public class User
{
public int UserId { get; set; }
...
...
public Addresses Addresses { get; set; }
}
public class Addresses
{
public string AddressOne { get; set; }
public string AddressTwo { get; set; }
}
}
HERE'S MY QUESTION:
Since I already have the data table filled with data, how can I update this in the Server Explorer?
Thanks ( if you need more info please let me know )
If you are using EF code first 4.3 you can use the concept of migrations to achive what you want.
You will need to do a code based manual migration since you change is a bit to advanced for the framework to figure it out itselfe.
Further reading: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
I'm learning WCF, and tried to make a small service that exposes a Project and its tasks (the standard Entity Framework hello world).
The class structure is the following:
public class Project
{
public int ProjectId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime CreationDate { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
}
public class Task
{
public int TaskId { get; set; }
public string Title { get; set; }
public virtual Project RelatedProject { get; set; }
}
The DB context comes after:
public class ProjectContext : DbContext
{
public DbSet<Project> Projects { get; set; }
public DbSet<Task> Tasks { get; set; }
}
Finally, the service endpoint:
public IEnumerable<Project> getProjects()
{
ProjectContext p = new ProjectContext();
return p.Projects.AsEnumerable();
}
The problem is that this model will throw a System.ServiceModel.CommunicationException, but, If I remove the virtual properties from the model, It would work, but I would loose the entity framework links between Project and Task.
Anyone with a similar setup?
I banged my head against the wall several hours with this one. After extensive debugging, google gave the answer and I feel right to post it here since this was the first result I got in google.
Add this class on top of your [ServiceContract] interface declaration (typically IProjectService.cs
public class ApplyDataContractResolverAttribute : Attribute, IOperationBehavior
{
public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
{
}
public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy)
{
var dataContractSerializerOperationBehavior =
description.Behaviors.Find<DataContractSerializerOperationBehavior>();
dataContractSerializerOperationBehavior.DataContractResolver =
new ProxyDataContractResolver();
}
public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch)
{
var dataContractSerializerOperationBehavior =
description.Behaviors.Find<DataContractSerializerOperationBehavior>();
dataContractSerializerOperationBehavior.DataContractResolver =
new ProxyDataContractResolver();
}
public void Validate(OperationDescription description)
{
// Do validation.
}
}
Requirements are
using System.ServiceModel.Description;
using System.Data.Objects;
using System.ServiceModel.Channels;
Then under the [OperationContract] keyword add [ApplyDataContractResolver] keyword and you are set!
Big thanks to http://blog.rsuter.com/?p=286
For sending data trough WCF you should disable lazy loading (dataContext.ContextOptions.LazyLoadingEnabled = false;).
To be sure the data you want is loaded you need to use eager loading ( trough the Include method).
You need to change your function to:
public IEnumerable<Project> getProjects()
{
ProjectContext p = new ProjectContext();
p.ContextOptions.LazyLoadingEnabled = false;
return p.Projects.Include("Tasks").AsEnumerable();
}