Quantcast
Channel: chsakell's Blog
Viewing all articles
Browse latest Browse all 42

BrowseDotNET: Manage your .NET Solutions and code snippets

$
0
0

BrowseDotNET is an open source ASP.NET MVC Web Application I created, that can help you manage your computer’s .NET solutions and code samples (programming language indepented) in one place. What does it solve? It’s common sense for developers to have dosens or hundrends of solutions projects in their personal computers with each of them providing a single solution to a specific problem. The thing is, that when the time comes to solve the same problem it’s quite difficult to find the respective solution among dosens and hence you are forced to seek over and over again the same solution on the internet. More over, you might have noticed that there are code snippets which you often use in your applications, but still you always have to get them from the internet.

BrowseDotNET features

BrowseDotNET came to solve these two important problems by providing three main features:
browsedotnet-01
This post’s objective is to show how to host and use BrowseDotNET in your personal computer. First let’s see the technologies, frameworks and techniques used for this application.

  1. ASP.NET MVC 5
  2. Entity Framework Code First development
  3. Code First Migrations
  4. Generic Repository pattern
  5. Dependency Injection using Autofac framework
  6. ASP.NET Identity
  7. Automapper
  8. FluentValidation API

Installation

Download BrowseDotNET source code from my Github account. You will find link at the bottom of this post. Build the application to restore packages. Rebuild. Open BrowseDotNET.Data and BrowseDotNET.Web and change the connection strings in their configuration files to reflect your development environment. Next, Open Package Manager Console and enter the following command while having BrowseDotNET.Data as the default project.

update-database -verbose

browsedotnet-02
That’s all you need to start BrowseDotNET. Fire the application and you will reach the starting page.
browsedotnet-03
First thing you need to do is create an account. You won’t be able to register solutions and code snippets unless you are an authorized user.
browsedotnet-04

Register single .NET Solution

From the top menu, select Register/Solution and fill all the relative fields. You will be asked to give information for solution’s to be registered file path, name and description and of course search term keys. On the right side, you will always have some hints to help you register either a solution or a code snippet.
browsedotnet-05

Open, Edit or Remove a registered solution

By the time you register a .NET solution, you will be able to open it from BrowseDotNET. From the top menu, select Open/Solution and view all your registered solutions. Of course you can filter your solution by typing into the table’s textbox.
browsedotnet-06

Multiple .NET Solutions registration (scan)

We all have more than one solution in our pc so I decided to create a scanning process to automate registration for you. All you have to do is enter a root directory and then check it’s subdirectories you want to be scanned for .net solutions. BrowseDotNET will search in these folders for .sln files and register them automatically. It will use solution’s file name as solution name and description but you can always edit them later. To start, select from the top menu Register/Scan Solutions and enter a valid root directory path.
browsedotnet-07
If the directory path is valid, you will be redirected to check child folders you want to be scanned.
browsedotnet-08
BrowseDotNET will do it’s magic and when finished it will show you registered solutions page.
browsedotnet-09

Code snippet registration

Select Register/Code Snippet from the top menu and fill the relative code snippet’s information. There are two tabs, one for snippet’s information and another to paste the code. You can paste code of any language you wish. One thing I want to point is the field Group. Use the same group name to group many code snippets together. For example you can register a C# code snippet and a jQuery code snippet under the same group. Later, you will be able to view them together by selecting this group. This is why I have used an autocomplete textbox for this field. It will help you find group names you have used before.
browsedotnet-10
As soon as you register the snippet you will be able to view it whenever you want. View all of your snippets by selecting Open/Snippets from the top menu.
browsedotnet-11
On the left menu you can select settings and set the available Solution Types for your solutions and the available programming languages for you Code Snippets.
browsedotnet-12
Type key terms on the top menu and search .NET Solutions or Code snippets by keys. You will be able to open directly the matched solutions and view the source of your snippets. You can type multiple key terms by comma separating them.
browsedotnet-13
Keys are really important to the search engine so try to be carefull when registering solutions or code snippets. For example if you register a .NET solution with a key mvc and use the same key for registering a code snippet, searching with that term will fetch you both results. Instead, if you use the key term mvc snippet for the snippet registration, BrowseDotNET would fetch again both results but the inner search engine will use two different key records from the database while only one record used on the first case.
browsedotnet-17
As soon as you start registering and opening .NET solutions from BrowseDotNET you will find the most recently used solutions on the first page.
browsedotnet-14

