Example #1
0
        /// <summary>
        /// 设置与MDataTable间的字段映射
        /// </summary>
        /// <param name="itemName">Rss名称</param>
        /// <param name="formatText">格式化,如“{0}.Name”,若无需要格式化,直接赋Null值</param>
        /// <param name="tableColumnNames">同DataTable的字段名称</param>
        public void SetMap(RssItemName itemName, string formatText, params object[] tableColumnNames)
        {
            RssItemMap map = new RssItemMap();

            map.RssItemName      = itemName.ToString();
            map.FormatText       = formatText;
            map.TableColumnNames = tableColumnNames;
            mapList.Add(map);
        }
Example #2
0
        private void BuildRss()
        {
            object propValue = null;

            XmlNode cNode = rssDoc.XmlDoc.DocumentElement.ChildNodes[0];

            CreateNode(cNode, channel);//Channel处理

            XmlNode iNode = null;

            if (img != null)
            {
                iNode = rssDoc.CreateNode("image", string.Empty);
                cNode.AppendChild(iNode);
                CreateNode(iNode, img);//Channel-Image处理
            }
            if (channel.Items.Count > 0)
            {
                foreach (RssItem item in channel.Items)
                {
                    iNode = rssDoc.CreateNode("item", string.Empty);
                    cNode.AppendChild(iNode);
                    CreateNode(iNode, item);//Channel-Items处理
                }
            }
            else if (_MTable != null && mapList.Count > 0)
            {
                foreach (MDataRow row in _MTable.Rows)
                {
                    iNode = rssDoc.CreateNode("item", string.Empty);
                    cNode.AppendChild(iNode);
                    //foreach (RssItemMap item in mapList)
                    RssItemMap item = null;
                    for (int k = 0; k < mapList.Count; k++)
                    {
                        item = mapList[k];
                        if (item.TableColumnNames.Length > 0)
                        {
                            MDictionary <string, string> dic = new MDictionary <string, string>(item.TableColumnNames.Length, StringComparer.OrdinalIgnoreCase);
                            object[] values = new object[item.TableColumnNames.Length];
                            for (int i = 0; i < item.TableColumnNames.Length; i++)
                            {
                                string columnName = item.TableColumnNames[i].ToString();
                                values[i] = row[columnName].Value;
                                dic.Set(columnName, Convert.ToString(values[i]));
                            }
                            if (OnForeach != null)
                            {
                                item.FormatText = OnForeach(item.FormatText, dic, k);
                            }
                            if (string.IsNullOrEmpty(item.FormatText))
                            {
                                propValue = values[0];
                            }
                            else
                            {
                                propValue = string.Format(item.FormatText, values);
                            }
                        }
                        //else if (item.TableColumnNames.Length > 0)
                        //{
                        //    propValue = row[item.TableColumnNames[0].ToString()].Value;
                        //    if (!string.IsNullOrEmpty(item.FormatText))
                        //    {
                        //        propValue = string.Format(item.FormatText, propValue);
                        //    }
                        //}
                        else
                        {
                            propValue = item.FormatText;
                        }
                        if (propValue == null || propValue == DBNull.Value)
                        {
                            continue;
                        }
                        if (item.RssItemName == "Description")
                        {
                            propValue = rssDoc.SetCDATA(propValue.ToString());
                        }
                        rssDoc.CreateNodeTo(iNode, item.RssItemName.Substring(0, 1).ToLower() + item.RssItemName.Substring(1), propValue.ToString());
                    }
                }
            }
        }
Example #3
0
File: Rss.cs Project: Angliy/Common
 public void SetMap(RssItemName itemName, string formatText, params object[] tableColumnNames)
 {
     RssItemMap map = new RssItemMap();
     map.RssItemName = itemName.ToString();
     map.FormatText = formatText;
     map.TableColumnNames = tableColumnNames;
     mapList.Add(map);
 }