Wednesday, September 10, 2014

AngularJS: introduction to $http.get method

There is no change in HTML file as described in previous lesson.

JS File code:

var appModule = angular.module('appModule',[]);
appModule.controller('appController', function ($scope, $http) {
    $http.get('js/phones.json').success(function(data){
            $scope.phones = data;
        }
    );
    $scope.orderPro = 'age';

});

Phone.json:

[
    {"name":"iPhone","snippet":"Good Phone from json","age":1 },
    {"name":"Windows","snippet":"Above Average Phone from json","age":3 },
    {"name":"Android","snippet":"Average Phone from json","age":2 }
]


AngularJS: Getting Started

HTML File code:

<!doctype html>
<html ng-app="appModule">
<head>
    <title>My Angular App</title>
    <script src="JS\app.js"></script>

</head>
<body ng-controller="appController">
<div>
    Search : <input ng-model="query">
</div>
<div>
    <select ng-model="orderPro">
        <option value="name">Alphabetical</option>
        <option value="age">Newest</option>
    </select>
</div>
<ul>
    <li ng-repeat="phone in phones | filter:query | orderBy:orderPro">
        {{phone.name}}
        <p>
            {{phone.snippet}}
        </p>
    </li>
</ul>
</body>
</html>


JS File Code :


var appModule = angular.module('appModule',[]);

appModule.controller('appController',function($scope){

$scope.phones = [
    {'name':'iPhone','snippet':'Good Phone','age':1 },
    {'name':'Windows','snippet':'Above Average Phone','age':3 },
    {'name':'Android','snippet':'Average Phone','age':2 }
];
    $scope.orderPro = 'age';

});

Wednesday, September 3, 2014

SharePoint 2007 : How to get User Information in HTML

You can get user profile information in HTML page by querying below url and iterate through each element using jQuery.

{Web Application URL}/_layouts/userdisp.aspx?force=true

Friday, August 8, 2014

WCF Self Hosted Service using http Binding

Create Project based on WCF Service Library. This project will come with Service implementation by default as below

IService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFSelfHostingService
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}


Service.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFSelfHostingService
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}



Create Console Application and replace code as below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using WCFSelfHostingService;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/MyService/Service1");

            ServiceHost host = new ServiceHost(typeof(Service1), baseAddress);

            host.AddServiceEndpoint(typeof(WCFSelfHostingService.IService1),
                                new WSHttpBinding(), baseAddress);
            host.Open();
            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();

            // Close the ServiceHost.
            host.Close();

        }
    }
}


Create Windows Form Application and add code as below in form load event

private IService1 channel = null;
var endPoint = new EndpointAddress("http://localhost:8080/MyService/Service1");
            channel = ChannelFactory<IService1>.CreateChannel(new NetTcpBinding(), endPoint);
            string temp = channel.GetData(10);


WCF Self Hosted Service using Net Tcp Binding

Create Project based on WCF Service Library. This project will come with Service implementation by default as below

IService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFSelfHostingService
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}


Service.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFSelfHostingService
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}



Create Console Application and replace code as below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using WCFSelfHostingService;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("net.tcp://localhost:8080/MyService/Service1");

            ServiceHost host = new ServiceHost(typeof(Service1), baseAddress);

            host.AddServiceEndpoint(typeof(WCFSelfHostingService.IService1),
                                new NetTcpBinding(), baseAddress);
            host.Open();
            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();

            // Close the ServiceHost.
            host.Close();

        }
    }
}


Create Windows Form Application and add code as below in form load event

private IService1 channel = null;
var endPoint = new EndpointAddress("net.tcp://localhost:8080/MyService/Service1");
            channel = ChannelFactory<IService1>.CreateChannel(new NetTcpBinding(), endPoint);
            string temp = channel.GetData(10);

Thursday, August 7, 2014

JavaScript: Create an array with distinct random numbers with in a specified range

function getDistinctRandomIntForArray(array, range) { var n = Math.floor((Math.random() * range)); if (array.indexOf(n) == -1) { return n; } else { return getDistinctRandomIntForArray(array, range); } } function generateArrayOfRandomInts(count, range) { var array = []; for (i = 0; i < count; ++i) { array[i] = getDistinctRandomIntForArray(array, range); }; return array; }

Tuesday, June 10, 2014

SharePoint 2013: How to override user permission in SharePoint App

Each app has a manifest.xml file where the developer can define a list of resources that the app
needs access to using the AppPermissionRequests element. The following code snippet shows an
example of this element used in a provider-hosted app:

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection"
Right="Read"/>
Right="Write">
<Property Name="BaseTemplateId" Value="101"/>
</AppPermissionRequest>
<AppPermissionRequest Scope="http://sharepoint/userprofilestore/feed"
Right="Post"/>
<AppPermissionRequest Scope="http://exchange/calendars" Right="Schedule"/>
</AppPermissionRequests>

Note the highlighted line in the code snippet. The app permission requests enable the app-only
policy, which means that only the app, and not the current user, requires the needed permissions. If
an app-only policy is not used, both the app and the current user require the necessary permissions
to complete a task such as accessing the entire site collection or writing to a list. The result would be
a context that contains both the app and the user identities.