private static CodeProfiler StartAndStopTwoSections()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section1);
			Thread.Sleep(1);
			profiler.Start(ProfilingMode.Rendering, Section2);
			Thread.Sleep(1);
			profiler.Stop(ProfilingMode.Rendering, Section1);
			profiler.Stop(ProfilingMode.Rendering, Section2);
			return profiler;
		}
        private static CodeProfiler StartAndStopTwoSections()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section1);
            Thread.Sleep(1);
            profiler.Start(ProfilingMode.Rendering, Section2);
            Thread.Sleep(1);
            profiler.Stop(ProfilingMode.Rendering, Section1);
            profiler.Stop(ProfilingMode.Rendering, Section2);
            return(profiler);
        }
예제 #3
0
        public void StoppingWithoutHavingStartedThrowsException()
        {
            var profiler = new CodeProfiler();

            Assert.Throws <CodeProfiler.SectionNeverStarted>(
                () => profiler.Stop(ProfilingMode.Rendering, Section));
        }
예제 #4
0
 private static void RunOneFrameOfProfiling(CodeProfiler profiler)
 {
     profiler.BeginFrame();
     profiler.Start(ProfilingMode.Rendering, Section);
     profiler.Stop(ProfilingMode.Rendering, Section);
     profiler.EndFrame();
 }
예제 #5
0
        private void Initialize()
        {
            Cards        = new FlashCardCollection();
            OptionDialog = new SelectionDialog();
            UseThread    = true;

            SpellingModeHintInterval        = 5000;
            SpellingModeHintIntervalInitial = 1000;

            CodeProfiler.Start("Load Characters");
            Debug.WriteLine("Loading characters audio...");
            string soundPath = RootPath + "\\System\\Characters\\";

            Characters = new Dictionary <char, NAudioPlayerWrapper>();
            for (char tChar = 'A'; tChar <= 'Z'; tChar++)
            {
                try
                {
                    string audioFile = soundPath + "Char_" + tChar.ToString() + ".mp3";
                    if (File.Exists(audioFile))
                    {
                        NAudioPlayerWrapper charPlayer = new NAudioPlayerWrapper(audioFile);
                        charPlayer.Load();
                        Characters.Add(tChar, charPlayer);
                    }
                    Debug.WriteLine("WARNING: Audio file for char " + tChar + "not found!");
                }
                catch
                {
                    Debug.WriteLine("WARNING: Unable to load audio file for char " + tChar);
                }
            }
            CodeProfiler.Stop("Load Characters");
        }
예제 #6
0
 private void LoadCardsData()
 {
     for (int x = 1; x < Cards.Count; x++)
     {
         CodeProfiler.Start("LoadCard " + Cards[x].Name);
         Cards[x].Load();
         CodeProfiler.Stop("LoadCard " + Cards[x].Name);
     }
     Debug.WriteLine("All cards loaded.");
 }
예제 #7
0
		public void StoppingUpdatesSectionTotalTime()
		{
			var profiler = new CodeProfiler();
			profiler.Start(ProfilingMode.Rendering, Section);
			Thread.Sleep(1);
			profiler.Stop(ProfilingMode.Rendering, Section);
			CodeProfilerSection section = profiler.Sections[2][0];
			Assert.AreEqual(1, section.Calls);
			Assert.IsTrue(section.TotalTime > 0.0f);
		}
예제 #8
0
        public void StoppingUpdatesSectionTotalTime()
        {
            var profiler = new CodeProfiler();

            profiler.Start(ProfilingMode.Rendering, Section);
            Thread.Sleep(1);
            profiler.Stop(ProfilingMode.Rendering, Section);
            CodeProfilerSection section = profiler.Sections[2][0];

            Assert.AreEqual(1, section.Calls);
            Assert.IsTrue(section.TotalTime > 0.0f);
        }
예제 #9
0
        public void ProfilingWhenInactiveDoesNothing()
        {
            var profiler = new CodeProfiler {
                IsActive = false
            };

            profiler.BeginFrame();
            profiler.Start(ProfilingMode.Rendering, Section);
            profiler.Stop(ProfilingMode.Rendering, Section);
            profiler.EndFrame();
            Assert.AreEqual(0, profiler.Sections[(int)ProfilingMode.Rendering].Count);
        }
예제 #10
0
        public Layout_01(FlashCardController controller)
        {
            CodeProfiler.Start("Begin Create Layout");
            InitializeComponent();

            Controller = controller;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            Controller.LessonLoaded += new EventHandler(Controller_LessonLoaded);
            Controller.MenuLoad     += new EventHandler(Controller_MenuLoad);

            BackColor = Color.Transparent;
            Stars.DimmedImageIndex = 2;
            InitializeControls();

            BtMenu.Text        = "Menu";
            lbCardCounter.Text = string.Empty;
            CodeProfiler.Stop("Begin Create Layout");

            Synth        = new SpeechSynthesizer();
            Synth.Volume = 100;
            Synth.Rate   = -5;
        }
예제 #11
0
        void Controller_LayoutChanged(object sender, EventArgs e)
        {
            CurrentLayout = Controller.SelectedLayout;
            if (CurrentLayout == null)
            {
                Application.Exit(); return;
            }

            //Speed up to reduce flickering
            Image ptrImage = BackgroundImage;

            BackgroundImage = null;

            CodeProfiler.Start("MainForm::LayoutChanged");
            UserControl ptrControl = (UserControl)CurrentLayout;

            ptrControl.Dock   = DockStyle.Fill;
            ptrControl.Parent = this;

            BackgroundImage = ptrImage;
            CodeProfiler.Stop("MainForm::LayoutChanged");
        }
