private string ReplaceTagsWithUmbracoHelpers(RapidUmbracoConversionObject conversionObject) { string fileContents = conversionObject.FileContent; foreach (var convertedProperty in conversionObject.PropertyCollection) { if (!String.IsNullOrWhiteSpace(convertedProperty.OriginalTag)) { //TODO: Switch on the property type fileContents = fileContents.Replace(convertedProperty.OriginalTag, $"@Umbraco.Field(\"{convertedProperty.Alias}\")"); } } return(fileContents); }
public void Convert(IEnumerable <Tuple <RapidUmbracoConversionObject, IContentType> > convertedMarkupAndDocumentTypes, FileCopyPair[] assetDirectories) { List <ITemplate> templateList = new List <ITemplate>(); //Copy all of the files from the defined asset directories foreach (FileCopyPair directory in assetDirectories) { DirectoryCopier.Copy(directory.CombinedSource, directory.CombinedDestination); } foreach (Tuple <RapidUmbracoConversionObject, IContentType> item in convertedMarkupAndDocumentTypes) { RapidUmbracoConversionObject conversionObject = item.Item1; IContentType documentType = item.Item2; Debug.WriteLine("Conversion Object:" + item.Item1.Name); //Create the strongly type template var attempt = ServiceContext.FileService.CreateTemplateForContentType(documentType.Alias, documentType.Name); if (attempt.Success) { ITemplate template = attempt.Result.Entity; Debug.WriteLine("Template created for Document Type. Template Id: " + template.Id); //Replace the markup string fileContents = this.ReplaceTagsWithUmbracoHelpers(conversionObject); //Append file's content to the .cshtml template template.Content += Environment.NewLine; template.Content += Environment.NewLine; template.Content += fileContents; //Replace any of the copied asset directories foreach (FileCopyPair copyPair in assetDirectories) { //Href with doublee quote string replaceString = $"href=\"{copyPair.MarkupReference}"; template.Content = template.Content.Replace(replaceString, $"href=\"{copyPair.Destination}"); //Src with double quote replaceString = $"src=\"{copyPair.MarkupReference}"; template.Content = template.Content.Replace(replaceString, $"src=\"{copyPair.Destination}"); //Background image tag with single quote replaceString = $"background-image:url('{copyPair.MarkupReference}"; template.Content = template.Content.Replace(replaceString, $"background-image:url('{copyPair.Destination}"); //Background image tag with double quote replaceString = $"background-image:url(\"{copyPair.MarkupReference}"; template.Content = template.Content.Replace(replaceString, $"background-image:url(\"{copyPair.Destination}"); } //Save the template to initialise the ID Debug.WriteLine($"Saving template: {template.Name}"); ServiceContext.FileService.SaveTemplate(template); //Set the default template on the paired content type Debug.WriteLine($"Setting DocumentType {documentType.Name}'s DefaultTemplate"); documentType.SetDefaultTemplate(template); ServiceContext.ContentTypeService.Save(documentType); } } }
/// <summary> /// Builds the Umbraco Document Type from the RapidUmbracoConversionObject /// </summary> /// <param name="umbracoDocumentTypeList"></param> /// <param name="conversionObject"></param> /// <returns></returns> public virtual IContentType CreateDocumentType(List <IContentType> umbracoDocumentTypeList, RapidUmbracoConversionObject conversionObject) { IContentType documentType = new ContentType(-1); documentType.Name = conversionObject.Name; documentType.Alias = conversionObject.Name.FirstCharacterToLower() + "DocumentType"; documentType.AdditionalData.Add(RapidUmbracoSettings.RapidUmbracoConverterUseKey, true); documentType.AdditionalData.Add(RapidUmbracoSettings.RapidUmbracoConverterDateConvertedKey, DateTime.Now); documentType.AdditionalData.Add(RapidUmbracoSettings.RapidUmbracoConverterOriginalFilePathKey, conversionObject.FilePath); this.ValidateAlias(umbracoDocumentTypeList, documentType); //Add the properties to the content type IEnumerable <IDataTypeDefinition> dataTypeDefinitionCollection = UmbracoServiceContext.DataTypeService.GetAllDataTypeDefinitions(); Debug.Indent(); foreach (var property in conversionObject.PropertyCollection) { string tabName = property.Tab.Trim(); this.AddTabToDocumentType(documentType, tabName); this.AddPropertyToDocumentType(documentType, property, tabName, dataTypeDefinitionCollection); } Debug.Unindent(); return(documentType); }