Tuesday, April 28, 2015

How good is your C#?

http://volatileread.com/Wiki?id=1073


Friday, April 24, 2015

How to solve problem "Unable to load the specified metadata resource." in Entity Framework?


Replace EDMX connection metadata part to
connectionString="metadata=res://*/;

Wednesday, April 22, 2015

How to create a SFTP server on the fly for unit test?\



Usage:
NuaneSFTPServer server = new NuaneSFTPServer("username", "Passw0rd!", SftpRootFolder, 990);
server.Start();

server.Stop();



    public class NuaneSFTPServer
    {
        volatile SftpServer sFTPserver = null;
        public string UserName;
        public string Password;
        public string FtpPath;
        public int PortNumber;
        private static Thread workerThread;

        public NuaneSFTPServer(string userName, string password, string ftpPath, int portNumber)
        {
            UserName = userName;
            Password = password;
            FtpPath = ftpPath;
            PortNumber = portNumber;
            SshKey rsaKey = SshKey.Generate(SshKeyAlgorithm.RSA, 1024);
            SshKey dssKey = SshKey.Generate(SshKeyAlgorithm.DSS, 1024);

            // add keys, bindings and users
            sFTPserver = new SftpServer();
            sFTPserver.Log = Console.Out;
            sFTPserver.Keys.Add(rsaKey);
            sFTPserver.Keys.Add(dssKey);
            sFTPserver.Bindings.Add(IPAddress.Any, portNumber);
            sFTPserver.Users.Add(new SshUser(userName, password, ftpPath));
        }
        public void Start()
        {
            workerThread = new Thread(sFTPserver.Start);
            workerThread.Start();
            while (!workerThread.IsAlive) ;
        }
        public void Stop()
        {
            sFTPserver.Stop();
            workerThread.Join();
        }
    }


How to fix The thread xxx has exited with code 259 (0x103)?

When try to wait for a thread to be alive, but not call thread Start method, will get a lot of errors like this::The thread xxx has exited with code 259 (0x103)

            workerThread = new Thread(StartMethod);
//            workerThread.Start();
            while (!workerThread.IsAlive) ;

:)

Tuesday, April 14, 2015

How to create a sub domain on the fly in IIS Server / ASP.NET project

How to create a sub domain on the fly in IIS Server / ASP.NET project

Step 1: Add following DNS records into your donmain:
example.com  IN A XXX.XXX.XXX.XXX
www.example.com  IN A XXX.XXX.XXX.XXX
default.example.com IN A XXX.XXX.XXX.XXX

# Wild card DNS record
*.example.com  IN CNAME default.example.com

Step 2: Create your website in IIS Server for default.example.com

Step 3: Get your sub domain name in ASP.NET MVC project
        var uri = Request.Url;
        var fullDomain = uri.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped);
        var domainParts = fullDomain
            .Split('.') // ["test", "example", "com"]
            .Take(1);    // ["com", "example"]
        var subdomain = String.Join(".", domainParts);

DTO vs Value Object vs POCO

http://enterprisecraftsmanship.com/2015/04/13/dto-vs-value-object-vs-poco/





Monday, April 13, 2015

Architectures Comparison Summary



For Event-Driven architecture. there are two problems:
Testability and Development

But with CQRS/Event Sourcing, it is very easy to create BDD unit test.

Source:
http://www.oreilly.com/programming/free/files/software-architecture-patterns.pdf

Friday, April 10, 2015

Complexity is the enemy

http://neugierig.org/software/blog/2011/04/complexity.html

Excerpt:

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."




Thursday, April 9, 2015