예제 #12
0
        private void LoadSelectedLesson()
        {
            CodeProfiler.Start("LoadLesson");
            Debug.WriteLine("Loading lesson: " + SelectedLesson);
            KillImageLoader();

            string lessonPath = LessonBasePath + SelectedLesson;

            string[] files = Directory.GetFiles(lessonPath);
            Array.Sort(files);

            //Clean up old cards. Dispose Audio object.
            foreach (FlashCardItem ptrItem in Cards)
            {
                ptrItem.Dispose();
            }
            Cards.Clear();
            FlashCardItem newItem;

            //Load and sort cards.
            CodeProfiler.Start("Generate Items");
            string CardName;
            string CardText;
            string CardImageType;

            foreach (string ptrFile in files)
            {
                //Card Format
                //[CardIndex]#<Card Name>.<Image type>
                CardImageType = Path.GetExtension(ptrFile).ToLower();
                if (!IsImageTypeSupported(CardImageType))
                {
                    continue;
                }

                CardName = CardText = Path.GetFileNameWithoutExtension(ptrFile);
                if (CardName.Contains("#"))
                {
                    CardText = CardName.Substring(CardName.IndexOf("#") + 1);
                }
                newItem = new FlashCardItem(CardName, CardText, ptrFile);
                Debug.WriteLine("> " + newItem.Text);
                Cards.Add(newItem);
            }
            CodeProfiler.Stop("Generate Items");

            //Load card contents.
            if (UseThread)
            {
                //Use threading to load images.
                CardsLoader = new Thread(LoadCardsData);
                CardsLoader.Start();
                CodeProfiler.Start("LoadCard1");
                Cards[0].Load(); //Make sure first image is loaded
                CodeProfiler.Stop("LoadCard1");
            }
            else
            {
                //Single thread operation (Slower) - Keep for debugging purpose
                foreach (FlashCardItem ptrItem in Cards)
                {
                    CodeProfiler.Start("Load Card " + ptrItem.Name);
                    ptrItem.Load();
                    CodeProfiler.Stop("Load Card " + ptrItem.Name);
                }
            }

            Cards.ResetIndex();
            CardsLoader.Join();
            OnLessonLoaded();
            Debug.WriteLine("Lesson loaded.");
            CodeProfiler.Stop("LoadLesson");
        }
예제 #13
0
		private static void RunOneFrameOfProfiling(CodeProfiler profiler)
		{
			profiler.BeginFrame();
			profiler.Start(ProfilingMode.Rendering, Section);
			profiler.Stop(ProfilingMode.Rendering, Section);
			profiler.EndFrame();
		}
예제 #14
0
		public void StoppingWithoutHavingStartedThrowsException()
		{
			var profiler = new CodeProfiler();
			Assert.Throws<CodeProfiler.SectionNeverStarted>(
				() => profiler.Stop(ProfilingMode.Rendering, Section));
		}
예제 #15
0
		public void ProfilingWhenInactiveDoesNothing()
		{
			var profiler = new CodeProfiler { IsActive = false };
			profiler.BeginFrame();
			profiler.Start(ProfilingMode.Rendering, Section);
			profiler.Stop(ProfilingMode.Rendering, Section);
			profiler.EndFrame();
			Assert.AreEqual(0, profiler.Sections[(int)ProfilingMode.Rendering].Count);
		}
예제 #16
0
        public void GetNextCard()
        {
            try
            {
                //Stop hint timer
                #region [ Spelling Mode ]
                if (Controller.Mode == FlashCardMode.Spelling)
                {
                    hintTimer.Enabled = false;
                    Debug.WriteLine("Timer Suspended");
                }
                #endregion

                Controller.Busy = true;
                SelectedCard    = Controller.GetNextCard();
                if (SelectedCard != null)
                {
                    CodeProfiler.Start("GetNextCard-LoadCard");
                    lbCardCounter.Text = Controller.Cards.IndexOf(SelectedCard).ToString() +
                                         " / " + Controller.Cards.Count.ToString();

                    MainPicture.Image = SelectedCard.Image;

                    //In Spelling mode, spell each characters
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        CardLabel.Text = String.Empty;
                        Cursor         = Cursors.WaitCursor;
                        if (SelectedCard.Audio != null)
                        {
                            SelectedCard.Audio.PlaySync();
                        }
                        else
                        {
                            Synth.Speak(SelectedCard.Text);
                        }

                        foreach (char ptrChar in SelectedCard.Text)
                        {
                            Controller.PlayCharSoundSync(ptrChar);
                        }
                        hintTimer.Interval = Controller.SpellingModeHintIntervalInitial;
                        Cursor             = Cursors.Default;
                    }
                    #endregion

                    if (Controller.CaseSensitive)
                    {
                        CardLabel.Text = SelectedCard.Text;
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }
                    else
                    {
                        CardLabel.Text = SelectedCard.Text.ToUpper();
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }

                    //Create puzzle hint
                    #region [ Puzzle Mode Only ]
                    if (Controller.Mode == FlashCardMode.Puzzle)
                    {
                        PuzzleHint.Text = CardLabel.Text;
                        PuzzleHint.Shuffle();
                        for (int x = 0; x < PuzzleHint.Text.Length; x++)
                        {
                            PuzzleHint.HighlightChar(x);
                        }
                    }
                    #endregion

                    MainPicture.Refresh();
                    CardLabel.Refresh();
                    CodeProfiler.Stop("GetNextCard-LoadCard");

                    //Read selected card
                    if (SelectedCard.Audio != null)
                    {
                        SelectedCard.Audio.PlaySync();
                    }
                    else
                    {
                        Synth.Speak(SelectedCard.Text);
                    }

                    //Start hint timer
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        hintTimer.Enabled = Controller.SpellingModePlayHint;
                    }
                    Debug.WriteLine("Timer Enabled");
                    #endregion
                }
            }
            finally { Controller.Busy = false; }
        }