• Wriju's BLOG

    Windows 10 – Latest Developer Resources

    • 0 Comments

    Microsoft Virtual Academy Training A Developer’s Guide to Windows 10

    BUILD 2015 Sessions

    Introducing the Windows 10 App Model - http://channel9.msdn.com/Events/Build/2015/2-617

    What's New in XAML for Universal Apps - http://channel9.msdn.com/Events/Build/2015/2-629

    UX Patterns and Responsive Techniques for Universal Windows Apps - http://channel9.msdn.com/Events/Build/2015/2-658

    All That is New in the Windows Store - http://channel9.msdn.com/Events/Build/2015/2-664

    From the Small Screen to the Big Screen: Building Universal Windows App Experiences with XAML - http://channel9.msdn.com/Events/Build/2015/2-679

    Project Centennial: Converting your Classic Windows App (Win32, .Net, COM) to a Universal Windows Apps - http://channel9.msdn.com/Events/Build/2015/2-692

    Acquiring Users and Monetizing Your Apps - http://channel9.msdn.com/Events/Build/2015/2-736

    XAML Performance: Techniques for Maximizing Universal Windows App Experiences Built with XAML - http://channel9.msdn.com/Events/Build/2015/3-698

    Store: Deep Dive on Publishing Universal Windows Apps - http://channel9.msdn.com/Events/Build/2015/3-710

    Moving to the Universal Windows Platform: Porting an App from Windows 8.1 XAML or Windows Phone - http://channel9.msdn.com/Events/Build/2015/3-741

    Enjoy learning.

    Namoskar!!!

  • Wriju's BLOG

    DocumentDB Add and Read – Simple Approach

    • 0 Comments

    I wanted to create a simple sample which would Add and Read records in DocumentDB.

    Created one Windows Forms Application, added NuGet Package

    image

    Then in the Windows Forms I have added simple Text box to enter data and grid to display it.

    image

    The data model would look like, this has dependency

    using Newtonsoft.Json;

     

    //Employee Data Model
    
    public class Employee
    
    {
    
        [JsonProperty(PropertyName = "id")]
    
        public string id { get; set; }
    
        [JsonProperty(PropertyName = "FullName")]
    
        public string FullName { get; set; }
    
    }

    After that behind the button’s click event, with dependencies

    using Microsoft.Azure.Documents;
    
    using Microsoft.Azure.Documents.Client;
    
    using Microsoft.Azure.Documents.Linq; 

    The actual working code,

    //Intializing the connection using the Uri and Key
    
    var client = new DocumentClient(new Uri("https://gids.documents.azure.com:443/"), 
    
        "eBuaGTYZJ+zjyCxbIWNbT5mGgI75Uo42su6PMbK1W6zT0CbaxqfBIXIM/UlZ6AXaBsUscNZN0fFTeDJaxAsSzg==");
    
    //Give a name to a database and create if it does not exist
    
    string databaseId = "hrdatabase";
    
    var db = client.CreateDatabaseQuery()
    
                .Where(d => d.Id == databaseId)
    
                .AsEnumerable()
    
                .FirstOrDefault();
    
    if (db == null)
    
    {
    
        db = client.CreateDatabaseAsync(new Database { Id = databaseId }).Result;
    
    }
    
    //Get a Collection and create if does  not exists
    
    string collectionId = "employee_test";
    
    var col = client.CreateDocumentCollectionQuery(db.SelfLink)
    
                    .Where(c => c.Id == collectionId)
    
                    .AsEnumerable()
    
                    .FirstOrDefault();
    
    if (col == null)
    
    {
    
        var collectionSpec = new DocumentCollection { Id = collectionId };
    
        var requestOptions = new RequestOptions { OfferType = "S1" };
    
        col = client.CreateDocumentCollectionAsync(db.SelfLink, collectionSpec, requestOptions).Result;
    
    }
    
    //There is a input text box, then insert the data (any format)
    
    if (txtFullName.Text.Trim() != "") { 
    
        //Insert Record
    
        Employee emp = new Employee() { FullName = txtFullName.Text };
    
        client.CreateDocumentAsync(col.SelfLink, emp);
    
                
    
        MessageBox.Show("Records Added");
    
        txtFullName.Text = "";
    
    }
    
    //Display
    
    var dataList = client.CreateDocumentQuery<Employee>(col.DocumentsLink).AsEnumerable();
    
    dataGridEmployee.DataSource = dataList.ToList();

    This works pretty well. I wanted to just let you know how simple it is. I did not follow any pattern. You can only become Formula One driver if you know the driving. Back to basic.

    Namoskar!!!

     

  • Wriju's BLOG

    Importing data from SQL to DocumentDB

    • 1 Comments

    I have posted on Blog which shows step by step how to configure and import data from SQL Server Database to DocumentDB. Here is the Channel9 post

    http://channel9.msdn.com/Blogs/wriju/Importing-SQL-Data-to-Azure-DocumentDB

    image

     

    Namoskar!!!

  • Wriju's BLOG

    Effectively use Azure MSDN Account to avoid exceeding the quota

    • 0 Comments

    Many of you use Free MSDN Azure account for Dev/Test. This post is all about using Free Azure account which has a limited quota for use. A lot of times where these kind accounts are temporarily suspected due to the excess use.

    I am writing this based on my personal experience maintaining similar account for Dev/Test about 100+ users. I had to worry about billing and coach people if there is a mistake. 

    Where is the problem?

    Here is how MSDN account works. As an user your get x amount of $ value credited to your account. This is for one month. So you should be able to use it during this one month. But if your bill reach that limit, your account will be suspended for the remaining days of that period. Let say you have used it only for 19 days then next 20 days you cannot use it anymore. Neither you can download anything. Because Azure charges you for all the downloads. It will be activated again once new billing cycle starts.

    What is the solution?

    Solution is that you need to tell MSDN to charge against your credit card. It can be done through a small setting change in your account. This has two options. 1. You can tell to adjust for current billing only. 2. You can have this setting for the lifetime. As soon as you do this, you account is active again.

    When can this happen?

    This can happen when you use Azure resources a lot and they have high cost associate.

    This can also happen for Non-Microsoft products (interesting)

    So if you are using MSDN account and create one Oracle VM from template image. Or you create a JDK Windows Server from template, almost immediately you account might be frozen. You will get frustrated and call up Microsoft. You will almost yell at them saying that you still have dollar value showing how come they have closed it?

    Hold on!!! It is because your MSDN account does not have Oracle License. I don't know why but it happened once with me for JDK Windows Server machine as well.

    Now these are postmortems. Lets fix them before. Do you really want to be in a face palm situation after all your visionary lectures? No, you never ever wanted to. In front of customer you will definitely lose you credibility.

    Let’s discuss some of the tips to avoid premature suspension of account.

    VMs are mostly costly. So shutdown ALL your VMs on regular basis. Every day. I recommend you use PowerShell it do it. I keep one PowerShell in my desktop to do it. However, Azure Automation is the best way to schedule it. There is a nice step by step guidance on how to create Azure Automation for VM shutdown. http://blogs.technet.com/b/georgewallace/archive/2014/11/05/shutting-down-a-azure-vm-with-azure-automation.aspx. However this is only for specific VM.

    I have a blog post on shutting down all the VMs under all the subscriptions through single PowerShell. Please refer http://blogs.msdn.com/b/wriju/archive/2015/01/09/azure-powershell-shutdown-all-azure-vms.aspx. Let me know if you need any help.

    Think twice before selecting VM size. When your have powerful VMs available like A10, A11, D-Series, G-Series, it is tempting. But select as per your stomach’s capacity. Some of these hungry VMs can eat up all your credits very quickly. Like, if you want to use domain specific scenario then put your Domain Controller in a smaller machine like shared (A0). Because at a given point in time at most 2-3 users will connect to that DC.

    GRS (Geo Redundant Storage) adds additional costs. Many automated scripts available today in internet deploys server based solution and creates GRS storage account to put their VHDs. In Dev/Test you don't really need GRS. LRS is enough. I use a PawerShell script to check it and modify,

    image

    HDinsight (Hadoop cluster) is costly. if you are working on HDInsight then you just don't have any choice. The more bigger cluster you make the more quick it will be consumed. So delete as soon as you are done. Don't forget to take the backup of your script etc.

    Media Services Live Channel. This is yet another culprit. Hides nicely within portal but generates a lot of bills.

    Media Services Streaming. Something also not so cheap.

    Identify orphaned Cloud Services. Any PaaS cloud service which does not have active Production/Staging deployment is adding cost for no reason. So identify and delete them. Also there could be cloud services with VMs where you have deleted the VM but not the cloud service. 

    Choose lower Azure SQL Database (SQL Azure) tier. You really don't need SQL Database with high DTU. This account is for demos so select lower configuration wherever possible.

    Use free Web Apps. Per account one gets 10 free Web Apps (aka WebSites). Use them as much as possible.

    Virtual Network with Point-to-Site or Site-to-Site. Whenever you have Virtual Network with P2S or S2S, you have a dedicated Gateway. This adds quite a lot of dollar value. So if you really need it then use, else delete. Now there is a problem, you might need it frequently with VMs. So you need to Capture the VMs so that they are available in your “My Template” section for another deployment with similar installation inside.

    Remember when preview product is going in GA. Any service which is in preview must go to GA. So the bill will start. Like today you have DocumentDB in preview hence it is free. But from April 8 2015 onwards it will be GA. Keep this in mind and revisit.

    Note: This is purely from my experience. Any suggestions would be helpful. Also this is not recommended in Production scenario.

    Stay happy in Cloud

  • Wriju's BLOG

    When you need to care about Online Payment

    • 2 Comments

    Often times we need to pay using our credit/debit card to many E-Commerce portal. We must verify if the site is PCI compliant.  But how a normal user would know? There are cases we easily fall into the trap. We need to be more careful and understand the complexity and save our hard earned money.

    I was trying to pay in a portal where I got this screen and I wanted to ensure.

    image

    So I checked the SSL in https://www.ssllabs.com/ssltest/ and got the below output

    This seems fine to me but few areas needs little attention

    image

    What worried me here that they are using SHA1 which is kind of not recommended anymore. Following are the few points about SHA-1

    image

    image

    image

    SHA-1 is not a major concern now but eventually will be.

    As per the test web website's guide documentation https://www.ssllabs.com/projects/rating-guide/index.html, this seems manageable.

    image

    Now, I wanted to check their Certificate too,

    image

    Good thing is that they are using SHA256

    As an end user you need to keep your money safe. There is a huge list of sites being compromised. You must check https://haveibeenpwned.com/PwnedWebsites

    image

    PCI DSS Quick Reference Guide v3.0

    Be safe and play safe.

    Namoskar!!!

     

  • Wriju's BLOG

    Azure Runbook Schedule Time Zone

    • 1 Comments

    When we select the time to create the Runbook Automation Scheduler we get confused which timezone it would take. Here are they,

    1. When you use portal to create the Schedule Job for Runbook it takes the browser time and converts it to UTC

    2. When you use PowerShell or SDK then you must use UTC

    image

    Namoskar!!!

  • Wriju's BLOG

    Azure PowerShell : Shutdown All Azure VMs

    • 0 Comments

    To Shutdown all Azure VM you don't need to go to individual and then press the button. But run an elegant PowerShell

    $AzureSubscriptions = Get-AzureSubscription
    foreach ($subscription in $AzureSubscriptions)
    {
        Write-Host $subscription.SubscriptionName
    
        Select-AzureSubscription -SubscriptionName $subscription.SubscriptionName
        #Write-Host $subscription.SubscriptionName
     
        foreach ($vm in Get-AzureVM)
        {
            $name = $vm.Name
            $servicename = $vm.ServiceName
        
            If($vm.Status -ne 'StoppedDeallocated')
            {
                # Add the VM's which should not be shutdown 
                
                Write-Host 'Stopping ' + $name
                Stop-AzureVM -Service $servicename -name $name
                
            }
            # do lots of other stuff
        }
    }

    Namoskar!!!

  • Wriju's BLOG

    Azure PowerShell : Get the List of VM Images

    • 2 Comments

    Addition:

    Thanks Roy Lofthus, I love the comment and hence adding

    You can run below comment to get the grid.

    Get-AzureVMImage | Select * | Out-Gridview –Passthru

    The –Passthru will get the context back to PowerShell window. You can do the further filter etc in that Grid.

    image

    To get all the VM Images you can use

    Get-AzureVMImage | SELECT ImageName

    And the output

    image

    Namoskar!!!

  • Wriju's BLOG

    Azure and PowerShell

    • 0 Comments

    Azure and PowerShell are the couples. If you talk about only one of them then you are not talking complete story. We have got couple of PowerShell modules available in Azure and many things can only be done through PowerShell. Here are few easy steps to connect to Azure through PowerShell

    1. Run “PowerShell_ISE”

    image

    2. Then run PS> Add-AzureAccount

    image

    3. The prompt will come, enter the credential which has access to your Azure Account.

    image

    4. Then you are connected. Just to test run

    Get-AzureSubscription

    This will get you the list of subscription access you have.

    5. Then to set the one you would be working on now, run

    Get-AzureSubscription -SubscriptionName "Your Subscription Name"

    6. Just to confirm you may run

    Get-AzureSubscription -Current

    Namoskar!!!

  • Wriju's BLOG

    Setting up Azure Active Directory and ASP.NET Single Sign On

    • 1 Comments

    SSO has become a piece of cake after Azure AD. Here is a short video on how to do it. http://channel9.msdn.com/Blogs/wriju/Azure-Active-Directory-and-Single-Sing-On#c635422030414273043

    image

    Namoskar!!!

  • Wriju's BLOG

    Selling Azure Open Licensing for Partners

    • 0 Comments

    In Worldwide Partner Conference 2014 we have announced the Azure Open Licensing for Partners. This is going live from August 1, 2014. Here are some resources to help understand

    image

    Watch this video at http://www.digitalwpc.com/Community/Perspectives/Pages/Announcing-Microsoft-Azure-in-Open-Licensing-for-partners.aspx#fbid=PsEQVDjbmOh

    Another very informative blog post Coming Next to Open Licensing: Microsoft Azure

    Ready To Go resources for partners

    image 

    https://readytogo.microsoft.com/global/_layouts/RTG/DownloadCampaign.aspx?campurl=https://readytogo.microsoft.com/global/campaign/pages/(global)%20microsoft%20azure%20in%20open%20licensing.aspx

    Additional Videos at http://microsoft.events27.com/rampup (requires partner login or register in the same portal)

    Namoskar!!!

  • Wriju's BLOG

    SQL Server in Azure VM High Availability and Disaster Recovery

    • 0 Comments

    This is the most commonly asked question on SQL Server in Azure Virtual Machine. How to maintain SQL Server up and running all the time. Options are

    High Availability (Azure)

    1. AlwaysOn Availability Groups (http://msdn.microsoft.com/en-us/library/azure/dn249504.aspx)

    2. Database Mirroring (http://msdn.microsoft.com/en-us/library/azure/jj870961.aspx)

    Disaster Recovery (Azure)

    1. AlwaysOn Availability Groups (http://msdn.microsoft.com/en-us/library/azure/dn690122.aspx)

    2. Database Mirroring (http://msdn.microsoft.com/en-us/library/azure/jj870960.aspx)

    3. Backup and Restore with Azure Blob Storage Service (http://msdn.microsoft.com/en-us/library/azure/dn133143.aspx)

    Hybrid IT : Disaster Recovery

    In this case we can use our on-premises SQL Server and have the HADR setup. Now to do that you have some options as well available.

    1. AlwaysOn Availability Groups

    2. Database Mirroring (http://msdn.microsoft.com/en-us/library/azure/jj870964.aspx)

    3. Log Shipping (http://msdn.microsoft.com/en-us/library/azure/jj889442.aspx)

    4. Backup and Restore with Azure Blob Storage Service (http://msdn.microsoft.com/en-us/library/azure/dn133143.aspx )

    Consideration for Azure HADR

    It is important to understand some important things of Azure. You need to keep the VMs in Availability Set. To keep the VMs in Availability Set you must keep them in same Cloud Service.

    Also it is mandatory that one should know How to Configure Windows Failover Cluster in Azure for AlwaysOn Availability Groups

    Namoskar!!!

  • Wriju's BLOG

    Exchange Web Service get Calendar information

    • 1 Comments

    Now we have our mailboxes and Exchange server serving and storing them in the sever. Using Exchange WebService you can get the information. First build one Windows Application (this case). Add EWS reference from Nuget https://www.nuget.org/packages/Microsoft.Exchange.WebServices/ or you may run this command in Tools > Package Manager Console

    image

    After that a very simple code as below

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
    
    service.UseDefaultCredentials = true; //Windows Auth, you can pass user id and password too
    
    service.Url = new Uri("https://mail.microsoft.com/EWS/Exchange.asmx"); //URL of the service
    
                          
    
    //Get the next 30 days appointment
    
    FindItemsResults<Appointment> foundAppointments =
    
        service.FindAppointments(WellKnownFolderName.Calendar,
    
            new CalendarView(DateTime.Now, DateTime.Now.AddDays(30)));
    
                            
    
                
    
    foreach (var appo in foundAppointments)
    
    {
    
        //Gather information on each Appointment
    
        //location, datetime, host, attendees, duration
    
        var location = appo.Location;
    
        var dt = appo.ICalDateTimeStamp;
    
        var host = appo.Organizer.Name;
    
        var duration = (appo.End - appo.Start).Minutes;
    
        string data = string.Format("Host:{0}\r\nDate:{1}\r\nDuration:{2}\r\nLocation:{3}\r\n", 
    
                                    host, dt, duration, location);
    
        textBox1.Text += "========\r\n"+data;
    
    }

    Till then enjoy. Its simple.

    Namoskar!!!

  • Wriju's BLOG

    Configure Apache Tomcat in Azure VM

    • 1 Comments

    Step by step demonstration on how to configure Apache Tomcal VM in Azure and run a public facing website. See my latest Chnnel9 video

    http://channel9.msdn.com/Blogs/wriju/Configuring-Tomcat-Server-in-Azure-VM

    image

    image

    Namoskar!!!

  • Wriju's BLOG

    Why you should consider Microsoft Azure IaaS

    • 0 Comments

    Latest Gartner report clearly indicates that Microsoft is leading in the league of IaaS Cloud space. Read the complete report

    http://www.gartner.com/technology/reprints.do?id=1-1UKQQA6&ct=140528&st=sb

    Figure 1.Magic Quadrant for Cloud Infrastructure as a Service

    Namoskar!!!

  • Wriju's BLOG

    Build 2014 some of my favorite sessions on Azure

    • 0 Comments

    What's New for Azure Developers in Visual Studio and Azure SDK

    http://channel9.msdn.com/Events/Build/2014/2-585

     

    Developing Office 365 Cloud Business Apps

    http://channel9.msdn.com/Events/Build/2014/3-573

     

    What's New for ASP.NET and Web in Visual Studio 2013 Update 2 and Beyond

    http://channel9.msdn.com/Events/Build/2014/3-602

     

    Microsoft Azure Storage – What's New, Best Practices and Patterns

    http://channel9.msdn.com/Events/Build/2014/3-628

     

    What’s New in IaaS for Developers

    http://channel9.msdn.com/Events/Build/2014/3-614

     

    Building Enterprise and SaaS Web Apps and Web APIs using Azure Active Directory for Sign In

    http://channel9.msdn.com/Events/Build/2014/3-599

     

    Building Web APIs for Mobile Apps Using ASP.NET Web API 2.1

    http://channel9.msdn.com/Events/Build/2014/3-603

     

    Powerful Mobile Apps with Mobile Services and ASP.NET Web API

    http://channel9.msdn.com/Events/Build/2014/3-623

     

    What’s New with Azure Web Sites

    http://channel9.msdn.com/Events/Build/2014/3-625

     

    Deep Dive into Hidden Gems, Tips and Tricks for Azure Web Sites

    http://channel9.msdn.com/Events/Build/2014/3-624

     

    Azure SQL Database: Under the Hood

    http://channel9.msdn.com/Events/Build/2014/3-630

     

    TypeScript

    http://channel9.msdn.com/Events/Build/2014/3-576

     

    Automation Everywhere with New SDKs, Tools, and Services in Azure

    http://channel9.msdn.com/Events/Build/2014/3-621

     

    Mobile Push Notifications to Any Client with Azure Notification Hubs

    http://channel9.msdn.com/Events/Build/2014/2-616

     

    Internet Explorer as a Web Application Platform

    http://channel9.msdn.com/Events/Build/2014/2-501

    Namoskar!!!

  • Wriju's BLOG

    Learn Modern Data Warehouse with Big Data Analytics

    • 0 Comments

    Another great live discussion is going to happen today. Register http://www.microsoftvirtualacademy.com/liveevents/microsoft-pdw-modern-data-warehouse-with-big-data-analytics

    image

    image

    Namoskar!!!

  • Wriju's BLOG

    Migrating Visual Studio Online to TFS on Premises

    • 1 Comments

    After trying out the free Visual Studio Online you started liking it. It might so happen that the Visual Studio Online has sent you an email that the early adopter program is ending soon. So you want to move your work to TFS on-premises where you have more control and the domain integration. Here is the step by step guidance

    You must contact Microsoft to enable this feature

    http://msdn.microsoft.com/en-us/library/7cb80f0d-0119-4277-82e8-719a8db1796e

    Namoskar!!!

  • Wriju's BLOG

    Microsoft Assessment and Planning(MAP) Toolkit

    • 0 Comments

    MAP or Microsoft Assessment and Planning Toolkit is an agentless inventory, assessment, and reporting tool that can securely assess IT environments for various platform migrations—including Windows 8, Windows 7, Office 2013, Office 2010, Office 365, Windows Server 2012 and Windows 2008 R2, SQL Server 2012, Hyper-V, Microsoft Private Cloud Fast Track, and Windows Azure.

    The toolkit 11 min demo at http://technet.microsoft.com/en-us/video/microsoft-assessment-and-planning-map-toolkit-demo-simplify-windows-azure-migration-planning-with-map 

    MAP Supports

    Download MAP from http://go.microsoft.com/fwlink/?LinkId=316883 

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 8.1 App Dev Jump Start

    • 0 Comments

    Watch it live http://www.microsoftvirtualacademy.com/liveevents/building-apps-for-windows-phone-8-1-jump-start

    image

    Namoskar!!!

  • Wriju's BLOG

    Why you should consider cloud as your Datacenter

    • 0 Comments

    If you are building an application and selling it to your customer as product, you need a place to host it. Now you can consider hosting it in your datacenter or customer’s datacenter. The question comes to us in terms of management. Apart from that there are quite a few challenges. If this application is internet facing then not only your datacenter should be responding to it but you need a high bandwidth internet connection for the datacenter. Also you need to make sure that the datacenter is up and running all the time. There are a lot of logistical challenges which directly proportionate to money. Now for a simple portal like HR application no company would be ready to invest that much amount. It does not really make sense, unless you have few other apps which will use the same datacenter.

    From the above discussion couple of points comes again and again which are classical in nature.

    1. Highly Available

    2. Expandable (Elastic)

    3. Reliable

    4. Secure

    5. Manageable

    Any standard cloud solution provides all of them. So in your budget you can easily cut the cost of your application hosting to zero. And whenever it starts it will bill you based on the usage. It is like electricity at your house. If the appliances are switched off then you are paying only the minimum amount and if you have used them heavily the bill will shoot up. You don't need to worry about the power grid or coal supply. Even if there is a damage in supply it will be fixed by the electricity company – not you.

    Now, many companies consider it a security threat. They assume if their data is shared between multiple customers. No it does not. This basic sandboxing mechanism is must for a cloud vendor. Even today there are banks who moved to public cloud. So security is well managed.

    Yes, there are few valid concerns like if the data should travel across geography. For example, if my customers are in Europe the policy might dictate not to store data outside of Europe. Hence you will choose your datacenter location in Europe.

    Now there are different way how you package your software. The packaging also considers how and where you will deploy them

    image

    Now from the above

    The legacy software which comes in DVD has some pre-requisites and then installs in the actual hardware box of customer location

    When it moves to cloud the nature of application ownership varies where you deploy.

    One of the biggest pushback comes from development teams. For them this is an unknown territory and they don't want to explore it. If it is brand new application the things becomes easy, but when we need to club it with any existing apps then the concept of Hybrid comes to the place. This allows not only flexibility to maintain legacy apps but bring new undocumented challenges.

    Cloud is the future and I see it as next thing to be considered while designing apps. As an Architect, Developer you need to think about it. Not only your new or upcoming apps but your apps which are running for years.

    Have a cloud vision for a successful mission.

    Namoskar!!!

  • Wriju's BLOG

    WinJS using alert() in your JavaScript

    • 2 Comments

    If you come from JavaScript world you will badly miss the alert() function. However, this habit can be entertained if you declare a function at default.js file. Then it will be accessible in all other pages which are navigated from default.html page.

    function alert(message) {
    
        var msgBox = new Windows.UI.Popups.MessageDialog(message);
    
        msgBox.showAsync();
    
    }

    Then this code would work,

    alert('Welcome back dear Alert');

    Namoskar!!!

  • Wriju's BLOG

    WinJS Global Error Handling in JavaScript

    • 2 Comments

    In Windows Store Apps if any unhandled error comes it closes the application. This sliently happens to terminate the app. This is a default behavior. We can change this behavior by handling the “unhandled” errors.

    app.onerror = function (e) {
    
        var message = e.detail.message;
    
        var description = e.detail.description;
    
        var code = e.detail.number;
    
        var stackTrace = e.detail.stack;
    
        var msgBox = new Windows.UI.Popups.MessageDialog(
    
            description, e.detail.errorMessage
    
            );
    
        msgBox.showAsync().done();
    
        return true;
    
    };
    

    Now by saying return true

    We are ensuring that application stays in the place and we continue to work. Else if we have return false then it will crash.

    This behavior is not something to be tested in debug mode from Visual Studio. One should test it from the Apps list of Windows 8 desktop.

    To test, put something like

    alert('1');

    As alert does not work in WinJS, it will crash the app.

    Namoskar!!!

  • Wriju's BLOG

    Working with jQuery in WinJS

    • 0 Comments

    Use Blank HTML Template

    Create project using Blank Template

    Install the jQuery and add it to Application

    Once you have your Windows Store Apps, use nugget.org and add jQuery to your application

    Go to your package manager console and run the below comment

    PM> Install-Package jQuery

    Then add the reference of the jQuery to the default.html (start page) so that it is by default loaded into other pages which gets navigated from this page.

    Right click the js folder and Add > Existing Item point the jquery-2.0.3.js which is located in the packages folder.

    Then to the default.html add this reference to the top

    <!--Add the jQuery Reference-->
    
    <script src="js/jquery-2.0.3.js"></script>

    Sample HTML

    </head>
    
    <body>
    
        <input type="text" id="txtData" />
    
        <br />
    
        <input type="button" id="btnAdd" value="Click Here"/>
    
    </body>
    
    </html>
    

    Sample JS

    (function () {
    
        "use strict";
    
        var app = WinJS.Application;
    
        var activation = Windows.ApplicationModel.Activation;
    
      
    
        app.onactivated = function (args) {
    
            if (args.detail.kind === activation.ActivationKind.launch) {
    
                if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
    
                } else {
    
                }
    
                
    
                args.setPromise(WinJS.UI.processAll().done(function () {
    
                    /*var button1 = document.getElementById("btnAdd");
    
                    button1.addEventListener("click", WhenButtonClicked, false);
    
                    */
    
                    $('#btnAdd').click(function () {
    
                        var data = $("#txtData").val(); //To Read the value
    
                        $('#txtData').val("KKKDD");
    
                    });
    
                }));
    
            }
    
        };
    
        function WhenButtonClicked() {
    
            var data = $("#txtData").val();
    
        }
    
        //var bttn = $('#add').click(function () {
    
        //    //alert('button clicked');
    
        //    $('#txtData').val = "Some text";
    
        //});
    
        app.oncheckpoint = function (args) {
    
        };
    
        app.start();
    
    })();

    References

    jQuery API reference http://api.jquery.com/

    jQuery Tutorial http://www.w3schools.com/jquery/default.asp

    Namoskar!!!

  • Wriju's BLOG

    Entity Framework CodeFirst : Simple Migrations

    • 0 Comments

    When I change my model from let’s say

    //Employee Entity
    
    public class Employee
    
    {
    
        public int Id { get; set; }
    
        public string FullName { get; set; }
    
    }

    to

    //Employee Entity
    
    public class Employee
    
    {
    
        public int Id { get; set; }
    
        public string FullName { get; set; }
    
        public string Email { get; set; } //New
    
    }

    Then I find a trouble. Either I have to drop create the whole database using

    Database.SetInitializer<HRContext>(new DropCreateDatabaseIfModelChanges<HRContext>());

    or I need to do it manually. But this deletes everything. Who wants that? No one. So I left with an option of reflecting only changes. Now in EF CodeFirst we call it as Migrations. This can be very in-depth customizable. I would like to show you the most simple option and you can take to complex user-defined approach based on your business need.

    Step1: Run this command to your Package Manager Console

    PM> Enable-Migrations

    And the output would look like

    image

    After this two files will be created in project under a new folder “Migrations”

    image

    Then we need a small change there in the file configuration

    internal sealed class Configuration : DbMigrationsConfiguration<ConsoleApplication1.HRContext>
    
    {

    Would be changed to

    public sealed class Configuration : DbMigrationsConfiguration<ConsoleApplication1.HRContext>
    
    {

    And

    AutomaticMigrationsEnabled = false;

    would change to

    AutomaticMigrationsEnabled = true;

    Now the new Database initializer would look like,

    Database.SetInitializer<HRContext>(new MigrateDatabaseToLatestVersion<HRContext, Migrations.Configuration>());

    So the complete code would look like

    public class Employee
    
    {
    
        public int Id { get; set; }
    
        public string FullName { get; set; }
    
        public string Email { get; set; } //New
    
    }
    
    public class HRContext : DbContext
    
    {
    
        public DbSet<Employee> Emps { get; set; }
    
    }
    
    class Program
    
    {
    
        static void Main(string[] args)
    
        {
    
            //Database.SetInitializer<HRContext>(new DropCreateDatabaseIfModelChanges<HRContext>());
    
            Database.SetInitializer<HRContext>(new MigrateDatabaseToLatestVersion<HRContext, Migrations.Configuration>());
    
            var emp = new Employee() { FullName = "Wriju Ghosh", Email = "some@contoso.com" };
    
            using (var ctx = new HRContext())
    
            {
    
                //This would get me the database information
    
                string strConnection = ctx.Database.Connection.ConnectionString;
    
                Console.WriteLine(strConnection);
    
                ctx.Emps.Add(emp);
    
                ctx.SaveChanges();
    
                foreach (var em in ctx.Emps)
    
                {
    
                    Console.WriteLine(em.FullName);
    
                    Console.WriteLine(em.Email==null?"null":em.Email);
    
                }
    
            }
    
        }
    
    }

    Namoskar!!!

Page 1 of 25 (618 items) 12345»