public ActionResult SearchTemplates(OfficeDevPnP.PartnerPack.Infrastructure.TargetScope scope, String parentSiteUrl, String templatesProvider, String searchText)
        {
            PnPPartnerPackSettings.ParentSiteUrl = parentSiteUrl;

            SearchTemplatesViewModel model = new SearchTemplatesViewModel();

            if (!PnPPartnerPackSettings.TemplatesProviders.ContainsKey(templatesProvider))
            {
                throw new Exception("Invalid templates provider key!");
            }

            model.SearchResults = PnPPartnerPackSettings.TemplatesProviders[templatesProvider]
                .SearchProvisioningTemplates(searchText, TargetPlatform.SharePointOnline, scope);

            //List<ProvisioningTemplateInformation> result = new List<ProvisioningTemplateInformation>();

            //var globalTemplates = ProvisioningRepositoryFactory.Current.GetGlobalProvisioningTemplates(scope);
            //result.AddRange(globalTemplates);

            //if (scope != TargetScope.Site)
            //{
            //    var localTemplates = ProvisioningRepositoryFactory.Current.GetLocalProvisioningTemplates(parentSiteUrl, scope);
            //    result.AddRange(localTemplates);
            //}

            //model.SearchResults = result.ToArray();

            return PartialView(model);
        }
        public static String SaveXamlToFile(this String xaml, Guid id, OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileConnectorBase connector)
        {
            using (Stream mem = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(mem, Encoding.Unicode, 2048, true))
                {
                    sw.Write(xaml);
                }
                mem.Position = 0;

                String xamlFileName = String.Format("{0}.xaml", id.ToString());
                connector.SaveFileStream(xamlFileName, mem);
                return (xamlFileName);
            }
        }
        public static String SaveXamlToFile(this String xaml, Guid id, OfficeDevPnP.Core.Framework.Provisioning.Connectors.FileConnectorBase connector, ListCollection lists)
        {
            // Tokenize XAML to replace any ListId attribute with the corresponding token
            XElement xamlDocument = XElement.Parse(xaml);
            var elements = (IEnumerable)xamlDocument.XPathEvaluate("//child::*[@ListId]");

            if (elements != null)
            {
                foreach (var element in elements.Cast<XElement>())
                {
                    var listId = element.Attribute("ListId").Value;
                    element.SetAttributeValue("ListId", TokenizeListIdProperty(listId, lists));
                }

                xaml = xamlDocument.ToString();
            }

            using (Stream mem = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(mem, Encoding.Unicode, 2048, true))
                {
                    sw.Write(xaml);
                }
                mem.Position = 0;

                String xamlFileName = String.Format("{0}.xaml", id.ToString());
                connector.SaveFileStream(xamlFileName, mem);
                return (xamlFileName);
            }
        }