<commit_before>using MarkerMetro.Unity.WinIntegration.Resources;
using MarkerMetro.Unity.WinIntegration.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if NETFX_CORE
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Contacts;
using Windows.System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.Networking.Connectivity;
using Windows.UI.Popups;
using Windows.Foundation;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.Networking.PushNotifications;
#endif

namespace MarkerMetro.Unity.WinIntegration
{
	/// <summary>
	/// Integration Helpers
	/// </summary>
	public class Helper
	{

		private static Helper _instance;
		private static readonly object _sync = new object();

		public static Helper Instance
		{
			get
			{
				lock (_sync)
				{
					if (_instance == null)
						_instance = new Helper();
				}
				return _instance;
			}
		}

		/// <summary>
		/// Fired when the App visibility has changed
		/// </summary>
		/// <remarks>
		/// This should be activated in CommonMainPage.cs, when a Window.Current.VisibilityChanged happens.
		/// </remarks>
		public Action<bool> OnVisibilityChanged;

		/// <summary>
		/// Returns the application package version 
		/// </summary>
		/// <returns></returns>
		public string GetAppVersion()
		{
#if NETFX_CORE
            var major = Package.Current.Id.Version.Major;
            var minor = Package.Current.Id.Version.Minor.ToString();
            var revision = Package.Current.Id.Version.Revision.ToString();
            var build = Package.Current.Id.Version.Build.ToString();
            var version = String.Format("{0}.{1}.{2}.{3}", major, minor, build, revision);
            return version;
#else
            return String.Empty;
#endif
		}

		/// <summary>
		/// Clears all local state
		/// </summary>
		/// <remarks>
		/// used to clear all local state from the app
		/// </remarks>
		public void ClearLocalState(Action<bool> callback)
		{
#if NETFX_CORE
            Dispatcher.InvokeOnUIThread(async () =>
            {
                try
                {
                    await Windows.Storage.ApplicationData.Current.ClearAsync(Windows.Storage.ApplicationDataLocality.Local);   
                    if (callback != null)
                    {
                        Dispatcher.InvokeOnAppThread(() => callback(true));
                    };            
                }
                catch
                {
                    if (callback != null)
                    {
                        Dispatcher.InvokeOnAppThread(() => callback(false));
                    };
                }
            });  
#else
            throw new PlatformNotSupportedException("ClearLocalState");
#endif
		}

		public void GetPushChannel(string channelName, Action<string> callback)
		{
#if NETFX_CORE 
			Dispatcher.InvokeOnUIThread(async () =>
			{
				try
				{
					var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
					if (callback != null)
					{
						Dispatcher.InvokeOnAppThread(() => callback(channel.Uri));
					}
				}
				catch
				{
					if (callback != null)
					{
						Dispatcher.InvokeOnAppThread(() => callback(String.Empty));
					}
				}
			});
#else
            throw new PlatformNotSupportedException("GetPushChannel(string channelName, Action<string> callback)");
#endif
		}

		/// <summary>
		/// Returns the application language
		/// </summary>
		/// <remarks>
		/// it's important to use this call rather than Unity APIs, which just return the top system language
		/// </remarks>
		public string GetAppLanguage()
		{
#if NETFX_CORE
            return Windows.Globalization.ApplicationLanguages.Languages[0];
#else
            return System.Globalization.CultureInfo.CurrentUICulture.Name;
#endif
		}

		/// <summary>
		/// Show the Share UI
		/// </summary>
		public void ShowShareUI()
		{
#if NETFX_CORE
            try
            {
                Dispatcher.InvokeOnUIThread(() => DataTransferManager.ShowShareUI());
            }
            catch (Exception ex)
            {
# if DEBUG
                Debug.WriteLine("Unable to show the share UI because of: " + ex.Message);
# else
                ExceptionLogger.Send(ex);
# endif
            }
#endif
		}

		/// <summary>
		/// Show the Share UI with a link - WP8 only
		/// </summary>
		/// <param name="text"></param>
		/// <param name="linkURL"></param>
		public void ShowShareUI(string text, string linkURL)
		{
			ShowShareUI(text, text, linkURL);
		}

		/// <summary>
		/// Show the Share UI with a link - WP8 only
		/// </summary>
		/// <param name="text"></param>
		/// <param name="message"></param>
		/// <param name="linkURL"></param>
		public void ShowShareUI(string text, string message, string linkURL)
		{
#if NETFX_CORE
            throw new NotImplementedException("Not implemented for Windows Store Apps, use ShowShareUI() instead.");
#endif
		}

