RSS

Monthly Archives: March 2013

SignalR Hub Connection Lifecycle

This applies to SignalR 1.0 and .Net 4.5

public override Task OnConnected()
{
}
public override Task OnDisconnected()
{
}
public override Task OnReconnected()
{
}
 
Leave a comment

Posted by on March 28, 2013 in General

 

Tags:

SignalR Transport Negotiation Order

This applies to SignalR 1.0 and .Net 4.5

WebSocket > SSE > Forever Frame > Long Pooling

 
Leave a comment

Posted by on March 28, 2013 in General

 

Tags:

Image

SignalR Data JSON Encode

 

 

 

 

This applies to SignalR 1.0 and .Net 4.5

signalr-data-json-encode

 
Leave a comment

Posted by on March 28, 2013 in General

 

Tags:

Cross Reference and Checking for CRUD Operations

Whenever you allow users to modify a list of data from a grid on client side, your server side code can get hairy, trying to perform create / update / delete operations. Part of this is knowing what’s being change, what user has created and deleted, and how we indicate each record.

Common approach could be marking each record the state they are in, for example, when a user creates a new record, the new record is marked as ‘Created’. Then, server-side code handle each one of them based on the state.

Cross reference and checking technique is used to handle this kind of situation. It can be applied to anything that needs create / update / delete at the same time (by that I don’t mean async). I am sure this technique is out there and widely popular already, but for those who haven’t seen it, here it is.

The idea is simple. First, you get all data from database and user input. Then, cross checking them to come up with three lists:

  • What exists only in database
  • What exists only in user input
  • What exists in both

What exists only in database is what needs to be deleted.
What exists only in user input is what needs to be created.
What exists in both is what needs to be updated.

The order in which you perform the operation is not really matter in most cases.

C# Linq samples. Note that in below samples, when my data is deleted from database, it’s being soft-deleted (in IsDeleted column). You can perform hard delete if you wish, the options are not related to this technique.

Get All Data

// Get all data from database
var accountsInDb = _context.GetAllAccounts();
// Get all user input data
var accountsInModel = model.Accounts;

Delete operation

var onlyExistInDb = accountsInDb.Except(accountsInModel).ToList();

onlyExistInDb.ForEach(x => _context.Remove(x));

_context.SaveChanges();

Create operation

var onlyExistInModel = accountsInModel.Except(accountsInDb).ToList();

onlyExistInModel.ForEach(x => {
    _context.Add(new Account {
        AccountId = x.Id,
        AccountName = x.Name,
        AccountRefNumber = x.RefNumber
    });
});

_context.SaveChanges();

Update operation

var existInBoth = accountsInModel.Intersect(accountsInDb).ToList();

existInBoth.ForEach(x => {
    var _account = _context.Accounts.Where(y => y.AccountId == x.AccountId);
    _account.Name = x.Name;
    _account.RefNumber = x.RefNumber;
});

_context.SaveChanges();
 
Leave a comment

Posted by on March 14, 2013 in General

 

Tags: , , ,

Circle of Trust

Idea

Often times, we are afraid to shop online because of fraud. We don’t trust individuals who sell items online. At least to me, this is true, especially with web site like CraigList where there is no specific rules regarding transactions. We don’t trust some individuals online because we can’t verify their identity and whether they have done something fraudulent before.

This idea is to create a system that will verify an individual identity and determine how trust worthy an individual is while allowing users to remain anonymous online.

This can be used in practically all online transactions and devices, be it web application or mobile app.

Benefit

  • Real-time identity verification.
  • Everybody can stay anonymous.
  • Peace of mind when it comes to buying online.

How?

Think of it like BBB, but for individuals person. Everybody will need to verify their information and identify with the system. Verification will require users to send in documents and the system must also verify the authenticity of the documents.

Online accounts can also be provided, such as Facebook’s profile, Twitter’s accounts, Google+ profile, Ebay accounts, etc, as additional information about the users. The system will verify each of the account provided by the users. For every additional information provided, it will increase the trust-worthiness of a user in online worlds.

The system will also allow feedback from other users / parties. The feedback can be positive or negative which will impact how each users reliability in doing online transactions. The feedback, along with users’ identity and online account information, will determine users final score which tells their trust-worthiness.

The system provides API that allows any body to check and see users trust-worthiness’s score by an authorized token that users have created. So, only with the authorized token, can one verify the score and trust-worthiness. In addition, the verification doesn’t reveal any information about the users, it will only reveal how trust-worthy, its score and any information the user wants to reveal. Verifying parties will only need an authorization token. This way, users can remain anonymous.

Will it work?

 
Leave a comment

Posted by on March 5, 2013 in General

 

Tags:

The Complex Type Refers to Entity Type Through the Property

This applies to ASP.NET Web API under MVC 4 and .Net 4.5

Similar to Type Deriving From error, this error message comes from ASP.NET Web API when I implemented using ODataConventionModelBuilder.

the-complex-type-refers-to-entity-type-through-the-property

GetEdmModel() is my ODdataConventionModelBuilder and what causing this is that I didn’t expose EntitySet that my complex type refers to, Account refers to User.

To get around this, expose EntitySet in ODataConventionModelBuilder.

ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();

// Exposed enitites to Odata
modelBuilder.EntitySet<Account>("Accounts");
modelBuilder.EntitySet<User>("Users");

There issue tracked on AspNetWebStack CodePlex

 
Leave a comment

Posted by on March 5, 2013 in General

 

Tags: , ,

 
%d bloggers like this: