Tuesday, January 24, 2017

Thursday, January 19, 2017

SSIS custom package as a package template

To designate a custom package as a package template

  1. In the file system, locate the package that you want to use as template.
  2. Copy the package to the DataTransformationItems folder. By default this folder is in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\ProjectItems\DataTransformationProject.

Wednesday, January 18, 2017

WebAPI start up page on deployment.

1. Properties --> Build --> Xml documentation file :  App_Data/XmlDocument.xml

2. HelpPageConfig.cs

 config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));


3. HelpPageAreaRegistration.cs

 public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "HelpPage_Default",
                "Help/{action}/{apiId}",
                new { controller = "Help", action = "Index", apiId = UrlParameter.Optional });

            context.MapRoute(
            "Help Area",
            "",
            new { controller = "Help", action = "Index" }
            );
            HelpPageConfig.Register(GlobalConfiguration.Configuration);
        }

4. Make sure all documentation exists:

        /// <summary>
        /// Get all products from web api call
        /// </summary>
        /// <param name="data">data</param>
        /// <returns></returns>
        [Route("products")]
        [HttpPost]
        public async Task<IHttpActionResult> GetProducts([FromBody] IDictionary<string, string> data)


5. in _Viewstart page
Layout = "~/Areas/HelpPage/Views/Shared/_Layout.cshtml";
Done:-)

Monday, January 9, 2017

MS Report Viewer in ASP.NET MVC5

  1. Add Report file(.rdlc) and Design your report.
  2. Add a View (aspx) into the Shared Folder
  3. Add asp.net control ScriptManager and ReportViewer In the View (ASPX) for show Report Viewer
  4. Add a new Controller.
  5.  Add view for the Action & design.

  • Right Click on Action Method (here right click on form action) > Add View... > Enter View Name > Select View Engine (Razor) > Check "Create a strong-typed view" > Select your model class > Add.
  • @Html.Partial("Report")
---------------------------------------------------------------------------

Microsoft ReportViewer
---------------------
Run the following command in the Package Manager Console
New:
PM>Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms  -->for correct web apps
-- changes version in report.aspx
-- add  ShowExportControls="true" ShowFindControls="true" ShowPrintButton="true" ShowRefreshButton="true"


----> Don't remove 'Microsoft.SqlServer.Types.' because 'Microsoft.ReportingServices.ReportViewerControl.WebForms.' depends on it.
----> use <ExcludeFoldersFromDeployment>SqlServerTypes</ExcludeFoldersFromDeployment> in publish profiles
--->  Build action ->embadedesource (default)-----ReportViewer1.LocalReport.ReportEmbeddedResource = "BSS.SubProj.Web.Reports.ProductReport.rdlc"; --namepspace.folder.reportname.rdlc
--->  Build action ->content-----ReportViewer1.LocalReport.ReportPath = System.Web.HttpContext.Current.Server.MapPath("~/Reports/ProductReport.rdlc");

Old1:
          PM>Install-Package Microsoft.ReportViewer.Runtime.WebForms
Old2:   not rqd
         PM>Install-Package ReportViewer.WebForms
         PM>Install-Package Microsoft.ReportViewer.Runtime.Common
------------------------------------------------------------------------------------------
Troubleshoot : make sure http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition in the report.
RDL vs RDLC
RDL reports are HOSTED reports generally. This means you need to implement SSRS Server. They are a built in extension of Visual Studio from SQL Server for the reporting language. When you install SSRS you should have an add on called 'Business Intelligence Development Studio' which is much easier to work with the reports than without it.
R eport
D efinition
L angauge
Benefits of RDL reports:
  1. You can host the reports in an environment that has services running for you on them.
  2. You can configure security on an item or inheriting level to handle security as a standalone concept
  3. You can configure the service to send out emails(provided you have an SMTP server you have access to) and save files on schedules
  4. You have a database generally called 'ReportServer' you can query for info on the reports once published.
  5. You can access these reports still through 'ReportViewer' in a client application written in ASP.NET, WPF (with a winform control bleh!), or Winforms in .NET using 'ProcessingMode.Remote'.
  6. You can set parameters a user can see and use to gain more flexibility.
  7. You can configure parts of a report to be used for connection strings as 'Data Sources' as well as a sql query, xml, or other datasets as a 'Dataset'. These parts and others can be stored and configured to cache data on a regular basis.
  8. You can write .NET proxy classes of the services http:// /ReportServer/ReportingService2010 or /ReportExecution2005. You can then make up your OWN methods in .NET for emailing, saving, or manipulating SSRS data from the service directly of a Server hosting SSRS reports in code. 
Downsides:
  1. SSRS is kind of wonkey compared to other things on getting it up fast. Most people get confused by the security policy and designing reports as an 'add on' to VS. SQL 2005 = VS BIDS 2005 , SQL 2008 = VS BIDS 2008, SQL 2012 = VS BIDS 2010(LOL).
  2. Continuing on 1 the policy for security settings IMHO are idiotically overcomplex. There is server security, database security and roles, two security settings on the page hosted for the service. Most people only set up an admin than can't get in and wonder why other users cannot. Most common complaint or question on SSRS is related to getting in generally from my experience.
  3. You can use 'expressions' that will supposeduly 'enhance' your report. Often times you do more than a few and your report goes to a crawl in performance.
  4. You have a set amount of things you can do and export to. SSRS has no hover over reporting I know of without a javascript hack.
  5. Speed and performance can take a hit as the stupid SSRS config recycles the system and a first report can take a while at times just loading the site. You can get around this by altering it but I have found making a keep alive service for it works better.
