Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new MainWindow object
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            //Set Dimensions of the Window
            Height = 600;
            Width  = 350;
            Left   = SystemParameters.FullPrimaryScreenWidth - Width;
            Top    = SystemParameters.FullPrimaryScreenHeight;

            //Animate from Bottom
            var da = new DoubleAnimation(SystemParameters.FullPrimaryScreenHeight, SystemParameters.WorkArea.Height - Height, TimeSpan.FromSeconds(1));

            da.EasingFunction = new QuinticEase();
            da.BeginTime      = TimeSpan.FromSeconds(2);
            BeginAnimation(TopProperty, da);

            //Set the greeting text
            HelloUser.Content = Greetings.Greet();

            //Attach the exiting code to the viewControllerConnector
            ViewControllerConnector.Exit += ExitAISA;

            //Initialize the OpenSpeak Engine
            OpenSpeak.Init();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new MainWindow object
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            //Set Dimensions of the Window
            Height = 600;
            Width  = 350;
            Left   = SystemParameters.FullPrimaryScreenWidth - Width;
            Top    = SystemParameters.FullPrimaryScreenHeight;

            //Animate from Bottom
            var da = new DoubleAnimation(SystemParameters.FullPrimaryScreenHeight, SystemParameters.WorkArea.Height - Height, TimeSpan.FromSeconds(1));

            da.EasingFunction = new QuinticEase();
            da.BeginTime      = TimeSpan.FromSeconds(2);
            BeginAnimation(TopProperty, da);

            //Set the greeting text
            HelloUser.Content = Greetings.Greet();

            //Attach the exiting code to the viewControllerConnector
            ViewControllerConnector.Exit += ExitAISA;

            //Initialize the OpenSpeak Engine
            OpenSpeak.Init();

            //Change the color of the Animating Lines according to Windows Accent Color.
            grid1.Background = SystemParameters.WindowGlassBrush;
            grid2.Background = SystemParameters.WindowGlassBrush;
            grid3.Background = SystemParameters.WindowGlassBrush;
            grid4.Background = SystemParameters.WindowGlassBrush;

            //Color the extraContent Topics
            Topic1.Foreground = SystemParameters.WindowGlassBrush;
            Topic2.Foreground = SystemParameters.WindowGlassBrush;
            Topic3.Foreground = SystemParameters.WindowGlassBrush;

            //Get the tips from the server
            var threadstart = new ThreadStart(() =>
            {
                try
                {
                    var healthtip  = AISA_API.Tips.Get(new AISA_API.HealthTip()).tip;
                    var weathertip = AISA_API.Tips.Get(new AISA_API.WeatherTip()).tip;
                    var studytip   = AISA_API.Tips.Get(new AISA_API.StudyTip()).tip;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        health_tip.Text  = healthtip;
                        weather_tip.Text = weathertip;
                        study_tip.Text   = studytip;
                    });
                }
                catch (Exception)
                {
                }
            });
            var thread = new Thread(threadstart);

            thread.Start();

            //Add the news items to the list in another thread
            var newsthreadstart = new ThreadStart(
                () =>
            {
                try
                {
                    var newsItems = AISA_API.News.GetAllNews();

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        foreach (var newsItem in newsItems.news)
                        {
                            //Add them to the newsContainer
                            var maingrid      = new Grid();
                            maingrid.Cursor   = Cursors.Hand;
                            maingrid.MouseUp += (a, b) =>
                            {
                                Process.Start(newsItem.url);
                            };

                            maingrid.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = new GridLength(50, GridUnitType.Pixel)
                            });
                            maingrid.ColumnDefinitions.Add(new ColumnDefinition()
                            {
                                Width = new GridLength(200, GridUnitType.Star)
                            });

                            var newsImage    = new Image();
                            newsImage.Source = new BitmapImage(new Uri(newsItem.thumbnail));
                            newsImage.Margin = new Thickness(0, 0, 10, 0);


                            var stackPanel = new StackPanel();

                            var newstitle          = new TextBlock();
                            newstitle.Text         = newsItem.title;
                            newstitle.TextTrimming = TextTrimming.CharacterEllipsis;
                            newstitle.Foreground   = new SolidColorBrush(Colors.White);

                            var newsdescription          = new TextBlock();
                            newsdescription.Text         = newsItem.description;
                            newsdescription.TextTrimming = TextTrimming.CharacterEllipsis;
                            newsdescription.Foreground   = new SolidColorBrush(Color.FromRgb(170, 170, 170));

                            stackPanel.Children.Add(newstitle);
                            stackPanel.Children.Add(newsdescription);

                            stackPanel.VerticalAlignment = VerticalAlignment.Center;

                            maingrid.Children.Add(newsImage);
                            maingrid.Children.Add(stackPanel);

                            Grid.SetColumn(newsImage, 0);
                            Grid.SetColumn(stackPanel, 1);

                            maingrid.Margin = new Thickness(0, 0, 0, 15);
                            NewsContainer.Children.Add(maingrid);
                        }
                    });
                }
                catch (Exception)
                {
                    // Error occurred while getting news information
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        var errorContainer = new Grid();
                        //Add the column definitions to this grid
                        errorContainer.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(2, GridUnitType.Pixel)
                        });
                        errorContainer.ColumnDefinitions.Add(new ColumnDefinition()
                        {
                            Width = new GridLength(248, GridUnitType.Star)
                        });

                        //Create the before of the label
                        var LabelBefore        = new Grid();
                        LabelBefore.Background = SystemParameters.WindowGlassBrush;

                        var errorlbl        = new Label();
                        errorlbl.Content    = "I'm having a trouble connecting to our servers.";
                        errorlbl.Foreground = new SolidColorBrush(Colors.White);
                        errorlbl.Margin     = new Thickness(5, 0, 0, 0);

                        errorContainer.Children.Add(errorlbl);
                        errorContainer.Children.Add(LabelBefore);

                        Grid.SetColumn(errorlbl, 1);
                        Grid.SetColumn(LabelBefore, 0);

                        NewsContainer.Children.Add(errorContainer);
                    }
                                                          );
                }
            });

            var newsThread = new Thread(newsthreadstart);

            newsThread.Start();
        }