Ejemplo n.º 1
0
        private void ProcessCell(Item item, ContentProperty propertyData, GridValueControlModel cell, Action action)
        {
            // cancel if there's no values
            if (cell.Value == null || cell.Value.HasValues == false)
            {
                return;
            }

            var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
            // get the ItemProvider for the ResolutionManager
            var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext);

            // Often there is only one entry in cell.Value, but with LeBlender
            // min/max you can easily get 2+ entries so we'll walk them all
            var newItemValue = new JArray();

            foreach (var properties in cell.Value)
            {
                // create object to store resolved properties
                var resolvedProperties = new JObject();

                // loop through each of the property objects
                foreach (dynamic leBlenderPropertyWrapper in properties)
                {
                    // deserialize the value of the wrapper object into a LeBlenderProperty object
                    var leBlenderPropertyJson = leBlenderPropertyWrapper.Value.ToString() as string;
                    // continue if there's no data stored
                    if (string.IsNullOrEmpty(leBlenderPropertyJson))
                    {
                        continue;
                    }

                    var leBlenderProperty = JsonConvert.DeserializeObject <LeBlenderProperty>(leBlenderPropertyJson);

                    // get the DataType of the property
                    var dataType = dataTypeService.GetDataTypeDefinitionById(leBlenderProperty.DataTypeGuid);
                    if (dataType == null)
                    {
                        // If the data type referenced by this LeBlender Property is missing on this machine
                        // we'll get a very cryptic error when it attempts to create the pseudo property data item below.
                        // Throw a meaningful error message instead
                        throw new ArgumentNullException(string.Format("Unable to find the data type for editor '{0}' ({1} {2}) referenced by '{3}'.", leBlenderProperty.EditorName, leBlenderProperty.EditorAlias,
                                                                      leBlenderProperty.DataTypeGuid, item.Name));
                        // Should we log a warning and continue instead?
                    }

                    // create a pseudo item for sending through resolvers
                    var pseudoPropertyDataItem = new ContentPropertyData
                    {
                        ItemId = item.ItemId,
                        Name   = string.Format("{0}: (LeBlender PropertyAlias: {1}, DataTypeEditorAlias: {2})", item.Name, leBlenderProperty.EditorAlias, dataType.PropertyEditorAlias),
                        Data   = new List <ContentProperty>
                        {
                            new ContentProperty
                            {
                                Alias               = propertyData.Alias,
                                DataType            = leBlenderProperty.DataTypeGuid,
                                PropertyEditorAlias = dataType.PropertyEditorAlias,
                                Value               = leBlenderProperty.Value
                            }
                        }
                    };
                    if (action == Action.Packaging)
                    {
                        // run the resolvers (convert Ids/integers into UniqueIds/guids)
                        ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                        // add in this editor's dependencies when packaging
                        item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies);
                        item.Resources.AddRange(pseudoPropertyDataItem.Resources);
                        // and include this editor's data type as a dependency too
                        item.Dependencies.Add(leBlenderProperty.DataTypeGuid.ToString(), ItemProviderIds.dataTypeItemProviderGuid);
                    }
                    else
                    {
                        // run the resolvers (convert UniqueIds/guids back to Ids/integers)
                        ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                    }
                    // replace the property value with the resolved value
                    leBlenderProperty.Value = pseudoPropertyDataItem.Data.First().Value;
                    // add the resolved property to the resolved properties object
                    resolvedProperties.Add(leBlenderProperty.EditorAlias, JObject.FromObject(leBlenderProperty));
                }
                newItemValue.Add(resolvedProperties);
            }
            // replace the cell value with all the resolved values
            cell.Value = JToken.FromObject(newItemValue);
        }
Ejemplo n.º 2
0
 public override void ExtractingCell(Item item, ContentProperty propertyData, GridValueControlModel cell)
 {
     ProcessCell(item, propertyData, cell, Action.Extracting);
     base.ExtractingCell(item, propertyData, cell);
 }
Ejemplo n.º 3
0
 public override bool ShouldRun(string view, GridValueControlModel cell)
 {
     return(view.Contains("leblender"));
 }
