using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Popups;
using C1.Xaml;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace StockPortfolio
{
  public enum TileStyle
   {
       Style1,
       Style2,
       Style3,
       Style4,
       Style5,
       Style6,
       Style7
   }
  public enum TileItemContainerStyle
  {
      Style1x1,
      Style2x2,
      Style1x2,
      Style2x1,

  }

    public enum TradeType
    {
        Sell,
        Buy
    }

    public static class Util
    {
        internal static Task ShowDialog(string msg, string title, List<IUICommand> commands)
        {
            CoreDispatcher dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            Func<object, Task<bool>> action = null;
            action = async (o) =>
            {
                try
                {
                    if (dispatcher.HasThreadAccess)
                    {
                        MessageDialog dialog = new MessageDialog(msg, title);
                        if (commands != null)
                        {
                            foreach (IUICommand com in commands)
                            {
                                dialog.Commands.Add(com);
                            }
                        }
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                        () => action(o));
                    }
                    return true;
                }
                catch (UnauthorizedAccessException)
                {
                    if (action != null)
                    {
                        Task.Delay(500).ContinueWith(async t => await action(o));
                    }
                }
                return false;
            };
            return action(null);
        }


      
    }

   

}
