示例#1
0
        public static void GenerateTileJpg(string msg)
        {
            Log.Debug("");
            var grid = new Grid()
            {
                Background          = new SolidColorBrush(Colors.Orange),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch,
                Height = 336,
                Width  = 336,
                Margin = new Thickness(0, 0, 0, 0),
            };

            var tbMsg = new TextBlock
            {
                Text          = msg,
                Foreground    = new SolidColorBrush(Colors.White),
                FontSize      = 42,
                TextAlignment = TextAlignment.Left,
            };

            grid.Children.Add(tbMsg);

            grid.Measure(new Size(grid.Width, grid.Height));
            grid.Arrange(new Rect(new Point(0, 0), new Size(grid.Width, grid.Height)));

            using (var stream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(m_tileImgPath, FileMode.Create))
            {
                WriteableBitmap bitmap = new WriteableBitmap(grid, null);
                bitmap.Render(grid, null);
                bitmap.Invalidate();
                bitmap.SaveJpeg(stream, (int)grid.Width, (int)grid.Height, 0, 100);
            }
        }
示例#2
0
 private void llsBuses_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     Log.Debug("");
     if (llsBuses.SelectedItem == null)
     {
         return;
     }
     Log.Debug("llsBuses.SelectedItem=" + (llsBuses.SelectedItem as StringVM).String);
     m_prevent_TextChangeEvent = true;
     tbBusName.Text            = (llsBuses.SelectedItem as StringVM).String;
     m_prevent_TextChangeEvent = false;
 }
示例#3
0
        static void UpdateTileImage(BusTag[] busTags)
        {
            Log.Debug("");
            GenerateTileJpg("\n".Joyn(busTags.Select(x => x.busName + " " + x.timeToArrive)));
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=FromTile"));

            if (tile != null)
            {
                tile.Update(new StandardTileData {
                    BackgroundImage = new Uri("isostore:/" + m_tileImgPath, UriKind.Absolute),
                    Title           = DateTime.Now.ToString("HH:mm:ss"),
                });
            }
        }
示例#4
0
        public static async Task <string> GetBusDueTime(string busName, string stationName, BusDir busDir)
        {
            string url = @"http://pda.5284.com.tw/MQS/businfo3.jsp?Mode=1&Dir={1}&Route={0}&Stop={2}".Fmt(
                Uri.EscapeUriString(busName), busDir == BusDir.go?1:0, Uri.EscapeUriString(stationName));

            var    client    = new HttpClient();
            string strResult = await client.GetStringAsync(new Uri(url));

            var doc = new HtmlDocument();

            doc.LoadHtml(strResult);

            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(
                "/html/body/center/table/tr[6]/td");

            if (nodes.Count == 0)
            {
                Log.Debug("nodes.Count == 0");
                return("網路障礙");
            }
            return(nodes[0].InnerText);
        }
示例#5
0
        protected override void OnInvoke(ScheduledTask task)
        {
            try
            {
                //Log.Create(false);
                ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DefaultTitle=FromTile"));

                bool bWiFiOnly = false;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue("WiFiOnly", out bWiFiOnly);
                if ((bWiFiOnly && !WifiConnected()) ||
                    tile == null)
                {
                    ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(1));
                    this.NotifyComplete();
                    return;
                }

                var busTags = new ObservableCollection <BusTagVM>(
                    from bus in LoadBusTags() orderby bus.tag select new BusTagVM(bus));

                Log.Debug("busTags=" + busTags.DumpArray());
                RefreshBusTime(busTags);

                //var tasks = busTags.Select(b => BusTicker.GetBusDueTime(b)).ToList();
                //var waIdx = Enumerable.Range(0, busTags.Length).ToList();

                //while (tasks.Count > 0)
                //{
                //    Task.WaitAny(tasks.ToArray());
                //    for (int i = tasks.Count - 1; i >= 0; --i)
                //    {
                //        if (tasks.Count == 0)
                //            break;
                //        if (tasks[i].IsCompleted)
                //        {
                //            int fIdx = waIdx[i];
                //            try
                //            {
                //                busTags[fIdx].timeToArrive = tasks[i].Result;
                //            }
                //            catch (Exception ex)
                //            {
                //                Log.Error(ex.DumpStr());
                //                busTags[fIdx].timeToArrive = "網路障礙";
                //            }
                //            waIdx.RemoveAt(i);
                //            tasks.RemoveAt(i);
                //        }
                //    }
                //}

                SaveBusTags(busTags.Select(x => x.BusTag).ToArray());

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    Log.Debug("Deployment.Current.Dispatcher.BeginInvoke enter");
                    try
                    {
                        Log.Debug("UpdateTileImage()");
                        UpdateTileImage(busTags.Select(x => x.BusTag).ToArray());
                        Log.Debug("Deployment.Current.Dispatcher.BeginInvoke exit");
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                    }
                    finally
                    {
                        ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(1));
                        this.NotifyComplete();
                        //Log.Close();
                    }
                });
            }
            catch (Exception e)
            {
                Log.Error(e.DumpStr());
            }
        }