/// <summary>
        /// Get node properties content from xml
        /// </summary>
        /// <param name="nodeXml"></param>
        /// <param name="selectedTemplateId"></param>
        /// <returns></returns>
        private HashSet<ContentProperty> GetNodeProperties(XElement nodeXml, HiveId selectedTemplateId)
        {
            var customProperties = new List<ContentProperty>();
            //var tabIds = _docTypes.SelectMany(tabs => tabs.DefinedTabs).Select(x => x.Id).ToList();

            //get the corresponding doc type for this node
            var docType = _docTypes.SingleOrDefault(x => x.Alias.ToLowerInvariant() == nodeXml.Name.LocalName.ToLowerInvariant());
            if (docType == null)
            {
                // doctype doesnt exist...but should we be checking this here?

            }

            //add node name property
            var nodeName = CreateNodeNameContentProperty(docType, nodeXml);
            customProperties.Add(nodeName);

            //add selected template (empty) property
            var selectedTemplate = CreateSelectedTemplateContentProperty(docType, selectedTemplateId);
            customProperties.Add(selectedTemplate);

            var propertiesXml = nodeXml.Elements().Where(e => e.Attribute("isDoc") == null);

            foreach (var e in propertiesXml)
            {
                //Assigning the doc type properties is completely arbitrary here, all I'm doing is
                //aligning a DocumentTypeProperty that contains the DataType that I want to render
                ContentProperty contentProperty;

                //get property by alias
                DocumentTypeProperty docTypeProperty = docType.Properties.SingleOrDefault(x => x.Alias == e.Name.LocalName);

                if (docTypeProperty == null)
                {
                    // content item is not in doctype schema
                    continue;
                }

                // if it's datatype alias is an upload, split the string and get the values
                if (docTypeProperty.DataType.Alias.ToLowerInvariant() == "uploader")
                {
                    var values = e.Value.Split(',');
                    contentProperty = new ContentProperty((HiveId)GetNodeProperty(e), docTypeProperty, new Dictionary<string, object> { { "MediaId", values[0] }, { "Value", values[1] } });
                }
                else
                {
                    contentProperty = new ContentProperty((HiveId)GetNodeProperty(e), docTypeProperty, e.Value);
                }

                //need to set the data type model for this property
                contentProperty.Alias = e.Name.LocalName;
                contentProperty.Name = e.Name.LocalName;

                //add to a random tab - wtf is this?
                //int currTab = 0;
                //contentProperty.TabId = tabIds[currTab];

                // get property tab?
                contentProperty.TabId = docTypeProperty.TabId;

                customProperties.Add(contentProperty);
            }

            return new HashSet<ContentProperty>(customProperties);
        }
        /// <summary>
        /// Create selected template content property.
        /// </summary>
        /// <param name="docType"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private ContentProperty CreateNodeNameContentProperty(DocumentTypeEditorModel docType, XElement nodeXml)
        {
            var prop = new ContentProperty((HiveId)Guid.NewGuid(),
                                                   docType.Properties.Single(x => x.Alias == NodeNameAttributeDefinition.AliasValue),
                                                   new Dictionary<string, object> { { "Name", (string)nodeXml.Attribute("nodeName") } })
            {
                Name = NodeNameAttributeDefinition.AliasValue,
                Alias = NodeNameAttributeDefinition.AliasValue,
                TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id

            };

            return prop;
        }
 /// <summary>
 /// Create selected template content property.
 /// </summary>
 /// <param name="docType"></param>
 /// <param name="selectedTemplateId"> </param>
 /// <returns></returns>
 private ContentProperty CreateSelectedTemplateContentProperty(DocumentTypeEditorModel docType, HiveId selectedTemplateId)
 {
     var prop = new ContentProperty((HiveId)Guid.NewGuid(),
                                                docType.Properties.Single(x => x.Alias == SelectedTemplateAttributeDefinition.AliasValue),
                                                selectedTemplateId.IsNullValueOrEmpty() ? new Dictionary<string, object>() : new Dictionary<string, object> { { "TemplateId", selectedTemplateId.ToString() } })
     {
         Name = SelectedTemplateAttributeDefinition.AliasValue,
         Alias = SelectedTemplateAttributeDefinition.AliasValue,
         TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id
     };
     return prop;
 }
