Example #1
0
        /// <summary>
        /// initializes the Description property of an <see cref="QSF.Model.ExampleInfo">example info</see>
        /// </summary>
        /// <param name="exampleInfo"> The example info to initialize</param>
        private static void InitializeDescription(IExampleInfo exampleInfo)
        {
            var info = exampleInfo as ExampleInfo;

            if (info != null)
            {
                var controlName     = string.IsNullOrEmpty(info.PackageName) ? info.ControlName : exampleInfo.PackageName;
                var controlAssembly = AssemblyCache.GetInstance()[controlName];

                // Description resource name is formed like:
                // path to example folder + Description.txt
                // e.g.: Chart.Gallery.Bar.Description.txt
                var descriptionName = string.Concat(info.Name.Substring(0, info.Name.LastIndexOf('.')), ".Description.txt");

                if (descriptionName != null)
                {
                    using (var stream = controlAssembly.GetManifestResourceStream(descriptionName))
                    {
                        if (stream != null)
                        {
                            using (StreamReader streamReader = new StreamReader(stream))
                            {
                                info.Description = streamReader.ReadToEnd();
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets the code text for each example XAML or CS file in the example info.
        /// </summary>
        /// <param name="example">Example whose files' code to retrieve.</param>
        /// <returns>Returns a dictionary&lt;filename, code text&gt;.</returns>
        public static List <CodeFileInfo> GetCodeFilesForExample(IExampleInfo example)
        {
            List <CodeFileInfo> codeFilesList = new List <CodeFileInfo>();

            var exampleInfo = example as ExampleInfo;

            if (exampleInfo == null)
            {
                throw new ArgumentException("Something went wrong. Example should be an ExampleInfo.");
            }
            else
            {
                var      controlAssembly         = GetControlAssembly(exampleInfo);
                string[] resourceNamesInAssembly = controlAssembly.GetManifestResourceNames();
                var      textToMatch             = exampleInfo.Name.Substring(0, exampleInfo.Name.LastIndexOf('.') + 1);
                var      resourcesWithCode       = resourceNamesInAssembly.Where(r => !r.Contains("AssemblyInfo.cs") && r.StartsWith(textToMatch) && !IsDataFile(r));

                foreach (var resourceName in resourcesWithCode)
                {
                    using (var stream = controlAssembly.GetManifestResourceStream(resourceName))
                    {
                        using (StreamReader streamReader = new StreamReader(stream))
                        {
                            var codeText = streamReader.ReadToEnd();
                            codeFilesList.Add(new CodeFileInfo {
                                FileName = resourceName, CodeContent = codeText
                            });
                        }
                    }
                }
            }

            return(codeFilesList);
        }
Example #3
0
        /// <summary>
        /// Loads the content of example, using an <see cref="QSF.Model.IExampleInfo">example info</see>.
        /// </summary>
        /// <param name="example">The example info.</param>
        /// <returns>Returns an UserControl with the contents of the example.</returns>
        public static UserControl LoadExampleContent(IExampleInfo example)
        {
            InitializeDescription(example);

            string controlName        = example.PackageName ?? example.ExampleGroup.Control.Name;
            var    exampleUserControl = LoadExampleContent(controlName, example.Name);

            return(exampleUserControl);
        }
Example #4
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            // close configurator in order to be closed for the next example that will be opened
            this.configuratorButton.IsChecked = false;
            this.CloseConfigurator();

            // set previousExample in order to be able to track whether we've been
            // navigating from and determine how to animate the example area
            this.previousExample = this.ViewModel.Example;
        }
        public void Initialize(IExampleInfo exampleInfo)
        {
            this.exampleObject      = null;
            this.configuratorObject = null;
            this.hints   = null;
            this.Example = exampleInfo;
            this.Control = exampleInfo.ExampleGroup.Control;
            this.ExampleCodeFilesCollectionViewSource = new CollectionViewSource()
            {
                Source = ExampleSourceCodeHelper.GetCodeFilesForExample(exampleInfo)
            };

            var warningSuppression = this.RefreshAsyncProperties();
        }
Example #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var          viewModel   = this.ViewModel;
            IExampleInfo exampleInfo = e.Parameter as IExampleInfo ?? ModelFactory.GetQuickStartDataSingleton().Examples.Single(ex => ex.Name.Equals(e.Parameter));

            viewModel.Initialize(exampleInfo);

            this.DataContext = viewModel;

            base.OnNavigatedTo(e);

            this.rootPivot.SelectedIndex = 0;

            this.BeginEntranceAnimation();
        }
        public static void ToggleFavourite(IExampleInfo exampleInfo)
        {
            var favorites = ApplicationData.Current.RoamingSettings.Values;

            string exampleName      = exampleInfo.Name;
            string controlName      = exampleInfo.ExampleGroup.Control.Name;
            string exampleUniqueKey = controlName + "|" + exampleName;

            if (favorites[exampleUniqueKey] != null)
            {
                // there is an example here added with that name and control, so remove it
                favorites.Remove(exampleUniqueKey);
                return;
            }

            ApplicationDataCompositeValue compositeValue = new ApplicationDataCompositeValue();

            compositeValue["ExampleName"] = exampleName;
            compositeValue["ControlName"] = controlName;
            favorites[exampleUniqueKey]   = compositeValue;
        }
 public static bool IsExampleFavourite(IExampleInfo exampleInfo)
 {
     return(allFavouritesNames.Contains(exampleInfo.Name));
 }
        private void UpdateExampleDescription(IExampleInfo example)
        {
            foreach (var commonFolder in example.CommonFolders.Where(f => f.Trim() != string.Empty))
            {
                var controlName = string.IsNullOrEmpty(example.PackageName) ? example.ExampleGroup.Control.Name : this.exampleToNavigate.PackageName;
                var resourcePath = string.Format("{0}/Description.txt", commonFolder.Substring(controlName.Length + 1)).ToLower();
                var assemblyName = string.IsNullOrEmpty(this.exampleToNavigate.PackageName)
                                   ? this.exampleToNavigate.ExampleGroup.Control.Name
                                   : this.exampleToNavigate.PackageName;

                if (ResourceToStreamHelper.ResourceExists(GetAssemblyByName(assemblyName), resourcePath))
                {
                    var uriSource = new Uri(
                        string.Format("pack://application:,,,/{0};component/{1}",
                            controlName,
                            resourcePath,
                            UriKind.RelativeOrAbsolute));
                    example.Description = ResourceToStreamHelper.ExtractSourceCodeFromSource(uriSource);
                }
            }
        }
        private void UpdateExampleResources(IExampleInfo currentExample, Assembly assembly)
        {
            if (currentExample.Resources.Count == 0)
            {
                foreach (XmlNode item in this.currentControlFilesListDocument.GetElementsByTagName("RelativePath"))
                {
                    var containsFolderOrFile = currentExample.CommonFolders.Contains(item.Attributes["Key"].InnerText) ||
                                               currentExample.CommonFolders.Contains(item.InnerText);
                    if (containsFolderOrFile && !item.InnerText.EndsWith(".txt"))
                    {
                        var control =
                                     string.IsNullOrEmpty(currentExample.PackageName) ? currentExample.ExampleGroup.Control :
                                      this.data.Controls.Where(c => c.Name == currentExample.PackageName).First();

                        var exampleFile = new ExampleFile(control, item.InnerText);

                        // add resource only if it exists, i.e. it can be retrieved from assembly resources
                        if (ResourceToStreamHelper.ResourceExists(assembly, exampleFile.AssemblyResourcePath)
                            || (exampleFile.AssemblyResourcePath.IsXaml()
                                && ResourceToStreamHelper.ResourceExists(assembly, exampleFile.AssemblyResourcePath.Replace(".xaml", ".baml")))
                            )
                        {
                            currentExample.Resources.Add(exampleFile);
                        }
                    }
                }
            }
        }
        private void InstantiateExampleContent(IExampleInfo example)
        {
            var assemblyName = string.IsNullOrEmpty(this.exampleToNavigate.PackageName)
                               ? this.exampleToNavigate.ExampleGroup.Control.Name
                               : this.exampleToNavigate.PackageName;

            var assembly = GetAssemblyByName(assemblyName);
            object exampleInstance = assembly.CreateInstance(example.Name);
            this.RaiseExampleInstantiatedEvent(exampleInstance);
            this.CurrentExample = example;
        }
        public void LoadExample(IExampleInfo exampleInfo, string themeName)
        {
            var newExample = exampleInfo;
            this.exampleToNavigate = newExample;
            this.CurrentExample = this.exampleToNavigate;
            var moduleName = string.IsNullOrEmpty(this.exampleToNavigate.PackageName)
                             ? this.exampleToNavigate.ExampleGroup.Control.Name
                             : this.exampleToNavigate.PackageName;

            this.ExampleProgress = 0;

            if (newExample.Type == Enums.ExampleType.Theming)
            {
                this.deployManager.LoadModule(DeployManager.ThemesDownloadGroupName, () =>
                {
                    this.LoadNormalExample(moduleName, themeName);
                }, p =>
                {
                    this.ExampleProgress = p;
                });
            }
            else
            {
                this.LoadNormalExample(moduleName, themeName);
            }
        }
		public void NavigateToExample(IExampleInfo exampleInfo, string themeName)
		{
			if (this.CurrentExample == null)
			{
				this.CurrentExample = exampleInfo;
			}

			if (this.CurrentExample != null &&
				(exampleInfo.ExampleGroup.Control != this.CurrentExample.ExampleGroup.Control || this.CurrentExample.PackageName != exampleInfo.PackageName))
			{
				telerikReferencesNamesForCurrentControl = null;
			}

			ExampleLoader.Instance.LoadExample(exampleInfo, themeName);
		}
		public void Initialize(IExampleInfo exampleInfo, Action exampleInstantiatedCallback)
		{
			this.exampleInstantiatedCallback = exampleInstantiatedCallback;

			// set IsQsfInTouchMode to Desktop mode if example is only in Desktop mode
			// or to Touch mode if example is only in Touch mode
			// this fixes an issue where searching from touch mode and selecting a Desktop example displays Win8Touch theme 

			if (!ModelExtensions.IsTouchAndDesktopExample(exampleInfo))
			{
				if (ModelExtensions.IsDesktopExample(exampleInfo))
				{
					IsQsfInTouchMode = false;
				}
				else
				{
					IsQsfInTouchMode = true;
				}
			}

			this.SetNextAndPreviousExample();

			this.NavigateToExample(exampleInfo, ApplicationThemeManager.GetDefaultThemeName(IsQsfInTouchMode));
		}
        private ApplicationView GetSingleExampleView(IExampleInfo example)
        {
            if (example == null || ModelExtensions.IsTouchAndDesktopExample(example))
            {
                return IsQsfInTouchMode ? ApplicationView.SingleExampleTouch : ApplicationView.SingleExample;
            }

            if (ModelExtensions.IsDesktopExample(example))
            {
                return ApplicationView.SingleExample;
            }
            else
            {
                return ApplicationView.SingleExampleTouch;
            }
        }