Exemplo n.º 1
0
        private async void ButtonPin_Click(object sender, RoutedEventArgs e)
        {
            ButtonPin.IsEnabled = false;

            string text = "Now, this is the story all about how my tile got text-wrapped upside down. And I'd like to take a minute, just sit right there, I'll tell you how I became the prince of a town called Bellevue. In South Arizona, born and raised, in the mountains is where I spent most of my days, climbin' up, runnin', posin' all cool, and all shootin' some videos outside of school. When a couple of guys who were up to no good, started leavin' trash at the trailhead.";

            await TilesHelper.PinNewSecondaryTile("text wrapping",
                                                  $@"
                <tile version='3'>
                    <visual>

                        <binding template='TileSmall'>
                            <text hint-wrap='true'>{text}</text>
                        </binding>

                        <binding template='TileMedium'>
                            <text hint-wrap='true'>{text}</text>
                        </binding>

                        <binding template='TileWide'>
                            <text hint-wrap='true'>{text}</text>
                        </binding>

                        <binding template='TileLarge'>
                            <text hint-wrap='true'>{text}</text>
                        </binding>

                </visual>
            </tile>");


            await new MessageDialog("SUCCESS").ShowAsync();
            ButtonPin.IsEnabled = true;
        }
Exemplo n.º 2
0
        private void Init()
        {
            InitDockLayout();

            PluginHelper.Init(this);

            ToolStripManager.LoadSettings(this);

            TilesHelper.Init(mnuTiles);

            InitLegend();

            this.InitMenus();

            RefreshUI();

            var gs = new GlobalSettings();

            gs.ApplicationCallback = _callback;

            Shown += (s, e) => Map.Focus();

            FormClosing += MainForm_FormClosing;

            App.Project.ProjectChanged += (s, e) => RefreshUI();

            App.Project.Load(AppSettings.Instance.LastProject);
        }
Exemplo n.º 3
0
        public async Task UpdateAllSecondaryTilesIfHas()
        {
            try
            {
                var tiles = await TilesHelper.FindAllSecondaryTilesAsync();

                foreach (var tile in tiles)
                {
                    long deckId  = 0;
                    var  success = long.TryParse(tile.TileId, out deckId);
                    if (success)
                    {
                        var deck = GetDeck(deckId);
                        TilesHelper.SendSecondaryTileNotification(tile.TileId, deck.NewCards.ToString(), deck.DueCards.ToString());
                        tile.VisualElements.BackgroundColor = GetColors(deck);

                        await tile.UpdateAsync();
                    }
                }
            }
            catch (Exception e)
            { //App should not crash if any error happen
                Debug.WriteLine("DeckListViewModel.UpdateAllSecondaryTilesIfHas: " + e.Message);
            }
        }
Exemplo n.º 4
0
        private async Task OnTimeBatteryLevelBackgroundTaskActivated(IBackgroundTaskInstance backgroundTaskInstance)
        {
            if (!TilesHelper.BatteryTileExists())
            {
                return;
            }

            var applicationsService = new ApplicationsService();

            var errorMessage = await DeviceManager.ConnectAsync(isBackgroundActivity : true);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return;
            }

            var percentage = await DeviceManager.GetBatteryPercentageAsync();

            if (percentage > 0)
            {
                TilesHelper.UpdateBatteryTile(percentage);
            }
            else
            {
                TilesHelper.ResetBatteryTile();
            }
        }
Exemplo n.º 5
0
 private IAsyncOperation <bool> GetLatestNews()
 {
     try {
         return(AsyncInfo.Run(token => TilesHelper.GetNewsAsync()));
     } catch (Exception) { /* ignored */ }
     return(null);
 }
Exemplo n.º 6
0
 public void UpdatePrimaryTile()
 {
     try
     {
         TilesHelper.SendPrimaryTileNoficiation(TotalNewCards.ToString(), TotalDueCards.ToString());
     }
     catch { }
 }
