Posts

Donate

Generate Sample XML From XSD Using Visual Studio 2012

Image
There was a question on how to generate sample XML from an XSD without using C# or VB.NET Code. I did some googling for a few hours and then stumbled upon a tutorial from Code project which is the reference of this post. Since, Im using Visual Studio 2012, I replicated the steps based from the article. 1. Add a new XSD file to Visual Studio. In my case, I reused the example from MSDN: <xsd:schema xmlns:xsd= "http://www.w3.org/2001/XMLSchema" xmlns:tns= "http://tempuri.org" targetNamespace= "http://tempuri.org" elementFormDefault= "qualified" > <xsd:element name= "PurchaseOrder" type= "tns:PurchaseOrderType" /> <xsd:complexType name= "PurchaseOrderType" > <xsd:sequence> <xsd:element name= "ShipTo" type= "tns:USAddress" maxOccurs= "2" /> <xsd:element name= "BillTo" type= "tns:USAddress" /> </xsd:...

Apply LINQ Grouping And Sum Aggregate To A Datatable Object (VB.NET)

Image
Good day! There's a question on vb forums on how to apply LINQ grouping and aggregate function sum to a datatable object. This can be achieved by familiarizing on IGrouping which is a key/value pair interface. Here's how i did it. VB.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Dim dt As New DataTable( "tblEntTable" ) dt.Columns.Add( "ID" , GetType ( String )) dt.Columns.Add( "amount" , GetType ( Decimal )) dt.Rows.Add( New Object () { "1" , 100.51}) dt.Rows.Add( New Object () { "1" , 200.52}) dt.Rows.Add( New Object () { "2" , 500.24}) dt.Rows.Add( New Object () { "2" , 400.31}) dt.Rows.Add( New Object () { "3" , 600.88}) dt.Rows.Add( New Object () { "3" , 700.11}) Dim result = (From orders In dt.AsEnumerable Group orders By ID = orders.Field( Of String )( "ID" ) Into g = Group Select New With { Key ID, .Amount = g.Sum(Function(r) r...

Simple Array Manipulation Using Knockout.js (Add, Remove All, Remove Item, Show)

Image
Most of KnockoutJS features involves binding of a viewmodel object to the a view. But there are special cases where in you want to manipulate ordinary arrays without using ko.observableArray(). So to expound more on this post, here's a sample code below: KnockoutJS code: $(document).ready( function () { function ProductViewModel() { //product array this .Products = [{ id: '1' , name: 'Wax' }, { id: '2' , name: 'Cotton Buds' }, { id: '3' , name: 'Nova' }, { id: '4' , name: 'Milo' } ]; //insert product this .Add = function () { console.log( 'Insert Activity' ); this .Products.push({ id: '5' , name: 'Test' }); console.log( 'Total products: ' + this .Products.length); };...

Unable to get value of the property 'nodeType': object is null or undefined (Knockout JS)

After completing a simple binding using Knockout Javascript framework, I decided to transfer the script tags to the header section of the page. Upon running my code, I stumbled upon an error as stated on the title. I believe, the DOM elements have not been initialized when the binding occurs. One solution I came up was to transfer the view model script inside the document ready function. <head runat= "server" > <title>Integrate jQuery with Knockout!</title> <script type= "text/javascript" src= "Scripts/knockout-3.1.0.js" ></script> <script type= "text/javascript" src= "Scripts/jquery-1.7.1.min.js" ></script> <script type= "text/javascript" > $(document).ready( function () { var myViewModel = { personName: 'PsychoGenes' , personAge: 33 }; ko.applyBindings(myViewModel); }); </scri...

Simple Knockout.js Example In ASP.NET Web Forms

Image
Intrigued with emerging Javascript framework called knockout, I decided to try a simple example myself. As defined by Wikipedia: Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates. The underlying principles are therefore: 1. A clear separation between domain data, view components and data to be displayed 2. The presence of a clearly defined layer of specialized code to manage the relationships between the view components The features of Knockout are based on Declarative bindings: A. Automatic UI refresh (when the data model's state changes, the UI updates automatically) B. Dependency tracking C. Templating (using a native template engine although other templating engines can be used, such as jquery.tmpl) I come to a conclusion that this has similar approach to WPF MVVM. So, to get started with, download the latest Knockout.js framework here: Knockout Home Page and add reference to your html or aspx markup: Code: <!...

Loop Through HTML Elements Using GeckoFX WebBrowser

Hello, Below are snippets on how to loop through HTML Elements Using GeckoFX WebBrowser both in C# and VB.NET. C#: 1 2 3 4 5 //Note: this.DomDocument is a class which inherits the GeckoWebBrowser control foreach (GeckoElement element in this .DomDocument.GetElementsByTagName( "span" )) { //some codes here } VB.NET: 1 2 3 4 'Note: this.DomDocument is a class which inherits the GeckoWebBrowser control For Each element As GeckoElement In Me .DomDocument.GetElementsByTagName( "span" ) 'some codes here Next

Predicate Wrapper Custom Class in C#

Based from this post: Predicate Wrapper Custom Class in VB.NET , here's the equivalent classes in C#. FindTrack class: public class SystemTrack { public int ID { get ; set ; } public string Author { get ; set ; } public string Title { get ; set ; } public static bool FindIndexTrackNumber(SystemTrack systrac, int searchArg) { return systrac.ID.Equals(searchArg); } } Predicate Class: public delegate bool PredicateWrapperDelegate<T, A>(T item, A argument); public class PredicateWrapper <T, A> { private A _argument; private PredicateWrapperDelegate<T, A> _wrapperDelegate; public PredicateWrapper(A argument, PredicateWrapperDelegate<T, A> wrapperDelegate) { _argument = argument; _wrapperDelegate = wrapperDelegate; } private bool InnerPredicate(T item) { return ...

Zooming Visual Studio 2012 Code Editor

Image
Just received a newsletter from dotnet videos regarding zooming in/out the code editor. In that email, there were three ways. However, there are several options to do it as presented below: 1). Using the zoom drop down control below the code editor. 2). Using Keyboard combinations: Zoom OUT = Ctrl + Shift + Comma, Zoom IN = Ctrl + Shift + Period 3). Type a zoom level directly in the the zoom control in the bottom left corner of the editor 4). Select a common zoom level from the dropdown list in the zoom control 5). Hold Ctrl key and scroll the mouse wheel (up/down). References: Visual Studio 2012 Zoom In or Zoom Out Visual Studio 2010 Zoom In or Zoom Out Cheers!