Ejemplo n.º 4
0
        private void ProcessCell(Item item, ContentProperty propertyData, GridValueControlModel cell, Action direction)
        {
            var documentTypeAlias = cell.Value["dtgeContentTypeAlias"].ToString();

            if (string.IsNullOrWhiteSpace(documentTypeAlias))
            {
                return;
            }
            var documentType = ExecutionContext.DatabasePersistence.RetrieveItem <DocumentType>(new ItemIdentifier(documentTypeAlias, ItemProviderIds.documentTypeItemProviderGuid));

            var cellValueJson = cell.Value["value"].ToString();

            if (string.IsNullOrWhiteSpace(cellValueJson))
            {
                return;
            }

            var cellValue = JsonConvert.DeserializeObject(cellValueJson);

            if (!(cellValue is JObject))
            {
                return;
            }

            var propertyValues = ((JObject)cellValue).ToObject <Dictionary <string, object> >();

            if (direction == Action.Packaging)
            {
                item.Dependencies.Add(documentType.UniqueId.ToString(), ItemProviderIds.documentTypeItemProviderGuid);
            }

            // get the ItemProvider for the ResolutionManager
            var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext);

            var properties = documentType.Properties;

            // check for compositions
            foreach (var masterDocumentTypeAlias in documentType.MasterDocumentTypes)
            {
                var masterDocumentType = ExecutionContext.DatabasePersistence.RetrieveItem <DocumentType>(new ItemIdentifier(masterDocumentTypeAlias, ItemProviderIds.documentTypeItemProviderGuid));
                if (masterDocumentType != null)
                {
                    properties.AddRange(masterDocumentType.Properties);
                }
            }

            foreach (var property in properties)
            {
                object value = null;
                if (!propertyValues.TryGetValue(property.Alias, out value) || value == null)
                {
                    continue;
                }

                var datatype = ExecutionContext.DatabasePersistence.RetrieveItem <DataType>(new ItemIdentifier(property.DataTypeDefinitionId.ToString(), ItemProviderIds.dataTypeItemProviderGuid));

                // create a pseudo item for sending through resolvers
                var pseudoPropertyDataItem = new ContentPropertyData
                {
                    ItemId = item.ItemId,
                    Name   = string.Format("{0} [{1}: Nested {2} ({3})]", item.Name, EditorAlias, datatype.PropertyEditorAlias, property.Alias),
                    Data   = new List <ContentProperty>
                    {
                        new ContentProperty
                        {
                            Alias               = property.Alias,
                            DataType            = datatype.UniqueID,
                            PropertyEditorAlias = datatype.PropertyEditorAlias,
                            Value               = value
                        }
                    }
                };

                if (direction == Action.Packaging)
                {
                    try
                    {
                        // run the resolvers (convert Ids/integers into UniqueIds/guids)
                        ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                    }
                    catch (Exception ex)
                    {
                        CourierLogHelper.Error <DocTypeGridEditorGridCellResolver>(string.Concat("Error packaging data value: ", pseudoPropertyDataItem.Name), ex);
                    }
                    // add in dependencies when packaging
                    item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies);
                    item.Resources.AddRange(pseudoPropertyDataItem.Resources);
                }
                else if (direction == Action.Extracting)
                {
                    try
                    {
                        // run the resolvers (convert UniqueIds/guids back to Ids/integers)
                        ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                    }
                    catch (Exception ex)
                    {
                        CourierLogHelper.Error <DocTypeGridEditorGridCellResolver>(
                            string.Concat("Error extracting data value: ", pseudoPropertyDataItem.Name), ex);
                    }
                }

                if (pseudoPropertyDataItem.Data != null && pseudoPropertyDataItem.Data.Any())
                {
                    // get the first (and only) property of the pseudo item created above
                    var firstProperty = pseudoPropertyDataItem.Data.FirstOrDefault();
                    if (firstProperty != null)
                    {
                        // replace the property value with the resolved value
                        propertyValues[property.Alias] = firstProperty.Value;

                        // (if packaging) add a dependency for the property's data-type
                        if (direction == Action.Packaging)
                        {
                            item.Dependencies.Add(firstProperty.DataType.ToString(), ItemProviderIds.dataTypeItemProviderGuid);
                        }
                    }
                }
            }

            // build up json as a string first, as directly converting
            // propValues to a JToken causes json objects to be converted into a string
            // (such as nested content inside a doctypegrid)
            var jsonString = new StringBuilder("{");

            foreach (var val in propertyValues)
            {
                jsonString.Append("\"");
                jsonString.Append(val.Key);
                jsonString.Append("\":");

                // check if it's a json object and not just a string
                if (val.Value.ToString().Trim().StartsWith("["))
                {
                    jsonString.Append(val.Value);
                }
                else
                {
                    jsonString.Append("\"");
                    jsonString.Append(val.Value);
                    jsonString.Append("\"");
                }

                jsonString.Append(",");
            }
            if (jsonString.Length > 1)
            {
                jsonString.Remove(jsonString.Length - 1, 1);
            }
            jsonString.Append("}");

            var tempCellValue = JToken.Parse(jsonString.ToString());

            cell.Value["value"] = tempCellValue;
        }
