Thursday, May 26, 2011
Thursday, May 19, 2011
ODATA Custom Exceptions
http://msdn.microsoft.com/en-us/library/ee391967.aspx#Y17001: public class AuthenticationInterceptor : RequestInterceptor2: {3: public AuthenticationInterceptor() : base(false) { }4: public override void ProcessRequest(ref RequestContext requestContext)5: {6: if (!IsValidApiKey(requestContext))7: GenerateErrorResponse(requestContext,8: HttpStatusCode.Unauthorized,9: "Missing or invalid user key (supply via the Authorization header)");10: }11: public bool IsValidUserKey(Message req, string key, string uri)12: {13: ... // ommitted for brevity14: }15: public void GenerateErrorResponse(RequestContext requestContext,16: HttpStatusCode statusCode, string errorMessage)17: {18: // The error message is padded so that IE shows the response by default19: string errorHtml =20: "<html><HEAD><TITLE>Request Error</TITLE></HEAD><BODY>" +21: "<H1>Error processing request</H1><P>{0}</P></BODY></html>";22: XElement response = XElement.Load(new StringReader(23: string.Format(errorHtml, errorMessage)));24: Message reply = Message.CreateMessage(MessageVersion.None, null, response);25: HttpResponseMessageProperty responseProp = new HttpResponseMessageProperty()26: {27: StatusCode = statusCode28: };29: responseProp.Headers[HttpResponseHeader.ContentType] = "text/html";30: reply.Properties[HttpResponseMessageProperty.Name] = responseProp;31: requestContext.Reply(reply);32: // set the request context to null to terminate processing of this request33: requestContext = null;34: }35: }
ODATA Custom Exceptions
http://msdn.microsoft.com/en-us/library/ee391967.aspx#Y1700
public class AuthenticationInterceptor : RequestInterceptor
{ public AuthenticationInterceptor() : base(false) { } public override void ProcessRequest(ref RequestContext requestContext) { if (!IsValidApiKey(requestContext)) GenerateErrorResponse(requestContext, HttpStatusCode.Unauthorized, "Missing or invalid user key (supply via the Authorization header)"); } public bool IsValidUserKey(Message req, string key, string uri) { ... // ommitted for brevity } public void GenerateErrorResponse(RequestContext requestContext, HttpStatusCode statusCode, string errorMessage) { // The error message is padded so that IE shows the response by default string errorHtml = "<html><HEAD><TITLE>Request Error</TITLE></HEAD><BODY>" + "<H1>Error processing request</H1><P>{0}</P></BODY></html>"; XElement response = XElement.Load(new StringReader( string.Format(errorHtml, errorMessage))); Message reply = Message.CreateMessage(MessageVersion.None, null, response); HttpResponseMessageProperty responseProp = new HttpResponseMessageProperty() { StatusCode = statusCode }; responseProp.Headers[HttpResponseHeader.ContentType] = "text/html"; reply.Properties[HttpResponseMessageProperty.Name] = responseProp; requestContext.Reply(reply); // set the request context to null to terminate processing of this request requestContext = null; }
}
Wednesday, May 18, 2011
КРИТИ[Ц|Н]ИЗМ
http://thisdeveloperslife.com/post/2-0-1-criticism
Ayende Rahien звезда, критик и девелопер NHIBERNATE, любит критиковать, говорит с чмошным французским акцентом (нот персонал инсалт бат, лет ми спик форм май харт, франзузский язык звучит чмошно а тем более его англицкий аналог), сказал важную вещь чуваки которые делают Light Switch лохи и лэйзи вот – дальше бла-бла-бла – дальше Хасельман – “зачто ты назвал мой подкаст о революции в еджипте крапом?” (это он уже какокумо то петру петровичу в твите) – петр петрович сказал что он ваще сам с балкан и знает что такое революции это когда главный меняется а система остается той же а делаьше дженерал дизапойтмент – бла-бла-бла – вис девлоперс лайв – кул стафф эктуали
Monday, May 16, 2011
mvc wish list
2.why it is needded to validate in ModelValidator, values which don't passed in request parameteres.
3. ValidateMessageFor - Template as for types
Sunday, May 15, 2011
jquery autocomplete with hidden id
jquery autocomplete works fine till you just use it to select some sting value and pass it to a server. But what if you need to pass not string label of the selected value but related to it id?
It's hard to override this behaviour (at least was for me). First of all there is a lot of solutions in the web
Such as custom widgets:
http://code.google.com/p/jquery-autocomplete/source/checkout
http://flux88.com/2009/06/jquery-autocomplete-with-a-hidden-value/
Won't use because of poor documentation and support
Or simplistic solutions like this one:
http://www.petefreitag.com/item/756.cfm
Here all works fine but some underlying issues are neglected: when you typed some text and out of input control before request to the server complete the id value not changed.
After searching the web more meticulously found this usefull pages:
Old-version:
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
Migration guide:
http://www.learningjquery.com/2010/06/autocomplete-migration-guide
Release notes:
http://blog.jqueryui.com/2010/08/extensible-autocomplete/
Extension for current widget:
https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js
Why old version mentioned? Because it has two very usefull methods which serve exactly for my purpose, unfortunately they are "depricated" in new version and at this point we have to use extension to help with.
Again the lack of this functionality in current version of jquery plugin is common, for examp:
Sebastian
July 31, 2010 at 4:39 pm
HI there, I have a question about the selectFirst option - you say it is gone with no need for replacement, but I disagree.
I have a strong case for an instance where I need to be able to input something - say the word 'Widget'. If present in the source list I have, 'Widget' contains all kind of other information such as ID's that I need to have access to when the user blurs out of the autocomplete.
However if I type out 'Widget' in the autocomplete and just tab out without selecting the matching item 'Widget' from the dropdown list, this item is never selected and I don't get that extra data. This is bad behavior, at least for my needs, and there's got to be a way to address this issue. Do you have any solutions or workarounds?
But even using extensions the solution is not out of box;
at first glance this fits -
https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.autoSelect.js
but actually it works only for static list, not for server queries.
This way I couldn’t find in the web implementation which suits to my purpose and here you could see custom implementation of my plugin.
Main feature of this extension is:
The value of hidden input filed will be changed either user directly select item from the list or user typed it before list was actually filled with item from the server, if one of the values from the server corresponds to text in input control, the corresponded id value will be set to the hidden field, if typed value isn’t contained in the list the hidden value will be reset to null.
<input type=”text” id=”item_label” data-autocomplete-for=”item_id” data-autocomplete-srv = “…” data-autocomplete-respformat=”…”/>
<input type=”hidden” id=”item_id”/>
$(“#item_label”).autoComplete(srvBaseUrl);
Ini params:
srvBaseUrl – base url to the srevice which provides data for control
examp:
$(“#item_label”).autoComplete(“http://localhost:58486/SomeODataService.svc”);
Attributes:
1. data-autocomplete-srv – Request to the service
Examp:
data-autocomplete-srv="Persons?$select=Id,NickName&$filter=startswith(NickName, '{0}')"
2. data-autocomplete-respformat – Format of the JSON response from the srevice
Format is “KeyValue, LabelValue, ListValue” where:
KeyValue – value which will be set as id value (value of hidden control)
LabelValue – value which will be shown as selected value for input control
ListValue – value which will be shown in selection list of input control
Examp:
data-autocomplete-respformat = "Id,NickName,NickName"
BUgs + 2
2. MS Test project .vdi file doesn't referesh till project not unloadaed-loadede