コード例 #1
0
        /// <summary>
        /// Updates the Sample Name and the Level labels.
        /// </summary>
        /// <param name="item">SampleBrowserItem containing Sample related
        /// information.</param>
        private void UpdateDifficultyLevel(SampleBrowserItem item)
        {
            Color SampleDifficultyLevelColor = Colors.Gray;

            SampleDifficultyLevel.Visibility = Visibility.Visible;
            if (SampleDifficultyLevel != null)
            {
                if (item.SampleLevel == DifficultyLevel.Basic)
                {
                    SampleDifficultyLevelColor = Colors.Green;
                }
                else if (item.SampleLevel == DifficultyLevel.Scenario)
                {
                    SampleDifficultyLevelColor = Colors.Orange;
                }
                else if (item.SampleLevel == DifficultyLevel.Advanced)
                {
                    SampleDifficultyLevelColor = Colors.Red;
                }
                else if (item.SampleLevel == DifficultyLevel.Scenario)
                {
                    SampleDifficultyLevelColor = Colors.DarkGray;
                }
                else if (item.SampleLevel == DifficultyLevel.None)
                {
                    SampleDifficultyLevel.Visibility = Visibility.Collapsed;
                }
                SampleDifficultyLevel.Background = new SolidColorBrush(SampleDifficultyLevelColor);
                SampleDifficultyLevel.Content    = item.SampleLevel.ToString();
            }
        }
コード例 #2
0
        /// <summary>
        /// Populate the Tab with samples name for a given control.
        /// </summary>
        /// <param name="sampleAssembly">Name of the sample assembly.</param>
        /// <param name="controlName">Name of the control.</param>
        private void PopulateSamplesTab(Assembly sampleAssembly, string controlName)
        {
            if (SamplesTab == null)
            {
                return;
            }

            // Unhook this event when dynamically before adding new tabs.
            SamplesTab.SelectionChanged -= OnSamplesTabSelectionChanged;

            if (SamplesTab.Items.Count > 0)
            {
                SamplesTab.Items.Clear();
            }

            // Construct a sorted list of samples
            IList <SampleBrowserItem> samples = new List <SampleBrowserItem>();

            foreach (Type type in sampleAssembly.GetTypes())
            {
                SampleAttribute attribute = type.GetCustomAttributes(typeof(SampleAttribute), false).OfType <SampleAttribute>().FirstOrDefault();

                CategoryAttribute categoryAttribute = type.GetCustomAttributes(typeof(CategoryAttribute), false).OfType <CategoryAttribute>().FirstOrDefault();
                if (attribute != null && categoryAttribute != null)
                {
                    if (categoryAttribute.Category.Equals(controlName))
                    {
                        SampleBrowserItem.AddSample(samples, type, attribute);
                    }
                }
            }
            // Populate the Tab Control with the samples.
            foreach (SampleBrowserItem item in samples)
            {
                TabItem tabItem = new TabItem();
                if (SampleTabItemStyle != null)
                {
                    tabItem.Style = SampleTabItemStyle;
                }

                tabItem.Header = item;
                SamplesTab.Items.Add(tabItem);
            }

            // Hook up this event when done creating the Sample tabs.
            SamplesTab.SelectionChanged += OnSamplesTabSelectionChanged;

            // Select first tab
            if (SamplesTab.Items.Count > 0)
            {
                (SamplesTab.Items[0] as TabItem).IsSelected = true;
                LoadSample();
            }
        }
コード例 #3
0
        /// <summary>
        /// Create a SampleBrowserItem and inserts into the right location.
        /// </summary>
        /// <param name="Samples">Collections of Samples.</param>
        /// <param name="type">Type of Sample.</param>
        /// <param name="attribute">Attributes for the Sample.</param>
        internal static void AddSample(IList <SampleBrowserItem> Samples, Type type, SampleAttribute attribute)
        {
            string name = attribute.Name;
            // Find any existing item
            SampleBrowserItem item = null;

            if (Samples != null)
            {
                foreach (SampleBrowserItem other in Samples)
                {
                    if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        item = other;
                        break;
                    }
                }
            }
            // Escape any name sorting
            string escapedName = name;

            if (name[0] == '(')
            {
                int index = name.IndexOf(')');
                if (index > 0)
                {
                    escapedName = name.Substring(index + 1, name.Length - index - 1);
                }
            }

            item = new SampleBrowserItem {
                Name = escapedName, OriginalName = name, SampleType = type, SampleLevel = attribute.DifficultyLevel
            };

            // Insert the item into the list in sorted order (linearly
            // because no item should have very many children)
            int sortedIndex = 0;

            foreach (SampleBrowserItem other in Samples)
            {
                if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) > 0)
                {
                    break;
                }
                else
                {
                    sortedIndex++;
                }
            }
            Samples.Insert(sortedIndex, item);
        }
