Click here to Skip to main content
15,885,980 members
Articles / Desktop Programming / WPF

An Easy Guide For Developing and Publishing Apps in Intel AppUp Store for New Ultrabook Devices

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
13 Jan 2013CPOL42 min read 29.7K   453   9  
How to build and publish Ultrabook desktop Apps in Intel AppUP store
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.IO;
using WpfImageGallery;




namespace Kidsoo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region variables
        BitmapImage img;
        BackgroundWorker workerClear;
        BackgroundWorker workerNewColor;
        Brush currentBrush;
        Random rnd = new Random();
        System.Speech.Synthesis.SpeechSynthesizer speaker;
        
        bool SongsMode = false;
        #endregion
        List<ImageEntity> childImages = new List<ImageEntity>();
        Random rndImg = new Random();
        void DisplayResource()
        {
            int n = rndImg.Next(childImages.Count);
            ImageEntity selectedIE = childImages[n];
            img = new BitmapImage(new Uri(selectedIE.ImagePath));
            Image1.Source = img;
            speaker.SpeakAsync(selectedIE.Info);

        }
        public MainWindow()
        {
           // MessageBox.Show(Environment.CurrentDirectory);
            InitializeComponent();
            speaker = new System.Speech.Synthesis.SpeechSynthesizer();
            speaker.Rate = -8;

            img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("main.bmp")));
           Image1.Source = img;
           Image1.Width = System.Windows.SystemParameters.PrimaryScreenWidth - 100;
           Image1.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
           currentBrush = new SolidColorBrush(Color.FromRgb(255,0,0));

////////////////////Worker Clear will be used to clear the screen////////////////////////////////////
           workerClear = new BackgroundWorker();
            workerClear.DoWork += workerClear_DoWork;
           workerClear.WorkerReportsProgress = true;
          workerClear.ProgressChanged += workerClear_ProgressChanged;
          workerClear.RunWorkerAsync();