ASP.NET MVC 4 Built-in Form Based Authentication

Image
Given that I have some background knowledge of ASP.NET Web Forms Authentication, I decided to try experimenting on MVC 4 authentication/authorization framework. Most of the articles in the internet regarding forms authentication in ASP.NET MVC are custom based approach and less on the built-in technology which is WebData.WebSecurity usage. Not until I found these articles: a. Forms Authentication Customized b. Introduction to forms based authentication in MVC 4 c. Authenticating Users In Asp.net MVC 4 So, to cut the story short, I made an application which utilized the built-in WebMatrix authentication in MVC 4. The first thing to do, is to familiarize those articles to get a good grasp on the topic. The setup of my application are as follows: 1. Web.config      1.1 Added authentication and custom errors <authentication mode= "Forms" > <forms loginUrl= "~/Account/Login" timeout= "2880" /> </...

Redirect Unauthorized Access To A Custom View Instead Of Redirecting To A Login View In ASP.NET MVC 4

One might encounter when implementing the forms authentication framework(WebMatrix)is that when a user access a specific url/controller and he/she is unauthorized, the application always redirect's to the default log-in view. In order to solve this minor issue, one solution is to develop a custom class that inherit's the AuthorizeAttribute class and override the HandleUnauthorizedRequest method as shown below: public class AuthorizeUsersAttribute : AuthorizeAttribute { private string redirectUrl = "" ; public string NotifyUrl { get { return redirectUrl; } set { redirectUrl = value ; } } public AuthorizeUsersAttribute() : base () { } public AuthorizeUsersAttribute( string redirectUrl) : base () { this .redirectUrl = redirectUrl; } protected override void HandleUnauthorizedRequest(Authorizati...

Donate