#

UWP Store Win32:

 

Code Beispiel zum abfragen der App im Windows Store und Kauf des ersten Addon

 

Die App läuft im Windows Store und ist als Win32 App konzipiert. Deshalb werden die Store Daten abgerufen mit den Windows.Store.Services.

 

Im folgenden C# Code wird

 

 

Dabei ist die App im Store so konzipiert, dass die App generell kostenlos ist und nach einer internen Testphase die erweiterungen nur gegen den Kauf der Voll-version möglich sind und die App im reduzierten Modus weiter betrieben werden kann.

 

C# Code zum Abrufen und Verwalten von App Produkt-Daten im Windows Store

      #region Windows-Store

        //------------------< region: Windows-Store >------------------

        private StoreContext _Store_context = null;

        private StoreAppLicense appLicense = null;

        private String _Store_SkuStoreId = null;

        private StoreLicense _Store_addOnLicense_0 = null;

 

        private bool _Store_IsPaid = false;

        private bool _Store_IsTestperiod = true;

        private DateTime _Store_DateStart_TestPeriod = Convert.ToDateTime(null);

        private int _Store_Testrange_in_Days = 30;

 

        private async void init_Store()

        {

            //-------------< init_Store()-------------

            //< get variables >

            await check_Store_IsPaid();

            if (_Store_IsPaid == false)

            {

                await check_init_Store_Testperiod();

            }

            //</ get variables >

 

            //< set Controls >

            if (_Store_IsPaid == true )

            {

                btnStore.Visibility = Visibility.Collapsed;

            }

            else

            {

                if (_Store_IsTestperiod==true  )

                {

                    //*IsTestperiod: everything works

                }

                else

                {

                    //< Testperiod is over >

                    btnStore.Visibility = Visibility.Visible;

                    btnOptions.IsEnabled = false;

                    btnControllers.IsEnabled = false;

                    //</ Testperiod is over >

                }

            }

            //</ set Controls >

 

 

            //-------------</ init_Store()-------------

        }

 

        public async Task<bool> check_init_Store_Testperiod()

        {

            //-------------< check_init_Store_Testperiod()-------------

            //----< get Start_Testperiod >----

            try

            {              

                //< Get Setting >

                var varDateStart_TestPeriod = ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"];

                //</ Get Setting >

 

                if (varDateStart_TestPeriod is null)

                {

                    //< init testperiod >

                    _Store_DateStart_TestPeriod = DateTime.Now;

                    //< Save Setting >

                    ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] = _Store_DateStart_TestPeriod.ToString();

                    //</ Save Setting >

                    //</ init testperiod >

                }

                else

                {

                    //< convert setting >

                    _Store_DateStart_TestPeriod = Convert.ToDateTime(varDateStart_TestPeriod);

                    //</ convert setting >

                }

            }

            catch (Exception ex)

            {

                //< error >

                MessageDialog dialog = new MessageDialog( ex.Message , "Information: Check Store TestPeriod");

                await dialog.ShowAsync();

                return false;

                //</ error >

            }

            //----</ get Start_Testperiod >----

 

            //----< check in TestPeriod >----

            if(_Store_DateStart_TestPeriod.AddDays(_Store_Testrange_in_Days)>DateTime.Now )

            { _Store_IsTestperiod  = true; }

            else

            { _Store_IsTestperiod = false ; }

            //----</ check in TestPeriod >----

 

            //< output >

            return _Store_IsTestperiod;

            //</ output >

 

            //-------------</ check_init_Store_Testperiod()-------------

        }

 

        public async Task<bool> check_Store_IsPaid()

        {

            //-------------< check_Store_IsPaid()-------------

            //< check ok >

            if(_Store_IsPaid ==true)

            {

                return true;

            }

            //</ check ok >

 

            //----< get Setting: Store_IsPaid >----

            try

            {

                //< Get Setting >

                var varStore_IsPaid = ApplicationData.Current.LocalSettings.Values["Store_IsPaid"];

                //</ Get Setting >

 

                if (varStore_IsPaid is null)

                {

                    //< init testperiod >

                    _Store_IsPaid = false;

                    //< Save Setting >

                    ApplicationData.Current.LocalSettings.Values["Store_IsPaid"] = _Store_IsPaid ;

                    //</ Save Setting >

                    //</ init testperiod >

                }

                else

                {

                    //< convert setting >

                    _Store_IsPaid = Convert.ToBoolean(varStore_IsPaid);

                    //</ convert setting >

                }

            }

            catch (Exception ex)

            {

                //< error >

                MessageDialog dialog = new MessageDialog(ex.Message, "Information: Check Store Addon is Paid");

                await dialog.ShowAsync();

                return false;

                //</ error >

            }

            //----</ get Setting: Store_IsPaid >----

 

 

 

            //< output >

            return _Store_IsPaid;

            //</ output >

 

            //-------------</ check_Store_IsPaid()-------------

        }

 

        public async Task<bool> get_Store_IsPaid()

        {

            //-------------< get_Store_LicenseInfo()-------------

            if (_Store_context == null)

            {

                _Store_context = StoreContext.GetDefault();  //UWP App

            }

           

            //< get Store Data >

            appLicense = await _Store_context.GetAppLicenseAsync();

            //</ get Store Data >

 

           

            if (appLicense == null)

            {

                return false;

            }

            else

            {

                //--< show License Infos >--

                _Store_SkuStoreId= appLicense.SkuStoreId;

                if (appLicense.AddOnLicenses.Count>0)

                {

                    foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)

                    {

                        _Store_addOnLicense_0 = item.Value;

                       

                        //--< check first AddOn >--

                        if(_Store_addOnLicense_0.IsActive==true)

                        {

                            _Store_IsPaid = true;

                            return true;                           

                        }

                        break;

                        //--</ check first AddOn >--

                    }

                }

                //* nothing found is false

                return false ;

                //--</ show License Infos >--

            }

 

           

            //-------------</ get_Store_LicenseInfo()-------------

        }

 

        public async Task<bool> get_Store_AddOn_License_0()

        {

            //-------------< get_Store_AddOn_License_0()-------------

            if (_Store_context == null)

            {

                _Store_context = StoreContext.GetDefault();  //UWP App

               

            }

 

            //< get Store Data >

            appLicense = await _Store_context.GetAppLicenseAsync();

            //</ get Store Data >

 

 

            if (appLicense == null)

            {

                return false;

            }

            else

            {

                //--< show License Infos >--

                if (appLicense.AddOnLicenses.Count > 0)

                {

                    foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)

                    {

                        _Store_addOnLicense_0 = item.Value;

                        return true;

                        //--</ check first AddOn >--

                    }

                }

                //* nothing found is false

                return false;

                //--</ show License Infos >--

            }

 

 

            //-------------</ get_Store_AddOn_License_0()-------------

        }

        #endregion /Windows-Store

 

 

