Exemplo n.º 1
0
        private XElement GetLinkElement(DataRow row, Dictionary <string, int> equalCounts, string customMappedName, string customPluralMappedName, bool useDb)
        {
            var linkId          = int.Parse(row["LINK_ID"].ToString());
            var contentId       = int.Parse(row["L_CONTENT_ID"].ToString());
            var linkedContentId = int.Parse(row["R_CONTENT_ID"].ToString());
            var mappedName      = GetLinkedMappedName(contentId, linkedContentId);

            if (string.IsNullOrEmpty(mappedName))
            {
                return(null);
            }

            var count = RegisterHit(equalCounts, $"{contentId} {linkedContentId}");

            mappedName = mappedName + "Article";

            var pluralMappedName = mappedName + "s";

            if (count > 1)
            {
                mappedName       = $"{mappedName}_{count}";
                pluralMappedName = $"{pluralMappedName}_{count}";
            }

            if (useDb)
            {
                var dbMappedName       = DbConnector.GetValue(row, "NET_LINK_NAME", "");
                var dbPluralMappedName = DbConnector.GetValue(row, "NET_PLURAL_LINK_NAME", "");
                mappedName       = string.IsNullOrEmpty(dbMappedName) ? mappedName : dbMappedName;
                pluralMappedName = string.IsNullOrEmpty(dbPluralMappedName) ? pluralMappedName : dbPluralMappedName;
            }

            var linkElement =
                new XElement("link",
                             new XAttribute("id", linkId),
                             new XAttribute("self", contentId == linkedContentId ? "1" : "0"),
                             new XAttribute("content_id", contentId),
                             new XAttribute("linked_content_id", linkedContentId),
                             new XAttribute("mapped_name", !string.IsNullOrEmpty(customMappedName) ? customMappedName : mappedName),
                             new XAttribute("plural_mapped_name", !string.IsNullOrEmpty(customPluralMappedName) ? customPluralMappedName : pluralMappedName)
                             );

            return(linkElement);
        }
Exemplo n.º 2
0
        private XElement GetContentElement(DataRow row, bool useDb)
        {
            var id         = int.Parse(row["CONTENT_ID"].ToString());
            var name       = row["CONTENT_NAME"].ToString();
            var mappedName = GetMappedName(name, id, true);

            mappedName = mappedName + "Article";
            var pluralMappedName     = mappedName + "s";
            var dbMappedName         = DbConnector.GetValue(row, "NET_CONTENT_NAME", "");
            var dbPluralMappedName   = DbConnector.GetValue(row, "NET_PLURAL_CONTENT_NAME", "");
            var useDefaultFiltration = ((bool)row["use_default_filtration"]).ToString().ToLower();

            mappedName       = string.IsNullOrEmpty(dbMappedName) ? mappedName : dbMappedName;
            pluralMappedName = string.IsNullOrEmpty(dbPluralMappedName) ? pluralMappedName : dbPluralMappedName;

            var contentElement =
                new XElement("content",
                             new XAttribute("id", id),
                             new XAttribute("name", name),
                             new XAttribute("mapped_name", mappedName),
                             new XAttribute("plural_mapped_name", pluralMappedName),
                             new XAttribute("use_default_filtration", useDefaultFiltration)
                             );

            var relatedCounts = new Dictionary <string, int>();
            var dv            = new DataView(Controller.FieldsTable)
            {
                RowFilter = "content_id = " + id
            };

            if (useDb)
            {
                dv.RowFilter += " and map_as_property = 1";
            }

            dv.Sort = "attribute_order";
            foreach (DataRowView drv in dv)
            {
                contentElement.Add(GetFieldElement(pluralMappedName, relatedCounts, drv, useDb));
            }

            return(contentElement);
        }
Exemplo n.º 3
0
        private XElement GetFieldElement(string pluralMappedName, Dictionary <string, int> relatedCounts, DataRowView drv, bool useDb)
        {
            var fieldName       = drv["ATTRIBUTE_NAME"].ToString();
            var fieldId         = int.Parse(drv["ATTRIBUTE_ID"].ToString());
            var mappedFieldName = GetMappedName(fieldName, fieldId, false);

            if (useDb)
            {
                var dbMappedName = DbConnector.GetValue(drv.Row, "NET_ATTRIBUTE_NAME", "");
                mappedFieldName = string.IsNullOrEmpty(dbMappedName) ? mappedFieldName : dbMappedName;
            }

            var fieldElement = new XElement("attribute", new XAttribute("name", fieldName));

            if (!string.IsNullOrEmpty(mappedFieldName) && !string.Equals(mappedFieldName, fieldName))
            {
                fieldElement.Add(
                    new XAttribute("mapped_name", mappedFieldName)
                    );
            }

            var fieldType = GetFieldType(drv);

            if (fieldType == "O2M")
            {
                var relCount            = RegisterHit(relatedCounts, GetRelatedContentId(drv).ToString());
                var mappedBackFieldName = relCount > 1 ? $"{pluralMappedName}_{relCount}" : pluralMappedName;
                if (useDb)
                {
                    var dbBackMappedName = DbConnector.GetValue(drv.Row, "NET_BACK_ATTRIBUTE_NAME", "");
                    mappedBackFieldName = string.IsNullOrEmpty(dbBackMappedName) ? mappedBackFieldName : dbBackMappedName;
                }

                fieldElement.Add(new XAttribute("mapped_back_name", mappedBackFieldName));
            }

            return(fieldElement);
        }