Beispiel #1
0
        public string CsvFeedContent(DataFeedResult feed, string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = "default";
            }

            var dt = feed.Data[key];

            StringBuilder sb    = new StringBuilder();
            string        comma = string.Empty;

            foreach (string k in dt.Keys())
            {
                sb.AppendFormat("{0}\"{1}\"", comma, k.Replace("\"", "\"\""));
                comma = ",";
            }
            sb.Append(Environment.NewLine);
            foreach (var dr in dt)
            {
                comma = string.Empty;
                foreach (string k in dr.Keys())
                {
                    sb.AppendFormat("{0}\"{1}\"", comma, dr[k].Replace("\"", "\"\""));
                    comma = ",";
                }
                sb.Append(Environment.NewLine);
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public string IcalFeedContent(DataFeedResult feed, string key, string localAddr)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = "default";
            }

            var dt = feed.Data[key];

            StringBuilder sb        = new StringBuilder();
            string        serverIP  = localAddr;
            DateTime      buildTime = DateTime.UtcNow;

            sb.AppendLine("BEGIN:VCALENDAR");
            sb.AppendLine("METHOD:PUBLISH");
            sb.AppendLine($"PRODID:-//{serverIP}//NONSGML {GlobalSettings.Current.CompanyName}-ICAL 1.0//");
            sb.AppendLine("VERSION:2.0");
            sb.AppendLine("X-WR-CALNAME:" + feed.Name);
            sb.AppendLine($"X-WR-CALDESC:{GlobalSettings.Current.CompanyName} Online Services Data Feed");
            sb.AppendLine("X-WR-TIMEZONE:US-Eastern");
            int i = 0;

            foreach (var dr in dt)
            {
                /*
                 * BEGIN:VEVENT
                 * UID:[email protected]
                 * DTSTAMP:20120320T155310Z
                 * DESCRIPTION:http://www.aadl.org/catalog/record/1163159
                 * DTSTART;VALUE=DATE:20120329
                 * SUMMARY:DUE: Proof positive
                 * END:VEVENT
                 */
                sb.AppendLine("BEGIN:VEVENT");
                sb.AppendLine("UID:" + feed.Alias + "@" + serverIP);
                sb.AppendLine("DTSTAMP:" + buildTime.ToString("yyyyMMdd'T'HHmmss'Z'"));
                if (dt.Keys().Contains("DESCRIPTION"))
                {
                    sb.AppendLine("DESCRIPTION:" + dr["DESCRIPTION"].ToString());
                }
                if (dt.Keys().Contains("DTSTART"))
                {
                    sb.AppendLine("DTSTART:" + Convert.ToDateTime(dr["DTSTART"]).ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'"));
                }
                if (dt.Keys().Contains("DTSTART"))
                {
                    sb.AppendLine("DTEND:" + Convert.ToDateTime(dr["DTSTART"]).ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'"));
                }
                if (dt.Keys().Contains("SUMMARY"))
                {
                    sb.AppendLine("SUMMARY:" + dr["SUMMARY"].ToString());
                }
                sb.AppendLine("END:VEVENT");
                i++;
            }
            sb.Append("END:VCALENDAR");

            return(sb.ToString());
        }
Beispiel #3
0
        public static string FeedItemURL(DataFeedResult feed, string format, Uri requestUri, string absolutePath)
        {
            string result = requestUri.GetLeftPart(UriPartial.Authority) + absolutePath + "/feed/";

            result += feed.Alias + "/";
            result += (string.IsNullOrEmpty(format) ? "xml" : format);
            return(result);
        }
Beispiel #4
0
        public string HtmlFeedContent(DataFeedResult feed, string format = null)
        {
            bool fullPage = format != "table";

            //DataSet ds = ExecuteQuery(feed, parameters);
            //IList<DataTable> tables = GetTables(ds, key);

            StringBuilder sb = new StringBuilder();

            if (fullPage)
            {
                sb.AppendLine("<!DOCTYPE html>");
                sb.AppendLine("<html>");
                sb.AppendLine("<head>");
                sb.AppendLine($"<title>{GlobalSettings.Current.CompanyName} Feed</title>");
                sb.AppendLine("<style>");
                sb.AppendLine(".lnf-feed-container {margin: 10px;}");
                sb.AppendLine(".grid.lnf-feed {margin-bottom: 10px;}");
                sb.AppendLine("</style>");
                sb.AppendLine("</head>");
                sb.AppendLine("<body>");
            }
            sb.AppendLine("<div class=\"lnf-feed-container app\">");
            foreach (var dt in feed.Data)
            {
                sb.AppendLine("<table class=\"lnf-feed grid table\">");
                sb.AppendLine("<thead>");
                sb.AppendLine("<tr>");
                foreach (string k in dt.Value.Keys())
                {
                    sb.AppendLine($"<th>{k}</th>");
                }
                sb.AppendLine("</tr>");
                sb.AppendLine("</thead>");
                sb.AppendLine("<tbody>");
                foreach (var dr in dt.Value)
                {
                    sb.AppendLine("<tr>");
                    foreach (string k in dr.Keys())
                    {
                        sb.AppendLine($"<td>{dr[k]}</td>");
                    }
                    sb.AppendLine("</tr>");
                }
                sb.AppendLine("</tbody>");
                sb.AppendLine("</table>");
            }
            sb.AppendLine("</div>");
            if (fullPage)
            {
                sb.AppendLine("</body>");
                sb.AppendLine("</html>");
            }

            return(sb.ToString());
        }
Beispiel #5
0
        public string JsonFeedContent(DataFeedResult feed, string key, string format = null)
        {
            object obj;

            Hashtable data = new Hashtable();

            foreach (var dt in feed.Data)
            {
                ArrayList table = new ArrayList();
                foreach (var dr in dt.Value)
                {
                    Hashtable hash = new Hashtable();
                    foreach (string k in dr.Keys())
                    {
                        hash.Add(k, dr[k]);
                    }
                    table.Add(hash);
                }

                data.Add(dt.Key, table);
            }

            if (format == "datatables")
            {
                if (string.IsNullOrEmpty(key))
                {
                    obj = new { aaData = data["default"] }
                }
                ;
                else
                {
                    obj = new { aaData = data[key] }
                };
            }
            else
            {
                obj = new
                {
                    feed.ID,
                    feed.GUID,
                    feed.Name,
                    feed.Private,
                    feed.Active,
                    Data = data
                };
            }

            string result = ServiceProvider.Current.Utility.Serialization.Json.Serialize(obj);

            return(result);
        }
Beispiel #6
0
        public string XmlFeedContent(DataFeedResult feed)
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<?xml version=\"1.0\"?><data></data>");
            XmlNode data = xdoc.SelectSingleNode("/data");

            XmlAttribute attr;

            attr       = xdoc.CreateAttribute("name");
            attr.Value = feed.Name;
            data.Attributes.Append(attr);

            if (feed.Data.Count > 0)
            {
                foreach (var kvp in feed.Data)
                {
                    XmlNode table = xdoc.CreateElement("table");
                    attr       = xdoc.CreateAttribute("name");
                    attr.Value = kvp.Key;
                    table.Attributes.Append(attr);

                    foreach (var item in kvp.Value)
                    {
                        XmlNode row = xdoc.CreateElement("row");

                        foreach (var k in item.Keys())
                        {
                            XmlNode child = xdoc.CreateElement(k.Replace("/", "_"));
                            child.InnerText = item[k].ToString();
                            row.AppendChild(child);
                        }

                        table.AppendChild(row);
                    }

                    data.AppendChild(table);
                }
            }

            StringWriter  sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            xdoc.WriteTo(xw);

            return(sw.GetStringBuilder().ToString());
        }