Exemplo n.º 7
0
        private async void ButtonPin_Click(object sender, RoutedEventArgs e)
        {
            ButtonPin.IsEnabled = false;

            await TilesHelper.UpdateTiles(TextBoxPayload.Text);

            ButtonPin.IsEnabled = true;
        }
Exemplo n.º 8
0
    void UpdateScore()
    {
        int[] nodesInt    = new int[nodesCount.Length];
        int[] clustersInt = new int[clustersCount.Length];

        // Count nodes per player
        foreach (GameObject candidateNode in btns)
        {
            int currentOwner = candidateNode.GetComponent <Node> ().owner;
            if (currentOwner != -1)
            {
                nodesInt[currentOwner] = nodesInt[currentOwner] + 1;
            }
        }

        // Update nodes count
        for (int i = 0; i < nodesInt.Length; i++)
        {
            string nodeText = " nodes";
            if (nodesInt[i] <= 1)
            {
                nodeText = " node";
            }
            nodesCount[i].GetComponent <Text>().text = nodesInt[i].ToString() + nodeText;
        }

        // Progress bars
        for (int i = 0; i < progressBars.Length; i++)
        {
            //int parentHeight = progressBars[i].GetComponentInParent<Transform>().height;
            float percent = (float)nodesInt[i] / (float)btns.Count;
            progressBars[i].GetComponent <Slider>().value = percent;
        }

        // Clusters score
        for (int i = 0; i < GameModel.players.Count; i++)
        {
            clustersInt[i] = TilesHelper.CountClusters(i, btns);

            string clusterText = " clusters";
            if (clustersInt[i] <= 1)
            {
                clusterText = " cluster";
            }

            clustersCount[i].GetComponent <Text>().text = clustersInt[i].ToString() + clusterText;
        }

        if (GameModel.IS_HUMAN)
        {
            playerScore = nodesInt [0] * clustersInt [0];
        }
        else
        {
            // Score vs. AI depends on the difficulty
            playerScore = nodesInt [0] * clustersInt [0] * (GameModel.AI_DIFFICULTY + 1);
        }
    }
Exemplo n.º 9
0
        private async void RenameFlyoutOKButtonClickHandler(object sender, RoutedEventArgs e)
        {
            await mainPage.CurrentDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var baseName = renameFlyout.NewName;
                if (String.IsNullOrWhiteSpace(baseName))
                {
                    return;
                }

                if (baseName.Equals("Default", StringComparison.OrdinalIgnoreCase) && deckShowContextMenu.Id != Constant.DEFAULTDECK_ID)
                {
                    await UIHelper.ShowMessageDialog("You can't name a non-default deck \"Default\"");
                    return;
                }

                var existingName = deckListViewModel.GetAllDeckBaseName();
                if (existingName.Contains(baseName))
                {
                    await NotifyNameAlreadyExist();
                    return;
                }

                try
                {
                    var newName = deckListViewModel.GetNewFullName(deckShowContextMenu, baseName);
                    var deck    = collection.Deck.Get(deckShowContextMenu.Id);
                    collection.Deck.Rename(deck, newName);
                    deckListViewModel.UpdateDeckName(deckShowContextMenu);

                    collection.Deck.Save(deck);
                    collection.SaveAndCommitAsync();

                    var tile = await TilesHelper.FindExisting(deckShowContextMenu.Id.ToString());
                    if (tile != null)
                    {
                        tile.DisplayName = newName;
                        await tile.UpdateAsync();
                    }
                }
                catch (DeckRenameException ex)
                {
                    if (ex.Error == DeckRenameException.ErrorCode.ALREADY_EXISTS)
                    {
                        await NotifyNameAlreadyExist();
                    }
                    else
                    {
                        await UIHelper.ShowMessageDialog("You cannot rename this deck!");
                    }
                }
                catch
                {
                    await UIHelper.ShowMessageDialog("Unexpected error!");
                }
            });
        }