II. RDLC reports are CLIENT CONTAINED reports that are NOT HOSTED ANYWHERE. The extra c in the name means 'Client'. Generally this is an extension of the RDL language meant for use only in Visual Studio Client Applications. It exists in Visual Studio when you add a 'reporting' item.
Benefits of RDLC reports:
  1. You can hookup a wcf service much much much more easier to the dataset.
  2. You have more control over the dataset and can use POCO classes filled with Entity framework objects or ADO.NET directly as well as tables themselves. You can monkey with the data for optimization it before binding it to the report.
  3. You can customize the look more with add on's directly in code behind.
Downsides:
  1. You need to handle parameters on your own and while you can implement wrapper methods to help the legwork is a little more than expected and unfortunate.
  2. The user cannot SEE the parameters in a 'ReportViewer' control unless it is in remote mode and accessing an RLD report. Thus you need to make textboxes, dropdowns, radio buttons on your own outside the control to pass to it. Some people like this added control, I do not personally.
  3. Anything you want to do with servicing the reports for distribution you need to build yourself. Emailing, subscriptions, saving. Sorry you need to build that in .NET or else implement a proxy that already does that from above you could just be getting using hosted reports.
Honestly I like both for different purposes. If I want something to go out to analysts that they use all the time and tweak for graphs, charts, drill downs and exports to Excel I use RDL and just have SSRS's site do all the legwork of handling the email distributions. If I want an application that has a report section and I know that application is it's own module with rules and governance I use an RDLC and having the parameters be smaller and be driven by the decisions the user made before getting to the report part of what client they are on and site and then they usually just choose a time frame or type and nothing more. So generally a complex report I would use RDL and for something simple I would use RDLC.

Tuesday, January 3, 2017

Open web application security

https://www.owasp.org/images/8/83/Securing_Enterprise_Web_Applications_at_the_Source.pdf

N-tier architecture

A large enterprise application will typically have one or more databases to store data and on top of this a data access layer (DAL) to access the database(s). On top of this there may be some repositories to communicate with the DAL, a business layer containing logic and classes representing the business domain, a service layer to expose the business layer to clients and finally some user interface application such as an ASP.NET web application or  a WPF desktop application.
CROSS CUTTING
SECURITY
LOGGING
EXCEPTION
BUSINESS TEMPLATE
User interface layer
MVC / ANGULAR / ASP.NET / WPF /  Console App / WinRT / …
Service layer
WebAPI / WCF / ASMX / …
Business logic layer
Data access layer
EF / ADO.NET / …
Database
SQL Server / Oracle / MySql / …

Sunday, January 1, 2017

Dependency Injection

Dependency Injection

Advantages of Dependency Injection:
  • ·         Reduces class coupling
  • ·         Increases code reusing
  • ·         Improves code maintainability
  • ·         Improves application testing


Popular DI containers?

Castle Windsor

·         Based on the Castle MicroKernel.
·         Well documented and used by many.
·         Understands Decorator
·         Typed factories
·         Commercial support available

Spring.NET

·         INTERCEPTION
·         Comprehensive documentation
·         Commercial support available

Autofac

·         Easy to learn API
·         second-generation DI Container
·         Commercial support available

Unity

·         INTERCEPTION
·         Good documentation
·         Consistent API

Ninject

·         Easy to learn API
·         Second-generation DI Container

Implementation of Dependency Injection Pattern in C#

Dependency Injection (DI) is a software design pattern that allow us to develop loosely coupled code. DI is a great way to reduce tight coupling between software components. DI also enables us to better manage future changes and other complexity in our software. The purpose of DI is to make code maintainable.

Constructor Injection


public interface IService
    {
        void Serve();
    }

    public class Service : IService
    {
        public void Serve()
        {
            Console.WriteLine("Service Called");
        }
    }

    public class Client
    {
        private IService _service;

        public Client(IService service)
        {
            _service = service;
        }

        public void Start()
        {
            _service.Serve();
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            Client client = new Client(new Service());
            client.Start();
        }
    }

Property injection


public interface IService
    {
        void Serve();
    }

    public class Service : IService
    {
        public void Serve()
        {
            Console.WriteLine("Service Called");
        }
    }

    public class Client
    {
        private IService _service;

        public IService Service
        {
            set
            {
                _service = value;
            }
        }

        public void Start()
        {
            _service.Serve();
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            Client client = new Client();
            client.Service = new Service();
            client.Start();
        }
    }

Method injection

public interface IService
    {
        void Serve();
    }

    public class Service : IService
    {
        public void Serve()
        {
            Console.WriteLine("Service Called");
        }
    }

    public class Client
    {
        private IService _service;

        public void Start(IService service)
        {
            _service = service;
            _service.Serve();
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            Client client = new Client();
            client.Start(new Service());
        }
    }



Encrypt/Decrypt the App.Config

Program.cs using System; using System.Diagnostics; using System.IO; namespace EncryptAppConfig {     internal class Program     {         pr...