Über einen Shop Button kann die erste Addon Produkt (Voll-Version) gekauft werden

       private async  void btnStore_Click(object sender, RoutedEventArgs e)

        {

            if (_Store_addOnLicense_0==null)

            {

                //--< get Addon >--

                bool result_AddOn_0=await get_Store_AddOn_License_0();

                if (result_AddOn_0==false )

                {

                    //< no addon >

                    msgBox("no Addon found for this app", "MS Windows Store");

                    return;

                    //</ no addon >

                }

                //--</ get Addon >--

            }

 

 

            //----< Buy Addon >----

            StorePurchaseResult store_Result = await _Store_context.RequestPurchaseAsync(_Store_addOnLicense_0.SkuStoreId);

            if (store_Result.ExtendedError != null)

            {               

                msgBox (store_Result.ExtendedError.Message , "Error on Store");

                return;

            }

 

            switch (store_Result.Status)

            {

                case StorePurchaseStatus.AlreadyPurchased:

                    msgBox("OK: You already bought this AddOn.", "Addon is purchased.");

                    break;

                case StorePurchaseStatus.Succeeded:

                    msgBox("OK: Thank You. You bought the FullVersion", "Addon is purchased.");

                    break;

                case StorePurchaseStatus.NotPurchased:

                    msgBox("Error Reason: it may have been canceled.", "Product is NOT purchased");

                    break;

                case StorePurchaseStatus.NetworkError:

                    msgBox("Error Reason: network error.", "Product is NOT purchased");

                    break;

                case StorePurchaseStatus.ServerError:

                    msgBox("Error Reason: server error.", "Product is NOT purchased");

                    break;

                default:

                    msgBox("Error: unknown error.", "Product is purchased");

                    break;

            }

            //----</ Buy Addon >----

 

        }

 

 

 

 

 

 

 

 

Win32:

Initalize the store under Win32 apps in UWP

[ComImport]

[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

public interface IInitializeWithWindow

{

   void Initialize(IntPtr hwnd);

}

 

Including the UWP functions for Windows 32 applications

using System.Runtime.InteropServices;

 

Solution

https://docs.microsoft.com/de-de/windows/uwp/monetize/in-app-purchases-and-trials#testing" ]

 

User zero Windows.System.User

Mobile

.

123movies