Exemplo n.º 10
0
        private async void ButtonPin_Click(object sender, RoutedEventArgs e)
        {
            await TilesHelper.GenerateSecondaryTile("CustomSmall", "Small").RequestCreateAsync();

            await TilesHelper.GenerateSecondaryTile("CustomMedium", "Medium").RequestCreateAsync();

            await TilesHelper.GenerateSecondaryTile("CustomWide", "Wide").RequestCreateAsync();

            await TilesHelper.GenerateSecondaryTile("CustomLarge", "Large").RequestCreateAsync();
        }
Exemplo n.º 11
0
 private async Task UpdateSecondaryTileIfHas(DeckInformation deck)
 {
     try
     {
         await TilesHelper.UpdateTile(deck.Id.ToString(), deck.NewCards.ToString(), deck.DueCards.ToString());
     }
     catch (Exception e)
     { //App should not crash if any error happen
         Debug.WriteLine("DeckListViewModel.DeleteSecondaryTileIfHas: " + e.Message);
     }
 }
Exemplo n.º 12
0
 private async Task RemoveSecondaryTileIfHas(long deckId)
 {
     try
     {
         await TilesHelper.RemoveTile(deckId.ToString());
     }
     catch (Exception e)
     { //App should not crash if any error happen
         Debug.WriteLine("DeckListViewModel.DeleteSecondaryTileIfHas: " + e.Message);
     }
 }
Exemplo n.º 13
0
        private async void UnpinBatteryTile()
        {
            var result = await TilesHelper.UnpinBatteryTileAsync();

            if (!result)
            {
                this.UseBatteryLiveTile = true;
                return;
            }

            BackgroundManager.Unregister(BackgroundManager.TimeBatteryLevelTaskName);
        }
Exemplo n.º 14
0
        private async void SecondTitleBtn_ClickAsync(object sender, RoutedEventArgs e)
        {
            Windows.UI.StartScreen.SecondaryTile tile = TilesHelper.GenerateSecondaryTile("SecondaryTitle", "Beansprout UWP", Colors.Transparent);
            tile.VisualElements.ShowNameOnSquare150x150Logo       =
                tile.VisualElements.ShowNameOnSquare310x310Logo   =
                    tile.VisualElements.ShowNameOnWide310x150Logo =
                        true;
            await tile.RequestCreateAsync();

            try {
                await TilesHelper.GetNewsAsync();
            } catch { /* Ignore */ }
        }
Exemplo n.º 15
0
        public override void Initialize()
        {
            this.ApplicationName         = Package.Current.DisplayName;
            this.CustomDate              = DateTimeOffset.Now;
            this.CustomTime              = DateTimeOffset.Now.TimeOfDay;
            this.DeviceName              = DeviceManager.DeviceName;
            this.EnableUserNotifications = BackgroundManager.IsBackgroundTaskRegistered(BackgroundManager.UserNotificationsTaskName);

            var lastSavedBatteryTaskFrequency = SettingsHelper.GetValue(Constants.LastSavedBatteryTaskFrequencySettingKey, (uint)15);

            this.BatteryCheckFrequency = this.AvailableBatteryCheckFrequencies.FirstOrDefault(bf => bf.Minutes == lastSavedBatteryTaskFrequency);

            this.UseBatteryLiveTile = TilesHelper.BatteryTileExists();
        }
Exemplo n.º 16
0
    public static int GetSizeOfTargetCluster(GameObject candidateNode, int targetTeam, List <GameObject> nodesList)
    {
        int        clusterSize     = 0;
        int        newDirection    = (candidateNode.GetComponent <Node>().direction + 1) % 4;
        GameObject destinationNode = TilesHelper.GetNeighbor(candidateNode, newDirection, nodesList);

        if (destinationNode != null)
        {
            int targetOwner = destinationNode.GetComponent <Node>().owner;
            if (targetOwner == targetTeam)
            {
                clusterSize = TilesHelper.GetClusterSize(destinationNode, nodesList);
            }
        }
        return(clusterSize);
    }
Exemplo n.º 17
0
        private async void ButtonPinTile_Click(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            _tileId = DateTime.Now.Ticks.ToString();

            SecondaryTile tile = TilesHelper.GenerateSecondaryTile(_tileId, "Secondary notification");

            tile.VisualElements.ShowNameOnSquare150x150Logo = true;
            tile.VisualElements.ShowNameOnSquare310x310Logo = true;
            tile.VisualElements.ShowNameOnWide310x150Logo   = true;
            await tile.RequestCreateAsync();

            stepsControl.Step++;
            base.IsEnabled = true;
        }
Exemplo n.º 18
0
        private async void PinBatteryTile()
        {
            var deviceId   = DeviceManager.DeviceId;
            var deviceName = DeviceManager.DeviceName;
            var result     = await TilesHelper.PinBatteryTileAsync(deviceId, deviceName);

            if (!result)
            {
                this.UseBatteryLiveTile = false;
                return;
            }

            this.RegisterBatteryTask();

            var batteryPercentage = await DeviceManager.GetBatteryPercentageAsync();

            TilesHelper.UpdateBatteryTile(batteryPercentage);
        }
Exemplo n.º 19
0
        private async void OnMenuFlyoutCreateDeckTileClick(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            var tileId = deckShowContextMenu.Id.ToString();

            SecondaryTile tile = TilesHelper.GenerateSecondaryTile(tileId, deckShowContextMenu.BaseName);

            tile.VisualElements.ShowNameOnSquare150x150Logo = true;
            tile.VisualElements.ShowNameOnSquare310x310Logo = true;
            tile.VisualElements.ShowNameOnWide310x150Logo   = true;
            tile.VisualElements.BackgroundColor             = DeckListViewModel.GetColors(deckShowContextMenu);

            await tile.RequestCreateAsync();

            base.IsEnabled = true;
            TilesHelper.SendSecondaryTileNotification(tileId, deckShowContextMenu.NewCards.ToString(), deckShowContextMenu.DueCards.ToString());
        }
Exemplo n.º 20
0
        /// <summary>
        /// 在应用程序由最终用户正常启动时进行调用。
        /// 将在启动应用程序以打开特定文件等情况下使用。
        /// </summary>
        /// <param name="e">有关启动请求和过程的详细信息。</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            InitAppStateWhenFirstDeployment();
            RegisterExceptionHandlingSynchronizationContext();

            Frame rootFrame = Window.Current.Content as Frame;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                }

                // 将框架放在当前窗口中
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // 当导航堆栈尚未还原时,导航到第一页,
                    // 并通过将所需信息作为导航参数传入来配置
                    // 参数
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // 确保当前窗口处于活动状态
                Window.Current.Activate();
            }

            try {
                await TilesHelper.GetNewsAsync(ignoreTime : true);
            } catch { /* Ignore */ }
        }
Exemplo n.º 21
0
    private GameObject CaptureBiggestClusterOptimal(int targetTeam, List <GameObject> nodesList)
    {
        GameObject potentialBestNode = null;
        int        bestClusterSize   = 0;

        // For each node that belongs to the current player
        foreach (GameObject candidateNode in nodesList)
        {
            if (candidateNode.GetComponent <Node>().owner == team)
            {
                int clusterSize = TilesHelper.GetSizeOfTargetCluster(candidateNode, targetTeam, nodesList);

                if (clusterSize > bestClusterSize)
                {
                    potentialBestNode = candidateNode;
                    bestClusterSize   = clusterSize;

                    bool cont  = true;
                    int  limit = 32;
                    while (cont && limit > 0)
                    {
                        cont = false;
                        limit--;
                        HashSet <GameObject> nodesBehind = TilesHelper.GetNodeBehind(potentialBestNode, nodesList);
                        foreach (GameObject nodeBehind in nodesBehind)
                        {
                            clusterSize = TilesHelper.GetSizeOfTargetCluster(nodeBehind, targetTeam, nodesList);
                            if (clusterSize >= bestClusterSize)
                            {
                                potentialBestNode = nodeBehind;
                                bestClusterSize   = clusterSize;
                                cont = true;
                            }
                        }
                    }
                }
            }
        }

        return(potentialBestNode);
    }
