Alfred khairy fahmey

Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean lacinia bibendum nulla sed consectetur.

top

Happy Anniversary

Liberty Fox Technologies is celebrating it’s third anniversary of charter. It wasn’t long ago that this company was just a dream, but thanks to the support received by so many friends, family and clients, we are a success! We can’t thank all of you enough for your continued support and business as we grow in this ever demanding technology industry!

top

Small Businesses

Own a small business or new start-up company? Liberty Fox can be your answer to your online technology needs. Whether you’re looking to build a small website to establish an online presence or looking to launch an e-commerce site to drive your business, we can help! Our development staff and its diverse experience can cater to even the smallest needs to give you that edge you’re looking for!

top

Mobile Applications

Mobile development is booming, and with that in mind, you need a technology partner to help you cope with increasing demands. Our senior architects have a diverse understanding of the plethora of platforms and devices on the market.

top

Enterprise Architecture

Have a project that seems like an insurmountable effort? Our senior staff has years of experience developing enterprise applications for a verbose portfolio of corporations and workflows. Ranging from internal intranet applications and portals to full heavy-weight web application platforms, Liberty Fox has the resources to achieve your development goals in an expert and timely fashion; saving you irreplaceable time and money.

top

New Website

Well everyone, Liberty Fox finally bit-the-bullet and sprung for a new website. This version 2.0 is a far cry from the original site that was just tossed up here back in the day. Thanks to continued successful business and support, we are growing and expanding which means we were well overdue for an upgrade. Feel free to peruse the new content and get a feel for our new digs!

top

Entity Framework – IQueryable vs IEnumerable

Working on an architecture framework for a client of Liberty Fox, I discovered a little known caveat of the Entity Framework. If you implement the repository pattern (or any data access methodology), then I am sure you’ve created a method to retrieve data from the data source based on some business rules.

For Example:  public IEnumerable<User> GetActiveUsers()

This method, as you may have guessed, returns an enumerable of the active users in the system. Now, because of the simplicity of LINQ, you would think you could do something like this in your presentation layer:

var users = repository.GetActiveUsers().Skip(10).Take(10)

This snippit of code would work just fine. You would end up retrieving users 11 through 20 in the result-set of active users. Now, being that LINQ is intelligently designed, you would think that it would tack-on the Skip() and Take() to the underlying SQL query and limit the result-set returned from the database, but you run the SQL profiler and you see:

SELECT UserId, UserName, LastActiveDate FROM Users

Oh No! Where is the “TOP(10)“? Where is the “WHERE rowcount() > 10“? I know LINQ is capable of this! I have seen it work before in my unit tests and in others’ example code. What’s going on?

Well, I spent an unnecessary amount of time figuring this out so that you don’t have to… As efficient developers, we’re taught to program against interfaces, and specifically, the least responsible interface to get the job done. To further clarify, if I’m working with a List of users, I may pass it to a method as an IEnumerable if I only need to foreach over it, or if I need to run a for loop with it, I may pass it as an ICollection. So therefore, its not uncommon to want to return the result of my repository method as an IEnumerable. The problem is that when you downcast a Linq-to-SQL query to an IEnumerable, it immediately becomes a Linq-to-Objects query and all further filtering is done in memory. Yikes! So if you had a method that returns an IEnumerable of all the users in the system and you use Linq to tack-on a filter, you’d expect that to be tacked-on as a WHERE clause in the underlying SQL query, but it won’t! It will load the entire table into memory and then do the filtering. This is extremely inefficient!

So, after my long rant of how I spent hours figuring this out, how can you avoid the same fate? Pass the result of your repository method as an IQueryable<User>.

For Example: public IQueryable<User> GetActiveUsers()

In your presentation layer, you will still be able to work with it similar to how you would have if it was an IEnumerable, but now any further limiters WILL be tacked-on to the SQL query, maintaining efficiency. I hope this saves somebody the time I lost. Cheers! 🙂

top

Encryption Error “Length of the data to decrypt is invalid”

So, last week we were beating our heads against a wall trying to figure out why we could not decrypt encrypted XML files supplied by our client along with the decryption algorithm.

We tried to rewrite the decryption method, researched the Rijndael Cryptography, tried other test files. We even encrypted our own files and then decrypted them with ease… so the decryption works. But, no matter what we did, we got the following error trying to decrypt the client supplied files:

System.Security.Cryptography.CryptographicException was unhandled
Length of the data to decrypt is invalid.

at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Decryptor.Program.Decode(Byte[] data) in C:\Projects\Decryptor\Program.cs:line 85
at Decryptor.Program.Main(String[] args) in C:\Projects\Decryptor\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Unfortunately, this error is not very descriptive and there are tons of blogs on Google containing developers with the same error but a totally different problem… Eventually, after bumping heads back and fourth, my client and I finally discovered the issue.

When he sent the files to me, he FTP’d them to his desktop, then emailed them to me. I wanted to eliminate all the possibilities of error and asked him to use his webmail to send me the files directly from the server and Voila! It worked! After further digging, we realized it was the FTP process that he hadn’t previously told me about. Since the files still had an “xml” extension, the FTP client transferred them in ASCII mode. This caused the encrypted data to get corrupted and therefore it could not be decrypted. Encrypted files MUST be transmitted in Binary mode over FTP. There are two ways to assure this: set your FTP client from “Auto” to “Binary” under its transfer options -OR- give the encrypted xml file a different extension like “exml” or “encxml”. Most FTP clients will fall back to binary if they don’t recognize the file extension, but your best bet is to always force Binary.

I hope this saves somebody the extra time and research it cost us! 🙂

top

Using Reflection with Dependency Injection

So recently we were working on a large enterprise project that involved Entity Framework 5, Repositories and Dependency Injection. We were working with a previously designed database, so every time we wanted to bring an entity into the project, we needed to create the entity, create it’s code-first map and add the map and the collection to the context. To top that off, we then had to go into our Ninject bindings and add a binding for the repositories.

I noticed that when my developers were adding entities, they continually forgot to add the repository bindings to Ninject (and I too forgot on occasion). I decided there had to be a better way and I decided to dig deeper into reflection. Finally, after a few hours of tinkering, this is what I came up with:

All of my domain objects implement a simple interface called IEntity. This interface is used to designate any c# object that represents an EF5 entity.

My Ninject bindings bind a GenericRepository<> to an IRepository<>. I recognize that some people will use a different repository for each entity, but in our Enterprise, the Generic repository has been well-written over time and is able to handle all of the repository needs with very rare occurrences in which it must be extended.

Finally, using some reflection and Linq, I was able to come up with this method in my NinjectModule to handle my bindings:

protected void ReflectRepositoryBindings()
{
    Logger.Info("Reflecting Repository Assemblies");
    var iRepo = typeof(IRepository<>);
    var genRepo = typeof(GenericRepository<>);

    var types = from t in Assembly.GetAssembly(typeof(IEntity)).GetTypes()
                where t.IsClass && !t.IsAbstract
                    && t.GetInterfaces().Contains(typeof(IEntity))
                select t;

    foreach (var type in types)
    {
        var iTypeRepo = iRepo.MakeGenericType(type);
        var genTypeRepo = genRepo.MakeGenericType(type);
        //Bind the interface type to the generic repository type
        Bind(iTypeRepo).To(genTypeRepo);
        Logger.Debug("Bound GenericRepository<" + type.Name 
                         + "> to IRepository<" + type.Name + ">");
    }
}

OK, so to explain whats going on here, I’m getting the type of an empty IRepository<> and GenericRepository<>. Then I’m using Assembly reflection to find the assembly which contains the IEntity interface and then fetch all of the types from that assembly that are non-abstract classes that implement that interface. Finally, I iterate over all the types that match that criteria and, once again using reflection, am able to attach the Generic to the IRepository and GenericRepository types to create a complete type. Once I have each of them, I am able to use the Ninject Bind() and To() methods to complete the bindings.

I then just call this method in my Ninject Module’s Load() method. If any of these default bindings need to use an extended repository, then after the reflection bindings, I just call Ninject’s Rebind() method to do so. Volia! Now, I can just create entities and mappings and the DI binding is handled for me in runtime. 🙂 Cheers!

top

We’re Moving!

Hey Everyone, we have some exciting news over here at Liberty Fox! Today we just singed our new commercial lease. Liberty Fox will have its own brick-and-mortar address now instead of shared space! If you ever want to come visit, you’re welcome at any time; we make tenancy on Monday, July 1st! Our new place of business will be: 931 Huntingdon Pike, Huntingdon Valley PA 19006. Looking forward to seeing some visitors!!

top
Page 1 of 8 12345...»