locked
Whether CurrentApp class uses WindowsStoreProxy.xml for licensing? RRS feed

  • Question

  • Whether CurrentApp class uses WindowsStoreProxy.xml for licensing? I think it will not use.

    Am I correct or not? Also I have to ask in the sample of licensing given in MSDN copies the WindowsStoreProxy.xml. How that xml is created in specified folder it is not given. Please tell me something this also.
    Tuesday, January 29, 2013 12:26 PM

Answers

  • Here is my example of a trial application.

    The function of the application is simply to display "Hello World" and the current date and time when a button is clicked.  During trial, the page also displays a panel that informs the user that it is a trial that expires in a certain number of days and offers a button to allow the user to buy the app from the store.  Once the app is purchased, the trial info panel is no longer visible.

    Here is the Xaml with the button, application panel and trial info panel.

    <Page
        x:Class="HelpWithTrialLicense.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:HelpWithTrialLicense"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <Button Click="Button_Click_1" HorizontalAlignment="Center">Click Me</Button>
                <TextBlock x:Name="Message" Margin="0,20,0,0" FontSize="20" HorizontalAlignment="Center"/>
                <TextBlock x:Name="Date" Margin="0,20,0,0" FontSize="20" HorizontalAlignment="Center"/>
            </StackPanel>
            
            <!--This panel is hidden if there is a fully paid license-->
            <StackPanel x:Name="TrialStatusPanel" Grid.Column="3" Margin="0,0,19,19" Orientation="Vertical" Grid.Row="5" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.RowSpan="3" Background="#FF464646">
                <TextBlock HorizontalAlignment="Right" Foreground="White" FontFamily="Segoe UI" FontSize="26.667" Text="Hello World Trial" Margin="0,0,6,0"/>
                <TextBlock x:Name="RemainingTime" TextWrapping="Wrap" Text="Expires in 3 days" Foreground="White" FontFamily="Segoe UI" FontSize="14.667" HorizontalAlignment="Right" Margin="8,0"/>
                <Button x:Name="PurchaseApp" Content="Purchase Now" HorizontalAlignment="Right" VerticalAlignment="Stretch" Foreground="White" Margin="8,0,8,8" Click="PurchaseApp_Click"/>
            </StackPanel>
        </Grid>
    </Page>

    The C# code for the page contains the logic for the trial scenario.  It contains the code for both debugging using the CurrentAppSimulator and for release with CurrentApp.  Note the sections between #if DEBUG and #else are compiled when Visual Studio is in Debug mode.  The sections between #else and #endif are compiled only when Visual Studio is compiling the release version.

    The main function of the app is to respond to a button click by calling a method "SayHello()".  This is only allowed to happen if the license is active.  This will occur under two conditions: the app is in the trial period or the app is purchased.

    When the page is navigated to under debug conditions, the proxy file is loaded and the trial status panel is updated.  Under release conditions, the trial status panel is updated.

    The trial logic also contains a button click event handler that allows the user to attempt to buy the app.  In debug mode, the purchase is simulated.  In release code, the Store is contacted.

    using System;
    using System.Threading.Tasks;
    using Windows.ApplicationModel;
    using Windows.ApplicationModel.Store;
    using Windows.Storage;
    using Windows.UI;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    
    namespace HelpWithTrialLicense
    {
    
        public sealed partial class MainPage : Page
        {
    
            LicenseChangedEventHandler licenseChangeHandler = null;
    
            public MainPage()
            {
                this.InitializeComponent();
            }
    
    
            protected override async void OnNavigatedTo(NavigationEventArgs e)
            {
    #if DEBUG
                await LoadTrialModeProxyFileAsync();
    #else
                licenseChangeHandler = new LicenseChangedEventHandler(UpdateTrialStatusPanel);
                CurrentApp.LicenseInformation.LicenseChanged += licenseChangeHandler;
                UpdateTrialStatusPanel();
    #endif
            }
    
    
            //The function of this button click is contingent on having a valid license
            //Either purchased or under trial conditions
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    #endif
                if (licenseInformation.IsActive)
                {
                    SayHello();
                }
            }
    
    
            //This is the main function for the app
            void SayHello()
            {
                Message.Text = "Hello World ";
                Date.Text = DateTime.Now.ToString();
            }
    
    
            
    #region Trial Plumbing
            //This function will not be called for the release
            //Its only purpose is to get the proxy file for debugging purposes
            private async Task LoadTrialModeProxyFileAsync()
            {
                licenseChangeHandler = new LicenseChangedEventHandler(UpdateTrialStatusPanel);
    
                StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data");
                StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml");
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
                await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
            }
    
            //Show the state of the license in the status panel
            private void UpdateTrialStatusPanel()
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation; 
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;  
    #endif
                if (licenseInformation.IsActive)
                {
                    if (licenseInformation.IsTrial)
                    {
                        //Current license mode: Trial license
                        TrialStatusPanel.Visibility = Visibility.Visible;
                        var remainingTrialTime = (licenseInformation.ExpirationDate - DateTime.Now).Days;
                        RemainingTime.Text = "Expires in " + remainingTrialTime + " days";
                    }
                    else
                    {
                        //Current license mode: Full license
                        TrialStatusPanel.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    //Current license mode: Inactive license
                    TrialStatusPanel.Visibility = Visibility.Visible;
                    var remainingTrialTime = (licenseInformation.ExpirationDate - DateTime.Now).Days;
                    RemainingTime.Text = "Trial has expired.";
                    RemainingTime.Foreground = new SolidColorBrush(Colors.Red);
                }
            } 
            
    
            //Attempt to purchase app in the application
            async void PurchaseApp_Click(object sender, RoutedEventArgs e)
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    #endif
                RemainingTime.Text = "Buying the full license...";
                if (licenseInformation.IsTrial)
                {
                    try
                    {
    #if DEBUG
                        await CurrentAppSimulator.RequestAppPurchaseAsync(false);
    #else
                        await CurrentApp.RequestAppPurchaseAsync(false);
    #endif
                        if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                        {
                            RemainingTime.Text = "Thank you.";
                            SayHello();  //Optional do something in app to show it works again
                        }
                        else
                        {
                            RemainingTime.Text = "You still have a trial license for this app.";
                        }
                    }
                    catch (Exception)
                    {
                        RemainingTime.Text = "The transaction failed.";
                    }
                }
                else
                {
                    //Should not reach this because the Purchase button would not be displayed
                    RemainingTime.Text = "You have already purchased this app.";
                }
            }
    #endregion
    
        }
    }
    

    Finally, here is the proxy xml file trial-mode.xml which should be placed in a folder named "Data" in the project.  You can play with the IsActive, IsTrial and ExpirationDate to simulate inital starting conditions.  Note that this file is not modified by your code or Visual Studio.  This is just for initial conditions.

    <?xml version="1.0" encoding="utf-16" ?>
    <CurrentApp>
      <ListingInformation>
        <App>
          <AppId>2B14D306-D8F8-4066-A45B-0FB3464C67F2</AppId>
          <LinkUri>http://apps.microsoft.com/webpdp/app/2B14D306-D8F8-4066-A45B-0FB3464C67F2</LinkUri>
          <CurrentMarket>en-US</CurrentMarket>
          <AgeRating>7</AgeRating>
          <MarketData xml:lang="en-us">
            <Name>Hello World App</Name>
            <Description>Demonstrate Trial App</Description>
            <Price>1.95</Price>
            <CurrencySymbol>$</CurrencySymbol>
            <CurrencyCode>USD</CurrencyCode>
          </MarketData>
        </App>
      </ListingInformation>
      <LicenseInformation>
        <App>
          <IsActive>true</IsActive>
          <IsTrial>true</IsTrial>
          <ExpirationDate>2013-03-01T00:00:00.00Z</ExpirationDate>
        </App>
      </LicenseInformation>
    </CurrentApp>
    

    Friday, February 22, 2013 1:13 PM
  • The WindowsStoreProxy.xml file is used only by the CurrentAppSimulator for app development and testing.  You have to create it and make sure the CurrentAppSimulator loads it when debugging.

    CurrentApp gets its licensing information from an undisclosed location.

    • Marked as answer by k_amol Wednesday, January 30, 2013 6:03 AM
    Tuesday, January 29, 2013 1:21 PM
  • When I am debugging, I call the following function in the constructor of my MainPage:

            //This function will not be called for the release
            private async Task LoadTrialModeProxyFileAsync()
            {
                licenseChangeHandler = new LicenseChangedEventHandler(ReloadLicense);
    
                StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data"); //REMOVE FOR RELEASE
                StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml");  //REMOVE FOR RELEASE      
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;  //REMOVE FOR RELEASE
                await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);  //REMOVE FOR RELEASE
            }
    Note, that I put the trial-mode.xml file inside a folder in my project called "Data".

    • Marked as answer by k_amol Thursday, January 31, 2013 11:33 AM
    Wednesday, January 30, 2013 11:32 AM

