Tuesday, October 30, 2012

Entity Framework, Inheritance, eager loading of association

Consider the following three objects:

Person:

string Name

Developer : Person

List<Skill> Skills

Skill:

Name

ID

I thought that in this simple inheritance I would be able to eagerly load the associated Skills of the developers  if any in the list, by doing the following:

var people = (FROM p in Db.people.include((dev as Developer) => dev.Skills) select p).ToList();

Or Maybe just using string based ‘include(“Skills”) ‘

But this simply doesn’t work, in term of no support for such syntax or failure in runtime (not finding skills)

The only method I found to resolve this is to:

var developers = (FROM p in Db.people.OfType<Developer>().include(dev =>dev.Skills) select p).ToList();

var people = (FROM p in Db.people WHERE !(p is Developer) select p).ToList();

var result = people.union(developers);

very ugly since I need to exclude the special entries but working.

 

This case was raised long time ago and was rejected by M$…. here

Thursday, October 18, 2012

Quick Web APP infrastructure called Meteor

Just got an email from a friend about a “new” infrastructure to write web apps quickly called Meteor.

From the screen cast and short examples I have seen this look like a real promising infrastructure that can really grow, while I do have lots of concerns related to security it seems that they did something and provided some mechanism for it – still I am sure lots of work has to be done

One of the things I really liked is that the entire page is actually listening to the server side, even when you deploy a new version it will automatically be update on the client side (magic).

…. wow ….

Tuesday, October 16, 2012

Sending emails–not as easy as you think

I am just doing the last few lines of code for my new site (To be released very soon), part of every site is the ability to send emails to your customers.

I will start with 1 important line – “The communication with your customers is the key for success and as such you need to ensure that you have the right infrastructure”

You might want to use your native SMTP on your ISP/Host, and have write fancy code that will manage delivery, OOO operations, Unsubscribe, Report on delivery, track clicks, bounces and the list can continue

But before you do that remember the first syntax and understand that to write such infrastructure you need deep understanding and tons of line of code and time, which no one has.

Another alternative is to integrate into online infrastructure (using SMTP, Rest api, etc) and get all the above features for small price between 10$ – 80$ for small business depend on usages.

I decided to use SendGrid because it was free for my usages, but there are other companies like MailChimp, etc

 

While writing the small piece of code that just send the messages using SendGrid SMTP, I face few road blocks:

  1. My email went to the SPAM folder
  2. When I finally got the email it was badly formatted without style sheet

You really need to read some articles that talk about how NOT to go to the SPAM folder before you write emails and as for the styling I found out that there are many constrains for HTML in emails

Luckily there is a good site called PreMailer that enables you to convert HTML page or text into a well formed email with inline stylesheet as needed and it will also alert you on risky in your current stylesheet

After all the above the key was to TEST-TEST-And TEST again, which is pretty weird when you think about it, since you see the output but you can never know what will happen

Monday, July 02, 2012

Code works on regular console but fails on StackOverFlow in IIS (0xc00000fd)

I have an entity framework project that simply failed all the time when running under IIS 32bit app while its always working when compiled into a console app.

The first exception is 0xc00000fd - take from the event viewer:

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7a5f8
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc00000fd
Fault offset: 0x0cc902b7
Faulting process id: 0x2038
Faulting application start time: 0x01cd58d87d82114e
Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
Faulting module path: unknown
Report Id: c3cbfc5a-c4cb-11e1-bbef-001c422bca8f

 

I used ADPLUS and used a preconfigured config file:

<ADPlus Version='2'>
    <Settings>
        <Runmode> Crash </Runmode>
    </Settings>

    <!-- defining and configuring exceptions -->
    <Exceptions>
        <!-- First we redefine all exceptions -->
        <AllExceptions>
            <Actions1>Log</Actions1>
            <Actions2>MiniDump;Log;EventLog</Actions2>
        </AllExceptions>

        <NewException Code="0xe053534f" Name="Unknown_Exception">
            <Actions1>FullDump;Log;EventLog</Actions1>
            <Actions2>FullDump;Log;EventLog</Actions2>
        </NewException>
        <NewException Code="0xc00000fd" Name="Unknown_Exception2">
            <Actions1>FullDump;Log;EventLog</Actions1>
            <Actions2>FullDump;Log;EventLog</Actions2>
        </NewException>       
    </Exceptions>
</ADPlus>

 

This automatically create full dump on the occurrence of the exception

After reviewing the issue in windbg I finally understood that the root cause is because the Stack Size limit in 32bit app pool in iis is 256kb while in regular console its much higher (here)

I am not going to update the default stack size for w3wp using editbin

I will adjust my code to be better suited for “small stack” environment.

Monday, February 13, 2012

