Thursday, 31 January 2013

.Net Resource file - multiple designers.cs files

Open the .csproj file
find the "LastGenOutput" tag for each resource file and make sure it is <resource file name>.Designer.cs


MVC - Sending Email using Exchange Server

Add the following in the Web.config file:

<system.net>
  <mailSettings>

    <smtp from="info@mycompany.com">
<network enableSsl="false" port="25" host="mail.mycompany.com" defaultCredentials="true" />
    </smtp>


  </mailSettings>


</system.net>

Without setting "defaultCredentials" to true, you can only send email in the same domain.  When you send email outside the domain, you will receive "Mailbox unavailable. The server response was: 5.7.1 Unable to relay for whoever@notmycompany.com" error.

Monday, 28 January 2013

Tough person around you...

You can’t change a person, but you can change the way you see him/her.

You may not change the person, but it’ll change your attitude toward him/her.  Who knows? Maybe he/she’ll start to change when you start to see him/her differently!

Friday, 25 January 2013

Bible

Yes, any Bible verse can be misused, but that doesn’t make it useless!

MVC Validation - Integer types

All the fields with Integer types will be required by default unless we declare it as <Nullable>.

Thursday, 3 January 2013

C# HashSet

A HashSet holds a set of objects, in a way that it allows you to easily and quickly determine whether an object is already in the set or not.

C# HashSet class preserves the order of the elements.

The only catch of HashSet is that there is no access by indices.

Saturday, 22 December 2012

Add Tag with folder and file names

TagScanner

Go to tab "TAG Processor" and select "Generate TAG from filename" from the Action group (2nd icon) on the tool bar