Exemplo n.º 22
0
    private GameObject CaptureInTwo(int targetTeam, List <GameObject> nodesList)
    {
        foreach (GameObject candidateNode in nodesList)
        {
            if (candidateNode.GetComponent <Node>().owner == team)
            {
                int        newDirection    = (candidateNode.GetComponent <Node>().direction + 2) % 4;
                GameObject destinationNode = TilesHelper.GetNeighbor(candidateNode, newDirection, nodesList);
                if (destinationNode != null)
                {
                    int targetOwner = destinationNode.GetComponent <Node>().owner;
                    if (targetOwner == targetTeam)
                    {
                        return(candidateNode);
                    }
                }
            }
        }

        return(null);
    }
Exemplo n.º 23
0
        private async Task PinTile(string style)
        {
            SecondaryTile tile = TilesHelper.GenerateSecondaryTile(style);

            tile.VisualElements.ShowNameOnSquare150x150Logo = true;
            tile.VisualElements.ShowNameOnSquare310x310Logo = true;
            tile.VisualElements.ShowNameOnWide310x150Logo   = true;

            await tile.RequestCreateAsync();

            string xml = $@"
                <tile version='3'>
                    <visual>
       
                        <binding template='TileSmall'>
                            <text hint-style='{style}'>This is a string of text that will be styled to the desired effect</text>
                        </binding>

                        <binding template='TileMedium'>
                            <text hint-style='{style}'>This is a string of text that will be styled to the desired effect</text>
                        </binding>

                        <binding template='TileWide'>
                            <text hint-style='{style}'>This is a string of text that will be styled to the desired effect</text>
                        </binding>

                        <binding template='TileLarge'>
                            <text hint-style='{style}'>This is a string of text that will be styled to the desired effect</text>
                        </binding>
                    </visual>
                </tile>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            TileNotification notification = new TileNotification(doc);

            TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notification);
        }
Exemplo n.º 24
0
    private GameObject CaptureBiggestCluster(int targetTeam, List <GameObject> nodesList)
    {
        GameObject potentialBestNode = null;
        int        bestClusterSize   = 0;

        // For each node that belongs to the current player
        foreach (GameObject candidateNode in nodesList)
        {
            if (candidateNode.GetComponent <Node>().owner == team)
            {
                int clusterSize = TilesHelper.GetSizeOfTargetCluster(candidateNode, targetTeam, nodesList);

                if (clusterSize > bestClusterSize)
                {
                    potentialBestNode = candidateNode;
                    bestClusterSize   = clusterSize;
                }
            }
        }

        return(potentialBestNode);
    }
Exemplo n.º 25
0
    int Propagate(GameObject source, int newOwner, int PreviousConverted)
    {
        int maxDepth = 1;

        //Rotate node
        source.GetComponent <Node>().ChangeOwner(newOwner);

        StartCoroutine(WaitForPlay(source, newOwner, PreviousConverted));

        // Update the target node
        int        targetDirection = source.GetComponent <Node>().direction;
        GameObject targetNeighbor  = TilesHelper.GetNeighbor(source, targetDirection, btns);

        if (targetNeighbor != null)
        {
            if (targetNeighbor.GetComponent <Node>().owner != newOwner)
            {
                maxDepth = Mathf.Max(maxDepth + 1, Propagate(targetNeighbor, newOwner, PreviousConverted + 1));
            }
        }

        // Update neighbors pointing to currentNode
        for (int neighDirection = 0; neighDirection < 4; neighDirection++)
        {
            GameObject neighbor = TilesHelper.GetNeighbor(source, neighDirection, btns);
            if (neighbor != null)
            {
                if (neighbor.GetComponent <Node>().owner != newOwner)
                {
                    if (neighbor.GetComponent <Node>().direction == (neighDirection + 2) % 4)
                    {
                        maxDepth = Mathf.Max(maxDepth + 1, Propagate(neighbor, newOwner, PreviousConverted + 1));
                    }
                }
            }
        }

        return(Mathf.Max(maxDepth, PreviousConverted + 1));
    }
