/// <summary> /// The method creates the template bundle for provided name and path. /// </summary> /// <param name="showName">Show name of the template bundle. Provided by the user in user interface.</param> /// <param name="sourceLocation">Path of the template bundle. Provided by the user in user interface.</param> /// <param name="templateBundleGuid">Globally unique identifier of template bundle</param> /// <returns>Created template bundle.</returns> private static TemplateBundle CreateTemplateBundle(string showName, string sourceLocation, Guid templateBundleGuid) { var templateBundle = new TemplateBundle(showName, sourceLocation, templateBundleGuid); templateBundle.SortTemplates(); return(templateBundle); }
/// <summary> /// Loads a template bundle from its original source and applies stored settings. /// </summary> /// <param name="templateBundle">The template bundle to reload.</param> /// <returns>True if the original location is available, false otherwise.</returns> private bool ReloadTemplateBundle(TemplateBundle templateBundle) { // Load the actual source if its available, otherwise load the cached version var reloadedTemplateBundle = CreateTemplateBundle(templateBundle.ShowName, templateBundle.SourceLocation, templateBundle.Guid); var isCached = (reloadedTemplateBundle.TemplateBundleState & TemplateBundleStates.TemplateBundleCached) == TemplateBundleStates.TemplateBundleCached; var isAvailable = (reloadedTemplateBundle.TemplateBundleState & TemplateBundleStates.TemplateBundleAvailable) == TemplateBundleStates.TemplateBundleAvailable; if (isAvailable) { // merge old settings into the reloaded template bundle reloadedTemplateBundle.HasProjectMappedFolderHierarchy = templateBundle.HasProjectMappedFolderHierarchy; foreach (var template in templateBundle.Templates) { var reloadedTemplate = reloadedTemplateBundle.Templates.FirstOrDefault(x => x.ShowName.Equals(template.ShowName, StringComparison.OrdinalIgnoreCase)); if (reloadedTemplate != null && reloadedTemplate.TemplateState != TemplateState.ErrorInTemplate && template.TemplateState == TemplateState.Disabled) { reloadedTemplate.TemplateState = TemplateState.Disabled; } } LoadTemplateBundle(reloadedTemplateBundle); } else if (isCached) { SyncServiceTrace.I(Resources.TemplateBundleNotAvailable, templateBundle.ShowName, templateBundle.SourceLocation); LoadTemplateBundle(templateBundle); templateBundle.TemplateBundleState |= TemplateBundleStates.TemplateBundleCached; } return(isAvailable); }
/// <summary> /// Adds a template bundle to the list of available template bundles. /// </summary> private void LoadTemplateBundle(TemplateBundle templateBundle) { templateBundle.SetTemplateBundleState(); templateBundle.TemplatesChanged += HandleTemplateBundleTemplatesChangedEvent; _templateBundles.Add(templateBundle); // toggle the bool value twice to trigger the value changed event in the setter. // The value changes templates which might not have been deserialized when the value is set. templateBundle.HasProjectMappedFolderHierarchy = !templateBundle.HasProjectMappedFolderHierarchy; templateBundle.HasProjectMappedFolderHierarchy = !templateBundle.HasProjectMappedFolderHierarchy; }
/// <summary> /// The method adds the template bundle to the collection of available template bundles /// and sorts the template bundles and templates in added template bundle. /// The properties <see cref="TemplateBundles"/> and <see cref="AvailableTemplates"/> are affected by this method. /// </summary> /// <param name="templateBundle">Template bundle to add.</param> public void AddTemplateBundle(TemplateBundle templateBundle) { if (templateBundle == null || TemplateBundles.Any(bundle => bundle.ShowName == templateBundle.ShowName)) { // Already exists. return; } templateBundle.TemplatesChanged += HandleTemplateBundleTemplatesChangedEvent; _templateBundles.Add(templateBundle); Refresh(); }