Breeze: server computed properties to breeze computed observable - object

I am able to have breeze capture server computed properties using this code, gotten from HERE.
var yourTypeCtor = function () {
this.calculatedProperty = "";
};
store.registerEntityTypeCtor("YourType", yourTypeCtor);
I have a computed property that returns an entity object. The entity type returned is part of the metadata. However, breeze returns this entity as an object, not an observable. Is it possible to configure breeze to return this object as an observable so that the object is updated based on the conditions of the computed properties that are defined on the server side?

Related

MVC5 with attribute routing: how to get route data associated with particular action

Let's assume I have an ActionDescriptor (or MethodInfo) object that points to some action method in my application. I want to get route table's entries (System.Web.Routing.Route objects) associated with this action.
Is there, by any chance, some framework method that might get me this information, or do I have to parse the route table somehow? How would you suggest to do this, in the second case?
That's how I did this:
var routeProvider = new DefaultDirectRouteProvider();
var routeEntries = routeProvider.GetDirectRoutes(
_actionDescriptor.ControllerDescriptor, new[] { _actionDescriptor }, new DefaultInlineConstraintResolver());

OpenNTF Domino API (ODA) WrapperFactory.fromLotus Usage

I have a situation where I need to get a org.openntf.domino.Document object from a lotus.domino.Document object. I found examples using Factory.fromLotus() but this is depreciated.
The JavaDocs pointed me to WrapperFactory.fromLotus() but I am unsure how to use this. I am currently doing this:
Document doc = WrapperFactory.fromLotus(lotusDoc, org.openntf.domino.Document.class, null);
Eclipse is marking this line with an error:
The method fromLotus(D, FactorySchema, P) in the type
WrapperFactory is not applicable for the arguments (Document,
Class, null)
How do I use WrapperFactory.fromLotus()?
That method wants the original Lotus object (as you're doing), a "schema" object, and then the parent.
For the schema, you can use org.openntf.domino.Document.SCHEMA.
For the parent, you'll need to pass in a wrapped version of the parent Database object. I believe can go up the chain by getting the Database and then the Session - wrap the session with Session s = fac.fromLotus(lotusSession, Session.SCHEMA, null), then the DB with Database db = fac.fromLotus(lotusDatabase, Database.SCHEMA, s), then the doc with Document doc = fac.fromLotus(lotusDoc, Document.SCHEMA, db).

Service bus message GetBody does not include inherited properties

I have a base class "Entity" and a derived class "Site" or "Group". Both are marked as serializable. I am sending them to the service bus and retrieving as follows. None of the inherited properties are set after reading, however; it's as if they are ignored during deserialization. Any way I can get these to work or do I need to write my own XML deserializer?
var queueEntity = new QueueEntity(e); // e is Entity, Site
var brokered = new BrokeredMessage(queueEntity);
QueueContext.QueueClient.Send(brokered);
Worker role
var message = receivedMessage.GetBody<QueueEntity>();
var e = message.Entity; // this only has derived class property values set
Thanks!
You could serialize it using existing serializers and pass into BrokeredMesdage as a Stream. On the receiving side do the other way around, serializing from a Stream into your object.

How would you implement a partial request & response, like the youtube api, using ServiceStack?

In the Youtube API, there is the power to request a "partial feed".
This allows the app developer to tailor the size and sturcture of the data returned, by specifying which "fields" to return.
i.e. GET api/person/1?fields=(id,email) would return a DTO containing only the id and the email fields, not the whole person response.
How would you attempt this using ServiceStack? Is there some way to attach a callback to the serialiser to control which properties to include in the response object?
From my experience servicestack only returns fields that actually has data. If my experience is correct then all you would need to do is figure out the best way to architect the request so that it is asking for specific data to return, this way you would only populate the response with data requested thus servicestack would only return that.
I implemented this for an API that only returns JSON.
First I created two structs to (de)serialize and interpret the "fields" query argument recursive syntax:
FieldSelector, which specifies a field and possibly its children FieldSelection enclosed between parenthesis;
FieldsSelection, which is a comma-separated list of FieldSelector.
I've used structs instead of classes because, AFAIK, you can't override class (de)serialization from/to URLs in ServiceStack. With structs you can do it by overriding ToString (serializer) and providing a constructor accepting a string as parameter (deserializer).
Then you include this on every request DTO that returns JSON:
FieldsSelection Fields { get; set; }
On a custom ServiceRunner<T>.OnAfterExecute you serialize the response DTO to JSON, parse it with ServiceStack.Text's JsonObject and apply the fields selection recursively with a method like this:
private static JsonObject Apply(this JsonObject json, FieldsSelection fieldMask)
{
IEnumerable<string> keysToRemove = json.Keys.ToList().Except(fieldMask.Keys);
foreach (var key in keysToRemove)
json.Remove(key);
foreach (var selector in fieldMask.Selectors.Values.Where(s => s.HasSubFieldsSelection))
{
var field = json[selector.Field];
if (field == null)
continue;
switch (field[0])
{
case '{':
json[selector.Field] = Apply(json.Object(selector.Field), selector.SubFieldsSelection).ToJson();
break;
case '[':
var itensArray = json.ArrayObjects(selector.Field);
for (int i = 0; i < itensArray.Count; i++)
itensArray[i] = Apply(itensArray[i], selector.SubFieldsSelection);
json[selector.Field] = itensArray.ToJson();
break;
default:
throw new ArgumentException("Selection incompatible with object structure");
}
}
return json;
}
Then you return the result as your response DTO. I've also implemented negative fields selectors (fields=-foo selects all DTO fields except foo), but you get the idea.
Look at ServiceStack.Text.JsConfig properties, they have all the hooks and customizations ServiceStack's text serializers support. Specifically the hooks that allow you to custom deserialization are:
JsConfig<T>.DeserializeFn
JsConfig<T>.RawDeSerializeFn
JsConfig<T>.OnDeserializedFn
We were able to implement said filtering by adding custom service runner and using some reflection in it to construct ExpandoObject with required field set by response DTO. See this for more info on service runners.

When no data is returned from database

I am intiating a loading panel in init method and hiding it in ReturnDataPayload event.This is working perfectly when data Table has got some values in it.But when there is no data returned from database , the control is not going to returnDataPayLoad event.Please help me in finding an event which will be fired even when the response doesn't have any data or tell me a way to hide the loading panel.
If you want a custom behavior, use DataSource's sendRequest method of the dataTable's dataSource
(function() {
var YdataTable = YAHOO.widget.DataTable,
YdataSource = YAHOO.util.DataSource;
var settings = {
container:"<DATATABLE_CONTAINER_GOES_HERE>",
source:"<URL_TO_RETRIEVE_YOUR_DATA>",
columnSettings:[
{key:"id", label:"Id"}
],
dataSourceSettings:{
responseType:YdataSource.TYPE_JSON,
responseSchema:{
resultsList:"rs",
fields:[
{key:"id"}
]
}
},
dataTableSettings:{
initialLoad:false
}
}
var dataTable = new YdataTable(
settings.container,
settings.columnSettings,
new YdataSource(
settings.source,
settings.dataSourceSettings),
settings.dataTableSettings);
})();
keep in mind No matter which source is your data: XML, JSON, JavaScript object, TEXT, you always will get your data in a unified way through DataSource's sendRequest method. So when you want to retrieve your data and, at the same time, add custom behavior, use it
dataTable.getDataSource().sendRequest(null, {
success:function(request, response, payload) {
if(response.results.length == 0) {
// No data returned
// Do what you want right here
// You can, for instance, hide the dataTable by calling this.setStyle("display", "none");
} else {
// Some data returned
// If you want to use default the DataTable behavior, just call
this.onDataReturnInitializeTable(request, response, payload);
}
},
scope:dataTable,
argument:dataTable.getState()
});
The properties of the response are
results (Array): Your source of data in a unified way. For each object in the results Array, There is a property according to responseSchema's fields property. Notice i use response.results.length to verify if some data has been returned
error (Boolean): Indicates data error
cached (Boolean): Indicates cached response
meta (Object): Schema-parsed meta data
On the YUI dataTable page, look for Loading data at runtime to see some built-in functions provided by YUI dataTable
I hope it can be useful and feel free to ask for help for anything else you want about YUI. See a demo page of nice features of YUI dataTable

Resources