├── .gitignore ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── appveyor.yml └── src ├── .nuget └── NuGet.config ├── Umbraco.Courier.Contrib.Resolvers ├── Action.cs ├── GridCellDataResolvers │ ├── DocTypeGridEditorGridCellResolver.cs │ └── LeBlenderGridCellResolver.cs ├── Properties │ ├── AssemblyInfo.cs │ └── VersionInfo.cs ├── PropertyDataResolvers │ ├── ImulusUrlPickerPropertyDataResolver.cs │ ├── InnerContentPropertyDataResolver.cs │ ├── MultiUrlPickerPropertyDataResolver.cs │ ├── NestedContentPropertyDataResolver.cs │ ├── StackedContentPropertyDataResolver.cs │ ├── UmbracoMultiUrlPickerPropertyDataResolver.cs │ ├── UmbracoNestedContentPropertyDataResolver.cs │ └── VortoPropertyDataResolver.cs ├── StringExtensions.cs ├── Umbraco.Courier.Contrib.Resolvers.csproj └── packages.config └── Umbraco.Courier.Contrib.sln /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | ._.DS_Store 3 | 4 | *.aps 5 | *.obj 6 | *.orig 7 | *.pch 8 | *.pdb 9 | *.suo 10 | *.user 11 | *.vspscc 12 | *.[Pp]ublish.xml 13 | [Bb]uild[Ll]og.* 14 | 15 | .vs/ 16 | [Bb]in/ 17 | [Db]ebug*/ 18 | [Oo]bj/ 19 | [Rr]elease*/ 20 | _ReSharper*/ 21 | [Tt]est[Rr]esult* 22 | packages/ 23 | [Aa]pp_[Dd]ata/ 24 | bower_components/ 25 | node_modules/ 26 | Umbraco.Deploy.UI.Client/build/ 27 | build/Tools/nuget.exe 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to this project 2 | 3 | Please take a moment to review this document in order to make the contribution 4 | process easy and effective for everyone involved. 5 | 6 | Following these guidelines helps to communicate that you respect the time of 7 | the developers managing and developing this open source project. In return, 8 | they should reciprocate that respect in addressing your issue or assessing 9 | patches and features. 10 | 11 | 12 | ## Using the issue tracker 13 | 14 | The issue tracker is the preferred channel for [bug reports](#bugs), 15 | [features requests](#features) and [submitting pull 16 | requests](#pull-requests), but please respect the following restrictions: 17 | 18 | * Please **do not** use the issue tracker for personal or commercial support 19 | requests (use the official Umbraco support channels). 20 | 21 | * Please **do not** derail or troll issues. Keep the discussion on topic and 22 | respect the opinions of others. 23 | 24 | 25 | 26 | ## Bug reports 27 | 28 | A bug is a _demonstrable problem_ that is caused by the code in the repository. 29 | Good bug reports are extremely helpful - thank you! 30 | 31 | Guidelines for bug reports: 32 | 33 | 1. **Use the GitHub issue search** — check if the issue has already been 34 | reported. 35 | 36 | 2. **Check if the issue has been fixed** — try to reproduce it using the 37 | latest `master` or development branch in the repository. 38 | 39 | 3. **Isolate the problem** — create a reduced test 40 | case and a live example. 41 | 42 | A good bug report shouldn't leave others needing to chase you up for more 43 | information. Please try to be as detailed as possible in your report. What is 44 | your environment? What steps will reproduce the issue? What browser(s) and OS 45 | experience the problem? What would you expect to be the outcome? All these 46 | details will help people to fix any potential bugs. 47 | 48 | Example: 49 | 50 | > Short and descriptive example bug report title 51 | > 52 | > A summary of the issue and the browser/OS environment in which it occurs. If 53 | > suitable, include the steps required to reproduce the bug. 54 | > 55 | > 1. This is the first step 56 | > 2. This is the second step 57 | > 3. Further steps, etc. 58 | > 59 | > `` - a link to the reduced test case 60 | > 61 | > Any other information you want to share that is relevant to the issue being 62 | > reported. This might include the lines of code that you have identified as 63 | > causing the bug, and potential solutions (and your opinions on their 64 | > merits). 65 | 66 | 67 | 68 | ## Feature requests 69 | 70 | Feature requests are welcome. But take a moment to find out whether your idea 71 | fits with the scope and aims of the project. It's up to *you* to make a strong 72 | case to convince the project's developers of the merits of this feature. Please 73 | provide as much detail and context as possible. 74 | 75 | 76 | 77 | ## Pull requests 78 | 79 | Good pull requests - patches, improvements, new features - are a fantastic 80 | help. They should remain focused in scope and avoid containing unrelated 81 | commits. 82 | 83 | **Please ask first** before embarking on any significant pull request (e.g. 84 | implementing features, refactoring code, porting to a different language), 85 | otherwise you risk spending a lot of time working on something that the 86 | project's developers might not want to merge into the project. 87 | 88 | Please adhere to the coding conventions used throughout a project (indentation, 89 | accurate comments, etc.) and any other requirements (such as test coverage). 90 | 91 | Follow this process if you'd like your work considered for inclusion in the 92 | project: 93 | 94 | 1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, 95 | and configure the remotes: 96 | 97 | ```bash 98 | # Clone your fork of the repo into the current directory 99 | git clone https://github.com// 100 | # Navigate to the newly cloned directory 101 | cd 102 | # Assign the original repo to a remote called "upstream" 103 | git remote add upstream https://github.com// 104 | ``` 105 | 106 | 2. If you cloned a while ago, get the latest changes from upstream: 107 | 108 | ```bash 109 | git checkout develop 110 | git pull upstream develop 111 | ``` 112 | 113 | 3. Create a new topic branch (off the main project `develop` branch) to 114 | contain your feature, change, or fix: 115 | 116 | ```bash 117 | git checkout -b 118 | ``` 119 | 120 | 4. Commit your changes in logical chunks. Please adhere to these [git commit 121 | message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 122 | or your code is unlikely be merged into the main project. Use Git's 123 | [interactive rebase](https://help.github.com/articles/interactive-rebase) 124 | feature to tidy up your commits before making them public. 125 | 126 | 5. Locally merge (or rebase) the upstream development branch into your topic branch: 127 | 128 | ```bash 129 | git pull [--rebase] upstream develop 130 | ``` 131 | 132 | 6. Push your topic branch up to your fork: 133 | 134 | ```bash 135 | git push origin 136 | ``` 137 | 138 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) 139 | with a clear title and description. 140 | 141 | **IMPORTANT**: By submitting a patch, you agree to allow the project owner to 142 | license your work under the same license as that used by the project. -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2016 Umbraco 4 | Copyright © 2016 Our Umbraco and other contributors 5 | Copyright © 2016 DIS/PLAY 6 | Copyright © 2014 Lee Kelleher, Umbrella Inc 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | this software and associated documentation files (the "Software"), to deal in 10 | the Software without restriction, including without limitation the rights to 11 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 | of the Software, and to permit persons to whom the Software is furnished to do 13 | so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build status](https://ci.appveyor.com/api/projects/status/bfotoy95lmos15b2/branch/master?svg=true)](https://ci.appveyor.com/project/Umbraco/umbraco-courier-contrib/branch/master) 2 | [![NuGet release](https://img.shields.io/nuget/v/Umbraco.Courier.Contrib.svg)](https://www.nuget.org/packages/Umbraco.Courier.Contrib) 3 | 4 | # Umbraco Courier Contrib 5 | 6 | This project contains community contributions for the Umbraco deployment tool, Courier. 7 | 8 | Primarily this project offers data-resolvers for the most popular Umbraco community packages - these are used by Courier (and [Umbraco Cloud](https://umbraco.com/cloud)) to aid with the deployment and transferring of content/property-data to a target environment. 9 | 10 | 11 | ## Data Resolvers 12 | 13 | This project offers Umbraco Courier data-resolvers for the following community packages: 14 | 15 | - [DocType Grid Editor](https://our.umbraco.org/projects/backoffice-extensions/doc-type-grid-editor/) 16 | - [UrlPicker](https://our.umbraco.org/projects/backoffice-extensions/urlpicker/) 17 | - [LeBlender](https://our.umbraco.org/projects/backoffice-extensions/leblender) 18 | - [Nested Content](https://our.umbraco.org/projects/backoffice-extensions/nested-content/) 19 | - [Stacked Content](https://github.com/umco/umbraco-stacked-content) 20 | - [Vorto](https://our.umbraco.org/projects/backoffice-extensions/vorto) 21 | - [Multi Url Picker](https://our.umbraco.org/projects/backoffice-extensions/multi-url-picker/) 22 | 23 | 24 | --- 25 | 26 | ## Getting Started 27 | 28 | ### Installation 29 | 30 | You can install the NuGet package using `Install-Package Umbraco.Courier.Contrib`. 31 | [![NuGet release](https://img.shields.io/nuget/v/Umbraco.Courier.Contrib.svg)](https://www.nuget.org/packages/Umbraco.Courier.Contrib) 32 | 33 | --- 34 | 35 | ## Contributing to this project 36 | 37 | Anyone who wishes to get involved with this project is more than welcome to contribute. Please take a moment to review the [guidelines for contributing](CONTRIBUTING.md), this applies for any bug reports, feature requests and pull requests. 38 | 39 | * [Bug reports](CONTRIBUTING.md#bugs) 40 | * [Feature requests](CONTRIBUTING.md#features) 41 | * [Pull requests](CONTRIBUTING.md#pull-requests) 42 | 43 | 44 | ### Issues 45 | 46 | We encourage you to report any issues you might find with these data-resolvers, so we can have them fixed for everyone! 47 | 48 | When reporting issues with a resolver it will help us a whole lot if you can reduce your report to being the absolute minimum required to encounter the error you are seeing. 49 | 50 | This means try removing anything unnecessary or unrelated to the actual issue, from your setup and also try reducing the steps to reproduce, to only cover exactly what we would need to do in order to see the error you are getting. 51 | 52 | For any questions or issues about this project specifically, please [raise an issue](https://github.com/umbraco/Umbraco.Courier.Contrib/issues) on GitHub. 53 | 54 | For any Courier specific enquiries, please use the [Umbraco Issue Tracker (for Courier)](http://issues.umbraco.org/issues/COU). 55 | 56 | 57 | ## Credits 58 | 59 | Special thanks to the following community members for providing the initial data-resolver code for this project. 60 | 61 | * [Umbrella](https://github.com/UmbrellaInc) and [Lee Kelleher](https://github.com/leekelleher) 62 | * [DIS/PLAY](https://github.com/display), [Rasmus Pedersen](https://github.com/rasmusjp) and [Kasper Kristensen](https://github.com/kasperhhk) 63 | * [Matt Brailsford](https://github.com/mattbrailsford) 64 | * [Heather Floyd](https://github.com/hfloyd), [Matt Morrison](https://github.com/mattmorrisonsolidstudios) 65 | 66 | 67 | ## License 68 | 69 | Copyright © 2016 Umbraco 70 | 71 | Copyright © 2016 Our Umbraco and [other contributors](https://github.com/leekelleher/umbraco-courier-dataresolvers/graphs/contributors) 72 | 73 | Copyright © 2016 DIS/PLAY 74 | 75 | Copyright © 2014 Lee Kelleher, Umbrella Inc 76 | 77 | Licensed under the [MIT License](LICENSE.md) 78 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # version format 2 | version: 1.0.{build} 3 | 4 | # Do not build on tags 5 | skip_tags: true 6 | 7 | build_script: 8 | - cd Build 9 | - Package.build.cmd %APPVEYOR_BUILD_VERSION% 10 | 11 | artifacts: 12 | - path: Releases\*.nupkg 13 | 14 | deploy: 15 | - provider: NuGet 16 | api_key: 17 | secure: SPZoI6dtnTnukMvoB6U7XA6QGBR6fpseGdPE3QG0I2p2Iauz/b5Oj2hzQQp7Y2q1 18 | skip_symbols: false 19 | artifact: /.*\.nupkg/ 20 | on: 21 | branch: master 22 | -------------------------------------------------------------------------------- /src/.nuget/NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/Action.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.Courier.Contrib.Resolvers 2 | { 3 | /// 4 | /// Indicates if we are packaging or extracting. 5 | /// 6 | internal enum Action 7 | { 8 | Packaging, 9 | Extracting 10 | } 11 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/GridCellDataResolvers/DocTypeGridEditorGridCellResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Linq; 6 | using Umbraco.Courier.Core; 7 | using Umbraco.Courier.Core.Logging; 8 | using Umbraco.Courier.Core.ProviderModel; 9 | using Umbraco.Courier.DataResolvers.PropertyDataResolvers; 10 | using Umbraco.Courier.ItemProviders; 11 | 12 | namespace Umbraco.Courier.Contrib.Resolvers.GridCellDataResolvers 13 | { 14 | /// 15 | /// DocTypeGridEditor Grid Cell Resolver for DTGE by Matt Brailsford & Lee Kelleher. 16 | /// 17 | public class DocTypeGridEditorGridCellResolver : GridCellResolverProvider 18 | { 19 | public override bool ShouldRun(string view, GridValueControlModel cell) 20 | { 21 | try 22 | { 23 | if (cell == null || cell.Value == null) 24 | return false; 25 | 26 | if (cell.Value is JValue) 27 | return false; 28 | 29 | if (cell.Value.Type == JTokenType.Array) 30 | return false; 31 | 32 | return cell.Value["dtgeContentTypeAlias"] != null && cell.Value["value"] != null; 33 | } 34 | catch (Exception ex) 35 | { 36 | CourierLogHelper.Error("Error reading grid cell value: ", ex); 37 | return false; 38 | } 39 | } 40 | 41 | public override void PackagingCell(Item item, ContentProperty propertyData, GridValueControlModel cell) 42 | { 43 | ProcessCell(item, propertyData, cell, Action.Packaging); 44 | } 45 | 46 | public override void ExtractingCell(Item item, ContentProperty propertyData, GridValueControlModel cell) 47 | { 48 | ProcessCell(item, propertyData, cell, Action.Extracting); 49 | } 50 | 51 | private void ProcessCell(Item item, ContentProperty propertyData, GridValueControlModel cell, Action direction) 52 | { 53 | var documentTypeAlias = cell.Value["dtgeContentTypeAlias"].ToString(); 54 | if (string.IsNullOrWhiteSpace(documentTypeAlias)) 55 | return; 56 | var documentType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(documentTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 57 | 58 | var cellValueJson = cell.Value["value"].ToString(); 59 | if (string.IsNullOrWhiteSpace(cellValueJson)) 60 | return; 61 | 62 | var cellValue = JsonConvert.DeserializeObject(cellValueJson); 63 | if (!(cellValue is JObject)) 64 | return; 65 | 66 | var propertyValues = ((JObject)cellValue).ToObject>(); 67 | 68 | //this editor can contain references to doctypes that no longer exist 69 | //then it would be pointless to iterate over properties, they can't be set anyway 70 | if (documentType != null) 71 | { 72 | if (direction == Action.Packaging) 73 | { 74 | item.Dependencies.Add(documentType.UniqueId.ToString(), ItemProviderIds.documentTypeItemProviderGuid); 75 | } 76 | 77 | // get the ItemProvider for the ResolutionManager 78 | var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); 79 | 80 | var properties = documentType.Properties; 81 | 82 | // check for compositions 83 | foreach (var masterDocumentTypeAlias in documentType.MasterDocumentTypes) 84 | { 85 | var masterDocumentType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(masterDocumentTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 86 | if (masterDocumentType != null) 87 | properties.AddRange(masterDocumentType.Properties); 88 | } 89 | 90 | foreach (var property in properties) 91 | { 92 | object value = null; 93 | if (!propertyValues.TryGetValue(property.Alias, out value) || value == null) 94 | continue; 95 | 96 | var datatype = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(property.DataTypeDefinitionId.ToString(), ItemProviderIds.dataTypeItemProviderGuid)); 97 | 98 | // create a pseudo item for sending through resolvers 99 | var pseudoPropertyDataItem = new ContentPropertyData 100 | { 101 | ItemId = item.ItemId, 102 | Name = string.Format("{0} [{1}: Nested {2} ({3})]", item.Name, EditorAlias, datatype.PropertyEditorAlias, property.Alias), 103 | Data = new List 104 | { 105 | new ContentProperty 106 | { 107 | Alias = property.Alias, 108 | DataType = datatype.UniqueID, 109 | PropertyEditorAlias = datatype.PropertyEditorAlias, 110 | Value = value 111 | } 112 | } 113 | }; 114 | 115 | if (direction == Action.Packaging) 116 | { 117 | try 118 | { 119 | // run the resolvers (convert Ids/integers into UniqueIds/guids) 120 | ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider); 121 | } 122 | catch (Exception ex) 123 | { 124 | CourierLogHelper.Error(string.Concat("Error packaging data value: ", pseudoPropertyDataItem.Name), ex); 125 | } 126 | 127 | // add in dependencies when packaging 128 | item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); 129 | item.Resources.AddRange(pseudoPropertyDataItem.Resources); 130 | } 131 | else if (direction == Action.Extracting) 132 | { 133 | try 134 | { 135 | // run the resolvers (convert UniqueIds/guids back to Ids/integers) 136 | ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider); 137 | } 138 | catch (Exception ex) 139 | { 140 | CourierLogHelper.Error( 141 | string.Concat("Error extracting data value: ", pseudoPropertyDataItem.Name), ex); 142 | } 143 | } 144 | 145 | if (pseudoPropertyDataItem.Data != null && pseudoPropertyDataItem.Data.Any()) 146 | { 147 | // get the first (and only) property of the pseudo item created above 148 | var firstProperty = pseudoPropertyDataItem.Data.FirstOrDefault(); 149 | if (firstProperty != null) 150 | { 151 | // get the resolved value 152 | var resolvedValue = firstProperty.Value; 153 | 154 | if (direction == Action.Extracting && resolvedValue is string && resolvedValue.ToString().DetectIsJson()) 155 | { 156 | // because the DTGE data must be a JSON object type, we'll want to deserialize any encoded strings 157 | propertyValues[property.Alias] = JsonConvert.DeserializeObject(resolvedValue.ToString()); 158 | } 159 | else 160 | { 161 | // replace the property value with the resolved value 162 | propertyValues[property.Alias] = resolvedValue; 163 | } 164 | 165 | // (if packaging) add a dependency for the property's data-type 166 | if (direction == Action.Packaging) 167 | item.Dependencies.Add(firstProperty.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 168 | } 169 | } 170 | } 171 | } 172 | 173 | // the value assigned back must be a JSON object type 174 | cell.Value["value"] = JObject.FromObject(propertyValues); 175 | } 176 | } 177 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/GridCellDataResolvers/LeBlenderGridCellResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using Newtonsoft.Json; 6 | using Newtonsoft.Json.Linq; 7 | using Umbraco.Core; 8 | using Umbraco.Courier.Core; 9 | using Umbraco.Courier.Core.ProviderModel; 10 | using Umbraco.Courier.DataResolvers.PropertyDataResolvers; 11 | using Umbraco.Courier.ItemProviders; 12 | 13 | namespace Umbraco.Courier.Contrib.Resolvers.GridCellDataResolvers 14 | { 15 | public class LeBlenderGridCellResolver : GridCellResolverProvider 16 | { 17 | public override bool ShouldRun(string view, GridValueControlModel cell) 18 | { 19 | return view.Contains("leblender"); 20 | } 21 | 22 | public override void PackagingCell(Item item, ContentProperty propertyData, GridValueControlModel cell) 23 | { 24 | ProcessCell(item, propertyData, cell, Action.Packaging); 25 | base.PackagingCell(item, propertyData, cell); 26 | } 27 | 28 | public override void ExtractingCell(Item item, ContentProperty propertyData, GridValueControlModel cell) 29 | { 30 | ProcessCell(item, propertyData, cell, Action.Extracting); 31 | base.ExtractingCell(item, propertyData, cell); 32 | } 33 | 34 | private void ProcessCell(Item item, ContentProperty propertyData, GridValueControlModel cell, Action action) 35 | { 36 | // cancel if there's no values 37 | if (cell.Value == null || cell.Value.HasValues == false) 38 | return; 39 | 40 | var dataTypeService = ApplicationContext.Current.Services.DataTypeService; 41 | // get the ItemProvider for the ResolutionManager 42 | var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); 43 | 44 | // Often there is only one entry in cell.Value, but with LeBlender 45 | // min/max you can easily get 2+ entries so we'll walk them all 46 | var newItemValue = new JArray(); 47 | foreach (var properties in cell.Value) 48 | { 49 | // create object to store resolved properties 50 | var resolvedProperties = new JObject(); 51 | 52 | // loop through each of the property objects 53 | foreach (dynamic leBlenderPropertyWrapper in properties) 54 | { 55 | // deserialize the value of the wrapper object into a LeBlenderProperty object 56 | var leBlenderPropertyJson = leBlenderPropertyWrapper.Value.ToString() as string; 57 | // continue if there's no data stored 58 | if (string.IsNullOrEmpty(leBlenderPropertyJson)) continue; 59 | 60 | var leBlenderProperty = JsonConvert.DeserializeObject(leBlenderPropertyJson); 61 | 62 | // get the DataType of the property 63 | var dataType = dataTypeService.GetDataTypeDefinitionById(leBlenderProperty.DataTypeGuid); 64 | if (dataType == null) 65 | { 66 | // If the data type referenced by this LeBlender Property is missing on this machine 67 | // we'll get a very cryptic error when it attempts to create the pseudo property data item below. 68 | // Throw a meaningful error message instead 69 | throw new ArgumentNullException(string.Format("Unable to find the data type for editor '{0}' ({1} {2}) referenced by '{3}'.", leBlenderProperty.EditorName, leBlenderProperty.EditorAlias, 70 | leBlenderProperty.DataTypeGuid, item.Name)); 71 | // Should we log a warning and continue instead? 72 | } 73 | 74 | // create a pseudo item for sending through resolvers 75 | var pseudoPropertyDataItem = new ContentPropertyData 76 | { 77 | ItemId = item.ItemId, 78 | Name = string.Format("{0}: (LeBlender PropertyAlias: {1}, DataTypeEditorAlias: {2})", item.Name, leBlenderProperty.EditorAlias, dataType.PropertyEditorAlias), 79 | Data = new List 80 | { 81 | new ContentProperty 82 | { 83 | Alias = propertyData.Alias, 84 | DataType = leBlenderProperty.DataTypeGuid, 85 | PropertyEditorAlias = dataType.PropertyEditorAlias, 86 | Value = leBlenderProperty.Value 87 | } 88 | } 89 | }; 90 | if (action == Action.Packaging) 91 | { 92 | // run the resolvers (convert Ids/integers into UniqueIds/guids) 93 | ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider); 94 | // add in this editor's dependencies when packaging 95 | item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); 96 | item.Resources.AddRange(pseudoPropertyDataItem.Resources); 97 | // and include this editor's data type as a dependency too 98 | item.Dependencies.Add(leBlenderProperty.DataTypeGuid.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 99 | } 100 | else 101 | { 102 | // run the resolvers (convert UniqueIds/guids back to Ids/integers) 103 | ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider); 104 | } 105 | // replace the property value with the resolved value 106 | leBlenderProperty.Value = pseudoPropertyDataItem.Data.First().Value; 107 | // add the resolved property to the resolved properties object 108 | resolvedProperties.Add(leBlenderProperty.EditorAlias, JObject.FromObject(leBlenderProperty)); 109 | } 110 | newItemValue.Add(resolvedProperties); 111 | } 112 | // replace the cell value with all the resolved values 113 | cell.Value = JToken.FromObject(newItemValue); 114 | } 115 | 116 | internal class LeBlenderProperty 117 | { 118 | private bool _isQuoted; 119 | private JRaw _jrawValue; 120 | 121 | [JsonProperty("value")] 122 | public JRaw JRawValue 123 | { 124 | get { return _jrawValue; } 125 | set 126 | { 127 | _jrawValue = value; 128 | _isQuoted = _isQuoted || value.ToString(CultureInfo.InvariantCulture).Trim().StartsWith("\""); 129 | } 130 | } 131 | 132 | [JsonIgnore] 133 | public object Value 134 | { 135 | get 136 | { 137 | if (_isQuoted) 138 | { 139 | // Umbraco.DropDown and other prevalue data types want an unquoted string 140 | // so we need to strip the leading and trailing quotation marks now 141 | // then put them back later 142 | var trimmed = JRawValue.ToString(CultureInfo.InvariantCulture).Trim(); 143 | trimmed = trimmed.Substring(1, trimmed.Length - 2); 144 | return trimmed; 145 | } 146 | // Complex data types like RJP.MultiUrlPicker expect the json as a string 147 | return JRawValue.ToString(CultureInfo.InvariantCulture); 148 | } 149 | set 150 | { 151 | string str = value as string; 152 | if (str != null && (_isQuoted || str == "¤")) 153 | { 154 | // We stripped quotes off so put them back now 155 | JRawValue = new JRaw("\"" + str + "\""); 156 | } 157 | else 158 | { 159 | JRawValue = new JRaw(value); 160 | } 161 | } 162 | } 163 | 164 | [JsonProperty("dataTypeGuid")] 165 | public Guid DataTypeGuid { get; set; } 166 | 167 | [JsonProperty("editorAlias")] 168 | public string EditorAlias { get; set; } 169 | 170 | [JsonProperty("editorName")] 171 | public string EditorName { get; set; } 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("Umbraco.Courier.Contrib.Resolvers")] 5 | [assembly: AssemblyDescription("A collection of community contributed data-resolvers for Umbraco Courier")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("Umbraco.Courier.Contrib.Resolvers")] 9 | [assembly: AssemblyCopyright("Copyright \xa9 Umbraco 2016")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | [assembly: Guid("D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A")] 15 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/Properties/VersionInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | using System.Runtime.CompilerServices; 14 | using System.Runtime.InteropServices; 15 | 16 | [assembly: AssemblyVersion("1.0.0.*")] 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/ImulusUrlPickerPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Web.Hosting; 5 | using Newtonsoft.Json; 6 | using Umbraco.Courier.Core; 7 | using Umbraco.Courier.Core.Enums; 8 | using Umbraco.Courier.Core.Helpers; 9 | using Umbraco.Courier.DataResolvers; 10 | using Umbraco.Courier.ItemProviders; 11 | 12 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 13 | { 14 | /// 15 | /// Url Picker Property Data Resolver for the Imulus Url Picker DataType 16 | /// 17 | public class ImulusUrlPickerPropertyDataResolver : PropertyDataResolverProvider 18 | { 19 | private static Lazy UrlPickerVersion 20 | { 21 | get 22 | { 23 | return new Lazy(() => 24 | { 25 | // we cannot just get the assembly and get version from that, as we need to check the FileVersion 26 | // (apparently that is different from the assembly version...) 27 | var urlPickerAssemblyPath = HostingEnvironment.MapPath("~/bin/UrlPicker.dll"); 28 | if (IO.FileExists(urlPickerAssemblyPath)) 29 | { 30 | var fileVersionInfo = FileVersionInfo.GetVersionInfo(urlPickerAssemblyPath); 31 | return new Version(fileVersionInfo.FileVersion); 32 | } 33 | return null; 34 | }); 35 | } 36 | } 37 | 38 | // from the versions found on Our - this version and forward stores arrays 39 | private readonly Version UrlPickerVersionStoringArray = new Version(0, 15, 0, 1); 40 | 41 | /// 42 | /// Alias of the editor this resolver should trigger on. 43 | /// 44 | public override string EditorAlias 45 | { 46 | get { return "Imulus.UrlPicker"; } 47 | } 48 | 49 | /// 50 | /// This is triggered when the property is about to be packaged (Umbraco -> Courier). 51 | /// 52 | /// Item being packaged 53 | /// UrlPicker property being packaged 54 | public override void PackagingProperty(Item item, ContentProperty propertyData) 55 | { 56 | ProcessPropertyData(item, propertyData, Action.Packaging); 57 | base.PackagingProperty(item, propertyData); 58 | } 59 | 60 | /// 61 | /// This is triggered when the property is about to be extracted (Courier -> Umbraco). 62 | /// 63 | /// Item being extracted 64 | /// UrlPicker property being extracted 65 | public override void ExtractingProperty(Item item, ContentProperty propertyData) 66 | { 67 | ProcessPropertyData(item, propertyData, Action.Extracting); 68 | base.ExtractingProperty(item, propertyData); 69 | } 70 | 71 | private void ProcessPropertyData(Item item, ContentProperty propertyData, Action action) 72 | { 73 | if (action == Action.Packaging) 74 | { 75 | //Umbraco stores the UrlPickerPropertyData w/integer ids as json in the database, so we want to look for the those 76 | //integer ids and convert them to guids. The resulting object will be saved to the Courier file. 77 | 78 | IEnumerable urlPickerPropertyDatas; 79 | 80 | // If using an old version of the UrlPicker - data is serialized as a single object 81 | // Otherwise data is serialized as an array of objects, even if only one is selected. 82 | if (UrlPickerVersion.Value < UrlPickerVersionStoringArray) 83 | { 84 | var urlPickerPropertyData = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 85 | urlPickerPropertyDatas = new List {urlPickerPropertyData}; 86 | } 87 | else 88 | { 89 | urlPickerPropertyDatas = JsonConvert.DeserializeObject>(propertyData.Value.ToString()); 90 | } 91 | 92 | var resolvedPropertyDatas = new List(); 93 | 94 | foreach (var urlPickerProperty in urlPickerPropertyDatas) 95 | { 96 | //Check for the 'content' type 97 | if (urlPickerProperty.Type.Equals("content", StringComparison.OrdinalIgnoreCase) && 98 | urlPickerProperty.TypeData.ContentId != null && 99 | (urlPickerProperty.TypeData.ContentId is int || urlPickerProperty.TypeData.ContentId is Int64) 100 | && int.Parse(urlPickerProperty.TypeData.ContentId.ToString()) != 0) 101 | { 102 | var identifier = Dependencies.ConvertIdentifier(urlPickerProperty.TypeData.ContentId.ToString(), IdentifierReplaceDirection.FromNodeIdToGuid, ExecutionContext); 103 | //Add the referenced Content item as a dependency 104 | item.Dependencies.Add(identifier, ItemProviderIds.documentItemProviderGuid); 105 | var packagedContentData = new UrlPickerPropertyData 106 | { 107 | Type = urlPickerProperty.Type, 108 | Meta = urlPickerProperty.Meta, 109 | TypeData = new TypeData { Url = urlPickerProperty.TypeData.Url, ContentId = new Guid(identifier) } 110 | }; 111 | resolvedPropertyDatas.Add(packagedContentData); 112 | continue; 113 | } 114 | 115 | //Check for the 'media' type 116 | if (urlPickerProperty.Type.Equals("media", StringComparison.OrdinalIgnoreCase) && 117 | urlPickerProperty.TypeData.MediaId != null && 118 | (urlPickerProperty.TypeData.MediaId is int || urlPickerProperty.TypeData.MediaId is Int64) 119 | && int.Parse(urlPickerProperty.TypeData.MediaId.ToString()) != 0) 120 | { 121 | var identifier = Dependencies.ConvertIdentifier(urlPickerProperty.TypeData.MediaId.ToString(), IdentifierReplaceDirection.FromNodeIdToGuid, ExecutionContext); 122 | //Add the referenced Content item as a dependency 123 | item.Dependencies.Add(identifier, ItemProviderIds.mediaItemProviderGuid); 124 | var packagedMediaData = new UrlPickerPropertyData 125 | { 126 | Type = urlPickerProperty.Type, 127 | Meta = urlPickerProperty.Meta, 128 | TypeData = new TypeData { Url = urlPickerProperty.TypeData.Url, MediaId = new Guid(identifier) } 129 | }; 130 | resolvedPropertyDatas.Add(packagedMediaData); 131 | continue; 132 | } 133 | 134 | //Convert the object to get the right types in the json output 135 | var packagedData = new UrlPickerPropertyData 136 | { 137 | Type = urlPickerProperty.Type, 138 | Meta = urlPickerProperty.Meta, 139 | TypeData = new TypeData { Url = urlPickerProperty.TypeData.Url } 140 | }; 141 | //Since the Imulus.UrlPicker is already handled in Archetype we need to ensure that guids that are already resolved 142 | //get passed on through to the property data value (for both Content and Media) 143 | if (urlPickerProperty.TypeData.ContentId != null && urlPickerProperty.TypeData.ContentId is string) 144 | { 145 | packagedData.TypeData.ContentId = new Guid(urlPickerProperty.TypeData.ContentId.ToString()); 146 | item.Dependencies.Add(urlPickerProperty.TypeData.ContentId.ToString(), ItemProviderIds.documentItemProviderGuid); 147 | } 148 | if (urlPickerProperty.TypeData.MediaId != null && urlPickerProperty.TypeData.MediaId is string) 149 | { 150 | packagedData.TypeData.ContentId = new Guid(urlPickerProperty.TypeData.MediaId.ToString()); 151 | item.Dependencies.Add(urlPickerProperty.TypeData.MediaId.ToString(), ItemProviderIds.documentItemProviderGuid); 152 | } 153 | resolvedPropertyDatas.Add(packagedData); 154 | } 155 | 156 | // If using an old version of the UrlPicker - data is serialized as a single object 157 | // Otherwise data is serialized as an array of objects, even if only one is selected. 158 | if (resolvedPropertyDatas.Count == 1 && UrlPickerVersion.Value < UrlPickerVersionStoringArray) 159 | propertyData.Value = JsonConvert.SerializeObject(resolvedPropertyDatas[0]); 160 | else 161 | propertyData.Value = JsonConvert.SerializeObject(resolvedPropertyDatas); 162 | } 163 | else 164 | { 165 | //The Courier file has data as UrlPickerPropertyData w/ids as guids, so we want to look for those guids and find their integer ids 166 | //so the object can be saved as (the original) json in the Umbraco database. 167 | 168 | IEnumerable packagedUrlPickerPropertyDatas; 169 | 170 | // If using an old version of the UrlPicker - data is serialized as a single object 171 | // Otherwise data is serialized as an array of objects, even if only one is selected. 172 | if (UrlPickerVersion.Value < UrlPickerVersionStoringArray) 173 | { 174 | var urlPickerPropertyData = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 175 | packagedUrlPickerPropertyDatas = new List { urlPickerPropertyData }; 176 | } 177 | else 178 | { 179 | packagedUrlPickerPropertyDatas = JsonConvert.DeserializeObject>(propertyData.Value.ToString()); 180 | } 181 | 182 | var resolvedPropertyDatas = new List(); 183 | 184 | foreach (var packagedUrlPickerProperty in packagedUrlPickerPropertyDatas) 185 | { 186 | //Check for the 'content' type 187 | if (packagedUrlPickerProperty.Type.Equals("content", StringComparison.OrdinalIgnoreCase) && 188 | packagedUrlPickerProperty.TypeData.ContentId != null) 189 | { 190 | var identifier = Dependencies.ConvertIdentifier(packagedUrlPickerProperty.TypeData.ContentId.ToString(), IdentifierReplaceDirection.FromGuidToNodeId, ExecutionContext); 191 | int id; 192 | if (int.TryParse(identifier, out id)) 193 | { 194 | var contentData = new UrlPickerPropertyData 195 | { 196 | Type = packagedUrlPickerProperty.Type, 197 | Meta = packagedUrlPickerProperty.Meta, 198 | TypeData = new TypeData 199 | { 200 | Url = packagedUrlPickerProperty.TypeData.Url, 201 | ContentId = id 202 | } 203 | }; 204 | resolvedPropertyDatas.Add(contentData); 205 | continue; 206 | } 207 | } 208 | 209 | //Check for the 'media' type 210 | if (packagedUrlPickerProperty.Type.Equals("media", StringComparison.OrdinalIgnoreCase) && 211 | packagedUrlPickerProperty.TypeData.MediaId != null) 212 | { 213 | var identifier = Dependencies.ConvertIdentifier(packagedUrlPickerProperty.TypeData.MediaId.ToString(), IdentifierReplaceDirection.FromGuidToNodeId, ExecutionContext); 214 | int id; 215 | if (int.TryParse(identifier, out id)) 216 | { 217 | var mediaData = new UrlPickerPropertyData 218 | { 219 | Type = packagedUrlPickerProperty.Type, 220 | Meta = packagedUrlPickerProperty.Meta, 221 | TypeData = new TypeData 222 | { 223 | Url = packagedUrlPickerProperty.TypeData.Url, 224 | MediaId = id 225 | } 226 | }; 227 | resolvedPropertyDatas.Add(mediaData); 228 | continue; 229 | } 230 | } 231 | 232 | //Convert the object to get the right types in the json output 233 | var extractedData = new UrlPickerPropertyData 234 | { 235 | Type = packagedUrlPickerProperty.Type, 236 | Meta = packagedUrlPickerProperty.Meta, 237 | TypeData = new TypeData { Url = packagedUrlPickerProperty.TypeData.Url } 238 | }; 239 | //As a precaution we check if the content and media ids already exist in which case we keep them 240 | //as they might already have been handled by Archetype 241 | if (packagedUrlPickerProperty.TypeData.ContentId != null) 242 | { 243 | extractedData.TypeData.ContentId = packagedUrlPickerProperty.TypeData.ContentId; 244 | } 245 | if (packagedUrlPickerProperty.TypeData.MediaId != null) 246 | { 247 | extractedData.TypeData.MediaId = packagedUrlPickerProperty.TypeData.MediaId; 248 | } 249 | resolvedPropertyDatas.Add(extractedData); 250 | } 251 | 252 | // If using an old version of the UrlPicker - data is serialized as a single object 253 | // Otherwise data is serialized as an array of objects, even if only one is selected. 254 | if (resolvedPropertyDatas.Count == 1 && UrlPickerVersion.Value < UrlPickerVersionStoringArray) 255 | propertyData.Value = JsonConvert.SerializeObject(resolvedPropertyDatas[0]); 256 | else 257 | propertyData.Value = JsonConvert.SerializeObject(resolvedPropertyDatas); 258 | } 259 | } 260 | 261 | internal class UrlPickerPropertyData 262 | { 263 | [JsonProperty("type")] 264 | public string Type { get; set; } 265 | [JsonProperty("meta")] 266 | public Meta Meta { get; set; } 267 | [JsonProperty("typeData")] 268 | public TypeData TypeData { get; set; } 269 | } 270 | 271 | internal class Meta 272 | { 273 | [JsonProperty("title")] 274 | public string Title { get; set; } 275 | [JsonProperty("newWindow")] 276 | public bool NewWindow { get; set; } 277 | } 278 | 279 | internal class TypeData 280 | { 281 | [JsonProperty("url")] 282 | public string Url { get; set; } 283 | [JsonProperty("contentId")] 284 | public object ContentId { get; set; } 285 | [JsonProperty("mediaId")] 286 | public object MediaId { get; set; } 287 | } 288 | } 289 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/InnerContentPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Linq; 6 | using Umbraco.Core; 7 | using Umbraco.Courier.Core; 8 | using Umbraco.Courier.Core.Logging; 9 | using Umbraco.Courier.Core.ProviderModel; 10 | using Umbraco.Courier.DataResolvers; 11 | using Umbraco.Courier.ItemProviders; 12 | 13 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 14 | { 15 | /// 16 | /// An abstract Property Data Resolver for Inner Content by Matt Brailsford & Lee Kelleher. 17 | /// 18 | public abstract class InnerContentPropertyDataResolver : PropertyDataResolverProvider 19 | { 20 | /// 21 | /// This is triggered when the property is about to be extracted (Courier -> Umbraco). 22 | /// 23 | /// Item being extracted 24 | /// Inner Content property being extracted 25 | public override void ExtractingProperty(Item item, ContentProperty propertyData) 26 | { 27 | ProcessPropertyData(item, propertyData, Action.Extracting); 28 | } 29 | 30 | /// 31 | /// This is triggered when the property is about to be packaged (Umbraco -> Courier). 32 | /// 33 | /// The DataType item being packaged 34 | public override void PackagingDataType(DataType item) 35 | { 36 | AddDataTypeDependencies(item); 37 | } 38 | 39 | /// 40 | /// This is triggered when the property is about to be packaged (Umbraco -> Courier). 41 | /// 42 | /// Item being packaged 43 | /// Inner Content property being packaged 44 | public override void PackagingProperty(Item item, ContentProperty propertyData) 45 | { 46 | ProcessPropertyData(item, propertyData, Action.Packaging); 47 | } 48 | 49 | private void AddDataTypeDependencies(DataType item) 50 | { 51 | if (item == null || item.Prevalues == null || item.Prevalues.Count == 0) 52 | return; 53 | 54 | var json = item.Prevalues.FirstOrDefault(x => x.Alias.InvariantEquals("contentTypes")); 55 | if (json == null) 56 | return; 57 | 58 | var contentTypes = JsonConvert.DeserializeObject(json.Value); 59 | if (contentTypes == null) 60 | return; 61 | 62 | var resolvedDocTypes = new Dictionary(); 63 | 64 | foreach (var contentType in contentTypes) 65 | { 66 | var alias = contentType["icContentTypeAlias"]; 67 | if (alias == null) 68 | continue; 69 | 70 | var documentType = GetDocumentType(alias.ToString(), resolvedDocTypes); 71 | if (documentType == null) 72 | continue; 73 | 74 | item.Dependencies.Add(documentType.UniqueId.ToString(), ItemProviderIds.documentTypeItemProviderGuid); 75 | } 76 | } 77 | 78 | private void ProcessPropertyData(Item item, ContentProperty propertyData, Action action) 79 | { 80 | // add a dependency to the dataType if packaging 81 | if (action == Action.Packaging) 82 | item.Dependencies.Add(propertyData.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 83 | 84 | // get the ItemProvider for the ResolutionManager 85 | var propertyItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); 86 | 87 | // deserialize the Inner Content value into an array of Inner Content items 88 | var innerContentItems = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 89 | 90 | ProcessItems(item, innerContentItems, propertyItemProvider, action); 91 | 92 | // serialize the whole Inner Content property back to JSON and save the value on the property data 93 | propertyData.Value = JsonConvert.SerializeObject(innerContentItems); 94 | } 95 | 96 | private void ProcessItems(Item item, JArray innerContentItems, ItemProvider propertyItemProvider, Action action) 97 | { 98 | // loop through all the Inner Content items 99 | if (innerContentItems != null && innerContentItems.Any()) 100 | { 101 | var resolvedDocTypes = new Dictionary(); 102 | var resolvedDataTypes = new Dictionary(); 103 | 104 | foreach (var innerContentItem in innerContentItems) 105 | { 106 | // get the document type for the item, if it can't be found, skip to the next item 107 | var documentTypeAlias = innerContentItem["icContentTypeAlias"]; 108 | if (documentTypeAlias == null) 109 | continue; 110 | 111 | var documentTypeAliasString = documentTypeAlias.ToString(); 112 | var documentType = GetDocumentType(documentTypeAliasString, resolvedDocTypes); 113 | if (documentType == null) 114 | continue; 115 | 116 | // get the properties available on the document type 117 | var propertyTypes = documentType.Properties; 118 | 119 | // add in properties from all composition document types, as these are not located on the document type itself 120 | foreach (var masterDocumentTypeAlias in documentType.MasterDocumentTypes) 121 | { 122 | var masterDocType = GetDocumentType(masterDocumentTypeAlias, resolvedDocTypes); 123 | if (masterDocType != null) 124 | propertyTypes.AddRange(masterDocType.Properties); 125 | } 126 | 127 | // run through all properties, creating pseudo items and sending them through the resolvers 128 | foreach (var propertyType in propertyTypes) 129 | { 130 | ProcessItemPropertyData(item, propertyType, innerContentItem, propertyItemProvider, action, resolvedDataTypes); 131 | } 132 | } 133 | } 134 | } 135 | 136 | private void ProcessItemPropertyData(Item item, ContentTypeProperty propertyType, JToken innerContentItem, ItemProvider propertyItemProvider, Action action, Dictionary resolvedDataTypes) 137 | { 138 | var value = innerContentItem[propertyType.Alias]; 139 | if (value != null) 140 | { 141 | var dataType = GetDataType(propertyType.DataTypeDefinitionId.ToString(), resolvedDataTypes); 142 | 143 | // create a 'fake' item for Courier to process 144 | var pseudoPropertyDataItem = new ContentPropertyData 145 | { 146 | ItemId = item.ItemId, 147 | Name = string.Format("{0} [{1}: Inner {2} ({3})]", item.Name, this.EditorAlias, dataType.PropertyEditorAlias, propertyType.Alias), 148 | Data = new List 149 | { 150 | new ContentProperty 151 | { 152 | Alias = propertyType.Alias, 153 | DataType = dataType.UniqueID, 154 | PropertyEditorAlias = dataType.PropertyEditorAlias, 155 | Value = value.ToString() 156 | } 157 | } 158 | }; 159 | 160 | if (action == Action.Packaging) 161 | { 162 | try 163 | { 164 | // run the 'fake' item through Courier's data resolvers 165 | ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyItemProvider); 166 | } 167 | catch (Exception ex) 168 | { 169 | CourierLogHelper.Error(string.Concat("Error packaging data value: ", pseudoPropertyDataItem.Name), ex); 170 | } 171 | } 172 | else if (action == Action.Extracting) 173 | { 174 | try 175 | { 176 | // run the 'fake' item through Courier's data resolvers 177 | ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyItemProvider); 178 | } 179 | catch (Exception ex) 180 | { 181 | CourierLogHelper.Error(string.Concat("Error extracting data value: ", pseudoPropertyDataItem.Name), ex); 182 | } 183 | } 184 | 185 | // pass up the dependencies and resources 186 | item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); 187 | item.Resources.AddRange(pseudoPropertyDataItem.Resources); 188 | 189 | if (pseudoPropertyDataItem.Data != null && pseudoPropertyDataItem.Data.Any()) 190 | { 191 | // get the first (and only) property of the pseudo item created above 192 | var firstProperty = pseudoPropertyDataItem.Data.FirstOrDefault(); 193 | if (firstProperty != null) 194 | { 195 | // serialize the value of the property 196 | var serializedValue = firstProperty.Value as string ?? JsonConvert.SerializeObject(firstProperty.Value); 197 | 198 | // replace the values on the Inner Content item property with the resolved values 199 | innerContentItem[propertyType.Alias] = new JValue(serializedValue); 200 | 201 | // if packaging - add a dependency for the property's data-type 202 | if (action == Action.Packaging) 203 | item.Dependencies.Add(firstProperty.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 204 | } 205 | } 206 | } 207 | } 208 | 209 | private DocumentType GetDocumentType(string docTypeAlias, IDictionary cache) 210 | { 211 | DocumentType documentType; 212 | //don't look it up if we already have done that 213 | if (cache.TryGetValue(docTypeAlias, out documentType) == false) 214 | { 215 | documentType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(docTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 216 | cache[docTypeAlias] = documentType; 217 | } 218 | return documentType; 219 | } 220 | 221 | private DataType GetDataType(string docTypeAlias, IDictionary cache) 222 | { 223 | DataType dataType; 224 | //don't look it up if we already have done that 225 | if (cache.TryGetValue(docTypeAlias, out dataType) == false) 226 | { 227 | dataType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(docTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 228 | cache[docTypeAlias] = dataType; 229 | } 230 | return dataType; 231 | } 232 | } 233 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/MultiUrlPickerPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using Umbraco.Core; 5 | using Umbraco.Courier.Core; 6 | using Umbraco.Courier.Core.Logging; 7 | using Umbraco.Courier.DataResolvers; 8 | using Umbraco.Courier.ItemProviders; 9 | 10 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 11 | { 12 | public class MultiUrlPickerPropertyDataResolver : PropertyDataResolverProvider 13 | { 14 | public override string EditorAlias 15 | { 16 | get 17 | { 18 | return "RJP.MultiUrlPicker"; 19 | } 20 | } 21 | 22 | public override void PackagingProperty(Item item, ContentProperty propertyData) 23 | { 24 | if (propertyData == null || propertyData.Value == null) 25 | return; 26 | 27 | JArray links; 28 | try 29 | { 30 | links = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 31 | } 32 | catch (Exception ex) 33 | { 34 | CourierLogHelper.Error(String.Format("There was a problem deserializing RJP.MultiUrlPicker data: {0}", propertyData.Value.ToString()), ex); 35 | throw; 36 | } 37 | 38 | if (links == null) 39 | return; 40 | 41 | foreach (var link in links) 42 | { 43 | var isMedia = link["isMedia"] != null || link["udi"] != null && link["udi"].ToString().StartsWith("umb://media"); 44 | 45 | if (link["id"] != null || link["udi"] != null) 46 | { 47 | var objectTypeId = isMedia 48 | ? UmbracoNodeObjectTypeIds.Media 49 | : UmbracoNodeObjectTypeIds.Document; 50 | 51 | var itemProviderId = isMedia 52 | ? ItemProviderIds.mediaItemProviderGuid 53 | : ItemProviderIds.documentItemProviderGuid; 54 | 55 | var nodeGuid = Guid.Empty; 56 | if (link["udi"] != null) 57 | { 58 | var guidString = isMedia 59 | ? link["udi"].ToString().TrimStart("umb://media/") 60 | : link["udi"].ToString().TrimStart("umb://document/"); 61 | 62 | Guid.TryParse(guidString, out nodeGuid); 63 | } 64 | else if (link["id"] != null) 65 | { 66 | int linkIdTemp; 67 | if (int.TryParse(link["id"].ToString(), out linkIdTemp)) 68 | { 69 | nodeGuid = ExecutionContext.DatabasePersistence.GetUniqueId(linkIdTemp, objectTypeId); 70 | } 71 | } 72 | 73 | if (Guid.Empty.Equals(nodeGuid)) 74 | continue; 75 | 76 | var guid = nodeGuid.ToString(); 77 | 78 | item.Dependencies.Add(guid, itemProviderId); 79 | 80 | // only need to adjust this if it was an id converted to a guid. udis are already unique and match on both source and destination 81 | if (link["id"] != null) 82 | { 83 | link["id"] = guid; 84 | } 85 | } 86 | else if (isMedia && link["url"] != null) 87 | { 88 | try 89 | { 90 | var mediaId = ExecutionContext.DatabasePersistence.GetUniqueIdFromMediaFile(link["url"].ToString()); 91 | 92 | if (!Guid.Empty.Equals(mediaId)) 93 | item.Dependencies.Add(mediaId.ToString(), ItemProviderIds.mediaItemProviderGuid); 94 | } 95 | catch (Exception ex) 96 | { 97 | CourierLogHelper.Error(string.Format("Error setting media-item dependency, name={0}, url={1}", link["name"], link["url"]), ex); 98 | } 99 | } 100 | } 101 | 102 | propertyData.Value = links.ToString(); 103 | } 104 | 105 | public override void ExtractingProperty(Item item, ContentProperty propertyData) 106 | { 107 | if (propertyData.Value != null) 108 | { 109 | var links = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 110 | if (links != null) 111 | { 112 | foreach (var link in links) 113 | { 114 | var isMedia = link["isMedia"] != null || link["udi"] != null && link["udi"].ToString().StartsWith("umb://media"); 115 | 116 | if (link["id"] == null) 117 | continue; 118 | 119 | var nodeObjectType = isMedia 120 | ? UmbracoNodeObjectTypeIds.Media 121 | : UmbracoNodeObjectTypeIds.Document; 122 | 123 | Guid nodeGuid; 124 | if (Guid.TryParse(link["id"].ToString(), out nodeGuid)) 125 | link["id"] = ExecutionContext.DatabasePersistence.GetNodeId(nodeGuid, nodeObjectType); 126 | } 127 | 128 | propertyData.Value = links; 129 | } 130 | } 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/NestedContentPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Linq; 6 | using Umbraco.Core; 7 | using Umbraco.Courier.Core; 8 | using Umbraco.Courier.Core.Logging; 9 | using Umbraco.Courier.Core.ProviderModel; 10 | using Umbraco.Courier.DataResolvers; 11 | using Umbraco.Courier.ItemProviders; 12 | 13 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 14 | { 15 | /// 16 | /// Nested Content Property Data Resolver for Nested Content (package) by Matt Brailsford & Lee Kelleher. 17 | /// 18 | public class NestedContentPropertyDataResolver : PropertyDataResolverProvider 19 | { 20 | /// 21 | /// Alias of the editor this resolver should trigger on. 22 | /// 23 | public override string EditorAlias 24 | { 25 | get { return "Our.Umbraco.NestedContent"; } 26 | } 27 | 28 | /// 29 | /// This is triggered when the property is about to be packaged (Umbraco -> Courier). 30 | /// 31 | /// Item being packaged 32 | /// Nested Content property being packaged 33 | public override void PackagingProperty(Item item, ContentProperty propertyData) 34 | { 35 | ProcessPropertyData(item, propertyData, Action.Packaging); 36 | } 37 | 38 | /// 39 | /// This is triggered when the property is about to be extracted (Courier -> Umbraco). 40 | /// 41 | /// Item being extracted 42 | /// Nested Content property being extracted 43 | public override void ExtractingProperty(Item item, ContentProperty propertyData) 44 | { 45 | ProcessPropertyData(item, propertyData, Action.Extracting); 46 | } 47 | 48 | public override void PackagingDataType(DataType item) 49 | { 50 | AddDataTypeDependencies(item); 51 | } 52 | 53 | private void AddDataTypeDependencies(DataType item) 54 | { 55 | if (item == null || item.Prevalues == null || item.Prevalues.Count == 0) 56 | return; 57 | 58 | var json = item.Prevalues.FirstOrDefault(x => x.Alias.InvariantEquals("contentTypes")); 59 | if (json == null) 60 | return; 61 | 62 | var contentTypes = JsonConvert.DeserializeObject(json.Value); 63 | if (contentTypes == null) 64 | return; 65 | 66 | foreach (var contentType in contentTypes) 67 | { 68 | var alias = contentType["ncAlias"]; 69 | if (alias == null) 70 | continue; 71 | 72 | var documentType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(alias.ToString(), ItemProviderIds.documentTypeItemProviderGuid)); 73 | if (documentType == null) 74 | continue; 75 | 76 | item.Dependencies.Add(documentType.UniqueId.ToString(), ItemProviderIds.documentTypeItemProviderGuid); 77 | } 78 | } 79 | 80 | private DocumentType GetDocumentType(string docTypeAlias, IDictionary cache) 81 | { 82 | DocumentType documentType; 83 | //don't look it up if we already have done that 84 | if (cache.TryGetValue(docTypeAlias, out documentType) == false) 85 | { 86 | documentType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(docTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 87 | cache[docTypeAlias] = documentType; 88 | } 89 | return documentType; 90 | } 91 | 92 | private DataType GetDataType(string docTypeAlias, IDictionary cache) 93 | { 94 | DataType dataType; 95 | //don't look it up if we already have done that 96 | if (cache.TryGetValue(docTypeAlias, out dataType) == false) 97 | { 98 | dataType = ExecutionContext.DatabasePersistence.RetrieveItem(new ItemIdentifier(docTypeAlias, ItemProviderIds.documentTypeItemProviderGuid)); 99 | cache[docTypeAlias] = dataType; 100 | } 101 | return dataType; 102 | } 103 | 104 | /// 105 | /// Processes the property data. 106 | /// This method is used both for packaging and extracting property data. 107 | /// We want to deserialize the property data and then run it through the ResolutionManager for either packaging or extracting. 108 | /// This is done by creating a pseudo item immitating a property data item and having the ResolutionManager use its normal resolvers for resolving and finding dependencies. 109 | /// If we are packaging we also add any found dependencies and resources to the item which the property data belongs to. 110 | /// 111 | /// Item being handled 112 | /// Nested Content property being handled 113 | /// Indicates if we are packaging or extracting the item/property 114 | private void ProcessPropertyData(Item item, ContentProperty propertyData, Action action) 115 | { 116 | // add a dependency to the dataType if packaging 117 | if (action == Action.Packaging) 118 | item.Dependencies.Add(propertyData.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 119 | 120 | // deserialize the Nested Content value into an array of Nested Content items 121 | var nestedContentItems = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 122 | 123 | // get the ItemProvider for the ResolutionManager 124 | var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); 125 | 126 | // loop through all the Nested Content items 127 | if (nestedContentItems != null) 128 | { 129 | var resolvedDocTypes = new Dictionary(); 130 | var resolvedDataTypes = new Dictionary(); 131 | 132 | var items = new List>(); 133 | 134 | foreach (var nestedContentItem in nestedContentItems) 135 | { 136 | // get the document type for the item, if it can't be found, skip to the next item 137 | var documentTypeAlias = nestedContentItem["ncContentTypeAlias"]; 138 | if (documentTypeAlias == null) 139 | continue; 140 | 141 | var documentTypeAliasString = documentTypeAlias.ToString(); 142 | var documentType = GetDocumentType(documentTypeAliasString, resolvedDocTypes); 143 | if (documentType == null) 144 | continue; 145 | 146 | // get the properties available on the document type 147 | var properties = documentType.Properties; 148 | 149 | // add in properties from all composition document types, as these are not located on the document type itself 150 | foreach (var masterDocumentTypeAlias in documentType.MasterDocumentTypes) 151 | { 152 | var masterDocumentType = GetDocumentType(masterDocumentTypeAlias, resolvedDocTypes); 153 | if (masterDocumentType != null) 154 | properties.AddRange(masterDocumentType.Properties); 155 | } 156 | 157 | var propertyValues = nestedContentItem.ToObject>(); 158 | 159 | // run through all properties, creating pseudo items and sending them through the resolvers 160 | foreach (var property in properties) 161 | { 162 | object value = null; 163 | if (!propertyValues.TryGetValue(property.Alias, out value) || value == null) 164 | continue; 165 | 166 | var dataType = GetDataType(property.DataTypeDefinitionId.ToString(), resolvedDataTypes); 167 | 168 | var pseudoPropertyDataItem = new ContentPropertyData 169 | { 170 | ItemId = item.ItemId, 171 | Name = string.Format("{0} [{1}: Nested {2} ({3})]", item.Name, propertyData.PropertyEditorAlias, dataType.PropertyEditorAlias, property.Alias), 172 | Data = new List 173 | { 174 | new ContentProperty 175 | { 176 | Alias = property.Alias, 177 | DataType = dataType.UniqueID, 178 | PropertyEditorAlias = dataType.PropertyEditorAlias, 179 | Value = value 180 | } 181 | } 182 | }; 183 | if (action == Action.Packaging) 184 | { 185 | try 186 | { 187 | // run the resolvers (convert Ids/integers into UniqueIds/guids) 188 | ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider); 189 | } 190 | catch (Exception ex) 191 | { 192 | CourierLogHelper.Error(string.Concat("Error packaging data value: ", pseudoPropertyDataItem.Name), ex); 193 | } 194 | 195 | // add in dependencies when packaging 196 | item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); 197 | item.Resources.AddRange(pseudoPropertyDataItem.Resources); 198 | } 199 | else 200 | { 201 | try 202 | { 203 | // run the resolvers (convert UniqueIds/guids back to Ids/integers) 204 | ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider); 205 | } 206 | catch (Exception ex) 207 | { 208 | CourierLogHelper.Error(string.Concat("Error extracting data value: ", pseudoPropertyDataItem.Name), ex); 209 | } 210 | } 211 | 212 | if (pseudoPropertyDataItem.Data != null && pseudoPropertyDataItem.Data.Count > 0) 213 | { 214 | // get the first (and only) property of the pseudo item created above 215 | var firstProperty = pseudoPropertyDataItem.Data.Count > 0 ? pseudoPropertyDataItem.Data[0] : null; 216 | if (firstProperty != null) 217 | { 218 | // get the resolved value 219 | var resolvedValue = firstProperty.Value; 220 | 221 | if (action == Action.Extracting && resolvedValue is string && resolvedValue.ToString().DetectIsJson()) 222 | { 223 | // because the nested-content data must be a JSON object type, we'll want to deserialize any encoded strings 224 | propertyValues[property.Alias] = JsonConvert.DeserializeObject(resolvedValue.ToString()); 225 | } 226 | else 227 | { 228 | // replace the property value with the resolved value 229 | propertyValues[property.Alias] = resolvedValue; 230 | } 231 | 232 | // if packaging - add a dependency for the property's data-type 233 | if (action == Action.Packaging) 234 | item.Dependencies.Add(firstProperty.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid); 235 | } 236 | } 237 | } 238 | items.Add(propertyValues); 239 | } 240 | 241 | // serialize the whole nested-content property back to JSON and save the value on the property data 242 | propertyData.Value = JsonConvert.SerializeObject(items); 243 | } 244 | } 245 | } 246 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/StackedContentPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 2 | { 3 | /// 4 | /// Stacked Content Property Data Resolver for Stacked Content by Matt Brailsford & Lee Kelleher. 5 | /// 6 | public class StackedContentPropertyDataResolver : InnerContentPropertyDataResolver 7 | { 8 | /// 9 | /// Alias of the editor this resolver should trigger on. 10 | /// 11 | public override string EditorAlias 12 | { 13 | get 14 | { 15 | return "Our.Umbraco.StackedContent"; 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/UmbracoMultiUrlPickerPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 2 | { 3 | public class UmbracoMultiUrlPickerPropertyDataResolver : MultiUrlPickerPropertyDataResolver 4 | { 5 | /// 6 | /// Alias of the editor this resolver should trigger on. 7 | /// 8 | public override string EditorAlias 9 | { 10 | get { return "Umbraco.MultiUrlPicker"; } 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/UmbracoNestedContentPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 2 | { 3 | /// 4 | /// Nested Content Property Data Resolver for Nested Content (Umbraco 7.7+) by Matt Brailsford & Lee Kelleher. 5 | /// This resolver is reusing the NestedContentPropertyDataResolver. 6 | /// By overriding the EditorAlias, we can reuse it for Nested Content which is now included in Umbraco 7.7+. 7 | /// 8 | public class UmbracoNestedContentPropertyDataResolver : NestedContentPropertyDataResolver 9 | { 10 | /// 11 | /// Alias of the editor this resolver should trigger on. 12 | /// 13 | public override string EditorAlias 14 | { 15 | get { return "Umbraco.NestedContent"; } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/PropertyDataResolvers/VortoPropertyDataResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Linq; 6 | using Umbraco.Core; 7 | using Umbraco.Courier.Core; 8 | using Umbraco.Courier.Core.ProviderModel; 9 | using Umbraco.Courier.DataResolvers; 10 | using Umbraco.Courier.ItemProviders; 11 | 12 | namespace Umbraco.Courier.Contrib.Resolvers.PropertyDataResolvers 13 | { 14 | /// 15 | /// Vorto Property Data Resolver for Vorto by Matt Brailsford. 16 | /// 17 | public class VortoPropertyDataResolver : PropertyDataResolverProvider 18 | { 19 | /// 20 | /// Alias of the editor this resolver should trigger on. 21 | /// 22 | public override string EditorAlias 23 | { 24 | get { return "Our.Umbraco.Vorto"; } 25 | } 26 | 27 | /// 28 | /// This is triggered when the property is about to be packaged (Umbraco -> Courier). 29 | /// 30 | /// Item being packaged 31 | /// Vorto property being packaged 32 | public override void PackagingProperty(Item item, ContentProperty propertyData) 33 | { 34 | ProcessPropertyData(item, propertyData, Action.Packaging); 35 | base.PackagingProperty(item, propertyData); 36 | } 37 | 38 | /// 39 | /// This is triggered when the property is about to be extracted (Courier -> Umbraco). 40 | /// 41 | /// Item being extracted 42 | /// Vorto property being extracted 43 | public override void ExtractingProperty(Item item, ContentProperty propertyData) 44 | { 45 | ProcessPropertyData(item, propertyData, Action.Extracting); 46 | base.ExtractingProperty(item, propertyData); 47 | } 48 | 49 | /// 50 | /// Processes the property data. 51 | /// This method is used both for packaging and extracting property data. 52 | /// We want to deserialize the property data and then run it through the ResolutionManager for either packaging or extracting. 53 | /// This is done by creating a pseudo item immitating a property data item and having the ResolutionManager use its normal resolvers for resolving and finding dependencies. 54 | /// If we are packaging we also add any found dependencies and resources to the item which the property data belongs to. 55 | /// 56 | /// Item being handled 57 | /// Vorto property being handled 58 | /// Indicates if we are packaging or extracting the item/property 59 | private void ProcessPropertyData(Item item, ContentProperty propertyData, Action action) 60 | { 61 | var vortoProperty = JsonConvert.DeserializeObject(propertyData.Value.ToString()); 62 | 63 | if (vortoProperty.Values != null) 64 | { 65 | // deserialize all the vorto data and find the inner datatypes 66 | var dataTypeService = ApplicationContext.Current.Services.DataTypeService; 67 | var dataType = dataTypeService.GetDataTypeDefinitionById(propertyData.DataType); 68 | var vortoDataTypePrevalueJson = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary().FirstOrDefault(x => x.Key == "dataType").Value.Value; 69 | var vortoDataTypePrevalue = JsonConvert.DeserializeObject(vortoDataTypePrevalueJson); 70 | 71 | // get the ItemProvider for the ResolutionManager 72 | var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext); 73 | 74 | // create object to store resolved values 75 | var resolvedValues = new JObject(); 76 | 77 | // run through all nested values, creating pseudo items and sending them through the resolvers 78 | foreach (var set in vortoProperty.Values) 79 | { 80 | var language = set.Key; 81 | var value = set.Value.ToString(); 82 | 83 | var pseudoPropertyDataItem = new ContentPropertyData 84 | { 85 | ItemId = item.ItemId, 86 | Name = string.Format("{0}: (PropertyAlias: {1}, Language: {2})", item.Name, propertyData.Alias, language), 87 | Data = new List 88 | { 89 | new ContentProperty 90 | { 91 | Alias = propertyData.Alias, 92 | DataType = vortoDataTypePrevalue.Guid, 93 | PropertyEditorAlias = vortoDataTypePrevalue.PropertyEditorAlias, 94 | Value = value 95 | } 96 | } 97 | }; 98 | if (action == Action.Packaging) 99 | { 100 | // run the resolvers (convert Ids/integers into UniqueIds/guids) 101 | ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider); 102 | // add in dependencies when packaging 103 | item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies); 104 | item.Resources.AddRange(pseudoPropertyDataItem.Resources); 105 | } 106 | else 107 | { 108 | // run the resolvers (convert UniqueIds/guids back to Ids/integers) 109 | ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider); 110 | } 111 | // add the resolved values to be replaced 112 | resolvedValues.Add(new JProperty(language, pseudoPropertyDataItem.Data.FirstOrDefault().IfNotNull(x => x.Value))); 113 | } 114 | // replace the values on the property with the resolved values 115 | vortoProperty.Values = resolvedValues; 116 | // serialize the whole vorto property back to json and save the value on the property data 117 | propertyData.Value = JsonConvert.SerializeObject(vortoProperty); 118 | } 119 | } 120 | 121 | /// 122 | /// Used to deserialize a Vorto property 123 | /// 124 | internal class VortoPropertyData 125 | { 126 | [JsonProperty("values")] 127 | public JObject Values { get; set; } 128 | 129 | [JsonProperty("dtdGuid")] 130 | public Guid DtdGuid { get; set; } 131 | } 132 | 133 | /// 134 | /// Used to deserialize a Vorto DataType Prevalue 135 | /// 136 | internal class VortoDatatypePrevalue 137 | { 138 | [JsonProperty("guid")] 139 | public Guid Guid { get; set; } 140 | 141 | [JsonProperty("name")] 142 | public string Name { get; set; } 143 | 144 | [JsonProperty("propertyEditorAlias")] 145 | public string PropertyEditorAlias { get; set; } 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.Courier.Contrib.Resolvers 2 | { 3 | internal static class StringExtensions 4 | { 5 | //From: http://stackoverflow.com/a/21455488/5018 6 | public static string EscapeForJson(this string text) 7 | { 8 | var quoted = System.Web.Helpers.Json.Encode(text); 9 | return quoted.Substring(1, quoted.Length - 2); 10 | } 11 | 12 | //From: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/StringExtensions.cs#L123 13 | public static bool DetectIsJson(this string input) 14 | { 15 | input = input.Trim(); 16 | return (input.StartsWith("{") && input.EndsWith("}")) 17 | || (input.StartsWith("[") && input.EndsWith("]")); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/Umbraco.Courier.Contrib.Resolvers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A} 8 | Library 9 | Properties 10 | Umbraco.Courier.Contrib.Resolvers 11 | Umbraco.Courier.Contrib.Resolvers 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | AnyCPU 24 | 25 | 26 | pdbonly 27 | true 28 | bin\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\Courier.Core.2.52.15\lib\Antlr3.Runtime.dll 36 | False 37 | 38 | 39 | ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll 40 | False 41 | 42 | 43 | ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll 44 | False 45 | 46 | 47 | ..\packages\UmbracoCms.Core.7.1.8\lib\businesslogic.dll 48 | False 49 | 50 | 51 | ..\packages\Courier.Core.2.52.15\lib\Castle.Core.dll 52 | False 53 | 54 | 55 | ..\packages\ClientDependency.1.8.2.1\lib\net45\ClientDependency.Core.dll 56 | False 57 | 58 | 59 | ..\packages\ClientDependency-Mvc.1.7.0.4\lib\ClientDependency.Core.Mvc.dll 60 | False 61 | 62 | 63 | ..\packages\UmbracoCms.Core.7.1.8\lib\cms.dll 64 | False 65 | 66 | 67 | ..\packages\UmbracoCms.Core.7.1.8\lib\controls.dll 68 | False 69 | 70 | 71 | ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll 72 | False 73 | 74 | 75 | ..\packages\Examine.0.1.57.2941\lib\Examine.dll 76 | False 77 | 78 | 79 | ..\packages\Courier.Core.3.1.7\lib\FluentNHibernate.dll 80 | 81 | 82 | ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll 83 | False 84 | 85 | 86 | ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll 87 | False 88 | 89 | 90 | ..\packages\Courier.Core.3.1.7\lib\Iesi.Collections.dll 91 | 92 | 93 | ..\packages\ImageProcessor.1.9.5.0\lib\ImageProcessor.dll 94 | False 95 | 96 | 97 | ..\packages\ImageProcessor.Web.3.3.0.0\lib\net45\ImageProcessor.Web.dll 98 | False 99 | 100 | 101 | ..\packages\UmbracoCms.Core.7.1.8\lib\interfaces.dll 102 | False 103 | 104 | 105 | ..\packages\UmbracoCms.Core.7.1.8\lib\log4net.dll 106 | False 107 | 108 | 109 | ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll 110 | False 111 | 112 | 113 | ..\packages\UmbracoCms.Core.7.1.8\lib\Microsoft.ApplicationBlocks.Data.dll 114 | False 115 | 116 | 117 | ..\packages\UmbracoCms.Core.7.1.8\lib\Microsoft.Web.Helpers.dll 118 | False 119 | 120 | 121 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 122 | False 123 | 124 | 125 | ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll 126 | False 127 | 128 | 129 | ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll 130 | False 131 | 132 | 133 | ..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll 134 | False 135 | 136 | 137 | ..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll 138 | False 139 | 140 | 141 | ..\packages\Courier.Core.3.1.7\lib\NHibernate.dll 142 | 143 | 144 | ..\packages\Courier.Core.2.52.15\lib\NHibernate.ByteCode.Castle.dll 145 | False 146 | 147 | 148 | ..\packages\UmbracoCms.Core.7.1.8\lib\SQLCE4Umbraco.dll 149 | False 150 | 151 | 152 | 153 | 154 | ..\packages\UmbracoCms.Core.7.1.8\lib\System.Data.SqlServerCe.dll 155 | False 156 | 157 | 158 | ..\packages\UmbracoCms.Core.7.1.8\lib\System.Data.SqlServerCe.Entity.dll 159 | False 160 | 161 | 162 | ..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll 163 | False 164 | 165 | 166 | 167 | 168 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll 169 | False 170 | 171 | 172 | ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll 173 | False 174 | 175 | 176 | ..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll 177 | False 178 | 179 | 180 | ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll 181 | False 182 | 183 | 184 | ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll 185 | False 186 | 187 | 188 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll 189 | False 190 | 191 | 192 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll 193 | False 194 | 195 | 196 | ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll 197 | False 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | ..\packages\UmbracoCms.Core.7.1.8\lib\TidyNet.dll 207 | False 208 | 209 | 210 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.dll 211 | False 212 | 213 | 214 | ..\packages\UmbracoCms.Core.7.1.8\lib\Umbraco.Core.dll 215 | False 216 | 217 | 218 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.Core.dll 219 | 220 | 221 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.DataResolvers.dll 222 | 223 | 224 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.EventHandlers.V7.dll 225 | 226 | 227 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.Persistence.dll 228 | 229 | 230 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.Persistence.V7.NHibernate.dll 231 | 232 | 233 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.Providers.dll 234 | 235 | 236 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.RepositoryProviders.dll 237 | 238 | 239 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Courier.UI.dll 240 | 241 | 242 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.DataLayer.dll 243 | False 244 | 245 | 246 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.editorControls.dll 247 | False 248 | 249 | 250 | ..\packages\Courier.Core.3.1.7\lib\Umbraco.Licensing.dll 251 | 252 | 253 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.MacroEngines.dll 254 | False 255 | 256 | 257 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.providers.dll 258 | False 259 | 260 | 261 | ..\packages\UmbracoCms.Core.7.1.8\lib\Umbraco.Web.UI.dll 262 | False 263 | 264 | 265 | ..\packages\UmbracoCms.Core.7.1.8\lib\umbraco.XmlSerializers.dll 266 | False 267 | 268 | 269 | ..\packages\UmbracoCms.Core.7.1.8\lib\UmbracoExamine.dll 270 | False 271 | 272 | 273 | ..\packages\UmbracoCms.Core.7.1.8\lib\UrlRewritingNet.UrlRewriter.dll 274 | False 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 304 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.Resolvers/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Umbraco.Courier.Contrib.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Courier.Contrib.Resolvers", "Umbraco.Courier.Contrib.Resolvers\Umbraco.Courier.Contrib.Resolvers.csproj", "{D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F80CA68B-F43A-4AA4-94A1-D9E0DBB329DD}" 9 | ProjectSection(SolutionItems) = preProject 10 | ..\README.md = ..\README.md 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {D34CBD9A-A1DA-4532-9BF8-1D246B5BA49A}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | --------------------------------------------------------------------------------