コード例 #4
0
        /// <summary>
        /// Populate the Tab with samples name for a given control.
        /// </summary>
        /// <param name="controlName">Name of the control.</param>
        private void PopulateSamplesTab(string controlName)
        {
            if (SamplesTab == null)
            {
                return;
            }

            // Unhook this event when dynamically before adding new tabs.
            SamplesTab.SelectionChanged -= OnSamplesTabSelectionChanged;

            if (SamplesTab.Items.Count > 0)
            {
                SamplesTab.Items.Clear();
            }

            // Construct a sorted list of samples
            IList <SampleBrowserItem> samples = new List <SampleBrowserItem>();

            foreach (var sample in Samples)
            {
                if (controlName.Equals(sample.Metadata.Category))
                {
                    SampleBrowserItem.AddSample(samples, sample);
                }
            }
            // Populate the Tab Control with the samples.
            foreach (SampleBrowserItem item in samples)
            {
                TabItem tabItem = new TabItem();
                if (SampleTabItemStyle != null)
                {
                    tabItem.Style = SampleTabItemStyle;
                }

                tabItem.Header = item;
                SamplesTab.Items.Add(tabItem);
            }

            // Hook up this event when done creating the Sample tabs.
            SamplesTab.SelectionChanged += OnSamplesTabSelectionChanged;

            // Select first tab
            if (SamplesTab.Items.Count > 0)
            {
                (SamplesTab.Items[0] as TabItem).IsSelected = true;
                LoadSample();
            }
        }
コード例 #5
0
        /// <summary>
        /// Create a SampleBrowserItem and inserts into the right location.
        /// </summary>
        /// <param name="Samples">Collections of Samples.</param>
        /// <param name="sample">Lazy version of the sample to add.</param>
        internal static void AddSample(IList <SampleBrowserItem> Samples, Lazy <FrameworkElement, ISampleMetadata> sample)
        {
            string name = sample.Metadata.Name;
            // Find any existing item
            SampleBrowserItem item = null;

            if (Samples != null)
            {
                foreach (SampleBrowserItem other in Samples)
                {
                    if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        item = other;
                        break;
                    }
                }
            }
            // Escape any name sorting
            string escapedName = name;

            if (name[0] == '(')
            {
                int index = name.IndexOf(')');
                if (index > 0)
                {
                    escapedName = name.Substring(index + 1, name.Length - index - 1);
                }
            }

            item = new SampleBrowserItem(escapedName, sample);

            // Insert the item into the list in sorted order (linearly
            // because no item should have very many children)
            int sortedIndex = 0;

            foreach (SampleBrowserItem other in Samples)
            {
                if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) > 0)
                {
                    break;
                }
                else
                {
                    sortedIndex++;
                }
            }
            Samples.Insert(sortedIndex, item);
        }
コード例 #6
0
        /// <summary>
        /// Change the selected sample.
        /// </summary>
        private void LoadSample()
        {
            SetSourceViewer(null);
            TabItem currentTab = SamplesTab.SelectedItem as TabItem;

            if (currentTab == null)
            {
                return;
            }

            // Get the new sample
            SampleBrowserItem item = currentTab.Header as SampleBrowserItem;

            currentTab.Content = item.GetSample();
            UpdateDifficultyLevel(item);
        }
コード例 #7
0
 /// <summary>
 /// Updates the Sample Name and the Level labels.
 /// </summary>
 /// <param name="item">SampleBrowserItem containing Sample related
 /// information.</param>
 private void UpdateDifficultyLevel(SampleBrowserItem item)
 {
     Color SampleDifficultyLevelColor = Colors.Gray;
     SampleDifficultyLevel.Visibility = Visibility.Visible;
     if (SampleDifficultyLevel != null)
     {
         if (item.SampleLevel == DifficultyLevel.Basic)
         {
             SampleDifficultyLevelColor = Colors.Green;
         }
         else if (item.SampleLevel == DifficultyLevel.Scenario)
         {
             SampleDifficultyLevelColor = Colors.Orange;
         }
         else if (item.SampleLevel == DifficultyLevel.Advanced)
         {
             SampleDifficultyLevelColor = Colors.Red;
         }
         else if (item.SampleLevel == DifficultyLevel.Scenario)
         {
             SampleDifficultyLevelColor = Colors.DarkGray;
         }
         else if (item.SampleLevel == DifficultyLevel.None)
         {
             SampleDifficultyLevel.Visibility = Visibility.Collapsed;
         }
         SampleDifficultyLevel.Background = new SolidColorBrush(SampleDifficultyLevelColor);
         SampleDifficultyLevel.Content = item.SampleLevel.ToString();
     }
 }
コード例 #8
0
        /// <summary>
        /// Create a SampleBrowserItem and inserts into the right location.
        /// </summary>
        /// <param name="Samples">Collections of Samples.</param>
        /// <param name="sample">Lazy version of the sample to add.</param>
        internal static void AddSample(IList<SampleBrowserItem> Samples, Lazy<FrameworkElement, ISampleMetadata> sample)
        {
            string name = sample.Metadata.Name;
            // Find any existing item
            SampleBrowserItem item = null;
            if (Samples != null)
            {
                foreach (SampleBrowserItem other in Samples)
                {
                    if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        item = other;
                        break;
                    }
                }
            }
            // Escape any name sorting
            string escapedName = name;
            if (name[0] == '(')
            {
                int index = name.IndexOf(')');
                if (index > 0)
                {
                    escapedName = name.Substring(index + 1, name.Length - index - 1);
                }
            }

            item = new SampleBrowserItem(escapedName, sample);

            // Insert the item into the list in sorted order (linearly
            // because no item should have very many children)
            int sortedIndex = 0;
            foreach (SampleBrowserItem other in Samples)
            {
                if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) > 0)
                {
                    break;
                }
                else
                {
                    sortedIndex++;
                }
            }
            Samples.Insert(sortedIndex, item);       
        }