Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label DOS. Show all posts
Showing posts with label DOS. Show all posts

Tuesday, October 25, 2016

ROBOCOPY : Auto Push static files to hosting environments



Developers are working on their development machine during website development phase. Once they are done with their file changes, they are going to publish those changes. 
They can do publishing at any time without any efforts. But if solutions have lots of projects then this process take times. 

Can we avoid and minimize this time and automate this process at least for static files like 
images, HTML, views, aspx, css, js etc.?

Answer is YES. We can automate this process to sync development static files folders with Published folders.

Even we can push development change static files to QA and staging environment folders which are across the network.

Sync
Sync


How to push the changes?

I am using a batch file with ROBOCOPY command in my development machine for this.

ROBOCOPY stand for robust file copy and this command allows you to copy files, directories, and even drives from one location to another.

Robocopy monitor the source folder and if any change happened in that folder like new file created, file deleted, updated etc. then Robocopy takes all the files and replace those files on destination folder.

Syntax : ROBOCOPY source destination [options]

Create a batch file in solution root folder and put below script 

@ECHO OFF

REM this batch file uses robocopy to monitor certain folders in the web projects for changes
REM and copies the changes to the web directory to save time when editing non compiled
REM files such as javascript CSS and cshtml

SET SITEROOT=C:\inetpub\wwwroot\SitecoreLessons\Website
SET SLNROOT=%~dp0
SET OPTS=/MIR /MON:1 /MOT:1 /NJS /NDL /NP /NS /NC

START ROBOCOPY "%SLNROOT%\SitecoreLessons\Assets" "%SITEROOT%\Assets" %OPTS%

REM You can put multiple Robocopy command here like

REM START ROBOCOPY "%SLNROOT%\SitecoreLessons\Views" "%SITEROOT%\Views" %OPTS%


@EXIT

Here is the description of this batch file for those who don’t have any knowledge of batch files

ECHO -> Used to print on output device
REM -> Used to write comment in batch file
SET -> Used for declaring the variable like SITEROOT variable is used to store my destination folder path.
%~dp0 -> Current directory path from where this batch file is running

I have defined “OPTS” variable which stores ROBOCOPY command options


Options
Description
MIR
MIRror a directory tree
MON:1
MONitor source. Run again when more than n changes seen.
MOT:1
MOnitor source. Run again in m minutes Time, if changed.
NJS
No Job Summary.
NDL
No Directory List - don't log directory names.
NP
No Progress - don't display percentage copied.
NS
No Size - don't log file sizes.
NC
No Class - don't log file classes.



You can get more option from http://www.computerhope.com/robocopy.htm

Double click on this batch file to start monitor our source “Assets” folder as

Batch File
Batch File


I have added “Assets\Images” folder in my VS projects and paste some image files in this folder. 

Note: - I have not build or publish my VS solution till now. 

But if I wait for 1 min. I got new all image files in my “C:\inetpub\wwwroot\SitecoreLessons\Website\Assets\Images” folder automatically.

Sync Images
Sync Images


Wowww. This is cool. Now I can write more Robocopy command in same batch file for copying Views, ASPX, HTML files etc.

I hope this pointer helps you to improve your productivity in your development environment.

Please leave your comments and share this trick with other developers.

Saturday, February 27, 2016

How to do database documentation freely



I am working on project where client asked for the documentation.

Developers hate documentation, especially when they have to create it :)

It’s fine if the documentation is about project, but what if client asked about database documentation?

My mind started to think, is there any way to create this documentation automatically or with least efforts?

I found three ways which are great to create database documentation.

1.    Database Diagrams

It provides database schema with relationships and tables-columns details in SQL Server itself as shown below


2.    DB>doc
It’s a free command line tool which can be download from https://sqldbdoc.codeplex.com/ .

It provides option to generate output report in HTML, wikiplex or XML format.

Its syntax is sqldbdoc connection fileName [/y] [/f:value] [/debug]

Parameter details are
·         connection -  connection string of database
·         filename - output file name
·         [/y] - overwrite output file
·         [/f:value] - output format: html, wikiplex, xml (autodetected when omitted)
·         [/debug] - debug mode (show detailed error messages)

How to use this tool?
1.    Download sqldbdoc.exe from https://sqldbdoc.codeplex.com/ and keep it in some folder, for example, D:\Share

2.    Type cmd in RUN window which open command prompt 

3.    Change directory to D:\Share and type below command with SQL server connection string and output file name
D:\Share>sqldbdoc.exe "Data Source=.\SqlExpress;user id=sa;password=test@123;DATABASE= Sitecore_WebForms" Report.htm
4.       You should get below output which indicate successful report generation
Altairis DB>doc version 1.0.0.0
Copyright (c) Altairis, 2011 | www.altairis.cz | SqlDbDoc.codeplex.com
Autodetecting output format...
Output format: html
5.    Open “Report.htm” from current directory i.e. D:\Share. You should get below nicely formatted report as

 
  
1.    SQL Server Compact & SQLite Toolbox

You can download and install this free Visual Studio addon SqlCeToolbox.4.5.0.1.vsix from https://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1/

How to use it?

·         Open Visual Studio and click on Tools -> SQL Server Compact/SQLite Toolbox menu item as


·         Connect to any SQL server database which need to be documented.
Once connected, you can create database graph of the tables by selecting option “Create SQL Server Database Graph (DGML)” as

 

·         This tool generate DGML file which show all selected tables with their columns and relationships. You can save this screen as image by clicking on Copy Image option as shown in the same screen.

 

·         You can also save the SQL connection database as SQL Server Compact file format which save this database in .sdf file format.
In this format you can do the database documentation in HTML format by selecting below option


You should get below HTML report


This HTML report is same as DB>Doc tool report. Internally this Visual studio add on uses DB>Doc utility.

My suggestion is that combine SQL Designer schema image with this HTML report to create better database documentation.

Also I found that command line utility DB>Doc is more easy to use for developers.

I hope these steps help you to do the boring documentation automatically and save your time.

Please leave your comments or share these technics if it’s useful for you.