Esempio n. 1
0
        private void SetTile(CinemaInfo ci, CinemaTileType cinemaType, double distance = 0)
        {
            if (ci == null)
            {
                return;
            }

            Grid gFront = new Grid();

            Image img = new Image()
            {
                Source = new BitmapImage(new Uri("Images/CineTileFront.png", UriKind.Relative))
            };

            gFront.Children.Add(img);

            TextBlock tbTitle = new TextBlock()
            {
                Margin = new Thickness(6), Text = ci.Name, TextWrapping = TextWrapping.Wrap, VerticalAlignment = System.Windows.VerticalAlignment.Bottom
            };

            Grid.SetRow(tbTitle, 1);
            gFront.Children.Add(tbTitle);

            switch (cinemaType)
            {
            case CinemaTileType.Nearest:
                gFront.Children.Add(new TextBlock()
                {
                    Margin = new Thickness(6), Text = String.Format("{0:N2} miles", distance), TextWrapping = TextWrapping.Wrap, VerticalAlignment = System.Windows.VerticalAlignment.Top
                });
                break;

            default:
                gFront.Children.Add(new TextBlock()
                {
                    Margin = new Thickness(6), Text = cinemaType.ToString(), TextWrapping = TextWrapping.Wrap, VerticalAlignment = System.Windows.VerticalAlignment.Top
                });
                break;
            }

            RadCustomHubTile t = new RadCustomHubTile()
            {
                CommandParameter = ci.ID,
                Margin           = new Thickness(12, 12, 0, 0),
                Height           = 144,
                Width            = 144,
                FrontContent     = gFront,
                IsFrozen         = true
            };

            t.Tap += t_Tap;

            TurnstileFeatherEffect.SetFeatheringIndex(t, tileIndex++);

            this.wpHubTiles.Children.Add(t);
        }
 /// <summary>
 /// Initializes a new instance of the RadCustomHubTileAutomationPeer class.
 /// </summary>
 /// <param name="owner">The owner.</param>
 public RadCustomHubTileAutomationPeer(RadCustomHubTile owner)
     : base(owner)
 {
 }
        private void LoadUpXMLAppMetrics(string metrics, Telerik.Windows.Controls.RadCartesianChart targetChart, Microsoft.Phone.Controls.PerformanceProgressBar progressBar,
                                         RadCustomHubTile rt1, RadCustomHubTile rt2, RadCustomHubTile rt3,
                                         TextBlock t1, TextBlock t2, TextBlock t3, TextBlock tb,
                                         String sDate, String eDate, TextBlock tr1, TextBlock tr2,
                                         int targetSeries)
        {
            App.lastRequest = Util.getCurrentTimestamp();
            String queryURL = sDate + " - " + eDate;

            if (targetSeries > 0)
            {
                // progressBar.Visibility = System.Windows.Visibility.Visible;
                rt1.IsFrozen   = false;
                rt2.IsFrozen   = false;
                rt3.IsFrozen   = false;
                tr2.Visibility = System.Windows.Visibility.Visible;
                tr2.Text       = "(" + DateTime.Parse(sDate).ToShortDateString() + " - " + DateTime.Parse(eDate).ToShortDateString() + ")";
            }
            else  // reset compare chart
            {
                TextBlock[] totals = { xtotal1, xtotal2, xtotal3, xtotal4, xtotal5, xtotal6, xtotal7, xtotal8 };
                if (MainPivot.SelectedIndex < 8)
                {
                    totals[MainPivot.SelectedIndex].Visibility = System.Windows.Visibility.Collapsed;
                }
                targetChart.Series[1].ItemsSource = null;
                tr1.Visibility = System.Windows.Visibility.Visible;
                tr2.Visibility = System.Windows.Visibility.Collapsed;
                tr1.Text       = "(" + DateTime.Parse(sDate).ToShortDateString() + " - " + DateTime.Parse(eDate).ToShortDateString() + ")";
                VisualStateManager.GoToState(rt1, "NotFlipped", true);
                VisualStateManager.GoToState(rt2, "NotFlipped", true);
                VisualStateManager.GoToState(rt3, "NotFlipped", true);
                rt1.IsFrozen = true;
                rt2.IsFrozen = true;
                rt3.IsFrozen = true;
            }

            Debug.WriteLine("LoadUpXMLAppMetrics:" + queryURL);

            WebClient w = new WebClient();

            Observable
            .FromEvent <DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted")
            .Subscribe(r =>
            {
                try
                {
                    XDocument loadedData = XDocument.Parse(r.EventArgs.Result);
                    //XDocument loadedData = XDocument.Load("getAllApplications.xml");

                    // ListTitle.Text = (string)loadedData.Root.Attribute("metric");
                    var data = from query in loadedData.Descendants("day")
                               select new ChartDataPoint
                    {
                        Value = (double)query.Attribute("value"),
                        Label = Util.stripOffYear(DateTime.Parse((string)query.Attribute("date")))
                    };

                    // for processed data for comparison
                    ObservableCollection <ChartDataPoint> newData = new ObservableCollection <ChartDataPoint>();

                    if (targetSeries > 0) // if it's compare we have to fake time
                    {
                        var previousData = targetChart.Series[0].ItemsSource;
                        IEnumerator <ChartDataPoint> enumerator = previousData.GetEnumerator() as System.Collections.Generic.IEnumerator <ChartDataPoint>;
                        int p = 0;

                        while (enumerator.MoveNext())
                        {
                            ChartDataPoint c = enumerator.Current;
                            ChartDataPoint n = data.ElementAt(p) as ChartDataPoint;
                            n.Label          = c.Label;
                            newData.Add(new ChartDataPoint {
                                Value = n.Value, Label = c.Label
                            });
                            p++;
                        }
                    }

                    progressBar.Visibility      = System.Windows.Visibility.Collapsed;
                    progressBar.IsIndeterminate = false;

                    if (targetSeries > 0)
                    {
                        targetChart.Series[targetSeries].ItemsSource = newData;
                        targetChart.Series[targetSeries].DisplayName = StartDate2 + " - " + EndDate2;
                    }
                    else
                    {
                        targetChart.Series[targetSeries].ItemsSource = data;
                    }

                    List <ChartDataPoint> count = data.ToList();

                    if (count != null)
                    {
                        targetChart.HorizontalAxis.LabelInterval = Util.getLabelIntervalByCount(count.Count);
                    }
                    else
                    {
                        targetChart.HorizontalAxis.LabelInterval = Util.getLabelInterval(DateTime.Parse(StartDate), DateTime.Parse(EndDate));
                    }

                    // count max,min,latest,total for display purposes
                    double latest = 0, minim = 9999999999999, maxim = 0, totalCount = 0;
                    IEnumerator <ChartDataPoint> Myenum = data.GetEnumerator();
                    while (Myenum.MoveNext())
                    {
                        ChartDataPoint oneValue = Myenum.Current;
                        latest     = oneValue.Value;
                        minim      = Math.Min(minim, oneValue.Value);
                        maxim      = Math.Max(maxim, oneValue.Value);
                        totalCount = totalCount + oneValue.Value;
                    }

                    t1.Text = latest.ToString();
                    t2.Text = minim.ToString();
                    t3.Text = maxim.ToString();
                    switch (metrics)
                    {
                    case "MedianSessionLength":
                    case "AvgSessionLength":
                        tb.Text = "N/A";     // makes no sense for these metrics
                        break;

                    default:
                        tb.Text = totalCount.ToString();
                        break;
                    }

                    tb.Visibility = System.Windows.Visibility.Visible;
                }
                catch (NotSupportedException)         // it's not XML - probably API overload
                {
                    MessageBox.Show("Flurry API overload, please try again later.");
                }
            });

            w.Headers[HttpRequestHeader.Accept] = "application/xml"; // get us XMLs version!
            string callURL = "http://api.flurry.com/appMetrics/" + metrics + "?apiAccessCode=" + apiKey + "&apiKey=" + appapikey + "&startDate=" + sDate + "&endDate=" + eDate;

            Debug.WriteLine("Calling URL:" + callURL);
            w.DownloadStringAsync(
                new Uri(callURL)
                );
        }
        private void LoadUpXMLAppMetrics(string metrics, Telerik.Windows.Controls.RadCartesianChart targetChart, Microsoft.Phone.Controls.PerformanceProgressBar progressBar,
                                        RadCustomHubTile rt1, RadCustomHubTile rt2, RadCustomHubTile rt3,
                                        TextBlock t1, TextBlock t2, TextBlock t3, TextBlock tb, 
                                        String sDate, String eDate, TextBlock tr1, TextBlock tr2,
                                        int targetSeries)
        {
            App.lastRequest = Util.getCurrentTimestamp();
            String queryURL = sDate + " - " + eDate;

            if (targetSeries > 0) {
                // progressBar.Visibility = System.Windows.Visibility.Visible;
                rt1.IsFrozen = false;
                rt2.IsFrozen = false;
                rt3.IsFrozen = false;
                tr2.Visibility = System.Windows.Visibility.Visible;
                tr2.Text = "(" + DateTime.Parse(sDate).ToShortDateString() + " - " + DateTime.Parse(eDate).ToShortDateString() + ")";
            }
            else  // reset compare chart
            {
                TextBlock[] totals = { xtotal1, xtotal2, xtotal3, xtotal4, xtotal5, xtotal6, xtotal7, xtotal8 };
                if (MainPivot.SelectedIndex < 8)
                {
                    totals[MainPivot.SelectedIndex].Visibility = System.Windows.Visibility.Collapsed;
                }
                targetChart.Series[1].ItemsSource = null;
                tr1.Visibility = System.Windows.Visibility.Visible;
                tr2.Visibility = System.Windows.Visibility.Collapsed;
                tr1.Text = "(" + DateTime.Parse(sDate).ToShortDateString() + " - " + DateTime.Parse(eDate).ToShortDateString() + ")";
                VisualStateManager.GoToState(rt1, "NotFlipped", true);
                VisualStateManager.GoToState(rt2, "NotFlipped", true);
                VisualStateManager.GoToState(rt3, "NotFlipped", true);
                rt1.IsFrozen = true;
                rt2.IsFrozen = true;
                rt3.IsFrozen = true;
            }

            Debug.WriteLine("LoadUpXMLAppMetrics:"+queryURL);

            WebClient w = new WebClient();

                Observable
                .FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted")
                .Subscribe(r =>
                {
                    try
                    {
                        XDocument loadedData = XDocument.Parse(r.EventArgs.Result);
                        //XDocument loadedData = XDocument.Load("getAllApplications.xml");

                    // ListTitle.Text = (string)loadedData.Root.Attribute("metric");
                    var data = from query in loadedData.Descendants("day")
                               select new ChartDataPoint
                               {
                                   Value = (double)query.Attribute("value"),
                                   Label = Util.stripOffYear(DateTime.Parse((string)query.Attribute("date")))
                               };

                    // for processed data for comparison
                    ObservableCollection<ChartDataPoint> newData = new ObservableCollection<ChartDataPoint>();

                    if (targetSeries > 0) // if it's compare we have to fake time
                    {
                        var previousData = targetChart.Series[0].ItemsSource;
                        IEnumerator<ChartDataPoint> enumerator = previousData.GetEnumerator() as System.Collections.Generic.IEnumerator<ChartDataPoint>;
                        int p = 0;

                        while (enumerator.MoveNext())
                        {
                            ChartDataPoint c = enumerator.Current;
                            ChartDataPoint n = data.ElementAt(p) as ChartDataPoint;
                            n.Label = c.Label;
                            newData.Add(new ChartDataPoint { Value = n.Value, Label = c.Label });
                            p++;
                        }

                    }

                    progressBar.Visibility = System.Windows.Visibility.Collapsed;
                    progressBar.IsIndeterminate = false;

                        if (targetSeries>0) {
                            targetChart.Series[targetSeries].ItemsSource = newData;
                            targetChart.Series[targetSeries].DisplayName = StartDate2 + " - " + EndDate2;
                        } else {
                            targetChart.Series[targetSeries].ItemsSource = data;
                        }

                    List<ChartDataPoint> count = data.ToList();

                    if (count != null)
                    {
                         targetChart.HorizontalAxis.LabelInterval = Util.getLabelIntervalByCount(count.Count);
                    }
                    else targetChart.HorizontalAxis.LabelInterval = Util.getLabelInterval(DateTime.Parse(StartDate),DateTime.Parse(EndDate));

                        // count max,min,latest,total for display purposes
                    double latest = 0, minim = 9999999999999, maxim = 0, totalCount = 0;
                    IEnumerator<ChartDataPoint> Myenum = data.GetEnumerator();
                    while (Myenum.MoveNext())
                        {
                            ChartDataPoint oneValue = Myenum.Current;
                            latest = oneValue.Value;
                            minim = Math.Min(minim, oneValue.Value);
                            maxim = Math.Max(maxim, oneValue.Value);
                            totalCount = totalCount + oneValue.Value;
                        }

                    t1.Text = latest.ToString();
                    t2.Text = minim.ToString();
                    t3.Text = maxim.ToString();
                    switch (metrics)
                    {
                        case "MedianSessionLength":
                        case "AvgSessionLength":
                            tb.Text = "N/A"; // makes no sense for these metrics
                            break;
                        default:
                            tb.Text = totalCount.ToString();
                            break;
                    }

                    tb.Visibility = System.Windows.Visibility.Visible;

                    }
                        catch (NotSupportedException) // it's not XML - probably API overload
                    {
                        MessageBox.Show("Flurry API overload, please try again later.");
                    }

                });

            w.Headers[HttpRequestHeader.Accept] = "application/xml"; // get us XMLs version!
            string callURL = "http://api.flurry.com/appMetrics/" + metrics + "?apiAccessCode=" + apiKey + "&apiKey=" + appapikey + "&startDate=" + sDate + "&endDate=" + eDate;
            Debug.WriteLine("Calling URL:" + callURL);
            w.DownloadStringAsync(
                new Uri(callURL)
                );
        }
        private void ParseXML(
                                XDocument what, 
                                int i, 
                                RadCartesianChart targetChart,
                                RadCustomHubTile rt1, RadCustomHubTile rt2, RadCustomHubTile rt3,
                                TextBlock t1, TextBlock t2, TextBlock t3, // stats numbers
                                TextBlock tb, // total info
                                String sDate, String eDate,
                                TextBlock tr1, // total info number
                                TextBlock tr2, // total info date/time range
                                int targetSeries // if it is basic or compare function
            ) {
            Debug.WriteLine("Processing..." + what);

            DataSource.getChartData()[i,targetSeries] = from query in what.Descendants("day")
                               select new ChartDataPoint
                               {
                                   Value = (double)query.Attribute("value"),
                                   Label = (string)query.Attribute("date")
                               };
            Debug.WriteLine("Setting DataContext of loaded data");
            /*
            var mydate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("month day");
            var mydatepattern = mydate.Patterns[0];
            sDate = String.Format(mydatepattern, DateTime.Parse(sDate));
            eDate = String.Format(mydatepattern, DateTime.Parse(eDate));
            */
            if (targetSeries > 0)
            {
                // progressBar.Visibility = System.Windows.Visibility.Visible;
                rt1.IsFrozen = false;
                rt2.IsFrozen = false;
                rt3.IsFrozen = false;
                tb.Visibility = Visibility.Visible;
                tr2.Visibility = Visibility.Visible;
                tr2.Text = "(" +  sDate + " - " + eDate + ")";
            }
            else  // reset compare chart
            {
                TextBlock[] totals = { info4Text1, info4Text2, info4Text3, info4Text4, info4Text5, info4Text6, info4Text7, info4Text8 };
                if (i < 8)
                {
                    totals[i].Visibility = Visibility.Collapsed;
                }
                targetChart.Series[1].ItemsSource = null;
                tr1.Visibility = Visibility.Visible;
                tr2.Visibility = Visibility.Collapsed;
                tr1.Text = "(" + sDate + " - " + eDate + ")";
                rt1.IsFlipped = false;
                rt2.IsFlipped = false;
                rt3.IsFlipped = false;
                rt1.IsFrozen = true;
                rt2.IsFrozen = true;
                rt3.IsFrozen = true;
            }
            Debug.WriteLine("Setting DataContext targetSeries:" + targetSeries);

            if (targetSeries > 0) // if it's compare we have to fake time
            {
                var previousData = DataSource.getChartData()[i, 0];
                ObservableCollection<ChartDataPoint> newData = new ObservableCollection<ChartDataPoint>();
                IEnumerator<ChartDataPoint> enumerator = previousData.GetEnumerator() as System.Collections.Generic.IEnumerator<ChartDataPoint>;
                int p = 0;
                while (enumerator.MoveNext())
                {
                    ChartDataPoint c = enumerator.Current;
                    Debug.WriteLine("Old Label:" + DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Label + " New Label:" + c.Label);
                    ChartDataPoint n = new ChartDataPoint { Value = DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Value, Label = c.Label };
                    newData.Add(n);
                    Debug.WriteLine("New label set:" + DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Label);
                    p++;
                }

                DataSource.getChartData()[i, 1] = newData;

            }

            targetChart.Series[targetSeries].ItemsSource = DataSource.getChartData()[i, targetSeries];
            targetChart.HorizontalAxis.LabelInterval = Util.getLabelIntervalByCount(DataSource.getChartData()[i, targetSeries].Count());

            // count max,min,latest,total for display purposes
            double latest = 0, minim = 9999999999999, maxim = 0, totalCount = 0;
            IEnumerator<ChartDataPoint> Myenum = DataSource.getChartData()[i,targetSeries].GetEnumerator();
            while (Myenum.MoveNext())
            {
                ChartDataPoint oneValue = Myenum.Current;
                latest = oneValue.Value;
                minim = Math.Min(minim, oneValue.Value);
                maxim = Math.Max(maxim, oneValue.Value);
                totalCount = totalCount + oneValue.Value;
            }

            t1.Text = latest.ToString();
            t2.Text = minim.ToString();
            t3.Text = maxim.ToString();
            switch (AppMetricsNames[i])
            {
                case "MedianSessionLength":
                case "AvgSessionLength":
                    tb.Text = "N/A"; // makes no sense for these metrics
                    break;
                default:
                    tb.Text = totalCount.ToString();
                    break;
            }

            tb.Visibility = Visibility.Visible; 


        } // ParseXML