0 Comments
Follow this tutorial to simply setup and run your first MongoDB as service on window 8. Also you can find full details on mongoDB official website .

  • create custom mongod.conf file
Here is an example:
#where data files will reside
dbpath=C:\Program Files\MongoDB\Sitecore\data

#where the log file will be stored
logpath=C:\Program Files\MongoDB\Sitecore\log\mongo-server.log

#how verbose the server will be logging
verbose=vvvvv
  • run install command
mongd -f "[your mongod.conf path]" --install
This command is used for installing the mongodb as a service on your local machine with the settings written in the mongod.conf
  • run net command
net start mongodb
After this command, you will see a message as below
"The MongoDB service was started successfully"

NOTE: to create a MongoDB as server, you will need to run the command as Administrator, otherwise you may get an deny error.

0 Comments
Nowadays, WebAPI is widely used for building a RESTful service. Given the fact that Web API can automatically serialize model to JSON format, so Json becomes a very common/popular argument for WebAPI.

The question is how to effectively validate the Json object before processing your business logic. Normally, you might do something like this

if (string.isNullEmpty(object.a)){
//your logical here
}

Thinking if you have 10 properties, you will have to check 10 times and the code will be pretty nasty. So the solution below is attempted to provide an elegant way for validating the JSON object.

Solution
Implement custom ValidationAttributeto the property. Look at the example below, NotNullableAttribute is a customValidationAttribute which will evaluate the value. If it's null, it will throw a NoNullAllowedException.

For example:

[NotNullable(ErrorMessage = "product field can not be null")]
public string Product { get; set; }

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class NotNullableAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value ==null){
//place your logical here
throw new NoNullAllowedException(ErrorMessage);
}

return true;
}
}

If you don't want to write your own code, here is theNuGet package, or you can run the following command in the Package Manager Console.

PM> Install-Package ObjectPropertyValidator


Usage of the NuGet Package

1. Step 1
Create your own class
public class Customer
{
[NotNullable]
public string Name { get; set; }

[NotEmptyWithValidData( Pattern= @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$")]
public string Email { get; set; }

[NotEmptyWithValidData(MaxLength =10, MinLength = 10)]
public string Phone { get; set; }
}

2.Step 2
Create your WebAPI.

[HttpPost]
public HttpResponseMessage Post(Customer customer)
{
// the argument customerwill be validated before reach your code below.
}
Conclusion
As you can see above, with the solution less code is required for data validation, and it's completely reusable.

0 Comments
After upgrading to Xcode 6.1, and iOS 8, I experienced network connecting issue in simulator. It worked for https requests, however, it returned an 1005 error for all http requests. I googled and tried all the suggestions that people commented on the internet[1] like "Reset simulator content", "remove ~/Library/Developer/Xcode/DeriveData", "re-install Xcode" etc. None of them was actually working for me.

For isolating the issue, I tried to run the same code on other mac and it works. Based on the most people's comments, it seems that it is due to the Xcode simulator doesn't support the network configuration somehow. So I decided to reset my Wi-Fi settings by removing extra preferred networks, and just keeping the one I normally use, and that did the magic fix.



Reference
[1] http://stackoverflow.com/questions/25372318/error-domain-nsurlerrordomain-code-1005-the-network-connection-was-lost

0 Comments
Today, I spent a few hours on researching about how to implement custom index field with Examine in Umbraco7. There are plenty of resources talking about IndexUserField, IndexAttributeField but none of them is actually using custom field.

So I looked into the Umbraco API, and worked it out. If you knew Examine, you can ignore this part, and jump to the solution straightaway. Otherwise, I want to give you a little intro to what is Examine.

What is Examine?

Examine wraps the Lucene.Net API, which makes it easy for Umbraco developers to build index and search data [1]. Lucene open source search engine enable us to build a search driven and a high performance website.

What is custom index field?

Custom index field, also called "computed filed", is normally not existing in your database, but frequently used in program.

How to implement?


There might be other ways to implement "custom index field", but here I am going to introduce "UmbracoContentIndexer". UmbracoContentIndexer is an indexer for creating index document by getting data from Umbraco nodes. All you need to do is to add "custom index field" by overriding "GetDataToIndex" method.

Reference
[1] http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine

0 Comments
Google Chrome removed showModalDialog API since version 37 or later

What does it mean?


The publish function of Sitecore which version is prior to 7.1 is no longer working. This is because that Google Chrome removed showModalDialog API from its version 37 or later. For information can be found here.

What's the Solutions?


Reference

[1] https://kb.sitecore.net/articles/581527
[2] http://blog.chromium.org/2014/07/disabling-showmodaldialog.html