Hosting

You could host BrowseDotNET in your local IIS but unfortunately you cannot start a GUI application from IIS (unless you make serious configurations). What you can do is create a simple .bat file with the following command.

"c:\Program Files\IIS Express\iisexpress.exe" /path:"C:\Path_To_BrowseDotNET\BrowseDotNet.Web" /port:20185

The above command will host BrowseDotNET in iisexpress without running Visual Studio.

Source Code

There is a lot of source code to study in BrowseDotNET and I totally recommend you read ASP.NET MVC Solution Architecture – Best Practices and Web API powerful Custom Model Validation with FluentValidation in case you aren’t familiar with those concepts. FluentValidation is used particularly for validating ViewModels. Let’s see the example for validating the FilePath in SolutiongViewModel, the model which is posted back to server when the user registers a solution.

public class SolutionViewModel : IValidatableObject
    {
        public int ID { get; set; }

        [MaxLength(50)]
        public string Author { get; set; }

        [Required]
        [MaxLength(100)]
        [Display(Name = "Application")]
        public string Name { get; set; }

        [Required]
        [MaxLength(250)]
        [Display(Name = "Full Path (.sln)")]
        [RegularExpression(@"^(?:[\w]\:|\\)(\\[a-zA-Z_\-\s0-9\.]+)+\.(sln)$", ErrorMessage = "Invalid file path format.")]
        public string FilePath { get; set; }

        [Required]
        [MaxLength(300)]
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        [MaxLength(200)]
        [DataType(DataType.Url)]
        public string Website { get; set; }

        [Required]
        [Display(Name = "Type")]
        public int SolutionTypeID { get; set; }

        [Display(Name = "Type")]
        public string SolutionTypeType { get; set; }

        [Required]
        [MaxLength(200)]
        [DataType(DataType.MultilineText)]
        public string Keys { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var validator = new SolutionViewModelValidator();
            var result = validator.Validate(this);
            return result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName }));
        }
    }

And it’s Validator..

public class SolutionViewModelValidator : AbstractValidator<SolutionViewModel>
    {
        public SolutionViewModelValidator()
        {
            RuleFor(s => s.FilePath)
                .Must(IsValidPath)
                .WithMessage("Enter solution's full file path.");
        }

        private bool IsValidPath(string filePath)
        {
            bool _isValidSolutionPath = new bool();

            try
            {

                if (File.Exists(filePath) && Path.GetExtension(filePath).EndsWith(".sln"))
                    _isValidSolutionPath = true;
            }
            catch
            {
                _isValidSolutionPath = false;
            }

            return _isValidSolutionPath;
        }
    }

Data annotations used for SolutionViewModel in conjuction with jQuery Validation will prevent the user post a string that doesn’t represent a file path ending in .sln.
browsedotnet-15
But even if he does enter a file path that ends with .sln, the ModelState.IsValid will return false if the path posted doesn’t exist in user’s pc. That’s the magic of FluentValidation.
browsedotnet-16

Conclusion

BrowseDotNET is certainly a powerfull tool for .NET developers. The more solutions you have on your pc and the more code snippets you want to easily access, the most you will benefit from BrowseDotNET. Download the source code from here. I’ m certain that you ‘ll enjoy working with it. Happy coding!

Update

Some folks asked me to add a Run as admin button cause they needed to open Visual Studio solutions with administrator rights, so I added that to.
browsedotnet-18



Viewing all articles
Browse latest Browse all 42

Trending Articles