Exemplo n.º 26
0
        private async void ButtonPinSecondaryTile_Click(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            _tileId = DateTime.Now.Ticks.ToString();

            string ImageUrl = "http://c.s-microsoft.com/en-us/CMSImages/windows_symbol.png?version=f1f9db81-67ef-8866-1be3-d5b1c1bb0b26";

            SecondaryTile tile = TilesHelper.GenerateSecondaryTile("Web Image");
            await tile.RequestCreateAsync();

            string tileXmlString =
                "<tile>"
                + "<visual>"
                + "<binding template='TileSmall'>"
                + "<image src='" + ImageUrl + "' alt='Web image'/>"
                + "</binding>"
                + "<binding template='TileMedium'>"
                + "<image src='" + ImageUrl + "' alt='Web image'/>"
                + "</binding>"
                + "<binding template='TileWide'>"
                + "<image src='" + ImageUrl + "' alt='Web image'/>"
                + "</binding>"
                + "<binding template='TileLarge'>"
                + "<image src='" + ImageUrl + "' alt='Web image'/>"
                + "</binding>"
                + "</visual>"
                + "</tile>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(tileXmlString);
            TileNotification notifyTile = new TileNotification(xmlDoc);

            TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notifyTile);

            base.IsEnabled = true;
        }
        private async void ButtonPinSecondaryTile_Click(object sender, RoutedEventArgs e)
        {
            base.IsEnabled = false;

            _tileId = DateTime.Now.Ticks.ToString();

            string ImageUrl = "ms-appx:///Assets/check.png";

            SecondaryTile tile = TilesHelper.GenerateSecondaryTile("App Package Image");
            await tile.RequestCreateAsync();

            string tileXmlString =
                "<tile>"
                + "<visual>"
                + "<binding template='TileSmall'>"
                + "<image src='" + ImageUrl + "' alt='image'/>"
                + "</binding>"
                + "<binding template='TileMedium'>"
                + "<image src='" + ImageUrl + "' alt='image'/>"
                + "</binding>"
                + "<binding template='TileWide'>"
                + "<image src='" + ImageUrl + "' alt='image'/>"
                + "</binding>"
                + "<binding template='TileLarge'>"
                + "<image src='" + ImageUrl + "' alt='image'/>"
                + "</binding>"
                + "</visual>"
                + "</tile>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(tileXmlString);
            TileNotification notifyTile = new TileNotification(xmlDoc);

            TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notifyTile);

            base.IsEnabled = true;
        }
Exemplo n.º 28
0
        private async void UpdateBatteryPercentage(int?newPercentage = null)
        {
            await DispatcherHelper.RunAsync(async() =>
            {
                if (!newPercentage.HasValue)
                {
                    newPercentage = await DeviceManager.GetBatteryPercentageAsync();
                }

                if (newPercentage > 0)
                {
                    TilesHelper.UpdateBatteryTile(newPercentage);
                }
                else
                {
                    TilesHelper.ResetBatteryTile();
                }

                var oldPercentage      = this.BatteryPercentage;
                this.BatteryPercentage = newPercentage.Value;
                this.BatteryLevel      = BatteryHelper.Parse(newPercentage.Value);
            });
        }
Exemplo n.º 29
0
 public void UpdatePrimaryTile()
 {
     TilesHelper.UpdatePrimaryTile(TotalNewCards, TotalDueCards);
 }