├── AddisCode.SOLIDTraining ├── RestDataCenter │ ├── Views │ │ ├── _ViewStart.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ └── _Layout.cshtml │ │ ├── Home │ │ │ └── Index.cshtml │ │ └── Web.config │ ├── Global.asax │ ├── favicon.ico │ ├── Scripts │ │ ├── _references.js │ │ ├── respond.min.js │ │ └── respond.js │ ├── Areas │ │ └── HelpPage │ │ │ ├── Views │ │ │ ├── Help │ │ │ │ ├── DisplayTemplates │ │ │ │ │ ├── ImageSample.cshtml │ │ │ │ │ ├── TextSample.cshtml │ │ │ │ │ ├── InvalidSample.cshtml │ │ │ │ │ ├── Samples.cshtml │ │ │ │ │ ├── ApiGroup.cshtml │ │ │ │ │ ├── HelpPageApiModel.cshtml │ │ │ │ │ └── Parameters.cshtml │ │ │ │ ├── Api.cshtml │ │ │ │ └── Index.cshtml │ │ │ ├── _ViewStart.cshtml │ │ │ ├── Shared │ │ │ │ └── _Layout.cshtml │ │ │ └── Web.config │ │ │ ├── SampleGeneration │ │ │ ├── SampleDirection.cs │ │ │ ├── TextSample.cs │ │ │ ├── InvalidSample.cs │ │ │ ├── ImageSample.cs │ │ │ └── HelpPageSampleKey.cs │ │ │ ├── HelpPageAreaRegistration.cs │ │ │ ├── Controllers │ │ │ └── HelpController.cs │ │ │ ├── ApiDescriptionExtensions.cs │ │ │ ├── Models │ │ │ └── HelpPageApiModel.cs │ │ │ ├── HelpPage.css │ │ │ ├── App_Start │ │ │ └── HelpPageConfig.cs │ │ │ └── XmlDocumentationProvider.cs │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ ├── App_Start │ │ ├── FilterConfig.cs │ │ ├── RouteConfig.cs │ │ ├── WebApiConfig.cs │ │ └── BundleConfig.cs │ ├── Controllers │ │ ├── HomeController.cs │ │ └── ValuesController.cs │ ├── Global.asax.cs │ ├── Content │ │ └── Site.css │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Web.config │ └── Project_Readme.html ├── Input Dcocuments │ ├── Document1.csv │ └── Document1.xml ├── AddisCode.SolidPrinciple.Dip │ ├── InvalidInputException.cs │ ├── App.config │ ├── DocumentSerializer.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ ├── FormatConverter.cs │ ├── DocumentStorage.cs │ ├── InputParser.cs │ └── AddisCode.SolidPrinciple.Dip.csproj ├── AddisCode.SolidPrinciple.Isp │ ├── InvalidInputException.cs │ ├── App.config │ ├── DocumentSerializer.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── FormatConverter.cs │ ├── DocumentStorage.cs │ ├── InputParser.cs │ └── AddisCode.SolidPrinciple.Isp.csproj ├── AddisCode.SolidPrinciple.Lsp │ ├── InvalidInputException.cs │ ├── App.config │ ├── DocumentSerializer.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── FormatConverter.cs │ ├── DocumentStorage.cs │ ├── InputParser.cs │ └── AddisCode.SolidPrinciple.Lsp.csproj ├── AddisCode.SolidPrinciple.Ocp │ ├── InvalidInputException.cs │ ├── App.config │ ├── DocumentSerializer.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── FormatConverter.cs │ ├── DocumentStorage.cs │ ├── InputParser.cs │ └── AddisCode.SolidPrinciple.Ocp.csproj ├── AddisCode.SolidPrinciple.Srp │ ├── InvalidInputException.cs │ ├── App.config │ ├── DocumentSerializer.cs │ ├── DocumentStorage.cs │ ├── Program.cs │ ├── InputParser.cs │ ├── FormatConverter.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── AddisCode.SolidPrinciple.Srp.csproj ├── TrainingDocumentCreater │ ├── App.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── TrainingDocumentCreater.csproj ├── AddisCode.SolidPrinciple.Refactored │ ├── App.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── AddisCode.SolidPrinciple.Refactored.csproj ├── Ouput Dcocuments │ └── Document1.json ├── DataModel │ ├── Student.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── DataModel.csproj ├── AddisCode.SolidPrinciple.Lsp.Principles │ ├── Entities │ │ ├── OutOfFuelException.cs │ │ ├── MetYourMakerException.cs │ │ └── Car.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── CarUnitTest.cs │ └── AddisCode.SolidPrinciple.Lsp.Principles.csproj └── AddisCode.SOLIDTraining.sln ├── README.md ├── .gitignore └── LICENSE /AddisCode.SOLIDTraining/RestDataCenter/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="RestDataCenter.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AddisCodeDev/SOLIDPrinciples/HEAD/AddisCode.SOLIDTraining/RestDataCenter/favicon.ico -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SOLIDPrinciples 2 | =============== 3 | 4 | A C# code demonstrating all five SOLID principles, (mainly based on Chris Klug's TechEd North America presentation) 5 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Scripts/_references.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AddisCodeDev/SOLIDPrinciples/HEAD/AddisCode.SOLIDTraining/RestDataCenter/Scripts/_references.js -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml: -------------------------------------------------------------------------------- 1 | @using RestDataCenter.Areas.HelpPage 2 | @model ImageSample 3 | 4 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml: -------------------------------------------------------------------------------- 1 | @using RestDataCenter.Areas.HelpPage 2 | @model TextSample 3 | 4 |
5 | @Model.Text
6 | 
-------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AddisCodeDev/SOLIDPrinciples/HEAD/AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AddisCodeDev/SOLIDPrinciples/HEAD/AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/Input Dcocuments/Document1.csv: -------------------------------------------------------------------------------- 1 | c1423681-0fd0-404e-a4c2-a0735dde6d7e,Derartu,Tulu,20 2 | d96f84c9-343c-4364-a216-7af1058d8b50,Teddy,Afro,21 3 | 62e946ac-1b10-44a1-8432-123ca880b3ae,Mesfin,Negash,22 -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AddisCodeDev/SOLIDPrinciples/HEAD/AddisCode.SOLIDTraining/RestDataCenter/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisCode.SolidPrinciple.Dip 4 | { 5 | public class InvalidInputFormatException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisCode.SolidPrinciple.Isp 4 | { 5 | public class InvalidInputFormatException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisCode.SolidPrinciple.Lsp 4 | { 5 | public class InvalidInputFormatException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisCode.SolidPrinciple.Ocp 4 | { 5 | public class InvalidInputFormatException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/InvalidInputException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisCode.SolidPrinciple.Srp 4 | { 5 | public class InvalidInputFormatException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | // Change the Layout path below to blend the look and feel of the help page with your existing web pages 3 | Layout = "~/Views/Shared/_Layout.cshtml"; 4 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/TrainingDocumentCreater/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Refactored/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/DocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace AddisCode.SolidPrinciple.Srp 4 | { 5 | public class DocumentSerializer 6 | { 7 | public object Serilize(object doc) 8 | { 9 | return JsonConvert.SerializeObject(doc); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/Ouput Dcocuments/Document1.json: -------------------------------------------------------------------------------- 1 | [{"StudentId":"fa02997b-2a0e-4c8a-9870-55bcaf3cb906","FirstName":"Derartu","LastName":"Tulu","Age":20},{"StudentId":"a4038bb7-c665-4936-8c37-4a912e8be84c","FirstName":"Teddy","LastName":"Afro","Age":21},{"StudentId":"65d0e49d-faf3-4e5b-970c-b82dd6987e2f","FirstName":"Mesfin","LastName":"Negash","Age":22}] -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/SampleGeneration/SampleDirection.cs: -------------------------------------------------------------------------------- 1 | namespace RestDataCenter.Areas.HelpPage 2 | { 3 | /// 4 | /// Indicates whether the sample is used for request or response 5 | /// 6 | public enum SampleDirection 7 | { 8 | Request = 0, 9 | Response 10 | } 11 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @RenderSection("scripts", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace RestDataCenter 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml: -------------------------------------------------------------------------------- 1 | @using RestDataCenter.Areas.HelpPage 2 | @model InvalidSample 3 | 4 | @if (HttpContext.Current.IsDebuggingEnabled) 5 | { 6 |
7 |

@Model.ErrorMessage

8 |
9 | } 10 | else 11 | { 12 |

Sample not available.

13 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 | 5 | 6 | 7 | 8 | 9 | Error 10 | 11 | 12 |
13 |

Error.

14 |

An error occurred while processing your request.

15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/DataModel/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DataModel 8 | { 9 | public class Student 10 | { 11 | public Guid StudentId { get; set; } 12 | public string FirstName { get; set; } 13 | public string LastName { get; set; } 14 | public int Age { get; set; } 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace RestDataCenter.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | ViewBag.Title = "Home Page"; 14 | 15 | return View(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/Input Dcocuments/Document1.xml: -------------------------------------------------------------------------------- 1 | 20DerartuTulufa02997b-2a0e-4c8a-9870-55bcaf3cb90621TeddyAfroa4038bb7-c665-4936-8c37-4a912e8be84c22MesfinNegash65d0e49d-faf3-4e5b-970c-b82dd6987e2f -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/Entities/OutOfFuelException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AddisCode.SolidPrinciple.Lsp.Principles.Entities 8 | { 9 | public class OutOfFuelException : Exception 10 | { 11 | protected string _message; 12 | 13 | public override string Message 14 | { 15 | get { return _message; } 16 | } 17 | 18 | public OutOfFuelException (string message) 19 | { 20 | _message = message; 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/Entities/MetYourMakerException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AddisCode.SolidPrinciple.Lsp.Principles.Entities 8 | { 9 | public class MetYourMakerException : Exception 10 | { 11 | protected string _message; 12 | 13 | public override string Message 14 | { 15 | get { return _message; } 16 | } 17 | 18 | public MetYourMakerException (string message) 19 | { 20 | _message = message; 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace RestDataCenter 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | 6 | namespace RestDataCenter 7 | { 8 | public static class WebApiConfig 9 | { 10 | public static void Register(HttpConfiguration config) 11 | { 12 | // Web API configuration and services 13 | 14 | // Web API routes 15 | config.MapHttpAttributeRoutes(); 16 | 17 | config.Routes.MapHttpRoute( 18 | name: "DefaultApi", 19 | routeTemplate: "api/{controller}/{id}", 20 | defaults: new { id = RouteParameter.Optional } 21 | ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/DocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | using DataModel; 2 | using Newtonsoft.Json; 3 | 4 | namespace AddisCode.SolidPrinciple.Dip 5 | { 6 | public interface IDocumentSerializer 7 | { 8 | string Serilize(Student[] doc); 9 | } 10 | 11 | public class JsonDocumentSerializer : IDocumentSerializer 12 | { 13 | public string Serilize(Student[] doc) 14 | { 15 | return JsonConvert.SerializeObject(doc); 16 | } 17 | } 18 | 19 | public class CamleCaseJsonSerializer : IDocumentSerializer 20 | { 21 | public string Serilize(Student[] doc) 22 | { 23 | return new CamleCaseJsonSerializer().Serilize(doc); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/DocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | using DataModel; 2 | using Newtonsoft.Json; 3 | 4 | namespace AddisCode.SolidPrinciple.Isp 5 | { 6 | public interface IDocumentSerializer 7 | { 8 | string Serilize(Student[] doc); 9 | } 10 | 11 | public class JsonDocumentSerializer : IDocumentSerializer 12 | { 13 | public string Serilize(Student[] doc) 14 | { 15 | return JsonConvert.SerializeObject(doc); 16 | } 17 | } 18 | 19 | public class CamleCaseJsonSerializer : IDocumentSerializer 20 | { 21 | public string Serilize(Student[] doc) 22 | { 23 | return new CamleCaseJsonSerializer().Serilize(doc); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/DocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | using DataModel; 2 | using Newtonsoft.Json; 3 | 4 | namespace AddisCode.SolidPrinciple.Lsp 5 | { 6 | public interface IDocumentSerializer 7 | { 8 | string Serilize(Student[] doc); 9 | } 10 | 11 | public class JsonDocumentSerializer : IDocumentSerializer 12 | { 13 | public string Serilize(Student[] doc) 14 | { 15 | return JsonConvert.SerializeObject(doc); 16 | } 17 | } 18 | 19 | public class CamleCaseJsonSerializer : IDocumentSerializer 20 | { 21 | public string Serilize(Student[] doc) 22 | { 23 | return new CamleCaseJsonSerializer().Serilize(doc); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/DocumentSerializer.cs: -------------------------------------------------------------------------------- 1 | using DataModel; 2 | using Newtonsoft.Json; 3 | 4 | namespace AddisCode.SolidPrinciple.Ocp 5 | { 6 | public interface IDocumentSerializer 7 | { 8 | string Serilize(Student[] doc); 9 | } 10 | 11 | public class JsonDocumentSerializer : IDocumentSerializer 12 | { 13 | public string Serilize(Student[] doc) 14 | { 15 | return JsonConvert.SerializeObject(doc); 16 | } 17 | } 18 | 19 | public class CamleCaseJsonSerializer : IDocumentSerializer 20 | { 21 | public string Serilize(Student[] doc) 22 | { 23 | return new CamleCaseJsonSerializer().Serilize(doc); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Mvc; 7 | using System.Web.Optimization; 8 | using System.Web.Routing; 9 | 10 | namespace RestDataCenter 11 | { 12 | public class WebApiApplication : System.Web.HttpApplication 13 | { 14 | protected void Application_Start() 15 | { 16 | AreaRegistration.RegisterAllAreas(); 17 | GlobalConfiguration.Configure(WebApiConfig.Register); 18 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 19 | RouteConfig.RegisterRoutes(RouteTable.Routes); 20 | BundleConfig.RegisterBundles(BundleTable.Bundles); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/Api.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using RestDataCenter.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; 8 | } 9 | 10 |
11 | 18 |
19 | @Html.DisplayFor(m => Model) 20 |
21 |
22 | 23 | @section Scripts { 24 | 25 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/HelpPageAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | 4 | namespace RestDataCenter.Areas.HelpPage 5 | { 6 | public class HelpPageAreaRegistration : AreaRegistration 7 | { 8 | public override string AreaName 9 | { 10 | get 11 | { 12 | return "HelpPage"; 13 | } 14 | } 15 | 16 | public override void RegisterArea(AreaRegistrationContext context) 17 | { 18 | context.MapRoute( 19 | "HelpPage_Default", 20 | "Help/{action}/{apiId}", 21 | new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 22 | 23 | HelpPageConfig.Register(GlobalConfiguration.Configuration); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | 19 | /* styles for validation helpers */ 20 | .field-validation-error { 21 | color: #b94a48; 22 | } 23 | 24 | .field-validation-valid { 25 | display: none; 26 | } 27 | 28 | input.input-validation-error { 29 | border: 1px solid #b94a48; 30 | } 31 | 32 | input[type="checkbox"].input-validation-error { 33 | border: 0 none; 34 | } 35 | 36 | .validation-summary-errors { 37 | color: #b94a48; 38 | } 39 | 40 | .validation-summary-valid { 41 | display: none; 42 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/DocumentStorage.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace AddisCode.SolidPrinciple.Srp 4 | { 5 | public class DocumentStorage 6 | { 7 | internal string GetData(string sourceFileName) 8 | { 9 | string output; 10 | using (var stream = File.OpenRead(sourceFileName)) 11 | using (var reader = new StreamReader(stream)) 12 | { 13 | output = reader.ReadToEnd(); 14 | } 15 | return output; 16 | } 17 | 18 | public void PersistDocument(object serializedDoc, string targetFileName) 19 | { 20 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 21 | using (var sw = new StreamWriter(stream)) 22 | { 23 | sw.Write(serializedDoc); 24 | sw.Close(); 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.Serialization; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AddisCode.SolidPrinciple.Srp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 16 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 17 | var formatConverter = new FormatConverter(); 18 | if (!formatConverter.ConvertFormat(sourceFileName, targetFileName)) 19 | { 20 | Console.WriteLine("Conversion Failed"); 21 | Console.ReadKey(); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Net.Http.Headers 2 | @model Dictionary 3 | 4 | @{ 5 | // Group the samples into a single tab if they are the same. 6 | Dictionary samples = Model.GroupBy(pair => pair.Value).ToDictionary( 7 | pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 8 | pair => pair.Key); 9 | var mediaTypes = samples.Keys; 10 | } 11 |
12 | @foreach (var mediaType in mediaTypes) 13 | { 14 |

@mediaType

15 |
16 | Sample: 17 | @{ 18 | var sample = samples[mediaType]; 19 | if (sample == null) 20 | { 21 |

Sample not available.

22 | } 23 | else 24 | { 25 | @Html.DisplayFor(s => sample); 26 | } 27 | } 28 |
29 | } 30 |
-------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/SampleGeneration/TextSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RestDataCenter.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents a preformatted text sample on the help page. There's a display template named TextSample associated with this class. 7 | /// 8 | public class TextSample 9 | { 10 | public TextSample(string text) 11 | { 12 | if (text == null) 13 | { 14 | throw new ArgumentNullException("text"); 15 | } 16 | Text = text; 17 | } 18 | 19 | public string Text { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | TextSample other = obj as TextSample; 24 | return other != null && Text == other.Text; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return Text.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Text; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AddisCode.SolidPrinciple.Isp 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 15 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.xml"); 16 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 17 | //var sorceFileName = "http:\\localhost\Values"; 18 | //var targetFileName = "http:\\localhpst\values"; 19 | var formatConverter = new FormatConverter(); 20 | if (!formatConverter.ConvertFormat(sourceFileName, targetFileName)) 21 | { 22 | Console.WriteLine("Conversion Failed"); 23 | Console.ReadKey(); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AddisCode.SolidPrinciple.Lsp 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | //var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 15 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.xml"); 16 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 17 | //var sorceFileName = "http:\\localhost\Values"; 18 | //var targetFileName = "http:\\localhpst\values"; 19 | var formatConverter = new FormatConverter(); 20 | if (!formatConverter.ConvertFormat(sourceFileName, targetFileName)) 21 | { 22 | Console.WriteLine("Conversion Failed"); 23 | Console.ReadKey(); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AddisCode.SolidPrinciple.Ocp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 16 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.xml"); 17 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 18 | //var sorceFileName = "http://localhost:10562/Api/Values"; 19 | 20 | 21 | 22 | 23 | var formatConverter = new FormatConverter(); 24 | if (!formatConverter.ConvertFormat(sourceFileName, targetFileName)) 25 | { 26 | Console.WriteLine("Conversion Failed"); 27 | Console.ReadKey(); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/SampleGeneration/InvalidSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RestDataCenter.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an invalid sample on the help page. There's a display template named InvalidSample associated with this class. 7 | /// 8 | public class InvalidSample 9 | { 10 | public InvalidSample(string errorMessage) 11 | { 12 | if (errorMessage == null) 13 | { 14 | throw new ArgumentNullException("errorMessage"); 15 | } 16 | ErrorMessage = errorMessage; 17 | } 18 | 19 | public string ErrorMessage { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | InvalidSample other = obj as InvalidSample; 24 | return other != null && ErrorMessage == other.ErrorMessage; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return ErrorMessage.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return ErrorMessage; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/InputParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DataModel; 4 | 5 | namespace AddisCode.SolidPrinciple.Srp 6 | { 7 | public class InputParser 8 | { 9 | public Student[] ParseInput(string input) 10 | { 11 | string[] studentsRead = input.Split('\n'); 12 | List students = new List(); 13 | try 14 | { 15 | foreach (var studentRead in studentsRead) 16 | { 17 | string[] studentData = studentRead.Split(','); 18 | Student student = new Student() 19 | { 20 | StudentId = Guid.Parse(studentData[0]), 21 | FirstName = studentData[1], 22 | LastName = studentData[2], 23 | Age = int.Parse(studentData[3]) 24 | }; 25 | students.Add(student); 26 | } 27 | } 28 | catch (Exception e) 29 | { 30 | throw new InvalidInputFormatException(); 31 | } 32 | return students.ToArray(); 33 | 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace RestDataCenter 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 15 | // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 16 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 17 | "~/Scripts/modernizr-*")); 18 | 19 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 20 | "~/Scripts/bootstrap.js", 21 | "~/Scripts/respond.js")); 22 | 23 | bundles.Add(new StyleBundle("~/Content/css").Include( 24 | "~/Content/bootstrap.css", 25 | "~/Content/site.css")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/SampleGeneration/ImageSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RestDataCenter.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an image sample on the help page. There's a display template named ImageSample associated with this class. 7 | /// 8 | public class ImageSample 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The URL of an image. 14 | public ImageSample(string src) 15 | { 16 | if (src == null) 17 | { 18 | throw new ArgumentNullException("src"); 19 | } 20 | Src = src; 21 | } 22 | 23 | public string Src { get; private set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | ImageSample other = obj as ImageSample; 28 | return other != null && Src == other.Src; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return Src.GetHashCode(); 34 | } 35 | 36 | public override string ToString() 37 | { 38 | return Src; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using System.Collections.ObjectModel 5 | @using RestDataCenter.Areas.HelpPage.Models 6 | @model Collection 7 | 8 | @{ 9 | ViewBag.Title = "ASP.NET Web API Help Page"; 10 | 11 | // Group APIs by controller 12 | ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); 13 | } 14 | 15 |
16 |
17 |
18 |

@ViewBag.Title

19 |
20 |
21 |
22 |
23 | 31 |
32 | @foreach (var group in apiGroups) 33 | { 34 | @Html.DisplayFor(m => group, "ApiGroup") 35 | } 36 |
37 |
38 | 39 | @section Scripts { 40 | 41 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using RestDataCenter.Areas.HelpPage 5 | @using RestDataCenter.Areas.HelpPage.Models 6 | @model IGrouping 7 | 8 | @{ 9 | var controllerDocumentation = ViewBag.DocumentationProvider != null ? 10 | ViewBag.DocumentationProvider.GetDocumentation(Model.Key) : 11 | null; 12 | } 13 | 14 |

@Model.Key.ControllerName

15 | @if (!String.IsNullOrEmpty(controllerDocumentation)) 16 | { 17 |

@controllerDocumentation

18 | } 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var api in Model) 25 | { 26 | 27 | 28 | 38 | 39 | } 40 | 41 |
APIDescription
@api.HttpMethod.Method @api.RelativePath 29 | @if (api.Documentation != null) 30 | { 31 |

@api.Documentation

32 | } 33 | else 34 | { 35 |

No documentation available.

36 | } 37 |
-------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Controllers/HelpController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http; 3 | using System.Web.Mvc; 4 | using RestDataCenter.Areas.HelpPage.Models; 5 | 6 | namespace RestDataCenter.Areas.HelpPage.Controllers 7 | { 8 | /// 9 | /// The controller that will handle requests for the help page. 10 | /// 11 | public class HelpController : Controller 12 | { 13 | public HelpController() 14 | : this(GlobalConfiguration.Configuration) 15 | { 16 | } 17 | 18 | public HelpController(HttpConfiguration config) 19 | { 20 | Configuration = config; 21 | } 22 | 23 | public HttpConfiguration Configuration { get; private set; } 24 | 25 | public ActionResult Index() 26 | { 27 | ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); 28 | return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 29 | } 30 | 31 | public ActionResult Api(string apiId) 32 | { 33 | if (!String.IsNullOrEmpty(apiId)) 34 | { 35 | HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId); 36 | if (apiModel != null) 37 | { 38 | return View(apiModel); 39 | } 40 | } 41 | 42 | return View("Error"); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/FormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace AddisCode.SolidPrinciple.Srp 8 | { 9 | class FormatConverter 10 | { 11 | private readonly DocumentStorage _documentStorage; 12 | private readonly InputParser _inputParser; 13 | private readonly DocumentSerializer _documentSerializer; 14 | 15 | public FormatConverter() 16 | { 17 | _documentStorage = new DocumentStorage(); 18 | _documentSerializer = new DocumentSerializer(); 19 | _inputParser = new InputParser(); 20 | } 21 | internal bool ConvertFormat(string sourceFileName, string targetFileName) 22 | { 23 | string input; 24 | try 25 | { 26 | input = _documentStorage.GetData(sourceFileName); 27 | } 28 | catch (FileNotFoundException) 29 | { 30 | return false; 31 | } 32 | 33 | var doc = _inputParser.ParseInput(input); 34 | var serializedDoc = _documentSerializer.Serilize(doc); 35 | 36 | try 37 | { 38 | _documentStorage.PersistDocument(serializedDoc, targetFileName); 39 | } 40 | catch (AccessViolationException) 41 | { 42 | return false; 43 | } 44 | return true; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("RestDataCenter")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("RestDataCenter")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("bf614b3a-a71c-4ff6-b170-99eaa1e2923e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 |
2 |

ASP.NET

3 |

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.

4 |

Learn more »

5 |
6 |
7 |
8 |

Getting started

9 |

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach 10 | a broad range of clients, including browsers and mobile devices. ASP.NET Web API 11 | is an ideal platform for building RESTful applications on the .NET Framework.

12 |

Learn more »

13 |
14 |
15 |

Get more libraries

16 |

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

17 |

Learn more »

18 |
19 |
20 |

Web Hosting

21 |

You can easily find a web hosting company that offers the right mix of features and price for your applications.

22 |

Learn more »

23 |
24 |
25 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/DataModel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Student")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Student")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c444f89f-dd48-44da-8a96-30d4178babad")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/TrainingDocumentCreater/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TrainingDocumentCreater")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TrainingDocumentCreater")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("95da9ea1-a385-4869-95c2-ee6daeabe017")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Dip")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Dip")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7e2781ee-c4c6-453f-b3fc-53d723d8732f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Isp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Isp")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("360c1c55-737a-4b46-b2ea-9d2f6318f6fb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Lsp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Lsp")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("87bc7ed9-e250-44f7-b304-c7df1b81402a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Ocp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Ocp")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("73a364bf-3077-4d11-a56c-9d9e769a8126")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Srp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Srp")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ace0a022-8830-4d7a-818a-cdac1a6bbacc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Microsoft.Practices.Unity; 8 | 9 | namespace AddisCode.SolidPrinciple.Dip 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | //var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 16 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.xml"); 17 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 18 | //var sorceFileName = "http:\\localhost\Values"; 19 | //var targetFileName = "http:\\localhpst\values"; 20 | var container = GetContainer(); 21 | 22 | 23 | var formatConverter = container.Resolve(); 24 | if (!formatConverter.ConvertFormat(sourceFileName, targetFileName)) 25 | { 26 | Console.WriteLine("Conversion Failed"); 27 | Console.ReadKey(); 28 | } 29 | } 30 | 31 | private static IUnityContainer GetContainer() 32 | { 33 | IUnityContainer container = new UnityContainer(); 34 | container.RegisterType(); 35 | container.RegisterType(); 36 | return container; 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Refactored/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Refactored")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Refactored")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("78692942-9585-4f10-bf07-4a6a993623d9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AddisCode.SolidPrinciple.Lsp.Principles")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AddisCode.SolidPrinciple.Lsp.Principles")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("287b76a2-0afd-40c4-9d9e-98c8402be77b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/ApiDescriptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Web; 4 | using System.Web.Http.Description; 5 | 6 | namespace RestDataCenter.Areas.HelpPage 7 | { 8 | public static class ApiDescriptionExtensions 9 | { 10 | /// 11 | /// Generates an URI-friendly ID for the . E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}" 12 | /// 13 | /// The . 14 | /// The ID as a string. 15 | public static string GetFriendlyId(this ApiDescription description) 16 | { 17 | string path = description.RelativePath; 18 | string[] urlParts = path.Split('?'); 19 | string localPath = urlParts[0]; 20 | string queryKeyString = null; 21 | if (urlParts.Length > 1) 22 | { 23 | string query = urlParts[1]; 24 | string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys; 25 | queryKeyString = String.Join("_", queryKeys); 26 | } 27 | 28 | StringBuilder friendlyPath = new StringBuilder(); 29 | friendlyPath.AppendFormat("{0}-{1}", 30 | description.HttpMethod.Method, 31 | localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty)); 32 | if (queryKeyString != null) 33 | { 34 | friendlyPath.AppendFormat("_{0}", queryKeyString); 35 | } 36 | return friendlyPath.ToString(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @Styles.Render("~/Content/css") 8 | @Scripts.Render("~/bundles/modernizr") 9 | 10 | 11 | 29 |
30 | @RenderBody() 31 |
32 |
33 |

© @DateTime.Now.Year - My ASP.NET Application

34 |
35 |
36 | 37 | @Scripts.Render("~/bundles/jquery") 38 | @Scripts.Render("~/bundles/bootstrap") 39 | @RenderSection("scripts", required: false) 40 | 41 | 42 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Models/HelpPageApiModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | using System.Net.Http.Headers; 4 | using System.Web.Http.Description; 5 | 6 | namespace RestDataCenter.Areas.HelpPage.Models 7 | { 8 | /// 9 | /// The model that represents an API displayed on the help page. 10 | /// 11 | public class HelpPageApiModel 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public HelpPageApiModel() 17 | { 18 | SampleRequests = new Dictionary(); 19 | SampleResponses = new Dictionary(); 20 | ErrorMessages = new Collection(); 21 | } 22 | 23 | /// 24 | /// Gets or sets the that describes the API. 25 | /// 26 | public ApiDescription ApiDescription { get; set; } 27 | 28 | /// 29 | /// Gets the sample requests associated with the API. 30 | /// 31 | public IDictionary SampleRequests { get; private set; } 32 | 33 | /// 34 | /// Gets the sample responses associated with the API. 35 | /// 36 | public IDictionary SampleResponses { get; private set; } 37 | 38 | /// 39 | /// Gets the error messages associated with this model. 40 | /// 41 | public Collection ErrorMessages { get; private set; } 42 | } 43 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/HelpPageApiModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using RestDataCenter.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | bool hasParameters = description.ParameterDescriptions.Count > 0; 8 | bool hasRequestSamples = Model.SampleRequests.Count > 0; 9 | bool hasResponseSamples = Model.SampleResponses.Count > 0; 10 | } 11 |

@description.HttpMethod.Method @description.RelativePath

12 |
13 | @if (description.Documentation != null) 14 | { 15 |

@description.Documentation

16 | } 17 | else 18 | { 19 |

No documentation available.

20 | } 21 | 22 | @if (hasParameters || hasRequestSamples) 23 | { 24 |

Request Information

25 | if (hasParameters) 26 | { 27 |

Parameters

28 | @Html.DisplayFor(apiModel => apiModel.ApiDescription.ParameterDescriptions, "Parameters") 29 | } 30 | if (hasRequestSamples) 31 | { 32 |

Request body formats

33 | @Html.DisplayFor(apiModel => apiModel.SampleRequests, "Samples") 34 | } 35 | } 36 | 37 | @if (hasResponseSamples) 38 | { 39 |

Response Information

40 | if (description.ResponseDescription.Documentation != null) 41 | { 42 |

@description.ResponseDescription.Documentation

43 | } 44 | else 45 | { 46 |

No documentation available.

47 | } 48 |

Response body formats

49 | @Html.DisplayFor(apiModel => apiModel.SampleResponses, "Samples") 50 | } 51 |
-------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/CarUnitTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using AddisCode.SolidPrinciple.Lsp.Principles.Entities; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace AddisCode.SolidPrinciple.Lsp.Principles 7 | { 8 | [TestClass] 9 | public class CarUnitTest 10 | { 11 | [TestMethod] 12 | public void Make_sure_car_can_start() 13 | { 14 | var car = new Car(Color.Aqua); 15 | //var car = new BrokenCar(Color.Aqua); //Post condition Weakened 16 | //var car = new CrimeBossCar(Color.Aqua, true); //Throws new type of exception 17 | try 18 | { 19 | car.StartEngine(); 20 | } 21 | catch (OutOfFuelException) 22 | { 23 | Assert.Fail("Car is out of gas...."); 24 | } 25 | Assert.IsTrue(car.IsEngineRunning); 26 | } 27 | 28 | [TestMethod] 29 | public void Make_sure_engine_is_running_after_start() 30 | { 31 | var car = new Car(Color.Aqua); 32 | //var car = new Prius(Color.Aqua); // Changing invariants 33 | //var car = new StolenCar(Color.Aqua); // Changing preconditions 34 | 35 | car.StartEngine(); 36 | 37 | Assert.IsTrue(car.IsEngineRunning); 38 | } 39 | 40 | [TestMethod] 41 | public void Make_sure_the_car_is_painted_correctly() 42 | { 43 | var car = new Car(Color.Aqua); 44 | //var car = new PimpedCar(Color.Aqua); // Violating history constraint 45 | //car.setTempreture(30); 46 | 47 | Assert.AreEqual(Color.Aqua, car.Color); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/FormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace AddisCode.SolidPrinciple.Lsp 5 | { 6 | class FormatConverter 7 | { 8 | private readonly InputParser _inputParser; 9 | private readonly IDocumentSerializer _documentSerializer; 10 | 11 | public FormatConverter() 12 | { 13 | //_documentSerializer = new CamleCaseJsonSerializer(); 14 | _documentSerializer = new JsonDocumentSerializer(); 15 | //_inputParser = new InputParser(); 16 | _inputParser = new XmlInputParser(); 17 | } 18 | internal bool ConvertFormat(string sourceFileName, string targetFileName) 19 | { 20 | string input; 21 | var documentStorage = GetDocumentStorage(sourceFileName); 22 | try 23 | { 24 | input = documentStorage.GetData(sourceFileName); 25 | } 26 | catch (FileNotFoundException) 27 | { 28 | return false; 29 | } 30 | 31 | var doc = _inputParser.ParseInput(input); 32 | var serializedDoc = _documentSerializer.Serilize(doc); 33 | 34 | try 35 | { 36 | documentStorage.PersistDocument(serializedDoc, targetFileName); 37 | } 38 | catch (AccessViolationException) 39 | { 40 | return false; 41 | } 42 | return true; 43 | } 44 | 45 | internal DocumentStorage GetDocumentStorage(string sourceFileName) 46 | { 47 | if (sourceFileName.StartsWith("http")) 48 | return new HttpInputRetriever(); 49 | return new FileDocumentStorage(); 50 | } 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/FormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace AddisCode.SolidPrinciple.Ocp 5 | { 6 | class FormatConverter 7 | { 8 | private readonly InputParser _inputParser; 9 | private readonly IDocumentSerializer _documentSerializer; 10 | 11 | public FormatConverter() 12 | { 13 | //_documentSerializer = new CamleCaseJsonSerializer(); 14 | _documentSerializer = new JsonDocumentSerializer(); 15 | //_inputParser = new InputParser(); 16 | _inputParser = new XmlInputParser(); 17 | } 18 | internal bool ConvertFormat(string sourceFileName, string targetFileName) 19 | { 20 | string input; 21 | var documentStorage = GetDocumentStorage(sourceFileName); 22 | try 23 | { 24 | input = documentStorage.GetData(sourceFileName); 25 | } 26 | catch (FileNotFoundException) 27 | { 28 | return false; 29 | } 30 | 31 | var doc = _inputParser.ParseInput(input); 32 | var serializedDoc = _documentSerializer.Serilize(doc); 33 | 34 | try 35 | { 36 | documentStorage.PersistDocument(serializedDoc, targetFileName); 37 | } 38 | catch (AccessViolationException) 39 | { 40 | return false; 41 | } 42 | return true; 43 | } 44 | 45 | internal DocumentStorage GetDocumentStorage(string sourceFileName) 46 | { 47 | if (sourceFileName.StartsWith("http")) 48 | return new HttpInputRetriever(); 49 | return new FileDocumentStorage(); 50 | } 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Views/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Web.Http; 7 | using DataModel; 8 | 9 | namespace RestDataCenter.Controllers 10 | { 11 | public class ValuesController : ApiController 12 | { 13 | // GET api/values 14 | public Student[] Get() 15 | { 16 | List students = new List(); 17 | Student student1 = new Student() 18 | { 19 | StudentId = Guid.NewGuid(), 20 | FirstName = "Derartu", 21 | LastName = "Tulu", 22 | Age = 20 23 | }; 24 | Student student2 = new Student() 25 | { 26 | StudentId = Guid.NewGuid(), 27 | FirstName = "Teddy", 28 | LastName = "Afro", 29 | Age = 21 30 | }; 31 | Student student3 = new Student() 32 | { 33 | StudentId = Guid.NewGuid(), 34 | FirstName = "Mesfin", 35 | LastName = "Negash", 36 | Age = 22 37 | }; 38 | students.Add(student1); 39 | students.Add(student2); 40 | students.Add(student3); 41 | return students.ToArray(); 42 | } 43 | 44 | // GET api/values/5 45 | public string Get(int id) 46 | { 47 | return "value"; 48 | } 49 | 50 | // POST api/values 51 | public void Post([FromBody]string value) 52 | { 53 | } 54 | 55 | // PUT api/values/5 56 | public void Put(int id, [FromBody]string value) 57 | { 58 | } 59 | 60 | // DELETE api/values/5 61 | public void Delete(int id) 62 | { 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/FormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace AddisCode.SolidPrinciple.Dip 5 | { 6 | class FormatConverter 7 | { 8 | private readonly InputParser _inputParser; 9 | private readonly IDocumentSerializer _documentSerializer; 10 | 11 | public FormatConverter(IDocumentSerializer documentSerializer, InputParser parser) 12 | { 13 | _documentSerializer = documentSerializer; 14 | _inputParser = parser; 15 | } 16 | internal bool ConvertFormat(string sourceFileName, string targetFileName) 17 | { 18 | string input; 19 | var inputRetriver = GetInputRetriever(sourceFileName); 20 | var inputPersister = GetInputPersister(targetFileName); 21 | try 22 | { 23 | input = inputRetriver.GetData(sourceFileName); 24 | } 25 | catch (FileNotFoundException) 26 | { 27 | return false; 28 | } 29 | 30 | var doc = _inputParser.ParseInput(input); 31 | var serializedDoc = _documentSerializer.Serilize(doc); 32 | 33 | try 34 | { 35 | inputPersister.PersistDocument(serializedDoc, targetFileName); 36 | } 37 | catch (AccessViolationException) 38 | { 39 | return false; 40 | } 41 | return true; 42 | } 43 | 44 | internal IInputRetriever GetInputRetriever(string sourceFileName) 45 | { 46 | if (sourceFileName.StartsWith("http")) 47 | return new HttpInputRetriever(); 48 | return new FileDocumentStorage(); 49 | } 50 | internal IInputPersister GetInputPersister(string targetFileName) 51 | { 52 | return new FileDocumentStorage(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/HelpPage.css: -------------------------------------------------------------------------------- 1 | pre.wrapped { 2 | white-space: -moz-pre-wrap; 3 | white-space: -pre-wrap; 4 | white-space: -o-pre-wrap; 5 | white-space: pre-wrap; 6 | } 7 | 8 | .warning-message-container { 9 | margin-top: 20px; 10 | padding: 0 10px; 11 | color: #525252; 12 | background: #EFDCA9; 13 | border: 1px solid #CCCCCC; 14 | } 15 | 16 | .help-page-table { 17 | width: 100%; 18 | border-collapse: collapse; 19 | text-align: left; 20 | margin: 0px 0px 20px 0px; 21 | border-top: 2px solid #D4D4D4; 22 | } 23 | 24 | .help-page-table th { 25 | text-align: left; 26 | font-weight: bold; 27 | border-bottom: 2px solid #D4D4D4; 28 | padding: 8px 6px 8px 6px; 29 | } 30 | 31 | .help-page-table td { 32 | border-bottom: 2px solid #D4D4D4; 33 | padding: 15px 8px 15px 8px; 34 | vertical-align: top; 35 | } 36 | 37 | .help-page-table pre, .help-page-table p { 38 | margin: 0px; 39 | padding: 0px; 40 | font-family: inherit; 41 | font-size: 100%; 42 | } 43 | 44 | .help-page-table tbody tr:hover td { 45 | background-color: #F3F3F3; 46 | } 47 | 48 | a:hover { 49 | background-color: transparent; 50 | } 51 | 52 | .sample-header { 53 | border: 2px solid #D4D4D4; 54 | background: #76B8DB; 55 | color: #FFFFFF; 56 | padding: 8px 15px; 57 | border-bottom: none; 58 | display: inline-block; 59 | margin: 10px 0px 0px 0px; 60 | } 61 | 62 | .sample-content { 63 | display: block; 64 | border-width: 0; 65 | padding: 15px 20px; 66 | background: #FFFFFF; 67 | border: 2px solid #D4D4D4; 68 | margin: 0px 0px 10px 0px; 69 | } 70 | 71 | .api-name { 72 | width: 40%; 73 | } 74 | 75 | .api-documentation { 76 | width: 60%; 77 | } 78 | 79 | .parameter-name { 80 | width: 20%; 81 | } 82 | 83 | .parameter-documentation { 84 | width: 50%; 85 | } 86 | 87 | .parameter-source { 88 | width: 30%; 89 | } 90 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Collections.ObjectModel 2 | @using System.Web.Http.Description 3 | @using System.Threading 4 | @model Collection 5 | 6 | 7 | 8 | 9 | 10 | 11 | @foreach (ApiParameterDescription parameter in Model) 12 | { 13 | string parameterDocumentation = parameter.Documentation != null ? 14 | parameter.Documentation : 15 | "No documentation available."; 16 | 17 | // Don't show CancellationToken because it's a special parameter 18 | if (parameter.ParameterDescriptor == null || 19 | (parameter.ParameterDescriptor != null && 20 | !typeof(CancellationToken).IsAssignableFrom(parameter.ParameterDescriptor.ParameterType))) 21 | { 22 | 23 | 24 | 25 | 40 | 41 | } 42 | } 43 | 44 |
NameDescriptionAdditional information
@parameter.Name
@parameterDocumentation
26 | @switch (parameter.Source) 27 | { 28 | case ApiParameterSource.FromBody: 29 |

Define this parameter in the request body.

30 | break; 31 | case ApiParameterSource.FromUri: 32 |

Define this parameter in the request URI.

33 | break; 34 | case ApiParameterSource.Unknown: 35 | default: 36 |

None.

37 | break; 38 | } 39 |
-------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/FormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace AddisCode.SolidPrinciple.Isp 5 | { 6 | class FormatConverter 7 | { 8 | private readonly InputParser _inputParser; 9 | private readonly IDocumentSerializer _documentSerializer; 10 | 11 | public FormatConverter() 12 | { 13 | //_documentSerializer = new CamleCaseJsonSerializer(); 14 | _documentSerializer = new JsonDocumentSerializer(); 15 | //_inputParser = new InputParser(); 16 | _inputParser = new XmlInputParser(); 17 | } 18 | internal bool ConvertFormat(string sourceFileName, string targetFileName) 19 | { 20 | string input; 21 | var inputRetriver = GetInputRetriever(sourceFileName); 22 | var inputPersister = GetInputPersister(targetFileName); 23 | try 24 | { 25 | input = inputRetriver.GetData(sourceFileName); 26 | } 27 | catch (FileNotFoundException) 28 | { 29 | return false; 30 | } 31 | 32 | var doc = _inputParser.ParseInput(input); 33 | var serializedDoc = _documentSerializer.Serilize(doc); 34 | 35 | try 36 | { 37 | inputPersister.PersistDocument(serializedDoc, targetFileName); 38 | } 39 | catch (AccessViolationException) 40 | { 41 | return false; 42 | } 43 | return true; 44 | } 45 | 46 | internal IInputRetriever GetInputRetriever(string sourceFileName) 47 | { 48 | if (sourceFileName.StartsWith("http")) 49 | return new HttpInputRetriever(); 50 | return new FileDocumentStorage(); 51 | } 52 | internal IInputPersister GetInputPersister(string targetFileName) 53 | { 54 | return new FileDocumentStorage(); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/TrainingDocumentCreater/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using DataModel; 8 | 9 | namespace TrainingDocumentCreater 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 16 | List students = new List(); 17 | Student student1 = new Student() 18 | { 19 | StudentId = Guid.NewGuid(), 20 | FirstName = "Derartu", 21 | LastName = "Tulu", 22 | Age = 20 23 | }; 24 | Student student2 = new Student() 25 | { 26 | StudentId = Guid.NewGuid(), 27 | FirstName = "Teddy", 28 | LastName = "Afro", 29 | Age = 21 30 | }; 31 | Student student3 = new Student() 32 | { 33 | StudentId = Guid.NewGuid(), 34 | FirstName = "Mesfin", 35 | LastName = "Negash", 36 | Age = 22 37 | }; 38 | students.Add(student1); 39 | students.Add(student2); 40 | students.Add(student3); 41 | string output = ""; 42 | for (int index = 0; index < 3; index++) 43 | { 44 | output += students.ElementAt(index).StudentId.ToString() + ","; 45 | output += students.ElementAt(index).FirstName + ","; 46 | output += students.ElementAt(index).LastName + ","; 47 | output += students.ElementAt(index).Age.ToString(); 48 | if (index!=2) 49 | output += '\n'; 50 | } 51 | using (var stream = File.Open(sourceFileName, FileMode.Create, FileAccess.Write)) 52 | using (var sw = new StreamWriter(stream)) 53 | { 54 | sw.Write(output); 55 | sw.Close(); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/DocumentStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | 6 | namespace AddisCode.SolidPrinciple.Lsp 7 | { 8 | public abstract class DocumentStorage 9 | { 10 | public abstract string GetData(string sourceFileName); 11 | 12 | public abstract void PersistDocument(object serializedDoc, string targetFileName); 13 | } 14 | 15 | public class FileDocumentStorage : DocumentStorage 16 | { 17 | public override string GetData(string sourceFileName) 18 | { 19 | string output; 20 | using (var stream = File.OpenRead(sourceFileName)) 21 | using (var reader = new StreamReader(stream)) 22 | { 23 | output = reader.ReadToEnd(); 24 | } 25 | return output; 26 | } 27 | 28 | public override void PersistDocument(object serializedDoc, string targetFileName) 29 | { 30 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 31 | using (var sw = new StreamWriter(stream)) 32 | { 33 | sw.Write(serializedDoc); 34 | sw.Close(); 35 | } 36 | } 37 | } 38 | 39 | public class HttpInputRetriever : DocumentStorage 40 | { 41 | public override string GetData(string sourceFileName) 42 | { 43 | if (!sourceFileName.StartsWith("http:")) 44 | throw new TargetException(); 45 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sourceFileName); 46 | request.Method = "GET"; 47 | String input = String.Empty; 48 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 49 | { 50 | Stream dataStream = response.GetResponseStream(); 51 | StreamReader reader = new StreamReader(dataStream); 52 | input = reader.ReadToEnd(); 53 | reader.Close(); 54 | dataStream.Close(); 55 | } 56 | return input; 57 | } 58 | 59 | public override void PersistDocument(object serializedDoc, string targetFileName) 60 | { 61 | throw new System.NotImplementedException(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/DocumentStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | 6 | namespace AddisCode.SolidPrinciple.Ocp 7 | { 8 | public abstract class DocumentStorage 9 | { 10 | public abstract string GetData(string sourceFileName); 11 | 12 | public abstract void PersistDocument(object serializedDoc, string targetFileName); 13 | } 14 | 15 | public class FileDocumentStorage : DocumentStorage 16 | { 17 | public override string GetData(string sourceFileName) 18 | { 19 | string output; 20 | using (var stream = File.OpenRead(sourceFileName)) 21 | using (var reader = new StreamReader(stream)) 22 | { 23 | output = reader.ReadToEnd(); 24 | } 25 | return output; 26 | } 27 | 28 | public override void PersistDocument(object serializedDoc, string targetFileName) 29 | { 30 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 31 | using (var sw = new StreamWriter(stream)) 32 | { 33 | sw.Write(serializedDoc); 34 | sw.Close(); 35 | } 36 | } 37 | } 38 | 39 | public class HttpInputRetriever : DocumentStorage 40 | { 41 | public override string GetData(string sourceFileName) 42 | { 43 | if (!sourceFileName.StartsWith("http:")) 44 | throw new TargetException(); 45 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sourceFileName); 46 | request.Method = "GET"; 47 | String input = String.Empty; 48 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 49 | { 50 | Stream dataStream = response.GetResponseStream(); 51 | StreamReader reader = new StreamReader(dataStream); 52 | input = reader.ReadToEnd(); 53 | reader.Close(); 54 | dataStream.Close(); 55 | } 56 | return input; 57 | } 58 | 59 | public override void PersistDocument(object serializedDoc, string targetFileName) 60 | { 61 | throw new System.NotImplementedException(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/DocumentStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | 6 | namespace AddisCode.SolidPrinciple.Dip 7 | { 8 | public interface IInputRetriever 9 | { 10 | string GetData(string sourceFileName); 11 | } 12 | 13 | public interface IInputPersister 14 | { 15 | void PersistDocument(object serializedDoc, string targetFileName); 16 | 17 | } 18 | public abstract class DocumentStorage : IInputRetriever, IInputPersister 19 | { 20 | public abstract string GetData(string sourceFileName); 21 | 22 | public abstract void PersistDocument(object serializedDoc, string targetFileName); 23 | } 24 | 25 | public class FileDocumentStorage : DocumentStorage 26 | { 27 | public override string GetData(string sourceFileName) 28 | { 29 | string output; 30 | using (var stream = File.OpenRead(sourceFileName)) 31 | using (var reader = new StreamReader(stream)) 32 | { 33 | output = reader.ReadToEnd(); 34 | } 35 | return output; 36 | } 37 | 38 | public override void PersistDocument(object serializedDoc, string targetFileName) 39 | { 40 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 41 | using (var sw = new StreamWriter(stream)) 42 | { 43 | sw.Write(serializedDoc); 44 | sw.Close(); 45 | } 46 | } 47 | } 48 | 49 | public class HttpInputRetriever : IInputRetriever 50 | { 51 | public string GetData(string sourceFileName) 52 | { 53 | if (!sourceFileName.StartsWith("http:")) 54 | throw new TargetException(); 55 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sourceFileName); 56 | request.Method = "GET"; 57 | String input = String.Empty; 58 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 59 | { 60 | Stream dataStream = response.GetResponseStream(); 61 | StreamReader reader = new StreamReader(dataStream); 62 | input = reader.ReadToEnd(); 63 | reader.Close(); 64 | dataStream.Close(); 65 | } 66 | return input; 67 | } 68 | 69 | } 70 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/DocumentStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Reflection; 5 | 6 | namespace AddisCode.SolidPrinciple.Isp 7 | { 8 | public interface IInputRetriever 9 | { 10 | string GetData(string sourceFileName); 11 | } 12 | 13 | public interface IInputPersister 14 | { 15 | void PersistDocument(object serializedDoc, string targetFileName); 16 | 17 | } 18 | public abstract class DocumentStorage : IInputRetriever, IInputPersister 19 | { 20 | public abstract string GetData(string sourceFileName); 21 | 22 | public abstract void PersistDocument(object serializedDoc, string targetFileName); 23 | } 24 | 25 | public class FileDocumentStorage : DocumentStorage 26 | { 27 | public override string GetData(string sourceFileName) 28 | { 29 | string output; 30 | using (var stream = File.OpenRead(sourceFileName)) 31 | using (var reader = new StreamReader(stream)) 32 | { 33 | output = reader.ReadToEnd(); 34 | } 35 | return output; 36 | } 37 | 38 | public override void PersistDocument(object serializedDoc, string targetFileName) 39 | { 40 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 41 | using (var sw = new StreamWriter(stream)) 42 | { 43 | sw.Write(serializedDoc); 44 | sw.Close(); 45 | } 46 | } 47 | } 48 | 49 | public class HttpInputRetriever : IInputRetriever 50 | { 51 | public string GetData(string sourceFileName) 52 | { 53 | if (!sourceFileName.StartsWith("http:")) 54 | throw new TargetException(); 55 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sourceFileName); 56 | request.Method = "GET"; 57 | String input = String.Empty; 58 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 59 | { 60 | Stream dataStream = response.GetResponseStream(); 61 | StreamReader reader = new StreamReader(dataStream); 62 | input = reader.ReadToEnd(); 63 | reader.Close(); 64 | dataStream.Close(); 65 | } 66 | return input; 67 | } 68 | 69 | } 70 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/InputParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using DataModel; 6 | 7 | namespace AddisCode.SolidPrinciple.Dip 8 | { 9 | public class InputParser 10 | { 11 | public virtual Student[] ParseInput(string input) 12 | { 13 | string[] studentsRead = input.Split('\n'); 14 | List students = new List(); 15 | try 16 | { 17 | foreach (var studentRead in studentsRead) 18 | { 19 | string[] studentData = studentRead.Split(','); 20 | Student student = new Student() 21 | { 22 | StudentId = Guid.Parse(studentData[0]), 23 | FirstName = studentData[1], 24 | LastName = studentData[2], 25 | Age = int.Parse(studentData[3]) 26 | }; 27 | students.Add(student); 28 | } 29 | } 30 | catch (Exception e) 31 | { 32 | throw new InvalidInputFormatException(); 33 | } 34 | return students.ToArray(); 35 | 36 | } 37 | } 38 | 39 | public class XmlInputParser : InputParser 40 | { 41 | public override Student[] ParseInput(string input) 42 | { 43 | try 44 | { 45 | var xDoc = XDocument.Parse(input); 46 | IEnumerable rootElements; 47 | rootElements = xDoc.Root.Elements(); 48 | Student[] students = new Student[rootElements.Count()]; 49 | for (int index = 0; index < students.Length; index++) 50 | { 51 | var xStudent = rootElements.ElementAt(index).Elements().ToArray(); 52 | Student student = new Student() 53 | { 54 | StudentId = Guid.Parse(xStudent[3].Value), 55 | FirstName = xStudent[1].Value, 56 | LastName = xStudent[2].Value, 57 | Age = int.Parse(xStudent[0].Value) 58 | }; 59 | students[index] = student; 60 | } 61 | return students; 62 | } 63 | catch (Exception) 64 | { 65 | throw new InvalidInputFormatException() ; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/InputParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using DataModel; 6 | 7 | namespace AddisCode.SolidPrinciple.Isp 8 | { 9 | public class InputParser 10 | { 11 | public virtual Student[] ParseInput(string input) 12 | { 13 | string[] studentsRead = input.Split('\n'); 14 | List students = new List(); 15 | try 16 | { 17 | foreach (var studentRead in studentsRead) 18 | { 19 | string[] studentData = studentRead.Split(','); 20 | Student student = new Student() 21 | { 22 | StudentId = Guid.Parse(studentData[0]), 23 | FirstName = studentData[1], 24 | LastName = studentData[2], 25 | Age = int.Parse(studentData[3]) 26 | }; 27 | students.Add(student); 28 | } 29 | } 30 | catch (Exception e) 31 | { 32 | throw new InvalidInputFormatException(); 33 | } 34 | return students.ToArray(); 35 | 36 | } 37 | } 38 | 39 | public class XmlInputParser : InputParser 40 | { 41 | public override Student[] ParseInput(string input) 42 | { 43 | try 44 | { 45 | var xDoc = XDocument.Parse(input); 46 | IEnumerable rootElements; 47 | rootElements = xDoc.Root.Elements(); 48 | Student[] students = new Student[rootElements.Count()]; 49 | for (int index = 0; index < students.Length; index++) 50 | { 51 | var xStudent = rootElements.ElementAt(index).Elements().ToArray(); 52 | Student student = new Student() 53 | { 54 | StudentId = Guid.Parse(xStudent[3].Value), 55 | FirstName = xStudent[1].Value, 56 | LastName = xStudent[2].Value, 57 | Age = int.Parse(xStudent[0].Value) 58 | }; 59 | students[index] = student; 60 | } 61 | return students; 62 | } 63 | catch (Exception) 64 | { 65 | throw new InvalidInputFormatException() ; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/InputParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using DataModel; 6 | 7 | namespace AddisCode.SolidPrinciple.Lsp 8 | { 9 | public class InputParser 10 | { 11 | public virtual Student[] ParseInput(string input) 12 | { 13 | string[] studentsRead = input.Split('\n'); 14 | List students = new List(); 15 | try 16 | { 17 | foreach (var studentRead in studentsRead) 18 | { 19 | string[] studentData = studentRead.Split(','); 20 | Student student = new Student() 21 | { 22 | StudentId = Guid.Parse(studentData[0]), 23 | FirstName = studentData[1], 24 | LastName = studentData[2], 25 | Age = int.Parse(studentData[3]) 26 | }; 27 | students.Add(student); 28 | } 29 | } 30 | catch (Exception e) 31 | { 32 | throw new InvalidInputFormatException(); 33 | } 34 | return students.ToArray(); 35 | 36 | } 37 | } 38 | 39 | public class XmlInputParser : InputParser 40 | { 41 | public override Student[] ParseInput(string input) 42 | { 43 | try 44 | { 45 | var xDoc = XDocument.Parse(input); 46 | IEnumerable rootElements; 47 | rootElements = xDoc.Root.Elements(); 48 | Student[] students = new Student[rootElements.Count()]; 49 | for (int index = 0; index < students.Length; index++) 50 | { 51 | var xStudent = rootElements.ElementAt(index).Elements().ToArray(); 52 | Student student = new Student() 53 | { 54 | StudentId = Guid.Parse(xStudent[3].Value), 55 | FirstName = xStudent[1].Value, 56 | LastName = xStudent[2].Value, 57 | Age = int.Parse(xStudent[0].Value) 58 | }; 59 | students[index] = student; 60 | } 61 | return students; 62 | } 63 | catch (Exception) 64 | { 65 | throw new InvalidInputFormatException() ; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/InputParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using DataModel; 6 | 7 | namespace AddisCode.SolidPrinciple.Ocp 8 | { 9 | public class InputParser 10 | { 11 | public virtual Student[] ParseInput(string input) 12 | { 13 | string[] studentsRead = input.Split('\n'); 14 | List students = new List(); 15 | try 16 | { 17 | foreach (var studentRead in studentsRead) 18 | { 19 | string[] studentData = studentRead.Split(','); 20 | Student student = new Student() 21 | { 22 | StudentId = Guid.Parse(studentData[0]), 23 | FirstName = studentData[1], 24 | LastName = studentData[2], 25 | Age = int.Parse(studentData[3]) 26 | }; 27 | students.Add(student); 28 | } 29 | } 30 | catch (Exception e) 31 | { 32 | throw new InvalidInputFormatException(); 33 | } 34 | return students.ToArray(); 35 | 36 | } 37 | } 38 | 39 | public class XmlInputParser : InputParser 40 | { 41 | public override Student[] ParseInput(string input) 42 | { 43 | try 44 | { 45 | var xDoc = XDocument.Parse(input); 46 | IEnumerable rootElements; 47 | rootElements = xDoc.Root.Elements(); 48 | Student[] students = new Student[rootElements.Count()]; 49 | for (int index = 0; index < students.Length; index++) 50 | { 51 | var xStudent = rootElements.ElementAt(index).Elements().ToArray(); 52 | Student student = new Student() 53 | { 54 | StudentId = Guid.Parse(xStudent[3].Value), 55 | FirstName = xStudent[1].Value, 56 | LastName = xStudent[2].Value, 57 | Age = int.Parse(xStudent[0].Value) 58 | }; 59 | students[index] = student; 60 | } 61 | return students; 62 | } 63 | catch (Exception) 64 | { 65 | throw new InvalidInputFormatException() ; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/DataModel/DataModel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA} 8 | Library 9 | Properties 10 | Student 11 | Student 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Refactored/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Newtonsoft.Json; 8 | using DataModel; 9 | 10 | namespace AddisCode.SolidPrinciple.Refactored 11 | { 12 | class Program 13 | { 14 | static void Main(string[] args) 15 | { 16 | var sourceFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Input Dcocuments\\Document1.csv "); 17 | var targetFileName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\Ouput Dcocuments\\Document1.json "); 18 | var input = GetInput(sourceFileName); 19 | var students = GetStudents(input); 20 | var serializedDoc = SerializeStudents(students); 21 | PersistStudents(serializedDoc, targetFileName); 22 | } 23 | 24 | private static string GetInput (string sourceFileName) 25 | { 26 | string output; 27 | using (var stream = File.OpenRead(sourceFileName)) 28 | using (var reader = new StreamReader(stream)) 29 | { 30 | output = reader.ReadToEnd(); 31 | } 32 | return output; 33 | } 34 | private static Student[] GetStudents(string input) 35 | { 36 | string[] studentsRead = input.Split('\n'); 37 | List students = new List(); 38 | foreach (var studentRead in studentsRead) 39 | { 40 | string[] studentData = studentRead.Split(','); 41 | Student student = new Student() 42 | { 43 | StudentId = Guid.Parse(studentData[0]), 44 | FirstName = studentData[1], 45 | LastName = studentData[2], 46 | Age = int.Parse(studentData[3]) 47 | }; 48 | students.Add(student); 49 | } 50 | return students.ToArray(); 51 | } 52 | private static string SerializeStudents(Student[] students) 53 | { 54 | return JsonConvert.SerializeObject(students); 55 | } 56 | private static void PersistStudents(string serializedDoc, string targetFileName) 57 | { 58 | using (var stream = File.Open(targetFileName, FileMode.Create, FileAccess.Write)) 59 | using (var sw = new StreamWriter(stream)) 60 | { 61 | sw.Write(serializedDoc); 62 | sw.Close(); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/TrainingDocumentCreater/TrainingDocumentCreater.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {14A65821-DEC7-4CC6-B319-617F0077ACF9} 8 | Exe 9 | Properties 10 | TrainingDocumentCreater 11 | TrainingDocumentCreater 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 53 | DataModel 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/Entities/Car.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AddisCode.SolidPrinciple.Lsp.Principles.Entities 9 | { 10 | public class Car 11 | { 12 | private bool _hasFuel = true; 13 | public bool IsEngineRunning { get; private set; } 14 | public Color Color { get; protected set; } 15 | 16 | public Car(Color color) 17 | { 18 | this.Color = color; 19 | } 20 | 21 | public virtual void StartEngine() 22 | { 23 | if (!_hasFuel) 24 | throw new OutOfFuelException("Cant start car without Fuel in tansk..."); 25 | IsEngineRunning = true; 26 | 27 | } 28 | public virtual void StopEngine() 29 | { 30 | IsEngineRunning = false; 31 | } 32 | 33 | } 34 | public class BrokenCar : Car 35 | { 36 | public BrokenCar(Color color) : base(color) 37 | { 38 | } 39 | 40 | public override void StartEngine() 41 | { 42 | throw new NotImplementedException(); 43 | } 44 | } 45 | 46 | public class CrimeBossCar : Car 47 | { 48 | private readonly bool _boobyTrap; 49 | public CrimeBossCar(Color color, bool boobyTrap) : base(color) 50 | { 51 | _boobyTrap = boobyTrap; 52 | } 53 | 54 | public override void StartEngine() 55 | { 56 | if (_boobyTrap) 57 | throw new MetYourMakerException("Boom!! You are dead!"); 58 | base.StartEngine(); 59 | } 60 | } 61 | 62 | public class Prius : Car 63 | { 64 | public Prius(Color color) : base(color) 65 | { 66 | } 67 | 68 | public override void StartEngine() 69 | { 70 | } 71 | 72 | public override void StopEngine() 73 | { 74 | } 75 | } 76 | 77 | public class StolenCar : Car 78 | { 79 | private bool _ignitionWiresStripped; 80 | 81 | public StolenCar(Color color) : base(color) 82 | { 83 | } 84 | 85 | public void StripIgnitionWire() 86 | { 87 | _ignitionWiresStripped = true; 88 | } 89 | 90 | public override void StartEngine() 91 | { 92 | if (!_ignitionWiresStripped) 93 | return; 94 | base.StartEngine(); 95 | } 96 | } 97 | 98 | public class PimpedCar : Car 99 | { 100 | private readonly Color _color; 101 | public PimpedCar(Color color) : base(color) 102 | { 103 | } 104 | 105 | public void setTempreture(int temp) 106 | { 107 | if (temp < 25) 108 | this.Color = _color; 109 | else 110 | Color = Color.Crimson; 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/Views/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/App_Start/HelpPageConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http.Headers; 4 | using System.Web; 5 | using System.Web.Http; 6 | 7 | namespace RestDataCenter.Areas.HelpPage 8 | { 9 | /// 10 | /// Use this class to customize the Help Page. 11 | /// For example you can set a custom to supply the documentation 12 | /// or you can provide the samples for the requests/responses. 13 | /// 14 | public static class HelpPageConfig 15 | { 16 | public static void Register(HttpConfiguration config) 17 | { 18 | //// Uncomment the following to use the documentation from XML documentation file. 19 | //config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 20 | 21 | //// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type. 22 | //// Also, the string arrays will be used for IEnumerable. The sample objects will be serialized into different media type 23 | //// formats by the available formatters. 24 | //config.SetSampleObjects(new Dictionary 25 | //{ 26 | // {typeof(string), "sample string"}, 27 | // {typeof(IEnumerable), new string[]{"sample 1", "sample 2"}} 28 | //}); 29 | 30 | //// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format 31 | //// and have IEnumerable as the body parameter or return type. 32 | //config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable)); 33 | 34 | //// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values" 35 | //// and action named "Put". 36 | //config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put"); 37 | 38 | //// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png" 39 | //// on the controller named "Values" and action named "Get" with parameter "id". 40 | //config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id"); 41 | 42 | //// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent. 43 | //// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter. 44 | //config.SetActualRequestType(typeof(string), "Values", "Get"); 45 | 46 | //// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent. 47 | //// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string. 48 | //config.SetActualResponseType(typeof(string), "Values", "Post"); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Refactored/AddisCode.SolidPrinciple.Refactored.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {905F1783-FC0C-4E8F-9A21-248A0031604D} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Refactored 11 | AddisCode.SolidPrinciple.Refactored 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 57 | DataModel 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | *.publishproj 132 | 133 | # NuGet Packages 134 | *.nupkg 135 | # The packages folder can be ignored because of Package Restore 136 | **/packages/* 137 | # except build/, which is used as an MSBuild target. 138 | !**/packages/build/ 139 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 140 | #!**/packages/repositories.config 141 | 142 | # Windows Azure Build Output 143 | csx/ 144 | *.build.csdef 145 | 146 | # Windows Store app package directory 147 | AppPackages/ 148 | 149 | # Others 150 | sql/ 151 | *.Cache 152 | ClientBin/ 153 | [Ss]tyle[Cc]op.* 154 | ~$* 155 | *~ 156 | *.dbmdl 157 | *.dbproj.schemaview 158 | *.pfx 159 | *.publishsettings 160 | node_modules/ 161 | 162 | # RIA/Silverlight projects 163 | Generated_Code/ 164 | 165 | # Backup & report files from converting an old project file 166 | # to a newer Visual Studio version. Backup files are not needed, 167 | # because we have git ;-) 168 | _UpgradeReport_Files/ 169 | Backup*/ 170 | UpgradeLog*.XML 171 | UpgradeLog*.htm 172 | 173 | # SQL Server files 174 | *.mdf 175 | *.ldf 176 | 177 | # Business Intelligence projects 178 | *.rdl.data 179 | *.bim.layout 180 | *.bim_*.settings 181 | 182 | # Microsoft Fakes 183 | FakesAssemblies/ 184 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Isp/AddisCode.SolidPrinciple.Isp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Isp 11 | AddisCode.SolidPrinciple.Isp 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 62 | DataModel 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp/AddisCode.SolidPrinciple.Lsp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Lsp 11 | AddisCode.SolidPrinciple.Lsp 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 62 | DataModel 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Ocp/AddisCode.SolidPrinciple.Ocp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Ocp 11 | AddisCode.SolidPrinciple.Ocp 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA} 62 | DataModel 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Srp/AddisCode.SolidPrinciple.Srp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Srp 11 | AddisCode.SolidPrinciple.Srp 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 62 | DataModel 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Dip/AddisCode.SolidPrinciple.Dip.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC} 8 | Exe 9 | Properties 10 | AddisCode.SolidPrinciple.Dip 11 | AddisCode.SolidPrinciple.Dip 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\..\..\..\Bitbucket\cardmanager\CardManager.CardAPI\bin\Debug\Microsoft.Practices.Unity.dll 37 | 38 | 39 | ..\..\..\..\Bitbucket\cardmanager\CardManager.API.Host\bin\Microsoft.Practices.Unity.Configuration.dll 40 | 41 | 42 | ..\..\..\..\Bitbucket\cardmanager\CardManager.API.Host\bin\Microsoft.Practices.Unity.RegistrationByConvention.dll 43 | 44 | 45 | False 46 | ..\..\..\..\Resources\Cloned Repos\Thinktecture.IdentityServer.v3.Samples\source\OAuthJS\JsImplicitOAuthLibraryDemo\bin\Newtonsoft.Json.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {ac111749-d8c2-41e1-bed4-fc27f7f3b9ea} 71 | DataModel 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Scripts/respond.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 16 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 17 | window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.style.background="none";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document); 18 | 19 | /*! Respond.js v1.2.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ 20 | (function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var w=e.document,s=w.documentElement,i=[],k=[],q=[],o={},h=30,f=w.getElementsByTagName("head")[0]||s,g=w.getElementsByTagName("base")[0],b=f.getElementsByTagName("link"),d=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,v=function(){var z,A=w.createElement("div"),x=w.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=w.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=w.compatMode==="CSS1Compat"&&B||w.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();if(I&&l&&z-l-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this); -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SolidPrinciple.Lsp.Principles/AddisCode.SolidPrinciple.Lsp.Principles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {B43B9959-184C-44B1-A834-A2BE292184D8} 7 | Library 8 | Properties 9 | AddisCode.SolidPrinciple.Lsp.Principles 10 | AddisCode.SolidPrinciple.Lsp.Principles 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | False 65 | 66 | 67 | False 68 | 69 | 70 | False 71 | 72 | 73 | False 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Project_Readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Your ASP.NET application 6 | 95 | 96 | 97 | 98 | 102 | 103 |
104 |
105 |

This application consists of:

106 |
    107 |
  • Help Page for documenting your Web APIs
  • 108 |
  • Theming using Bootstrap
  • 109 |
  • Authentication, if selected, shows how to register and sign in
  • 110 |
  • ASP.NET features managed using NuGet
  • 111 |
112 |
113 | 114 | 130 | 131 |
132 |

Deploy

133 | 138 |
139 | 140 |
141 |

Get help

142 | 146 |
147 |
148 | 149 | 150 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/XmlDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Web.Http.Controllers; 6 | using System.Web.Http.Description; 7 | using System.Xml.XPath; 8 | 9 | namespace RestDataCenter.Areas.HelpPage 10 | { 11 | /// 12 | /// A custom that reads the API documentation from an XML documentation file. 13 | /// 14 | public class XmlDocumentationProvider : IDocumentationProvider 15 | { 16 | private XPathNavigator _documentNavigator; 17 | private const string TypeExpression = "/doc/members/member[@name='T:{0}']"; 18 | private const string MethodExpression = "/doc/members/member[@name='M:{0}']"; 19 | private const string ParameterExpression = "param[@name='{0}']"; 20 | 21 | /// 22 | /// Initializes a new instance of the class. 23 | /// 24 | /// The physical path to XML document. 25 | public XmlDocumentationProvider(string documentPath) 26 | { 27 | if (documentPath == null) 28 | { 29 | throw new ArgumentNullException("documentPath"); 30 | } 31 | XPathDocument xpath = new XPathDocument(documentPath); 32 | _documentNavigator = xpath.CreateNavigator(); 33 | } 34 | 35 | public string GetDocumentation(HttpControllerDescriptor controllerDescriptor) 36 | { 37 | XPathNavigator typeNode = GetTypeNode(controllerDescriptor); 38 | return GetTagValue(typeNode, "summary"); 39 | } 40 | 41 | public virtual string GetDocumentation(HttpActionDescriptor actionDescriptor) 42 | { 43 | XPathNavigator methodNode = GetMethodNode(actionDescriptor); 44 | return GetTagValue(methodNode, "summary"); 45 | } 46 | 47 | public virtual string GetDocumentation(HttpParameterDescriptor parameterDescriptor) 48 | { 49 | ReflectedHttpParameterDescriptor reflectedParameterDescriptor = parameterDescriptor as ReflectedHttpParameterDescriptor; 50 | if (reflectedParameterDescriptor != null) 51 | { 52 | XPathNavigator methodNode = GetMethodNode(reflectedParameterDescriptor.ActionDescriptor); 53 | if (methodNode != null) 54 | { 55 | string parameterName = reflectedParameterDescriptor.ParameterInfo.Name; 56 | XPathNavigator parameterNode = methodNode.SelectSingleNode(String.Format(CultureInfo.InvariantCulture, ParameterExpression, parameterName)); 57 | if (parameterNode != null) 58 | { 59 | return parameterNode.Value.Trim(); 60 | } 61 | } 62 | } 63 | 64 | return null; 65 | } 66 | 67 | public string GetResponseDocumentation(HttpActionDescriptor actionDescriptor) 68 | { 69 | XPathNavigator methodNode = GetMethodNode(actionDescriptor); 70 | return GetTagValue(methodNode, "returns"); 71 | } 72 | 73 | private XPathNavigator GetMethodNode(HttpActionDescriptor actionDescriptor) 74 | { 75 | ReflectedHttpActionDescriptor reflectedActionDescriptor = actionDescriptor as ReflectedHttpActionDescriptor; 76 | if (reflectedActionDescriptor != null) 77 | { 78 | string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(reflectedActionDescriptor.MethodInfo)); 79 | return _documentNavigator.SelectSingleNode(selectExpression); 80 | } 81 | 82 | return null; 83 | } 84 | 85 | private static string GetMemberName(MethodInfo method) 86 | { 87 | string name = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", method.DeclaringType.FullName, method.Name); 88 | ParameterInfo[] parameters = method.GetParameters(); 89 | if (parameters.Length != 0) 90 | { 91 | string[] parameterTypeNames = parameters.Select(param => GetTypeName(param.ParameterType)).ToArray(); 92 | name += String.Format(CultureInfo.InvariantCulture, "({0})", String.Join(",", parameterTypeNames)); 93 | } 94 | 95 | return name; 96 | } 97 | 98 | private static string GetTagValue(XPathNavigator parentNode, string tagName) 99 | { 100 | if (parentNode != null) 101 | { 102 | XPathNavigator node = parentNode.SelectSingleNode(tagName); 103 | if (node != null) 104 | { 105 | return node.Value.Trim(); 106 | } 107 | } 108 | 109 | return null; 110 | } 111 | 112 | private static string GetTypeName(Type type) 113 | { 114 | if (type.IsGenericType) 115 | { 116 | // Format the generic type name to something like: Generic{System.Int32,System.String} 117 | Type genericType = type.GetGenericTypeDefinition(); 118 | Type[] genericArguments = type.GetGenericArguments(); 119 | string typeName = genericType.FullName; 120 | 121 | // Trim the generic parameter counts from the name 122 | typeName = typeName.Substring(0, typeName.IndexOf('`')); 123 | string[] argumentTypeNames = genericArguments.Select(t => GetTypeName(t)).ToArray(); 124 | return String.Format(CultureInfo.InvariantCulture, "{0}{{{1}}}", typeName, String.Join(",", argumentTypeNames)); 125 | } 126 | 127 | return type.FullName; 128 | } 129 | 130 | private XPathNavigator GetTypeNode(HttpControllerDescriptor controllerDescriptor) 131 | { 132 | Type controllerType = controllerDescriptor.ControllerType; 133 | string controllerTypeName = controllerType.FullName; 134 | if (controllerType.IsNested) 135 | { 136 | // Changing the nested type name from OuterType+InnerType to OuterType.InnerType to match the XML documentation syntax. 137 | controllerTypeName = controllerTypeName.Replace("+", "."); 138 | } 139 | string selectExpression = String.Format(CultureInfo.InvariantCulture, TypeExpression, controllerTypeName); 140 | return _documentNavigator.SelectSingleNode(selectExpression); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Areas/HelpPage/SampleGeneration/HelpPageSampleKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Net.Http.Headers; 5 | 6 | namespace RestDataCenter.Areas.HelpPage 7 | { 8 | /// 9 | /// This is used to identify the place where the sample should be applied. 10 | /// 11 | public class HelpPageSampleKey 12 | { 13 | /// 14 | /// Creates a new based on media type and CLR type. 15 | /// 16 | /// The media type. 17 | /// The CLR type. 18 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, Type type) 19 | { 20 | if (mediaType == null) 21 | { 22 | throw new ArgumentNullException("mediaType"); 23 | } 24 | if (type == null) 25 | { 26 | throw new ArgumentNullException("type"); 27 | } 28 | ControllerName = String.Empty; 29 | ActionName = String.Empty; 30 | ParameterNames = new HashSet(StringComparer.OrdinalIgnoreCase); 31 | ParameterType = type; 32 | MediaType = mediaType; 33 | } 34 | 35 | /// 36 | /// Creates a new based on , controller name, action name and parameter names. 37 | /// 38 | /// The . 39 | /// Name of the controller. 40 | /// Name of the action. 41 | /// The parameter names. 42 | public HelpPageSampleKey(SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 43 | { 44 | if (!Enum.IsDefined(typeof(SampleDirection), sampleDirection)) 45 | { 46 | throw new InvalidEnumArgumentException("sampleDirection", (int)sampleDirection, typeof(SampleDirection)); 47 | } 48 | if (controllerName == null) 49 | { 50 | throw new ArgumentNullException("controllerName"); 51 | } 52 | if (actionName == null) 53 | { 54 | throw new ArgumentNullException("actionName"); 55 | } 56 | if (parameterNames == null) 57 | { 58 | throw new ArgumentNullException("parameterNames"); 59 | } 60 | ControllerName = controllerName; 61 | ActionName = actionName; 62 | ParameterNames = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); 63 | SampleDirection = sampleDirection; 64 | } 65 | 66 | /// 67 | /// Creates a new based on media type, , controller name, action name and parameter names. 68 | /// 69 | /// The media type. 70 | /// The . 71 | /// Name of the controller. 72 | /// Name of the action. 73 | /// The parameter names. 74 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 75 | { 76 | if (mediaType == null) 77 | { 78 | throw new ArgumentNullException("mediaType"); 79 | } 80 | if (!Enum.IsDefined(typeof(SampleDirection), sampleDirection)) 81 | { 82 | throw new InvalidEnumArgumentException("sampleDirection", (int)sampleDirection, typeof(SampleDirection)); 83 | } 84 | if (controllerName == null) 85 | { 86 | throw new ArgumentNullException("controllerName"); 87 | } 88 | if (actionName == null) 89 | { 90 | throw new ArgumentNullException("actionName"); 91 | } 92 | if (parameterNames == null) 93 | { 94 | throw new ArgumentNullException("parameterNames"); 95 | } 96 | ControllerName = controllerName; 97 | ActionName = actionName; 98 | MediaType = mediaType; 99 | ParameterNames = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); 100 | SampleDirection = sampleDirection; 101 | } 102 | 103 | /// 104 | /// Gets the name of the controller. 105 | /// 106 | /// 107 | /// The name of the controller. 108 | /// 109 | public string ControllerName { get; private set; } 110 | 111 | /// 112 | /// Gets the name of the action. 113 | /// 114 | /// 115 | /// The name of the action. 116 | /// 117 | public string ActionName { get; private set; } 118 | 119 | /// 120 | /// Gets the media type. 121 | /// 122 | /// 123 | /// The media type. 124 | /// 125 | public MediaTypeHeaderValue MediaType { get; private set; } 126 | 127 | /// 128 | /// Gets the parameter names. 129 | /// 130 | public HashSet ParameterNames { get; private set; } 131 | 132 | public Type ParameterType { get; private set; } 133 | 134 | /// 135 | /// Gets the . 136 | /// 137 | public SampleDirection? SampleDirection { get; private set; } 138 | 139 | public override bool Equals(object obj) 140 | { 141 | HelpPageSampleKey otherKey = obj as HelpPageSampleKey; 142 | if (otherKey == null) 143 | { 144 | return false; 145 | } 146 | 147 | return String.Equals(ControllerName, otherKey.ControllerName, StringComparison.OrdinalIgnoreCase) && 148 | String.Equals(ActionName, otherKey.ActionName, StringComparison.OrdinalIgnoreCase) && 149 | (MediaType == otherKey.MediaType || (MediaType != null && MediaType.Equals(otherKey.MediaType))) && 150 | ParameterType == otherKey.ParameterType && 151 | SampleDirection == otherKey.SampleDirection && 152 | ParameterNames.SetEquals(otherKey.ParameterNames); 153 | } 154 | 155 | public override int GetHashCode() 156 | { 157 | int hashCode = ControllerName.ToUpperInvariant().GetHashCode() ^ ActionName.ToUpperInvariant().GetHashCode(); 158 | if (MediaType != null) 159 | { 160 | hashCode ^= MediaType.GetHashCode(); 161 | } 162 | if (SampleDirection != null) 163 | { 164 | hashCode ^= SampleDirection.GetHashCode(); 165 | } 166 | if (ParameterType != null) 167 | { 168 | hashCode ^= ParameterType.GetHashCode(); 169 | } 170 | foreach (string parameterName in ParameterNames) 171 | { 172 | hashCode ^= parameterName.ToUpperInvariant().GetHashCode(); 173 | } 174 | 175 | return hashCode; 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/AddisCode.SOLIDTraining.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrainingDocumentCreater", "TrainingDocumentCreater\TrainingDocumentCreater.csproj", "{14A65821-DEC7-4CC6-B319-617F0077ACF9}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple", "AddisCode.SolidPrinciples\AddisCode.SolidPrinciple.csproj", "{23C0FBA9-26CE-46BE-8785-54963AA8C6D9}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0. RAG", "0. RAG", "{91884358-A48B-4CF0-880B-15410081B798}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Refactored", "AddisCode.SolidPrinciple.Refactored\AddisCode.SolidPrinciple.Refactored.csproj", "{905F1783-FC0C-4E8F-9A21-248A0031604D}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1. SRP", "1. SRP", "{5BFA7A20-60E4-4F0A-88AF-CD764A1B9E8A}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Srp", "AddisCode.SolidPrinciple.Srp\AddisCode.SolidPrinciple.Srp.csproj", "{98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModel", "DataModel\DataModel.csproj", "{AC111749-D8C2-41E1-BED4-FC27F7F3B9EA}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2. OCP", "2. OCP", "{6FD40095-06E1-4B33-80FD-B7773E69900C}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Ocp", "AddisCode.SolidPrinciple.Ocp\AddisCode.SolidPrinciple.Ocp.csproj", "{F91C51E3-C4F1-4B6C-86ED-5DE37210B702}" 23 | EndProject 24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestDataCenter", "RestDataCenter\RestDataCenter.csproj", "{6F7F1BA6-FE9E-48DD-AC7E-D52F956225A1}" 25 | EndProject 26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3. LSP", "3. LSP", "{ACCD4B0E-7294-48F5-A7ED-415212E79342}" 27 | EndProject 28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Lsp", "AddisCode.SolidPrinciple.Lsp\AddisCode.SolidPrinciple.Lsp.csproj", "{949B7112-4B9A-4C78-B9A9-4C17BCF40F14}" 29 | EndProject 30 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Lsp.Principles", "AddisCode.SolidPrinciple.Lsp.Principles\AddisCode.SolidPrinciple.Lsp.Principles.csproj", "{B43B9959-184C-44B1-A834-A2BE292184D8}" 31 | EndProject 32 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4. ISP", "4. ISP", "{32B9FE00-9A4A-4DAF-967B-CDD2D8B5E190}" 33 | EndProject 34 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Isp", "AddisCode.SolidPrinciple.Isp\AddisCode.SolidPrinciple.Isp.csproj", "{5C3910BF-95CF-4824-848B-9BB31CF71F4B}" 35 | EndProject 36 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5. DIP", "5. DIP", "{3AAC9964-0986-4A16-A80B-F43FEA40CB58}" 37 | EndProject 38 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddisCode.SolidPrinciple.Dip", "AddisCode.SolidPrinciple.Dip\AddisCode.SolidPrinciple.Dip.csproj", "{E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC}" 39 | EndProject 40 | Global 41 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 42 | Debug|Any CPU = Debug|Any CPU 43 | Release|Any CPU = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 46 | {14A65821-DEC7-4CC6-B319-617F0077ACF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {14A65821-DEC7-4CC6-B319-617F0077ACF9}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {14A65821-DEC7-4CC6-B319-617F0077ACF9}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {14A65821-DEC7-4CC6-B319-617F0077ACF9}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {23C0FBA9-26CE-46BE-8785-54963AA8C6D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {23C0FBA9-26CE-46BE-8785-54963AA8C6D9}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {23C0FBA9-26CE-46BE-8785-54963AA8C6D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {23C0FBA9-26CE-46BE-8785-54963AA8C6D9}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {905F1783-FC0C-4E8F-9A21-248A0031604D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {905F1783-FC0C-4E8F-9A21-248A0031604D}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {905F1783-FC0C-4E8F-9A21-248A0031604D}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {905F1783-FC0C-4E8F-9A21-248A0031604D}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {AC111749-D8C2-41E1-BED4-FC27F7F3B9EA}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {6F7F1BA6-FE9E-48DD-AC7E-D52F956225A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {6F7F1BA6-FE9E-48DD-AC7E-D52F956225A1}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {6F7F1BA6-FE9E-48DD-AC7E-D52F956225A1}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {6F7F1BA6-FE9E-48DD-AC7E-D52F956225A1}.Release|Any CPU.Build.0 = Release|Any CPU 74 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {B43B9959-184C-44B1-A834-A2BE292184D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {B43B9959-184C-44B1-A834-A2BE292184D8}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {B43B9959-184C-44B1-A834-A2BE292184D8}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 | {B43B9959-184C-44B1-A834-A2BE292184D8}.Release|Any CPU.Build.0 = Release|Any CPU 82 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 83 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU 84 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU 85 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B}.Release|Any CPU.Build.0 = Release|Any CPU 86 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 87 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU 88 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU 89 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC}.Release|Any CPU.Build.0 = Release|Any CPU 90 | EndGlobalSection 91 | GlobalSection(SolutionProperties) = preSolution 92 | HideSolutionNode = FALSE 93 | EndGlobalSection 94 | GlobalSection(NestedProjects) = preSolution 95 | {23C0FBA9-26CE-46BE-8785-54963AA8C6D9} = {91884358-A48B-4CF0-880B-15410081B798} 96 | {905F1783-FC0C-4E8F-9A21-248A0031604D} = {91884358-A48B-4CF0-880B-15410081B798} 97 | {98EA4A22-B73D-43B5-8DBD-32A8DD5E65EF} = {5BFA7A20-60E4-4F0A-88AF-CD764A1B9E8A} 98 | {F91C51E3-C4F1-4B6C-86ED-5DE37210B702} = {6FD40095-06E1-4B33-80FD-B7773E69900C} 99 | {949B7112-4B9A-4C78-B9A9-4C17BCF40F14} = {ACCD4B0E-7294-48F5-A7ED-415212E79342} 100 | {B43B9959-184C-44B1-A834-A2BE292184D8} = {ACCD4B0E-7294-48F5-A7ED-415212E79342} 101 | {5C3910BF-95CF-4824-848B-9BB31CF71F4B} = {32B9FE00-9A4A-4DAF-967B-CDD2D8B5E190} 102 | {E9BF54FD-A150-4E42-BFF4-8F52D5C33DCC} = {3AAC9964-0986-4A16-A80B-F43FEA40CB58} 103 | EndGlobalSection 104 | EndGlobal 105 | -------------------------------------------------------------------------------- /AddisCode.SOLIDTraining/RestDataCenter/Scripts/respond.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 16 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 17 | window.matchMedia = window.matchMedia || (function(doc, undefined){ 18 | 19 | var bool, 20 | docElem = doc.documentElement, 21 | refNode = docElem.firstElementChild || docElem.firstChild, 22 | // fakeBody required for 23 | fakeBody = doc.createElement('body'), 24 | div = doc.createElement('div'); 25 | 26 | div.id = 'mq-test-1'; 27 | div.style.cssText = "position:absolute;top:-100em"; 28 | fakeBody.style.background = "none"; 29 | fakeBody.appendChild(div); 30 | 31 | return function(q){ 32 | 33 | div.innerHTML = '­'; 34 | 35 | docElem.insertBefore(fakeBody, refNode); 36 | bool = div.offsetWidth == 42; 37 | docElem.removeChild(fakeBody); 38 | 39 | return { matches: bool, media: q }; 40 | }; 41 | 42 | })(document); 43 | 44 | 45 | 46 | 47 | /*! Respond.js v1.2.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ 48 | (function( win ){ 49 | //exposed namespace 50 | win.respond = {}; 51 | 52 | //define update even in native-mq-supporting browsers, to avoid errors 53 | respond.update = function(){}; 54 | 55 | //expose media query support flag for external use 56 | respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches; 57 | 58 | //if media queries are supported, exit here 59 | if( respond.mediaQueriesSupported ){ return; } 60 | 61 | //define vars 62 | var doc = win.document, 63 | docElem = doc.documentElement, 64 | mediastyles = [], 65 | rules = [], 66 | appendedEls = [], 67 | parsedSheets = {}, 68 | resizeThrottle = 30, 69 | head = doc.getElementsByTagName( "head" )[0] || docElem, 70 | base = doc.getElementsByTagName( "base" )[0], 71 | links = head.getElementsByTagName( "link" ), 72 | requestQueue = [], 73 | 74 | //loop stylesheets, send text content to translate 75 | ripCSS = function(){ 76 | var sheets = links, 77 | sl = sheets.length, 78 | i = 0, 79 | //vars for loop: 80 | sheet, href, media, isCSS; 81 | 82 | for( ; i < sl; i++ ){ 83 | sheet = sheets[ i ], 84 | href = sheet.href, 85 | media = sheet.media, 86 | isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; 87 | 88 | //only links plz and prevent re-parsing 89 | if( !!href && isCSS && !parsedSheets[ href ] ){ 90 | // selectivizr exposes css through the rawCssText expando 91 | if (sheet.styleSheet && sheet.styleSheet.rawCssText) { 92 | translate( sheet.styleSheet.rawCssText, href, media ); 93 | parsedSheets[ href ] = true; 94 | } else { 95 | if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) 96 | || href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){ 97 | requestQueue.push( { 98 | href: href, 99 | media: media 100 | } ); 101 | } 102 | } 103 | } 104 | } 105 | makeRequests(); 106 | }, 107 | 108 | //recurse through request queue, get css text 109 | makeRequests = function(){ 110 | if( requestQueue.length ){ 111 | var thisRequest = requestQueue.shift(); 112 | 113 | ajax( thisRequest.href, function( styles ){ 114 | translate( styles, thisRequest.href, thisRequest.media ); 115 | parsedSheets[ thisRequest.href ] = true; 116 | makeRequests(); 117 | } ); 118 | } 119 | }, 120 | 121 | //find media blocks in css text, convert to style blocks 122 | translate = function( styles, href, media ){ 123 | var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ), 124 | ql = qs && qs.length || 0, 125 | //try to get CSS path 126 | href = href.substring( 0, href.lastIndexOf( "/" )), 127 | repUrls = function( css ){ 128 | return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" ); 129 | }, 130 | useMedia = !ql && media, 131 | //vars used in loop 132 | i = 0, 133 | j, fullq, thisq, eachq, eql; 134 | 135 | //if path exists, tack on trailing slash 136 | if( href.length ){ href += "/"; } 137 | 138 | //if no internal queries exist, but media attr does, use that 139 | //note: this currently lacks support for situations where a media attr is specified on a link AND 140 | //its associated stylesheet has internal CSS media queries. 141 | //In those cases, the media attribute will currently be ignored. 142 | if( useMedia ){ 143 | ql = 1; 144 | } 145 | 146 | 147 | for( ; i < ql; i++ ){ 148 | j = 0; 149 | 150 | //media attr 151 | if( useMedia ){ 152 | fullq = media; 153 | rules.push( repUrls( styles ) ); 154 | } 155 | //parse for styles 156 | else{ 157 | fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1; 158 | rules.push( RegExp.$2 && repUrls( RegExp.$2 ) ); 159 | } 160 | 161 | eachq = fullq.split( "," ); 162 | eql = eachq.length; 163 | 164 | for( ; j < eql; j++ ){ 165 | thisq = eachq[ j ]; 166 | mediastyles.push( { 167 | media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all", 168 | rules : rules.length - 1, 169 | hasquery: thisq.indexOf("(") > -1, 170 | minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ), 171 | maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ) 172 | } ); 173 | } 174 | } 175 | 176 | applyMedia(); 177 | }, 178 | 179 | lastCall, 180 | 181 | resizeDefer, 182 | 183 | // returns the value of 1em in pixels 184 | getEmValue = function() { 185 | var ret, 186 | div = doc.createElement('div'), 187 | body = doc.body, 188 | fakeUsed = false; 189 | 190 | div.style.cssText = "position:absolute;font-size:1em;width:1em"; 191 | 192 | if( !body ){ 193 | body = fakeUsed = doc.createElement( "body" ); 194 | body.style.background = "none"; 195 | } 196 | 197 | body.appendChild( div ); 198 | 199 | docElem.insertBefore( body, docElem.firstChild ); 200 | 201 | ret = div.offsetWidth; 202 | 203 | if( fakeUsed ){ 204 | docElem.removeChild( body ); 205 | } 206 | else { 207 | body.removeChild( div ); 208 | } 209 | 210 | //also update eminpx before returning 211 | ret = eminpx = parseFloat(ret); 212 | 213 | return ret; 214 | }, 215 | 216 | //cached container for 1em value, populated the first time it's needed 217 | eminpx, 218 | 219 | //enable/disable styles 220 | applyMedia = function( fromResize ){ 221 | var name = "clientWidth", 222 | docElemProp = docElem[ name ], 223 | currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp, 224 | styleBlocks = {}, 225 | lastLink = links[ links.length-1 ], 226 | now = (new Date()).getTime(); 227 | 228 | //throttle resize calls 229 | if( fromResize && lastCall && now - lastCall < resizeThrottle ){ 230 | clearTimeout( resizeDefer ); 231 | resizeDefer = setTimeout( applyMedia, resizeThrottle ); 232 | return; 233 | } 234 | else { 235 | lastCall = now; 236 | } 237 | 238 | for( var i in mediastyles ){ 239 | var thisstyle = mediastyles[ i ], 240 | min = thisstyle.minw, 241 | max = thisstyle.maxw, 242 | minnull = min === null, 243 | maxnull = max === null, 244 | em = "em"; 245 | 246 | if( !!min ){ 247 | min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 ); 248 | } 249 | if( !!max ){ 250 | max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 ); 251 | } 252 | 253 | // if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true 254 | if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){ 255 | if( !styleBlocks[ thisstyle.media ] ){ 256 | styleBlocks[ thisstyle.media ] = []; 257 | } 258 | styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] ); 259 | } 260 | } 261 | 262 | //remove any existing respond style element(s) 263 | for( var i in appendedEls ){ 264 | if( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){ 265 | head.removeChild( appendedEls[ i ] ); 266 | } 267 | } 268 | 269 | //inject active styles, grouped by media type 270 | for( var i in styleBlocks ){ 271 | var ss = doc.createElement( "style" ), 272 | css = styleBlocks[ i ].join( "\n" ); 273 | 274 | ss.type = "text/css"; 275 | ss.media = i; 276 | 277 | //originally, ss was appended to a documentFragment and sheets were appended in bulk. 278 | //this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one! 279 | head.insertBefore( ss, lastLink.nextSibling ); 280 | 281 | if ( ss.styleSheet ){ 282 | ss.styleSheet.cssText = css; 283 | } 284 | else { 285 | ss.appendChild( doc.createTextNode( css ) ); 286 | } 287 | 288 | //push to appendedEls to track for later removal 289 | appendedEls.push( ss ); 290 | } 291 | }, 292 | //tweaked Ajax functions from Quirksmode 293 | ajax = function( url, callback ) { 294 | var req = xmlHttp(); 295 | if (!req){ 296 | return; 297 | } 298 | req.open( "GET", url, true ); 299 | req.onreadystatechange = function () { 300 | if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){ 301 | return; 302 | } 303 | callback( req.responseText ); 304 | } 305 | if ( req.readyState == 4 ){ 306 | return; 307 | } 308 | req.send( null ); 309 | }, 310 | //define ajax obj 311 | xmlHttp = (function() { 312 | var xmlhttpmethod = false; 313 | try { 314 | xmlhttpmethod = new XMLHttpRequest(); 315 | } 316 | catch( e ){ 317 | xmlhttpmethod = new ActiveXObject( "Microsoft.XMLHTTP" ); 318 | } 319 | return function(){ 320 | return xmlhttpmethod; 321 | }; 322 | })(); 323 | 324 | //translate CSS 325 | ripCSS(); 326 | 327 | //expose update for re-running respond later on 328 | respond.update = ripCSS; 329 | 330 | //adjust on resize 331 | function callMedia(){ 332 | applyMedia( true ); 333 | } 334 | if( win.addEventListener ){ 335 | win.addEventListener( "resize", callMedia, false ); 336 | } 337 | else if( win.attachEvent ){ 338 | win.attachEvent( "onresize", callMedia ); 339 | } 340 | })(this); 341 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------