Ejemplo n.º 5
0
 public override void PackagingCell(Item item, ContentProperty propertyData, GridValueControlModel cell)
 {
     ProcessCell(item, propertyData, cell, Action.Packaging);
 }
        private void ProcessCell(Item item, ContentProperty propertyData, GridValueControlModel cell, Action action)
        {
            var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
            // get the ItemProvider for the ResolutionManager
            var propertyDataItemProvider = ItemProviderCollection.Instance.GetProvider(ItemProviderIds.propertyDataItemProviderGuid, ExecutionContext);

            // create object to store resolved properties
            var resolvedProperties = new JObject();

            // cancel if there's no values
            if (cell.Value == null || cell.Value.HasValues == false)
            {
                return;
            }

            // actual data seems to be nested inside an object...
            var properties = cell.Value.First;

            // loop through each of the property objects
            foreach (dynamic leBlenderPropertyWrapper in properties)
            {
                // deserialize the value of the wrapper object into a LeBlenderProperty object
                var leBlenderPropertyJson = leBlenderPropertyWrapper.Value.ToString() as string;
                var leBlenderProperty     = JsonConvert.DeserializeObject <LeBlenderProperty>(leBlenderPropertyJson);

                // get the DataType of the property
                var dataType = dataTypeService.GetDataTypeDefinitionById(leBlenderProperty.DataTypeGuid);

                // create a pseudo item for sending through resolvers
                var pseudoPropertyDataItem = new ContentPropertyData
                {
                    ItemId = item.ItemId,
                    Name   = string.Format("{0}: (LeBlender PropertyAlias: {1}, DataTypeEditorAlias: {2})", item.Name, leBlenderProperty.EditorAlias, dataType.PropertyEditorAlias),
                    Data   = new List <ContentProperty>
                    {
                        new ContentProperty
                        {
                            Alias               = propertyData.Alias,
                            DataType            = leBlenderProperty.DataTypeGuid,
                            PropertyEditorAlias = dataType.PropertyEditorAlias,
                            Value               = leBlenderProperty.Value
                        }
                    }
                };
                if (action == Action.Packaging)
                {
                    // run the resolvers (convert Ids/integers into UniqueIds/guids)
                    ResolutionManager.Instance.PackagingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                    // add in dependencies when packaging
                    item.Dependencies.AddRange(pseudoPropertyDataItem.Dependencies);
                    item.Resources.AddRange(pseudoPropertyDataItem.Resources);
                }
                else
                {
                    // run the resolvers (convert UniqueIds/guids back to Ids/integers)
                    ResolutionManager.Instance.ExtractingItem(pseudoPropertyDataItem, propertyDataItemProvider);
                }
                // replace the property value with the resolved value
                leBlenderProperty.Value = pseudoPropertyDataItem.Data.First().Value.ToString();
                // add the resolved property to the resolved properties object
                resolvedProperties.Add(leBlenderProperty.EditorAlias, JObject.FromObject(leBlenderProperty));
            }
            // replace the cell value with all the resolved values - wrap in a JToken+JArray to get it stored like LeBlender does
            cell.Value = JToken.FromObject(new JArray(resolvedProperties));
        }