////////////////////////////////// This will be used for changing the Color///////////////////////
          workerNewColor = new BackgroundWorker();
          workerNewColor.DoWork += workerNewColor_DoWork;
          workerNewColor.WorkerReportsProgress = true;
          workerNewColor.ProgressChanged += workerNewColor_ProgressChanged;
          workerNewColor.RunWorkerAsync();
            //// Why do we have ProgressChanged? There is no progress bar here.
            // ProgressChange pumps a message to parent thread when invoked. This is a good way to 
            // let your parent thread know about any background thread to avoid application hang
        }

        void workerNewColor_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            
        }

        void workerNewColor_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                System.Threading.Thread.Sleep(5000);
                byte r = (byte)rnd.Next(0, 255);
                byte g = (byte)rnd.Next(0, 255);
                byte b = (byte)rnd.Next(0, 255);
           
                this.Dispatcher.Invoke(
                     DispatcherPriority.Normal,
                     (System.Windows.Forms.MethodInvoker)delegate()
                     {

                         currentBrush = new SolidColorBrush(Color.FromRgb(r, g, b));
                     }
         );
                workerNewColor.ReportProgress(10);
                System.Threading.Thread.Sleep(1000);
                //throw new NotImplementedException();
            }
            //throw new NotImplementedException();

        }

        void workerClear_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //throw new NotImplementedException();
        }

        void workerClear_DoWork(object sender, DoWorkEventArgs e)
        {
            
            while (true)
            {
                System.Threading.Thread.Sleep(40000);
                if (!SongsMode)
                {
                    this.Dispatcher.Invoke(
                            DispatcherPriority.Normal,
                            (System.Windows.Forms.MethodInvoker)delegate()
                            {/////////////
                                try
                                {
                                    string fileName = WorkingPath.Path+"\\"+DateTime.Now.Date.ToShortDateString() + "_" + DateTime.Now.TimeOfDay.TotalMilliseconds + ".jpg";
                                    Save(fileName, Image1.Source as BitmapSource);
                                }
                                catch (Exception ) {//MessageBox.Show(ex.ToString()) ;
                                }

                                //////////////

                                img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("main.bmp")));
                                Image1.Source = img;

                            }
                );
                }
                workerClear.ReportProgress(2);
                System.Threading.Thread.Sleep(1000);
            }
            //throw new NotImplementedException();
        }
        Random r = new Random();
        private int outDeviceID = 0;
        private Sanford.Multimedia.Midi.OutputDevice od = new Sanford.Multimedia.Midi.OutputDevice(0);
        private void Image1_MouseMove_1(object sender, MouseEventArgs e)
        {
            //if (e.LeftButton.Equals(MouseButtonState.Pressed))
            {
                
                //MessageBox.Show(img.Height + "-->" + System.Windows.SystemParameters.PrimaryScreenWidth);
              //  Point current = e.GetPosition(Image1);
                Point current = new Point(Math.Floor(e.GetPosition(Image1).X * img.Width / (System.Windows.SystemParameters.PrimaryScreenWidth - 100)), Math.Floor(e.GetPosition(Image1).Y * img.Height / System.Windows.SystemParameters.PrimaryScreenHeight));
                img = Logic.DrawPoint(img, current, currentBrush, new Pen(currentBrush, 2), 3);
                Image1.Source = img;
               
                int n = r.Next(30, 96);
                od.Send(new Sanford.Multimedia.Midi.ChannelMessage(Sanford.Multimedia.Midi.ChannelCommand.NoteOn, 0, n,127));
            }
        }

        private void Window_Closed_1(object sender, EventArgs e)
        {
            this.Dispatcher.InvokeShutdown();
        }

        private void Image1_TouchMove_1(object sender, TouchEventArgs e)
        {
            SongsMode = false;
            Point current = new Point(Math.Floor(e.TouchDevice.GetTouchPoint(Image1).Position.X * img.Width / (System.Windows.SystemParameters.PrimaryScreenWidth - 100)), Math.Floor(e.TouchDevice.GetTouchPoint(Image1).Position.Y * img.Height / System.Windows.SystemParameters.PrimaryScreenHeight));
            img = Logic.DrawPoint(img, current, currentBrush, new Pen(currentBrush, 2), 3);
            Image1.Source = img;

        }

        private void Window_KeyDown_1(object sender, KeyEventArgs e)
        {
            SongsMode = false;
            switch (e.Key)
            {
                case Key.A:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/A.png")));
                            Image1.Source = img;
                            System.Threading.Thread.Sleep(400);                    
                            speaker.SpeakAsync("A for Apple");
                    break;
                case Key.B:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/B.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("B for Ball");
                    break;

                case Key.C:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/C.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("C for Cat");
                    break;

                case Key.D:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/D.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("D for Dog");
                    break;

                case Key.E:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/E.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("E for Egg");
                    break;

                case Key.F:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/F.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("F for Fan");
                    break;
                case Key.G:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/G.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("G for Grapes");
                    break;

                case Key.H:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/H.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("H for Horse");
                    break;

                case Key.I:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/I.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("I for Icecream");
                    break;

                case Key.J:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/J.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("J for Jug");
                    break;

                case Key.K:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/K.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("K for Kite");
                    break;

                case Key.L:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/L.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("L for Lion");
                    break;

                case Key.M:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/M.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("M for Mango");
                    break;

                case Key.N:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/N.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("N for Nest");
                    break;

                case Key.O:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/O.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("O for Orange");
                    break;
                
                case Key.P:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/P.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("P for Pot");
                    break;

                case Key.Q:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Q.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("Q for Queen");
                    break;

                case Key.R:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/R.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("R for Rat");
                    break;

                case Key.S:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/S.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("S for Ship");
                    break;

                case Key.T:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/T.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("T for Tiger");
                    break;

                case Key.U:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/U.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("U for Umbrella");
                    break;

                case Key.V:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/V.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("V for Violin");
                    break;

                case Key.W:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/W.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("W for Watermelon");
                    break;

                case Key.X:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/X.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("X for X-mas");
                    break;

                case Key.Y:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Y.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("Y for Yarn");
                    break;

                case Key.Z:
                    img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Z.png")));
                    Image1.Source = img;
                    speaker.SpeakAsync("Z for Zebra");
                    break;
            }
                
        }
        void StopAllSongs()
        {
            mediaTwinkle.Stop();
            mediaAlphabet.Stop();
        }

        private void btnOther_Click(object sender, RoutedEventArgs e)
        {
            SongsMode = true;
            img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Songs/alphabet.jpg")));
            
            Image1.Source = img;
            StopAllSongs();
            mediaAlphabet.Play();
            
          
            
            
        }

        private void btnTwinkle_Click(object sender, RoutedEventArgs e)
        {
            SongsMode = true;
            img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Songs/Twinkle_Twinkle_Little_Star.gif")));
            Image1.Source = img;
            StopAllSongs();
            mediaTwinkle.Play();

        }

        private void mediaTwinkle_MediaEnded_1(object sender, RoutedEventArgs e)
        {
            
        }

        public void Save(string filePath,BitmapSource Image)
        {
            try
            {
                BitmapEncoder encoder = null;
                var image = Image;
                using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                {
                    if (filePath.EndsWith(".jpg"))
                        encoder = new JpegBitmapEncoder();


                    if (filePath.EndsWith(".jpeg"))
                        encoder = new JpegBitmapEncoder();


                    if (filePath.EndsWith(".jpg"))
                        encoder = new JpegBitmapEncoder();


                    if (filePath.EndsWith(".png"))
                        encoder = new PngBitmapEncoder();


                    if (filePath.EndsWith(".tif"))
                        encoder = new TiffBitmapEncoder();


                    if (filePath.EndsWith(".tiff"))
                        encoder = new TiffBitmapEncoder();


                    if (filePath.EndsWith(".bmp"))
                        encoder = new BmpBitmapEncoder();

                    encoder.Frames.Add(BitmapFrame.Create(image));
                    encoder.Save(fileStream);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not save! Make sure you have permission to access the folder and that image is not opened elsewhere");
            }
        }
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\Integrated Ideas"))
                {
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas");
                  
                }
                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas\\Kidsoo"))
                {
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas\\Kidsoo");
                }
            }
            catch (Exception ex) 
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Integrated Ideas
India India
gasshopper.iics is a group of like minded programmers and learners in codeproject. The basic objective is to keep in touch and be notified while a member contributes an article, to check out with technology and share what we know. We are the "students" of codeproject.

This group is managed by Rupam Das, an active author here. Other Notable members include Ranjan who extends his helping hands to invaluable number of authors in their articles and writes some great articles himself.

Rupam Das is mentor of Grasshopper Network,founder and CEO of Integrated Ideas Consultancy Services, a research consultancy firm in India. He has been part of projects in several technologies including Matlab, C#, Android, OpenCV, Drupal, Omnet++, legacy C, vb, gcc, NS-2, Arduino, Raspberry-PI. Off late he has made peace with the fact that he loves C# more than anything else but is still struck in legacy style of coding.
Rupam loves algorithm and prefers Image processing, Artificial Intelligence and Bio-medical Engineering over other technologies.

He is frustrated with his poor writing and "grammer" skills but happy that coding polishes these frustrations.
This is a Organisation

115 members

Comments and Discussions