All replies

  • The WindowsStoreProxy.xml file is used only by the CurrentAppSimulator for app development and testing.  You have to create it and make sure the CurrentAppSimulator loads it when debugging.

    CurrentApp gets its licensing information from an undisclosed location.

    • Marked as answer by k_amol Wednesday, January 30, 2013 6:03 AM
    Tuesday, January 29, 2013 1:21 PM
  • Thank you very much jrboddie. Actually I was confuse by considering that point. And also I was thinking that if CurrentApp is not considering WindowsStoreProxy.xml then from where it is accessing the software data. But from your answer I understood the scenario. Now I have one more problem when I am loading that xml file I am getting error that access is denied. Do you know how to load that xml file when project is debugging.
    Wednesday, January 30, 2013 6:02 AM
  • When I am debugging, I call the following function in the constructor of my MainPage:

            //This function will not be called for the release
            private async Task LoadTrialModeProxyFileAsync()
            {
                licenseChangeHandler = new LicenseChangedEventHandler(ReloadLicense);
    
                StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data"); //REMOVE FOR RELEASE
                StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml");  //REMOVE FOR RELEASE      
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;  //REMOVE FOR RELEASE
                await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);  //REMOVE FOR RELEASE
            }
    Note, that I put the trial-mode.xml file inside a folder in my project called "Data".

    • Marked as answer by k_amol Thursday, January 31, 2013 11:33 AM
    Wednesday, January 30, 2013 11:32 AM
  • Thank you very much jrboddie for your reply...

    I want to share here something. Actually I have done same code but I have not included that "*.xml" in my solution(It's childish mistake). That is why it gives me error that "Access to file dinied".  Then I have tried for Document Library. I generated the file programmatically and tried to access it still it has given me the same error. Then I realized that I have not added that file in my solution and I am trying to access it...Then i added that file in solution and then tried again and I found that it is working. What I want to share is  that when we are generating the "*.xml" file outside the insatllation folder then "ReloadSimulatorAsync" throws the error "Access denied".

    • Proposed as answer by Seven 007 Saturday, February 16, 2013 7:37 AM
    • Unproposed as answer by Seven 007 Saturday, February 16, 2013 7:37 AM
    Thursday, January 31, 2013 11:32 AM
  • Hi jrboddie,

             I don;t know how to create the WindowsStoreProxy.xml  ???

    In the link of CurrenAppSimulator (http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.currentappsimulator.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1) The CurrentAppSimulator object gets its data from the WindowsStoreProxy.xml file in the %userprofile%\appdata\local\packages\<package-moniker>\localstate\microsoft\Windows Store\Apidata folder. 

    But, I can't find any folder inside the Localstate.??

    Can you explain how to do that?


    • Edited by Seven 007 Saturday, February 16, 2013 8:22 AM
    Saturday, February 16, 2013 7:19 AM
  • The proxy file is part of your project in your solution.

    Here is one way to create it:

    1. In Visual Studio Solution Explorer panel, add a new folder called, "Data"
    2. Right click on the Data folder and Add New
    3. Select xml File and name it "trial-mode.xml"
    4. From the link  in your post, copy one of the xml examples
    5. Paste into your trial-mode.xml file
    6. Add the LoadTrialModeProxyFileAsync() method that I listed in my last post
    7. Add a call to it in your page loaded or OnNavigatedTo event handler.  (You should only call this method for debug--not release.)
    Saturday, February 16, 2013 12:39 PM
  • Thanks for your reply.
    Sunday, February 17, 2013 11:09 AM
  • I tried all the ways got from this forum. I don't know why WindowsStoreProxy.xml is not created in the ApiData folder. :(

    Thursday, February 21, 2013 12:57 PM
  • I think you are missing something.  In my post above, the trial-mode.xml is the proxy--it just does not use the name "WindowsStoreProxy."  

    It is not created by Visual Studio.  You have to do it.  Reread and follow my post.  

    There is no need for you to look in the data folder.  Just use the LoadTrialModeProxyFileAsync to acquire it for use with CurrentAppSimulator.

    If you like, I can put together a super simple trial mode app with the plumbing for debugging.

    Thursday, February 21, 2013 1:17 PM
  • Is that Correct Way of doing : Here is my MainPage.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;
    using Windows.ApplicationModel;
    using Windows.ApplicationModel.Store;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Storage;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
    
    namespace Template
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
            private LicenseChangedEventHandler licenseChangeHandler;
            public MainPage()
            {
                this.InitializeComponent();
            //    licenseInformation = CurrentAppSimulator.LicenseInformation;
    
            //    licenseInformation.LicenseChanged += new LicenseChangedEventHandler(licenseChangedEventHandler);
                
            }
          
            /*
            private void licenseChangedEventHandler()
            {
                ReloadLicense();
            }
             * */
            /// <summary>
            /// Invoked when this page is about to be displayed in a Frame.
            /// </summary>
            /// <param name="e">Event data that describes how this page was reached.  The Parameter
            /// property is typically used to configure the page.</param>
            protected override async void OnNavigatedTo(NavigationEventArgs e)
            {
                await LoadTrialModeProxyFileAsync();
            }
    		public SwapChainBackgroundPanel GetSwapChainBackgroundPanel()
    		{
    			return DXSwapChainPanel;
    		}
    
            private async Task LoadTrialModeProxyFileAsync()
            {
                licenseChangeHandler = new LicenseChangedEventHandler(ReloadLicense);
    
                StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data"); //REMOVE FOR RELEASE
                StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml");  //REMOVE FOR RELEASE      
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;  //REMOVE FOR RELEASE
                await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);  //REMOVE FOR RELEASE
            }
    
            private void ReloadLicense()
            {
                if (licenseInformation.IsActive)
                {
                    if (licenseInformation.IsTrial)
                    {
                        // Show the features that are available during trial only.
                        CONTROLLER.TimeforTrail = 3.0f;
                    }
                    else
                    {
                        // Show the features that are available only with a full license.
                    }
                }
                else
                {
                    // A license is inactive only when there's an error.
                }
            }
    
    
            public LicenseInformation licenseInformation { get; set; }
        }
    }
    


    Friday, February 22, 2013 6:23 AM
  • Here is my example of a trial application.

    The function of the application is simply to display "Hello World" and the current date and time when a button is clicked.  During trial, the page also displays a panel that informs the user that it is a trial that expires in a certain number of days and offers a button to allow the user to buy the app from the store.  Once the app is purchased, the trial info panel is no longer visible.

    Here is the Xaml with the button, application panel and trial info panel.

    <Page
        x:Class="HelpWithTrialLicense.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:HelpWithTrialLicense"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <Button Click="Button_Click_1" HorizontalAlignment="Center">Click Me</Button>
                <TextBlock x:Name="Message" Margin="0,20,0,0" FontSize="20" HorizontalAlignment="Center"/>
                <TextBlock x:Name="Date" Margin="0,20,0,0" FontSize="20" HorizontalAlignment="Center"/>
            </StackPanel>
            
            <!--This panel is hidden if there is a fully paid license-->
            <StackPanel x:Name="TrialStatusPanel" Grid.Column="3" Margin="0,0,19,19" Orientation="Vertical" Grid.Row="5" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.RowSpan="3" Background="#FF464646">
                <TextBlock HorizontalAlignment="Right" Foreground="White" FontFamily="Segoe UI" FontSize="26.667" Text="Hello World Trial" Margin="0,0,6,0"/>
                <TextBlock x:Name="RemainingTime" TextWrapping="Wrap" Text="Expires in 3 days" Foreground="White" FontFamily="Segoe UI" FontSize="14.667" HorizontalAlignment="Right" Margin="8,0"/>
                <Button x:Name="PurchaseApp" Content="Purchase Now" HorizontalAlignment="Right" VerticalAlignment="Stretch" Foreground="White" Margin="8,0,8,8" Click="PurchaseApp_Click"/>
            </StackPanel>
        </Grid>
    </Page>

    The C# code for the page contains the logic for the trial scenario.  It contains the code for both debugging using the CurrentAppSimulator and for release with CurrentApp.  Note the sections between #if DEBUG and #else are compiled when Visual Studio is in Debug mode.  The sections between #else and #endif are compiled only when Visual Studio is compiling the release version.

    The main function of the app is to respond to a button click by calling a method "SayHello()".  This is only allowed to happen if the license is active.  This will occur under two conditions: the app is in the trial period or the app is purchased.

    When the page is navigated to under debug conditions, the proxy file is loaded and the trial status panel is updated.  Under release conditions, the trial status panel is updated.

    The trial logic also contains a button click event handler that allows the user to attempt to buy the app.  In debug mode, the purchase is simulated.  In release code, the Store is contacted.

    using System;
    using System.Threading.Tasks;
    using Windows.ApplicationModel;
    using Windows.ApplicationModel.Store;
    using Windows.Storage;
    using Windows.UI;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    
    namespace HelpWithTrialLicense
    {
    
        public sealed partial class MainPage : Page
        {
    
            LicenseChangedEventHandler licenseChangeHandler = null;
    
            public MainPage()
            {
                this.InitializeComponent();
            }
    
    
            protected override async void OnNavigatedTo(NavigationEventArgs e)
            {
    #if DEBUG
                await LoadTrialModeProxyFileAsync();
    #else
                licenseChangeHandler = new LicenseChangedEventHandler(UpdateTrialStatusPanel);
                CurrentApp.LicenseInformation.LicenseChanged += licenseChangeHandler;
                UpdateTrialStatusPanel();
    #endif
            }
    
    
            //The function of this button click is contingent on having a valid license
            //Either purchased or under trial conditions
            private void Button_Click_1(object sender, RoutedEventArgs e)
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    #endif
                if (licenseInformation.IsActive)
                {
                    SayHello();
                }
            }
    
    
            //This is the main function for the app
            void SayHello()
            {
                Message.Text = "Hello World ";
                Date.Text = DateTime.Now.ToString();
            }
    
    
            
    #region Trial Plumbing
            //This function will not be called for the release
            //Its only purpose is to get the proxy file for debugging purposes
            private async Task LoadTrialModeProxyFileAsync()
            {
                licenseChangeHandler = new LicenseChangedEventHandler(UpdateTrialStatusPanel);
    
                StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data");
                StorageFile proxyFile = await proxyDataFolder.GetFileAsync("trial-mode.xml");
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
                await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
            }
    
            //Show the state of the license in the status panel
            private void UpdateTrialStatusPanel()
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation; 
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;  
    #endif
                if (licenseInformation.IsActive)
                {
                    if (licenseInformation.IsTrial)
                    {
                        //Current license mode: Trial license
                        TrialStatusPanel.Visibility = Visibility.Visible;
                        var remainingTrialTime = (licenseInformation.ExpirationDate - DateTime.Now).Days;
                        RemainingTime.Text = "Expires in " + remainingTrialTime + " days";
                    }
                    else
                    {
                        //Current license mode: Full license
                        TrialStatusPanel.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    //Current license mode: Inactive license
                    TrialStatusPanel.Visibility = Visibility.Visible;
                    var remainingTrialTime = (licenseInformation.ExpirationDate - DateTime.Now).Days;
                    RemainingTime.Text = "Trial has expired.";
                    RemainingTime.Foreground = new SolidColorBrush(Colors.Red);
                }
            } 
            
    
            //Attempt to purchase app in the application
            async void PurchaseApp_Click(object sender, RoutedEventArgs e)
            {
    #if DEBUG
                LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    #else
                LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    #endif
                RemainingTime.Text = "Buying the full license...";
                if (licenseInformation.IsTrial)
                {
                    try
                    {
    #if DEBUG
                        await CurrentAppSimulator.RequestAppPurchaseAsync(false);
    #else
                        await CurrentApp.RequestAppPurchaseAsync(false);
    #endif
                        if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                        {
                            RemainingTime.Text = "Thank you.";
                            SayHello();  //Optional do something in app to show it works again
                        }
                        else
                        {
                            RemainingTime.Text = "You still have a trial license for this app.";
                        }
                    }
                    catch (Exception)
                    {
                        RemainingTime.Text = "The transaction failed.";
                    }
                }
                else
                {
                    //Should not reach this because the Purchase button would not be displayed
                    RemainingTime.Text = "You have already purchased this app.";
                }
            }
    #endregion
    
        }
    }
    

    Finally, here is the proxy xml file trial-mode.xml which should be placed in a folder named "Data" in the project.  You can play with the IsActive, IsTrial and ExpirationDate to simulate inital starting conditions.  Note that this file is not modified by your code or Visual Studio.  This is just for initial conditions.

    <?xml version="1.0" encoding="utf-16" ?>
    <CurrentApp>
      <ListingInformation>
        <App>
          <AppId>2B14D306-D8F8-4066-A45B-0FB3464C67F2</AppId>
          <LinkUri>http://apps.microsoft.com/webpdp/app/2B14D306-D8F8-4066-A45B-0FB3464C67F2</LinkUri>
          <CurrentMarket>en-US</CurrentMarket>
          <AgeRating>7</AgeRating>
          <MarketData xml:lang="en-us">
            <Name>Hello World App</Name>
            <Description>Demonstrate Trial App</Description>
            <Price>1.95</Price>
            <CurrencySymbol>$</CurrencySymbol>
            <CurrencyCode>USD</CurrencyCode>
          </MarketData>
        </App>
      </ListingInformation>
      <LicenseInformation>
        <App>
          <IsActive>true</IsActive>
          <IsTrial>true</IsTrial>
          <ExpirationDate>2013-03-01T00:00:00.00Z</ExpirationDate>
        </App>
      </LicenseInformation>
    </CurrentApp>
    

    Friday, February 22, 2013 1:13 PM
  • Thanks jrboddie,  Finally Got Worked Now.

    Friday, February 22, 2013 2:22 PM
  • @jrboddie Thanks for the post. It's great and just what I've spent the last week looking for. This needs to be added to the code samples pages. Great post.

    Saturday, April 6, 2013 9:37 PM
  • @jrboddie

     I completed the InApp Purchase and all. But I have one doubt what are the files to delete for uploading in windows store.

     I list the name & details of the files to be deleted . If Its wrong file to delete (or) some other files need to deleted for upload to windows 8 store means. Please let me know.

    Here is the details of the file:

    1. License.xml  and lines in App.xaml.cs which calls to this .xml file

     if (profile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
                {
                    // Initialize CurrentAppSimulator
                    var file = await Package.Current.InstalledLocation.GetFileAsync("Data\\license.xml");
                    await Windows.ApplicationModel.Store.CurrentAppSimulator.ReloadSimulatorAsync(file);
                }

    are to be deleted .

    2. Change from CurrentAppsimulator to Current App. 

    Is that changes and Modification are enough for uploading?????

    Friday, April 26, 2013 6:32 AM
  • Mr. Sarwon,

    In my application that is based on the structure of the example in my previous post, I did not delete any files before uploading.  Notice the #if DEBUG #else and #endIf directives.  These statements include or exclude the calls to the CurrentAppSimulator depending on whether I am compiling for Debug or Release scenarios.  

    Friday, April 26, 2013 3:21 PM
  • @jrboddie

    How could i restore or recover my purchases after reinstall the application.

    i.e:  I bought an app and after sometimes i uninstalled and then reinstalled. At the moment i need to restore the app if the particular customer

    bought full version.

    Monday, April 29, 2013 1:29 PM
  • I believe that if the customer bought the application, uninstalled then re-installed it (from the store), then the license info from the store would indicate that it was fully licensed and the app would run normally (at least that is what mine does.)
    Monday, April 29, 2013 1:56 PM
  • Thanks for reply.

    I have Doubt in Settings pane.

    When i am calling settings pane for custom settings. Settings pane appears and i can customize the settings.

    But My doubt is,

    After entering into the App While calling the default settings pane via programming or (pressing WIN + C) -> settings will not allow the background icons to accessible.

    But After Clicking Settings from above window will show customized settings of app (that is created via usercontrol stackpanel) 

    will be accessible the icon behind that screen.

    How to solve this????

    Tuesday, April 30, 2013 3:43 PM
  • Hi Sarwon,

    Please post only one question per thread. Please post your new questions in new threads.

    As JRboddie says, the license information is stored on the server so if the user uninstalls and reinstalls then then license information will persist automatically.

    If the user uninstalls the app then all local settings are removed, so if you store your custom settings locally they will be gone. If you store them in roaming settings then they will roam back to the machine after a reinstall.

    --Rob

    Tuesday, April 30, 2013 3:51 PM
    Moderator