This avoids the need to install Visual Studio on the build server.
I have just tried this out now, and can verify that it works:
Before:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
After the install:
[Builds correctly]
This is a far better solution than installing Visual Studio on a build server, obviously.
Get to know all the Windows service related commands by typing “mongod --help“.
C:\MongoDB\bin>mongod --help
Windows Service Control Manager options:
--installinstall mongodb service
--remove remove mongodb service
--reinstall reinstall mongodb service (equivilant of mongod
--remove followed by mongod --install)--serviceName arg windows service name
--serviceDisplayName arg windows service display name
--serviceDescription arg windows service description
--serviceUser arg user name service executes as--servicePassword arg password used to authenticate serviceUser
Two “--install” and “--remove” arguments are what you need.
2. Install as Windows Service
To install as Windows service, issue “mongod --install“, for example :
#> mongod --dbpath "c:\mymongodb" --logpath "c:\mymongodb\logs.txt" --install --serviceName "MongoDB"
all output going to: c:\mymongodb\logs.txt
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.
It means, install a MongoDB, which point to “c:\mymongodb” data directory, log outputs to “c:\mymongodb\logs.txt“, and a Windows service named “MongoDB“.
Figure : MongoDB is installed as Windows Service
3. Uninstall It
To uninstall above installed MongoDB service, issue “mongod --remove“, along with the installed service name.
#> mongod --remove --serviceName "MongoDB"
Deleting service MongoDB.
Service deleted successfully.
Fri Apr 2918:39:06 dbexit:
Fri Apr 2918:39:06 shutdown: going to close listening sockets...
Fri Apr 2918:39:06 shutdown: going to flush diaglog...
Fri Apr 2918:39:06 shutdown: going to close sockets...
Fri Apr 2918:39:06 shutdown: waiting for fs preallocator...
Fri Apr 2918:39:06 shutdown: closing all files...
Fri Apr 2918:39:06 closeAllFiles() finished
Fri Apr 2918:39:06 dbexit: really exiting now
Type type =typeof(MessageProcessor<>).MakeGenericType(key);
That's the best you can do, however without actually knowing what type it is, there's really not much more you can do with it.
EDIT: I should clarify. I changed from var type to Type type. My point is, now you can do something like this:
object obj =Activator.CreateInstance(type);
obj will now be the correct type, but since you don't know what type "key" is at compile time, there's no way to cast it and do anything useful with it.
This is by no means any detailed post on how to use reflection. The other day I had the need to use reflection to call a generic method. So after playing around with reflection for few minutes I figured it out. Here is how the code looks like.
The generic method is pretty simple. I am taking a parameter of type T which makes it a generic method. I simply print that generic parameter value to the console as the method name states.
In the order to call the generic method, I first create an instance of Printing class by calling Activator.CreateInstance passing in type of object I want to instantiate. The reason I am creating an instance of Printing type is because PrintAnyThing generic method is an instance method. If the method would have been static I do not need to create an instance of it. Next from the type, I try to get method info for PrintAnyThing. Notice at this point it is still a generic method and I cannot invoke it directly. I need to convert it to closed method by specifying the value for T which I do by making a call to MakeGenericMethod. Once I have the closed method, I pass in the instance on which this method is to be invoked along with the method arguments that the method requires.
Last week when I was conducting a MVC training with one of my clients, I was asked about some possible ways to implement auto-complete in ASP.NET MVC Views, similar to what we have in Google Search or the AJAX Extender. My solution was to use Query UI. You can get this free library from www.jquery.com and www.jqueryui.com. If you use Visual Studio for your development, you can use the respective Nuget Packages to get the dependencies installed via Nuget.
For this article, the Sql Server Database server is used with ‘Company’ as database and ‘EmployeeInfo’ as the table. The script is as below:
CREATE TABLE [dbo].[EmployeeInfo](
[EmpNo] [int] IDENTITY(1,1) NOT NULL, [EmpName] [varchar](50) NOT NULL, [Salary] [decimal](18, 0) NOT NULL, [DeptName] [varchar](50) NOT NULL, [Designation] [varchar](50) NOT NULL, CONSTRAINT [PK_EmployeeInfo] PRIMARY KEY CLUSTERED ( [EmpNo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO Step 1: Open VS2012 and create a MVC application. Name it as ‘MVC_jQuery_AutoComplete’. In this project, add the model for the above table using Ado.NET EF. After completing the wizard for ADO.NET, the entity will be displayed as below:
Step 2: Build the Project. Now to add a WEB API Controller, right- click on the controller folder and add the new WEB API controller based upon the ADO.NET EF. This will generate Read/Write API Actions as below:
This step will add a new WEB API class with Read and Write methods. These methods perform communication using JSON.
Step 3: In the project, add a new empty EmployeeInfoController. This controller will only have the Index method. We are doing this so that we can add a new Empty Index View.
Step 4: Add a new Index Empty view in the project by right clicking on the Index method of the EmployeeInfoController class. In this View, add the HTML control as below:
Step 6: Refer these files in the Index.cshtml as below:
Step 7: Write the below style in the Index.cshtml, this defines the appearance for the Auto-Complete:
Step 8: Add the following script shown here. This makes an AJAX call to the WEB API (your port may be different), the JSON data is received and then it is converted into an Array. This array is then passed to the source parameter of the autocomplete method defined for the textbox.
Step 9: Run the application and navigate to the EmployeeInfo/Index, you will see the textbox. Add some text into it. If it matches with the data returned from the WEB API call, it will be displayed in the AutoComplete area as below:
Conclusion
Ideally we should restrict the number of rows returned to Top 10 or 20 results for performance considerations. It’s pretty easy to use the jQuery UI plugin and add AutoComplete behavior to a text box. Overall jQuery UI is a powerful tool kit to have in one’s web development portfolio.
This article will demonstrate, how to make and validate cascading dropdown list with in Asp.Net MVC4 Razor application using custom server-side and client-side validation. In this article, you will learn how set selected value with in Dropdown list in MVC Razor.
How to do it..
Follow the following steps for making and validating cascading dropdown list in mvc razor.
Step 1 : Design Model
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.ComponentModel.DataAnnotations;
usingSystem.Web.Mvc;
usingSystem.Text.RegularExpressions;
namespaceMvc4_Validate_CascadingDropdown.Models
{
publicclassRegistrationModel
{
[Required(ErrorMessage="Please Enter Email Address")]
[Display(Name="UserName (Email Address)")]
[RegularExpression(".+@.+\\..+",ErrorMessage="Please Enter Correct Email Address")]
It's time to run the project and let's see the result as shown below :
What do you think?
I hope you will enjoy the tricks while programming with MVC Razor. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.