		/// <summary>
		/// Show the Rate UI
		/// </summary>
		public void ShowRateUI()
		{
#if NETFX_CORE
            Dispatcher.InvokeOnUIThread(
                async () =>
                {
                    try
                    {
                        var data = Package.Current.Id.FamilyName;
# if DEBUG
                        Debug.WriteLine(data);
# endif
                        await Launcher.LaunchUriAsync(new Uri("ms-windows-store:REVIEW?PFN=" + data));
                    }
                    catch (Exception ex)
                    {
# if DEBUG
                        Debug.WriteLine("Unable to show MarketplaceReviewTask because of: " + ex.Message);
# else
                        ExceptionLogger.Send(ex);
# endif
                    }
                });
#else
            throw new NotImplementedException("Not implemented for unknown platform");
#endif<commit_msg>Fix for review uri on WP8.1<commit_after>using MarkerMetro.Unity.WinIntegration.Resources;
using MarkerMetro.Unity.WinIntegration.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if NETFX_CORE
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Contacts;
using Windows.System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.Networking.Connectivity;
using Windows.UI.Popups;
using Windows.Foundation;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.Networking.PushNotifications;
using Windows.ApplicationModel.Store;
#endif

namespace MarkerMetro.Unity.WinIntegration
{
	/// <summary>
	/// Integration Helpers
	/// </summary>
	public class Helper
	{

		private static Helper _instance;
		private static readonly object _sync = new object();

		public static Helper Instance
		{
			get
			{
				lock (_sync)
				{
					if (_instance == null)
						_instance = new Helper();
				}
				return _instance;
			}
		}

		/// <summary>
		/// Fired when the App visibility has changed
		/// </summary>
		/// <remarks>
		/// This should be activated in CommonMainPage.cs, when a Window.Current.VisibilityChanged happens.
		/// </remarks>
		public Action<bool> OnVisibilityChanged;

		/// <summary>
		/// Returns the application package version 
		/// </summary>
		/// <returns></returns>
		public string GetAppVersion()
		{
#if NETFX_CORE
            var major = Package.Current.Id.Version.Major;
            var minor = Package.Current.Id.Version.Minor.ToString();
            var revision = Package.Current.Id.Version.Revision.ToString();
            var build = Package.Current.Id.Version.Build.ToString();
            var version = String.Format("{0}.{1}.{2}.{3}", major, minor, build, revision);
            return version;
#else
            return String.Empty;
#endif
		}

		/// <summary>
		/// Clears all local state
		/// </summary>
		/// <remarks>
		/// used to clear all local state from the app
		/// </remarks>
		public void ClearLocalState(Action<bool> callback)
		{
#if NETFX_CORE
            Dispatcher.InvokeOnUIThread(async () =>
            {
                try
                {
                    await Windows.Storage.ApplicationData.Current.ClearAsync(Windows.Storage.ApplicationDataLocality.Local);   
                    if (callback != null)
                    {
                        Dispatcher.InvokeOnAppThread(() => callback(true));
                    };            
                }
                catch
                {
                    if (callback != null)
                    {
                        Dispatcher.InvokeOnAppThread(() => callback(false));
                    };
                }
            });  
#else
            throw new PlatformNotSupportedException("ClearLocalState");
#endif
		}

		public void GetPushChannel(string channelName, Action<string> callback)
		{
#if NETFX_CORE 
			Dispatcher.InvokeOnUIThread(async () =>
			{
				try
				{
					var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
					if (callback != null)
					{
						Dispatcher.InvokeOnAppThread(() => callback(channel.Uri));
					}
				}
				catch
				{
					if (callback != null)
					{
						Dispatcher.InvokeOnAppThread(() => callback(String.Empty));
					}
				}
			});
#else
            throw new PlatformNotSupportedException("GetPushChannel(string channelName, Action<string> callback)");
#endif
		}

		/// <summary>
		/// Returns the application language
		/// </summary>
		/// <remarks>
		/// it's important to use this call rather than Unity APIs, which just return the top system language
		/// </remarks>
		public string GetAppLanguage()
		{
#if NETFX_CORE
            return Windows.Globalization.ApplicationLanguages.Languages[0];
#else
            return System.Globalization.CultureInfo.CurrentUICulture.Name;
#endif
		}

		/// <summary>
		/// Show the Share UI
		/// </summary>
		public void ShowShareUI()
		{
#if NETFX_CORE
            try
            {
                Dispatcher.InvokeOnUIThread(() => DataTransferManager.ShowShareUI());
            }
            catch (Exception ex)
            {
# if DEBUG
                Debug.WriteLine("Unable to show the share UI because of: " + ex.Message);
# else
                ExceptionLogger.Send(ex);
# endif
            }
#endif
		}

		/// <summary>
		/// Show the Share UI with a link - WP8 only
		/// </summary>
		/// <param name="text"></param>
		/// <param name="linkURL"></param>
		public void ShowShareUI(string text, string linkURL)
		{
			ShowShareUI(text, text, linkURL);
		}

		/// <summary>
		/// Show the Share UI with a link - WP8 only
		/// </summary>
		/// <param name="text"></param>
		/// <param name="message"></param>
		/// <param name="linkURL"></param>
		public void ShowShareUI(string text, string message, string linkURL)
		{
#if NETFX_CORE
            throw new NotImplementedException("Not implemented for Windows Store Apps, use ShowShareUI() instead.");
#endif
		}

		/// <summary>
		/// Show the Rate UI
		/// </summary>
		public void ShowRateUI()
		{
#if NETFX_CORE
            Dispatcher.InvokeOnUIThread(
                async () =>
                {
                    try
                    {
                        Uri uri;
#if WINDOWS_PHONE_APP
                        uri = new Uri(String.Format("ms-windows-store:REVIEWAPP?appid={0}", CurrentApp.AppId));
#else
                        var data = Package.Current.Id.FamilyName;
                        uri = new Uri(String.Format("ms-windows-store:REVIEW?PFN={0}", data));
#endif

# if DEBUG
                        Debug.WriteLine(uri.ToString());
# endif
                        await Launcher.LaunchUriAsync(uri);
                    }
                    catch (Exception ex)
                    {
# if DEBUG
                        Debug.WriteLine("Unable to show MarketplaceReviewTask because of: " + ex.Message);
# else
                        ExceptionLogger.Send(ex);
# endif
                    }
                });
#else
            throw new NotImplementedException("Not implemented for unknown platform");
#endif
{'fraction_non_alphanumeric': 0.11503482179434658, 'fraction_numerical': 0.001474805407619828, 'mean_word_length': 2.035563292713255, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4501794', 'n_tokens_mistral': 3679, 'n_tokens_neox': 3215, 'n_words': 802}