Beispiel #7
0
        public string RssFeedContent(DataFeedResult feed, string key, Uri requestUri, string absolutePath)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = "default";
            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\"><channel></channel></rss>");
            XmlNode channel = xdoc.SelectSingleNode("/rss/channel");

            XmlNode child;

            child           = xdoc.CreateElement("title");
            child.InnerText = feed.Name;
            channel.AppendChild(child);

            child = xdoc.CreateElement("description");
            if (string.IsNullOrEmpty(feed.Description))
            {
                child.InnerText = $"{GlobalSettings.Current.CompanyName} On-Line Services Data Feed";
            }
            else
            {
                child.InnerText = feed.Description;
            }
            channel.AppendChild(child);

            child           = xdoc.CreateElement("link");
            child.InnerText = requestUri.GetLeftPart(UriPartial.Authority);
            channel.AppendChild(child);

            child           = xdoc.CreateElement("lastBuildDate");
            child.InnerText = DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH':'mm':'ss '+0000'");
            channel.AppendChild(child);

            child           = xdoc.CreateElement("pubDate");
            child.InnerText = DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH':'mm':'ss '+0000'");
            channel.AppendChild(child);

            var dt = feed.Data[key];

            int i = 0;

            foreach (var dr in dt)
            {
                XmlNode item = xdoc.CreateElement("item");

                child = xdoc.CreateElement("title");
                if (dr.Keys().Contains("Title"))
                {
                    child.InnerText = dr["Title"].ToString();
                }
                else
                {
                    child.InnerText = "Missing \"Title\" field.";
                }
                item.AppendChild(child);

                child = xdoc.CreateElement("description");
                if (dr.Keys().Contains("Description"))
                {
                    child.InnerText = dr["Description"].ToString();
                }
                else
                {
                    child.InnerText = "Missing \"Description\" field.";
                }
                item.AppendChild(child);

                child = xdoc.CreateElement("link");
                if (dr.Keys().Contains("Link"))
                {
                    child.InnerText = dr["Link"].ToString();
                }
                else
                {
                    child.InnerText = "Missing \"Link\" field.";
                }
                item.AppendChild(child);

                child           = xdoc.CreateElement("guid");
                child.InnerText = DataFeedUtility.FeedItemURL(feed, "rss", requestUri, absolutePath) + "&i=" + i.ToString();
                item.AppendChild(child);

                child = xdoc.CreateElement("pubDate");
                if (dr.Keys().Contains("PubDate"))
                {
                    child.InnerText = Convert.ToDateTime(dr["PubDate"]).ToString("ddd, dd MMM yyyy HH':'mm':'ss '+0000'");
                }
                else
                {
                    child.InnerText = DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH':'mm':'ss '+0000'");
                }
                item.AppendChild(child);

                channel.AppendChild(item);

                i++;
            }

            StringWriter  sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            xdoc.WriteTo(xw);

            return(sw.GetStringBuilder().ToString());
        }