The story about Applet, Load balancer and HTTPONLY

Our application requires Load balancer stickiness (affinity).

We were investigating a problem that our Applet that was trying to connect to the application server behind a load balancer was having difficulties, it seems as if the request was routed to different App server without sticking to one app server

It was very interesting, all the web applications were working and 0nlt the applet failed

After few hours of investigation using Fiddler, we have found that the load balancer was configured to have the cookie set as HTTPONLY (very Secured).

The problem is that by declaring the cookie as HTTPONLY, it is not visible to JS but also to Applets.

Apparently Applets DO NOT support HTTPONLY cookies.

The key support element was to record a working session in the lab and a non working session on the customer environment and compare –> that way you can pinpoint the issue easily, even without knowledge.

Hope this saves you few hours

Sunday, December 25, 2011

Its all about the version

last week I downloaded couple of good frameworks I am going to use more and more for the client side:

  • CoffeeScript – I was skeptic at start, but I am addicted now
  • KnockOutJS – MVVM, its all about two way binding
  • BackBone – MVC, utilities and good app design
  • KnockBack – takes the good of KnockOutJS & BackBone and combine them together

 

I started to write a simple code that will show list of items (Customer name and severity) and allow the user to double click on the customer name / Severity text so that it will become editable

It took me 10 min to write it and 4 hours to debug why it was not working

 

CoffeeScript code:

TicketViewModel = (ticket) ->
@customer_name = kb.observable(ticket, {key: 'CustomerName', write: ((text) -> ticket.save({CustomerName: text}))}, this)
@editingCustomerName = ko.observable(false)
@editCustomerName = (event) => @editingCustomerName(true)

@severity = kb.observable(ticket, {key: 'Severity', write: ((text) -> ticket.save({Severity: text}))}, this)
@editingSeverity = ko.observable(false)
@editSeverity = (event) => @editingSeverity(true)
@destroyTodo = => model.destroy()
@

TicketListViewModel = (tickets) ->
@tickets = ko.observableArray([])
@collection_observable = kb.collectionObservable(tickets, @tickets, { view_model_constructor: TicketViewModel })
@removeTicket = (ticket) =>
@tickets.remove(ticket)
@
@

app_view_model =
tickets_list: new TicketListViewModel(tickets)


 



HTML:



<ul class="ticket-list" data-bind="foreach: tickets_list.tickets">
<
li
>
<
div class
="ticket">
<
span class="ticket-customer" data-bind="text: customer_name, visible: !editingCustomerName(), dblclick: editCustomerName"></span
>
<
input data-bind
="value: customer_name, visible: editingCustomerName, hasfocus: editingCustomerName" />
<
span class="ticket-severity" data-bind="text: severity, visible: !editingSeverity(), dblclick: editSeverity"></span
>
<
select data-bind
="value: severity, visible: editingSeverity, hasfocus: editingSeverity">
<
option value="P1">P1</option
>
<
option value="P2">P2</option
>
<
option value="P3">P3</option
>
</
select
>
<
a href="#" data-bind="click: $parent.removeTicket">Delete me</a
>
</
div
>
</
li
>
</
ul
>


 



I had two problems:




  • The click event was not binded to my function on my model


  • After fixing it, When clicking the function didn’t get as first parameter the current item



to make a long story short I had two key problems




  • The context I was looping on was the root rather than the collection, so I had to specifically write the function name with its parent , so instead of “$parent.removeTicket” I had to write “$root.tickets_list.removeTicket”


  • the version of KnockoutJS that is delivered with KnockBack is OLD! and didn’t have support of passing the current item



I need to find a better way to share code…. any suggestions?

Saturday, November 26, 2011

Tips when working with web designers

I have few suggestions for you to focus more on your next work with web designer that should save you time and money (based on my experience)

  • you should decide if you want static min width or fluid (stretches) – this will change the web designer entire work. choosing fluid is harder and requires more time
  • Make sure that all the mockups work and move from one page to the other, this will ensure you really see the flow of movement in the site and you can use this mockup to show your investors something realistic quickly
  • Use latest JQuery – sometimes the web designers use old version that will cause you more work later
  • For forms make sure you also show the validation errors – this is crucial because playing later with the validation styles by your self will take you time or money if you will outsource it again
  • Use HTML5 – there is NO reason not to use (use the relevant shim for old browsers)
  • I really think your site should start with some standard template like boilerplate
  • It is your responsibility to test the site on all browsers! (personally I think you should NOT support IE6 Smile)
  • Don’t forget the sample you got from web designer got static text with static width, you should make sure you test the design using larger text
  • to support localization, your design should support RTL also (by using relevant classes without any tweaks from your side), although it doesn’t look important at start , not doing it now will cause you to pay more later

Hope this works for you