e.g. \%album%\%disc% <%title%->\%track%-%title%
  • You can use the file and folder names
  • You can combine tag fields like I put %title% twice here, TagScanner will just concatenate them together
  • You can add text to the field (<%tag filed%> like what I have done <%title-%> to add a "-" after the first part of the %title so that my title tag will be part of the folder name and a "-" and part of the file name
  • You can preview the result before you generate the tags



Mp3tag

After select the folder(s) / file(s), select the file(s), right click and select Convert, Filename -Tag

but it is very slow...

Friday, 21 December 2012

Ubiquitous Language

A core principle of domain-driven design is to use a language based on the model.

Wednesday, 19 December 2012

Create a DDD Solution


Starting a New Solution

  • Create a Blank Solution
  • Add a Core Class Library Project
  • Add an Infrastructure Class Library Project
  • Add your UI project (Console, WinForms, WPF, ASP.NET MVC)
  • Add references to Core from Infrastructure and UI 
  • Add a reference to Infrastructure from UI

  • Add a Controller, View
  • Add an Interface <IMyInterface> (new folder "Interfaces" in Core) with a method
  • Implement the Interface in Infrastructure (in a class <MyInterface>) with the method
  • In the controller:
  • Add the private field of the <IMyInterface>
  • Add the constructor with <IMyInterface> as parameter
  • Add the constrcutor without parameter to add the parameter
  • In the control, call the method and show the result to the view



Onion Architecture Principles

All code depends on layers closer to center (Domain Model)
Inner layers define interfaces; outer layers implement these interfaces
Layered behavior around the Domain Model
Infrastructure and UI concerns pushed to edge
  • Depend on Application Core, not vice versa



Dependency Inversion Principle (DIP)

High-level modules should not depend on low-level modules.  Both should depend on abstractions.
Abstractions should not depend on details.  Details should depend on abstractions.

Domain-Centric Design / Domain Driven Design

The problem-space of your application is its domain.  If you are going to write a banking software system, you need to have a good understanding of what banking is all about, you must understand the domain of banking.

A domain is something of this world and we need to create an abstraction (a blueprint) of the domain to transform the domain into software constructs.  The abstraction is a model, our internal representation of the target domain.

The model is the common ground, the place where the software meets the domain.

The objects you design to model the domain are domain objects (model objects / model).
  • Encapsulate application business logic and rules
  • Maintain any state required to do so
  • Do not depend on external infrastructure concers


Page Inspector in ASP.NET MVC

Page Inspector in Visual Studio 2012 is a web development tool with an integrated browser and browser tools. Select any element in the integrated browser, and the Inspect feature instantly highlights the element's source and CSS. You can browse any MVC view, quickly find the sources of rendered markup, and use browser tools right within the Visual Studio environment.

It is something like the FireBug add-on in FireFox.

Friday, 7 December 2012

Installing SQL Server 2012 Express

Problem:
Cannot find the vc_red.msi file in <temp folder>\redist\visualstudioshell\VC10SP1
  • The file is in the x86 folder insider VC10SP1.  But even I copied the content in x86 to VX10SP1, it is still not work.
  • Try to manually uncompressed the package
  • Run as administrator
Solution:

  • Make sure to download the right version of the setup file.  Download 64-bit version for 64-bit OS.


Wednesday, 5 December 2012

C# "??" Operator

The "??" operator is called the null-coalescing operator and is used to define a default value for a null able value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.

objNullable = objNullable ?? new objMyObject();

Tuesday, 20 November 2012

Share Mouse and Keyboard with computers (software)

The following software are working with me between my Windows 7 and OS X:
  • Synergy http://synergy-foss.org/
  • ShareMouse http://www.share-mouse.com/



Wednesday, 7 November 2012

Crop / Rotate images in Batch using IrfanView

After scanning a book, I need to crop (all images, the same way) and rotate (half of the images) the images.

Open IrfanView with one of the image, try to crop it correctly, save it and get the width and height (and the X and Y offsets, if needed) of the final image.

In IrfanView
  • File, Batch Conversion/Rename...
  • Select "Batch conversion" or "Batch conversion - Rename result files" accordingly
  • Check "Use advanced options (for bulk resize...)
  • Click "Advanced" button
  • A popup window (Set for all images:) appears
Cropping the images
It depends on how you scanned, you should crop all images first.  In my case, all the image can be cropped the same way, therefore, if I rotate the images first, I may need to crop the rotated images differently
  • Uncheck any options that are not applicable
  • Check "CROP"
  • Enter the Width and Height (from the above)
  • Enter the X-pos and Y-pos, if necessary
  • Click "OK"
continue with "Common Steps"
Rotating the images
  • Uncheck "CROP" and any other options that are not applicable
  • Check "Fine rotation"
  • Enter "180" (i.e. to rotate left/right twice)
  • Click "OK"
continue with "Common Steps"
Common Steps
  • Select the files from the top right windows, click the "Add" or "Add all" button.  Be careful if the order of the images is important (if you rename the file), the last selected file is always on the top.  You will need to change it in the "File name" text box or move it in the "Input files" window
  • Change the "Name pattern" (if you want to rename the file and in a specific way)
  • Enter the "Output directory for result files"
  • Click "Start Batch"



Thursday, 18 October 2012

Turn Off Ad Tracking on iOS 6 (iPhone, iPad)

Apple sets IFA / IDFA (identifier for advertisers) on by default:
  • Go to Settings, General, About, Advertising, Limit Ad Tracking : ON





Friday, 7 September 2012

PayPal - Preferred Payment Method

There are times when you cannot change the account when making payment by PayPal.  Payments will be made with your default payment method unless you select a preferred payment method.

After making the payment, login to PayPal, click on "Profile" (ignore the drop down menu), click "My money" on the left, click "update" in the "My preapproved payments" section.

You will see the transaction there and click on the "Merchant" link of the transaction, click "Change" of the "Backup Funding Source" in "Funding Source" to select your preferred payment method.

Tuesday, 4 September 2012

Shallow Copy and Deep Copy


Shallow copy versus deep copy is only meaningful with "reference types" and not with "value types".

Shallow Copy
http://0.tqn.com/d/visualbasic/1/0/4/a/dsgnshlwdeepcopy-1.gif
Deep Copy
http://0.tqn.com/d/visualbasic/1/0/6/a/dsgnshlwdeepcopy-Dup.gif