Example #4
0
        private HashSet<ContentProperty> GetNodeProperties(int id, HiveId selectedTemplateId)
        {

            var customProperties = new List<ContentProperty>();
            var tabIds = _docTypes.SelectMany(tabs => tabs.DefinedTabs).Select(x => x.Id).ToList();
            var currTab = 0;

            var node = XmlData.Root.Descendants()
                .Where(x => (string)x.Attribute("id") == id.ToString())
                .Single();

            var docTypeArray = _docTypes.ToArray();
            //get the corresponding doc type for this node
            var docType = docTypeArray
                .Where(x => x.Id == HiveId.ConvertIntToGuid(int.Parse((string)node.Attribute("nodeType"))))
                .Single();

            //add node name
            var nodeName = new ContentProperty((HiveId)Guid.NewGuid(),
                                               docType.Properties.Where(x => x.Alias == NodeNameAttributeDefinition.AliasValue).Single(),
                                               new Dictionary<string, object> { { "Name", (string)node.Attribute("nodeName") } })
                {
                    Name = NodeNameAttributeDefinition.AliasValue,
                    Alias = NodeNameAttributeDefinition.AliasValue,
                    TabId = docType.DefinedTabs.Where(x => x.Alias == _generalGroup.Alias).Single().Id
                    
                };
            customProperties.Add(nodeName);

            //add selected template (empty)
            var selectedTemplate = new ContentProperty((HiveId)Guid.NewGuid(),
                                                       docType.Properties.Where(x => x.Alias == SelectedTemplateAttributeDefinition.AliasValue).Single(),
                                                       selectedTemplateId.IsNullValueOrEmpty() ? new Dictionary<string, object>() : new Dictionary<string, object> { { "TemplateId", selectedTemplateId.ToString() } })
                {
                    Name = SelectedTemplateAttributeDefinition.AliasValue,
                    Alias = SelectedTemplateAttributeDefinition.AliasValue,
                    TabId = docType.DefinedTabs.Where(x => x.Alias == _generalGroup.Alias).Single().Id
                };
            customProperties.Add(selectedTemplate);

            customProperties.AddRange(
                node.Elements()
                    .Where(e => e.Attribute("isDoc") == null)
                    .Select(e =>
                    {

                        //Assigning the doc type properties is completely arbitrary here, all I'm doing is 
                        //aligning a DocumentTypeProperty that contains the DataType that I want to render

                        ContentProperty np;
                        DocumentTypeProperty dp;
                        switch (e.Name.LocalName)
                        {
                            case "bodyText":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]);
                                dp = docType.Properties.Where(x => x.Alias == "bodyText").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "colorSwatchPicker":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[2]);
                                dp = docType.Properties.Where(x => x.Alias == "colorSwatchPicker").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "tags":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[3]);
                                dp = docType.Properties.Where(x => x.Alias == "tags").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "textBox":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[4]) { OverriddenPreValues = overridenPreVals };
                                dp = docType.Properties.Where(x => x.Alias == "textBox").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "publisher":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[4]) { OverriddenPreValues = overridenPreVals };
                                dp = docType.Properties.Where(x => x.Alias == "publisher").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "numberOfPages":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[4]) { OverriddenPreValues = overridenPreVals };
                                dp = docType.Properties.Where(x => x.Alias == "numberOfPages").Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                            case "image":
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[4]) { OverriddenPreValues = overridenPreVals };
                                dp = docType.Properties.Where(x => x.Alias == "image").Single();
                                var values = e.Value.Split(',');
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, new Dictionary<string, object> { { "MediaId", values[0] }, { "Value", values[1] } });
                                break;
                            default:
                                //dp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]);
                                dp = docType.Properties.Where(x => x.Alias == e.Name.LocalName).Single();
                                np = new ContentProperty((HiveId)GetNodeProperty(e), dp, e.Value);
                                break;
                        }

                        //need to set the data type model for this property

                        np.Alias = e.Name.LocalName;
                        np.Name = e.Name.LocalName;

                        //add to a random tab
                        currTab = 0; // currTab == 2 ? 0 : ++currTab;
                        np.TabId = tabIds[currTab];

                        return np;
                    }).ToList());

            return new HashSet<ContentProperty>(customProperties);
        }