Exemplo n.º 1
0
        public static void Serialize(rss snbFeedRss, string filename)
        {
            XmlSerializer serializer   = new XmlSerializer(typeof(rss));
            StreamWriter  streamWriter = new StreamWriter(filename);

            serializer.Serialize(streamWriter, snbFeedRss);
        }
Exemplo n.º 2
0
        public List <FeedDto> GetFeeds()
        {
            try {
                XDocument document = XDocument.Load(_appSettings.UriXmlMinutoSeguros);
                rss       Rss      = SerializationUtil.Deserialize <rss>(document);

                var feeds = new List <FeedDto>();

                foreach (var item in Rss.channel.item)
                {
                    feeds.Add(new FeedDto()
                    {
                        Title       = item.title,
                        Description = item.description,
                        Categories  = item.category
                    });
                }

                return(feeds);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static TestCase ConvertDto2TestCase(rss dto)
        {
            var testCase = new TestCase();

            testCase.IdAndTitle    = GetIdAndTitle(dto);
            testCase.Setups        = GetSetups(dto, testCase);
            testCase.Verifications = GetVerifications(dto, testCase);
            return(testCase);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            SmartMirrorClient client = new SmartMirrorClient();
            rss element = client.getTechNews();
            // Usuario user = client.getUsuario("1");
            WeatherInfo forecast = client.getWeatherByWOEID(133475);

            rssChannelItem[] items = element.channel.item;
            Console.WriteLine(items[0].description);
            Console.ReadKey();
        }
Exemplo n.º 5
0
        private async void cargarNoticias()
        {
            resultNews = await cliente.getTechNewsAsync();

            noticias    = resultNews.channel.item;
            tBNew1.Text = noticias[0].title;
            tBNew2.Text = noticias[1].title;
            tBNew3.Text = noticias[2].title;
            tBNew4.Text = noticias[3].title;
            tBNew5.Text = noticias[4].title;
        }
Exemplo n.º 6
0
        protected override int Process(IEnumerable <IBaseEntity> datas, dynamic sender = null)
        {
            if (datas == null || datas.Count() == 0)
            {
                return(0);
            }

            var tableInfo = new TableInfo(datas.First().GetType());

            StreamWriter writer;
            //var identity = GetIdentity(sender);
            var dataFolder = Path.Combine(Env.BaseDirectory, "rss", DateTime.Now.ToString("yyyyMMddHHmmss"));
            var jsonFile   = Path.Combine(dataFolder, $"{tableInfo.Schema.FullName}.xml");

            if (_writers.ContainsKey(jsonFile))
            {
                writer = _writers[jsonFile];
            }
            else
            {
                if (!Directory.Exists(dataFolder))
                {
                    Directory.CreateDirectory(dataFolder);
                }
                writer = new StreamWriter(File.OpenWrite(jsonFile), Encoding.UTF8);
                _writers.Add(jsonFile, writer);
            }
            rss feed = new rss();

            feed.channel.title         = Title;
            feed.channel.link          = Link;
            feed.channel.description   = Description;
            feed.channel.lastBuildDate = DateTime.Now.ToString();

            var lists = NewMethod(datas);

            foreach (var itemr in lists)
            {
                Extension.Model.item model = new Extension.Model.item();
                model.title       = itemr["title"];
                model.description = itemr["description"];
                model.guid        = itemr["guid"];
                model.link        = itemr["link"];

                feed.channel.item.Add(model);
            }
            var serializer = new XmlSerializer(typeof(rss));

            serializer.Serialize(writer, feed);


            return(datas.Count());
        }
Exemplo n.º 7
0
        //
        // GET: /Xml2Model/

        public ActionResult Index()
        {
            rss cars = null;
            //  System.Net.WebClient client = new WebClient();
            //  byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            // string path = System.Text.Encoding.UTF8.GetString(page);
            //string path = "cars.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(rss));

            //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心
            // request.CookieContainer = new CookieContainer();
            // request.AllowAutoRedirect = false;
            //  WebResponse response = (WebResponse)request.GetResponse();
            //  Stream sm = response.GetResponseStream();
            //  System.IO.StreamReader streamReader = new System.IO.StreamReader(sm);
            //将流转换为字符串
            // string html = streamReader.ReadToEnd();
            // streamReader.Close();

            //  TextReader reader = new StreamReader(path);

            XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");

            cars = (rss)serializer.Deserialize(reader);

            /*var serializer = new XmlSerializer(typeof(rss));
             * using (TextReader reader = new StringReader(html))
             * {
             *    cars = (rss)serializer.Deserialize(reader);
             * }*/


            //  reader.Close();


            db.sources.Add(new Models.source("NYTimes", DateTime ???));

            for (var i = 0; i < cars.item.Length; i++)
            {
                string   httpTime = cars.item[i].pubDate;
                DateTime time     = DateTime.Parse(httpTime);


                Models.item item = new Models.item(cars.item[i], time, "NYTimes");

                db.channel.Add(item);               //item include 4 elements
                //db.channel.Add(cars.item[i]);
            }
            db.SaveChanges();
            return(View(db.channel.ToList()));
        }
Exemplo n.º 8
0
        public List <WarframeItemDTO> ReadXMLAlerts()
        {
            List <WarframeItemDTO> MyAlertItems = new List <WarframeItemDTO>();

            WebRequest      request    = WebRequest.Create("http://content.warframe.com/dynamic/rss.php");
            HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
            Stream          dataStream = response.GetResponseStream();
            //StreamReader reader = new StreamReader(dataStream);


            XmlSerializer serializer   = new XmlSerializer(typeof(rss));
            rss           WarframeData = (rss)serializer.Deserialize(new XmlTextReader(dataStream));

            if (response.StatusCode.ToString().Equals("OK"))
            {
                foreach (rssChannelItem AlertItem in WarframeData.channel.item)
                {
                    if (AlertItem.Items.Length == 7)
                    {
                        WarframeAlertItemDTO temp = new WarframeAlertItemDTO
                                                    (
                            AlertItem.Items[0],
                            AlertItem.Items[1],
                            AlertItem.Items[2],
                            AlertItem.Items[3],
                            AlertItem.Items[4],
                            AlertItem.Items[5],
                            AlertItem.Items[6],
                            "Expiry"
                                                    );
                        MyAlertItems.Add(temp);
                    }

                    if (AlertItem.Items.Length == 4)
                    {
                        WarframeNonAlertItemDTO temp = new WarframeNonAlertItemDTO
                                                       (
                            AlertItem.Items[0],
                            AlertItem.Items[1],
                            AlertItem.Items[2],
                            AlertItem.Items[3]
                                                       );
                        MyAlertItems.Add(temp);
                    }
                }
            }
            else
            {
                MyAlertItems.Clear();
            }

            return(MyAlertItems);
        }
Exemplo n.º 9
0
        private static string GetIdAndTitle(rss dto)
        {
            string result = dto
                            ?.channel
                            ?.item
                            ?.title;

            if (result == null)
            {
                throw new InvalidDataException("Can't extract ID and Title");
            }
            result = result.Replace("[", "");
            return(result.Replace("] ", "-"));
        }
Exemplo n.º 10
0
        public EpisodeViewModel(IDirectoryProvider directoryProvider, rss rss, Episode episode)
        {
            if (directoryProvider == null)
            {
                throw new ArgumentNullException("directoryProvider");
            }

            _directoryProvider = directoryProvider;

            Rss      = rss;
            _episode = episode;
            State    = File.Exists(FilePath) ? EpisodeState.Downloaded : EpisodeState.NotDownloaded;

            //todo delegateCommand version that doesn't pass arg?
            DownloadCommand = new DelegateCommand(Download);
            PlayCommand     = new DelegateCommand(Play);
        }
Exemplo n.º 11
0
        protected override int Process(IEnumerable <IBaseEntity> datas, dynamic sender)
        {
            ResponseMessage = new System.Xml.Linq.XDocument();
            XDocument doc = null;;

            if (datas == null || datas.Count() == 0)
            {
                return(0);
            }
            //doc = (XDocument)CacheScheduler.GetCache(Link);
            if (doc == null)
            {
                doc = new XDocument();
                rss feed = new rss();
                feed.channel.title         = Title;
                feed.channel.link          = Link;
                feed.channel.description   = Description;
                feed.channel.lastBuildDate = DateTime.Now.ToString();


                var lists = GetListDic(datas);
                foreach (var itemr in lists)
                {
                    item model = new item();
                    model.title       = itemr["title"];
                    model.description = itemr["description"];
                    model.guid        = itemr["guid"];
                    model.link        = itemr["link"];

                    feed.channel.item.Add(model);
                }


                using (var writer = doc.CreateWriter())
                {
                    // write xml into the writer
                    var serializer = new DataContractSerializer(feed.GetType());
                    serializer.WriteObject(writer, feed);
                }                 /**/
                                  //CacheScheduler.AddCache(Link, doc);
            }
            ResponseMessage = doc;

            return(datas.Count());
        }
Exemplo n.º 12
0
 public bool GetFeed()
 {
     try
     {
         WebClient webClient = new WebClient();
         webClient.Headers.Add("user-agent", "MyRSSReader/1.0");
         using (XmlReader reader = XmlReader.Create(webClient.OpenRead(rssChannelUrl)))
         {
             var serializer = new XmlSerializer(typeof(Models.rss));
             rss = new rss();
             rss = (rss)serializer.Deserialize(reader);
         }
         return(true);
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
         return(false);
     }
 }
Exemplo n.º 13
0
        private static List <Verification> GetVerifications(rss dto, TestCase testCase)
        {
            var result = new List <Verification>();

            var customfields = dto
                               ?.channel
                               ?.item
                               ?.customfields;

            if (customfields == null)
            {
                return(result);
            }

            rssChannelItemCustomfield customfield;

            try
            {
                customfield = customfields.First(n => n.customfieldname == "Manual Test Steps");
            }
            catch (Exception)
            {
                return(result);
            }

            var verificationItems = customfield
                                    ?.customfieldvalues
                                    ?.steps;

            if (verificationItems == null)
            {
                return(result);
            }

            foreach (var verificationItem in verificationItems)
            {
                result.Add(GetVerification(verificationItem, testCase));
            }
            return(result);
        }
Exemplo n.º 14
0
        private static List <Setup> GetSetups(rss dto, TestCase testCase)
        {
            var result = new List <Setup>();
            var fields = dto
                         ?.channel
                         ?.item
                         ?.customfields;

            if (fields == null)
            {
                return(result);
            }
            rssChannelItemCustomfield field;

            try
            {
                field = fields.First(n => n.customfieldname == "Setup");
            }
            catch
            {
                return(result);
            }
            string fieldValue = field
                                ?.customfieldvalues
                                ?.customfieldvalue;

            if (fieldValue == null)
            {
                return(result);
            }
            foreach (var line in DivideHtmlIntoLinesByTags(fieldValue, HtmlTags))
            {
                result.Add(new Setup(line, testCase));
            }
            return(result);
        }
        private void Dto2TestCaseTest1()
        {
            const string stringID                        = "ID";
            const string stringTitle                     = "Title";
            const string stringSetup0                    = "- setup item 1";
            const string stringSetup1                    = "- setup item 2";
            const int    indexVerification0              = 1;
            const string stringVerification0Data0        = "v1 data item 1";
            const string stringVerification0Data1        = "v1 data item 2";
            const string stringVerification0Step0        = "v1 step 1";
            const string stringVerification0Step0Result0 = "result 1 for v1 step 1";
            const string stringVerification0Step1        = "v1 step 2";
            const string stringVerification0Step1Result0 = "result 1 for v1 step 2";
            const int    indexVerification1              = 3;
            const string stringVerification1Data0        = "v2 data item 1";
            const string stringVerification1Data1        = "v2 data item 2";
            const string stringVerification1Step0        = "v2 step 1";
            const string stringVerification1Step0Result0 = "result 1 for v2 step 1";
            const string stringVerification1Step1        = "v2 step 2";
            const string stringVerification1Step1Result0 = "result 1 for v2 step 2";

            var dto = new rss
            {
                channel = new rssChannel
                {
                    item = new rssChannelItem
                    {
                        title        = "[" + stringID + "] " + stringTitle,
                        customfields = new rssChannelItemCustomfield[2]
                        {
                            new rssChannelItemCustomfield
                            {
                                customfieldname   = "Setup",
                                customfieldvalues = new rssChannelItemCustomfieldCustomfieldvalues
                                {
                                    customfieldvalue = stringSetup0 + " " + "<br/>" + stringSetup1
                                }
                            },
                            new rssChannelItemCustomfield
                            {
                                customfieldname   = "Manual Test Steps",
                                customfieldvalues = new rssChannelItemCustomfieldCustomfieldvalues
                                {
                                    steps = new rssChannelItemCustomfieldCustomfieldvaluesStep[2]
                                    {
                                        new rssChannelItemCustomfieldCustomfieldvaluesStep
                                        {
                                            index = indexVerification0,
                                            data  = new rssChannelItemCustomfieldCustomfieldvaluesStepData
                                            {
                                                Text = stringVerification0Data0 + " "
                                                       + "<br/>" + stringVerification0Data1
                                            },
                                            step = new rssChannelItemCustomfieldCustomfieldvaluesStepStep
                                            {
                                                Text = "<p> 1. " + stringVerification0Step0 + " "
                                                       + "<br/> 2. " + stringVerification0Step1 + "</p>"
                                            },
                                            result = new rssChannelItemCustomfieldCustomfieldvaluesStepResult
                                            {
                                                Text = "<ul><li>Step 1. " + stringVerification0Step0Result0
                                                       + "</li><li>Step 2. " + stringVerification0Step1Result0 + "</li></ul>"
                                            }
                                        },
                                        new rssChannelItemCustomfieldCustomfieldvaluesStep
                                        {
                                            index = indexVerification1,
                                            data  = new rssChannelItemCustomfieldCustomfieldvaluesStepData
                                            {
                                                Text = stringVerification1Data0 + " "
                                                       + "<br/>" + stringVerification1Data1
                                            },
                                            step = new rssChannelItemCustomfieldCustomfieldvaluesStepStep
                                            {
                                                Text = "<p> 1. " + stringVerification1Step0 + "  "
                                                       + "<br/> 2. " + stringVerification1Step1 + "</p>"
                                            },
                                            result = new rssChannelItemCustomfieldCustomfieldvaluesStepResult
                                            {
                                                Text = "<ul><li>Step 1. " + stringVerification1Step0Result0
                                                       + "</li><li>Step 2. " + stringVerification1Step1Result0 + "</li></ul>"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestCase testCase = Dto2TestCaseConverter.ConvertDto2TestCase(dto);

            Assert.IsTrue(testCase.IdAndTitle == stringID + "-" + stringTitle);
            Assert.IsTrue(testCase.Setups.Count == 2);
            Assert.IsTrue(testCase.Setups[0].Text == stringSetup0);
            Assert.IsTrue(testCase.Setups[1].Text == stringSetup1);
            Assert.IsTrue(testCase.Verifications.Count == 2);
            Assert.IsTrue(testCase.Verifications[0].Number == indexVerification0);
            Assert.IsTrue(testCase.Verifications[0].Data.Count == 2);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Data[0], stringVerification0Data0));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Data[1], stringVerification0Data1));
            Assert.IsTrue(testCase.Verifications[0].Steps.Count == 2);
            Assert.IsTrue(testCase.Verifications[0].Steps[0].Text == stringVerification0Step0);
            Assert.IsTrue(testCase.Verifications[0].Steps[0].Results.Count == 1);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[0].Results[0], stringVerification0Step0Result0));
            Assert.IsTrue(testCase.Verifications[0].Steps[1].Text == stringVerification0Step1);
            Assert.IsTrue(testCase.Verifications[0].Steps[1].Results.Count == 1);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[1].Results[0], stringVerification0Step1Result0));
            Assert.IsTrue(testCase.Verifications[1].Number == indexVerification1);
            Assert.IsTrue(testCase.Verifications[1].Data.Count == 2);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[1].Data[0], stringVerification1Data0));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[1].Data[1], stringVerification1Data1));
            Assert.IsTrue(testCase.Verifications[1].Steps.Count == 2);
            Assert.IsTrue(testCase.Verifications[1].Steps[0].Text == stringVerification1Step0);
            Assert.IsTrue(testCase.Verifications[1].Steps[0].Results.Count == 1);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[1].Steps[0].Results[0], stringVerification1Step0Result0));
            Assert.IsTrue(testCase.Verifications[1].Steps[1].Text == stringVerification1Step1);
            Assert.IsTrue(testCase.Verifications[1].Steps[1].Results.Count == 1);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[1].Steps[1].Results[0], stringVerification1Step1Result0));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Rss()
        {
            rss        rss        = new rss();
            RssChannel rssChannel = new RssChannel();

            rss.channel = rssChannel;

            Image feedImage = new Image();

            feedImage.link   = WeblogUri.AbsoluteUri;
            feedImage.title  = WeblogTitle;
            feedImage.width  = WeblogImageWidth.ToString(RssLocFormat);
            feedImage.height = WeblogImageHeight.ToString(RssLocFormat);
            feedImage.url    = WeblogImageUri.AbsoluteUri;

            rssChannel.ItemsElementName = new ItemsChoiceType[] {
                // Ordering must correspond to the contents of rssChannel.Items
                ItemsChoiceType.title,
                ItemsChoiceType.link,
                ItemsChoiceType.language,
                ItemsChoiceType.image
            };

            rssChannel.Items = new object[] {
                WeblogTitle,
                WeblogUri.AbsoluteUri,     // Must be a string value
                WeblogLanguage.ToString(), // Must be a string value
                feedImage
            };

            // Gets all the blog post items from repo.
            var     json      = await(await this.httpClient.GetAsync($"blogPosts/paginate/{this.pageSize}/1")).Content.ReadAsStringAsync();
            dynamic blogPosts = JsonConvert.DeserializeObject(json);

            var rssItemList = new List <RssItem>();

            foreach (dynamic post in blogPosts.data)
            {
                var rssItem = new RssItem();
                rssItem.ItemsElementName = new ItemsChoiceType1[]
                {
                    ItemsChoiceType1.link,
                    ItemsChoiceType1.pubDate,
                    ItemsChoiceType1.guid,
                    ItemsChoiceType1.title,
                    ItemsChoiceType1.description,
                    ItemsChoiceType1.category
                };

                var itemGuid = new RssItemGuid
                {
                    isPermaLink = false,
                    Value       = ((int)post.id).ToString()
                };


                var link         = Url.Action("Post", "BlogPosts", new { id = (int)post.id }, Url.ActionContext.HttpContext.Request.Scheme);
                var itemUri      = new Uri(link);
                var itemPubDate  = (DateTime)post.datePublished;
                var itemTitle    = (string)post.title;
                var itemBody     = (string)post.content;
                var itemCategory = new Category {
                    Value = ItemCategoryName
                };

                rssItem.Items = new object[] {
                    itemUri.AbsoluteUri,  // Must be a string value
                    itemPubDate.ToString( // Format data value
                        DateTimeFormatInfo.InvariantInfo.RFC1123Pattern,
                        RssLocFormat),
                    itemGuid,
                    itemTitle,
                    itemBody,
                    itemCategory
                };

                rssItemList.Add(rssItem);
            }

            rssChannel.item = rssItemList.ToArray();

            XmlSerializer serializer = new XmlSerializer(typeof(rss));

            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, rss);
                return(Content(Encoding.UTF8.GetString(ms.ToArray()), "application/xml"));
            }
        }
Exemplo n.º 17
0
        static async Task Main(string[] args)
        {
            List <string> channelItems = new List <string>();

            string feed = null;
            string url  = "https://www.tv2east.dk/rss";

            bool firstIte = true;

            string[] keywords = new string[] {
                "ulykke",
                "uheld",
                "spærret",
                "politi ",
                "politi-",
                "politiet",
                "aks",
                "udrykning",
                "fastklæmt",
                "skud",
                "færdselsuheld",
                "brand",
                "voldsom"
            };

            while (true)
            {
                try
                {
                    using (var client = new HttpClient())
                    {
                        try
                        {
                            feed = await client.GetStringAsync(url);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }

                    if (feed != null)
                    {
                        DateTime now      = DateTime.Now;
                        string   filename = now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + "-" + now.Hour.ToString() + now.Minute.ToString();

                        if (!Directory.Exists(@"\RSS\log\"))
                        {
                            Directory.CreateDirectory(@"\RSS\log\");
                        }

                        using (StreamWriter writer = new StreamWriter(@"\RSS\log\" + filename + ".json"))
                        {
                            writer.Write(feed);
                        }

                        XmlSerializer serializer = new XmlSerializer(typeof(rss));
                        StringReader  sr         = new StringReader(feed);
                        rss           content    = (rss)serializer.Deserialize(sr);

                        string baseUrl = @"\RSS\";

                        foreach (rssChannelItem item in content.channel.item)
                        {
                            DateTime pub = DateTime.Parse(item.pubDate);
                            if (!Directory.Exists(baseUrl + item.category + @"\"))
                            {
                                Directory.CreateDirectory(baseUrl + item.category + @"\");
                            }

                            bool doesExist = false;

                            if (channelItems.Contains(item.guid))
                            {
                                doesExist = true;
                            }
                            else
                            {
                                Console.WriteLine("New story: " + item.title, Color.Red);
                            }

                            if (!doesExist)
                            {
                                channelItems.Add(item.guid);
                                if (channelItems.Count > 1000)
                                {
                                    channelItems.RemoveAt(0);
                                }

                                bool exciting = false;
                                foreach (string kw in keywords)
                                {
                                    if (item.title.Contains(kw) || firstIte)
                                    {
                                        exciting = true;
                                        Console.WriteLine("Sending notification...", Color.FromArgb(255, 100, 100));

                                        var parameters = new NameValueCollection {
                                            { "token", "agneeuvoupztvd18us6kqhveaudz8n" },
                                            { "user", "ubv377xnnrxujede3efpmxm3v6r5j4" },
                                            { "message", item.title + "\n" + item.description },
                                            { "title", "ALARM TV2EAST" },
                                            { "priority", "1" },
                                            { "url", item.link }
                                        };

                                        using (var client = new WebClient())
                                        {
                                            if (!firstIte)
                                            {
                                                client.UploadValues("https://api.pushover.net/1/messages.json", parameters);
                                            }
                                        }
                                        break;
                                    }
                                }

                                if (!exciting)
                                {
                                    Console.WriteLine("Not exciting...", Color.CadetBlue);
                                }

                                using (StreamWriter sw = new StreamWriter(baseUrl + item.category + @"\" + pub.Year + pub.Month + pub.Day + "-" + item.guid.Remove(0, 33) + ".txt"))
                                {
                                    sw.WriteLine("Title:\n" + item.title + "\n");
                                    sw.WriteLine("Published:\n" + item.pubDate + "\n");
                                    sw.WriteLine("Category:\n" + item.category + "\n");
                                    sw.WriteLine("Link:\n" + item.link);
                                }
                            }
                        }

                        if (firstIte)
                        {
                            Console.WriteLine("First iteration done", Color.Yellow);
                            firstIte = false;
                        }
                    }

                    //½Console.WriteLine("Iteration done. Pausing for 5 seconds...", Color.Green);
                    Thread.Sleep(5000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString(), Color.Red);
                    break;
                }
            }

            Console.WriteLine("\nPress any key to close...");
            Console.ReadKey();
        }
Exemplo n.º 18
0
        public EpisodesViewModelMock() : base(new Logger(), new DeserialisedRssProvider(new Logger()), new DirectoryProvider())
        {
            Rss = new rss
            {
                version = 1m,
                lang    = "lang",
                channel = new rssChannel
                {
                    author   = "author",
                    category = new category
                    {
                        text = "category",
                    },
                    copyright   = "copywrite",
                    description = "description",
                    generator   = "generator",
                    keyword     = "anjunabeats, above and beyond",
                    owner       = new owner
                    {
                        email = "email",
                        name  = "name",
                    },
                    link     = "http://static.aboveandbeyond.nu/grouptherapy/podcast.xml",
                    title    = "Above & Beyond: Group Therapy",
                    subtitle = "subtitle",
                    language = "en",
                    summary  = "Hailing from Hungary, Myon & Shane 54 have achieved extraordinary success in the international dance music scene, having established a solid reputation for themselves with notable releases including numerous Beatport number ones and consistent rankings among DJ Mag's Top 100 DJs. They produce for some of the biggest names in music, are constant fixtures in set lists of some of world’s best known DJs, and regularly feature in a multitude of EDM radio show playlists. Myon & Shane 54 also host their own weekly radio show “International Departures”, frequently one of the most popular music podcasts around due in large part to their shameless, all-encompassing approach to mash-ups. In addition, their extensive tour diary “International Departures TV” provides an in depth view of life on the road for the well-traveled duo.",
                    item     = new Episode[]
                    {
                        new Episode()
                        {
                            author      = "Above & Beyond",
                            author1     = "author1",
                            description = "description",
                            duration    = "duration",
                            keywords    = "keywords",
                            enclosure   = new rssChannelItemEnclosure
                            {
                                length = 1,
                                type   = "type",
                                url    = "url",
                            },
                            subtitle  = "subtitle",
                            title     = "Anjunadeep 06 mini-mix (available to pre-order now)",
                            summary   = "summary",
                            link      = "www.anjunadeep.com",
                            guid      = "Anjunadeep 06",
                            @explicit = "no",
                            pubDate   = "29 August 2014",
                        },
                        new Episode()
                        {
                            author      = "Above & Beyond",
                            author1     = "author1",
                            description = "01. Time Takers - Things You Want 02. Nibc & Life So Far - You Let Me Go (LKiD Remix) 03. Jerome Isma-Ae - Overdrive 04. Pryda - Axis 05. Helena feat Shawnee Taylor - Levity (Freaky Flavour Remix) 06. Reunity feat Danyka Nadeau - Come Closer 07. Boom Jinx & Meredith Call - The Dark Track Of The Moment: 08. Myon & Shane 54 with Kyler England - Summer Of Love (Club Mix) 09. Above & Beyond - Blue Sky Action (Club Mix) 10. Cosmic Gate & Kristina Antuna - Alone 11. Michael Jackson - Slave To The Rhythm (Audien Remix) Blast From The Past: 12. Nic Chagall - This Moment",
                            duration    = "duration",
                            keywords    = "keywords",
                            enclosure   = new rssChannelItemEnclosure
                            {
                                length = 1,
                                type   = "type",
                                url    = "url",
                            },
                            subtitle  = "subtitle",
                            title     = "#093 Group Therapy Radio with Above & Beyond",
                            summary   = "01. Time Takers - Things You Want 02. Nibc & Life So Far - You Let Me Go (LKiD Remix) 03. Jerome Isma-Ae - Overdrive 04. Pryda - Axis 05. Helena feat Shawnee Taylor - Levity (Freaky Flavour Remix) 06. Reunity feat Danyka Nadeau - Come Closer 07. Boom Jinx & Meredith Call - The Dark Track Of The Moment: 08. Myon & Shane 54 with Kyler England - Summer Of Love (Club Mix) 09. Above & Beyond - Blue Sky Action (Club Mix) 10. Cosmic Gate & Kristina Antuna - Alone 11. Michael Jackson - Slave To The Rhythm (Audien Remix) Blast From The Past: 12. Nic Chagall - This Moment",
                            link      = "www.anjunadeep.com",
                            guid      = "Anjunadeep 06",
                            @explicit = "no",
                            pubDate   = "22 November 2014",
                        },
                    }
                },
            };

            Episodes = new EpisodeViewModel[]
            {
                new EpisodeViewModel(new DirectoryProvider(), Rss, Rss.channel.item[0])
                {
                    Progress = 50
                },
                new EpisodeViewModel(new DirectoryProvider(), Rss, Rss.channel.item[1]),
            };
        }
Exemplo n.º 19
0
        public void laggTillNyPodcast(bool nyKategori, String URL, String namn, string intervall, String kategori)
        {
            if (nyKategori)
            {
                Directory.CreateDirectory(kategori);
            }


            string path = Directory.GetCurrentDirectory() + @"/" + kategori + @"\" + namn + @".xml";

            Console.WriteLine(path);
            rss               rssVar   = new rss();
            XmlDocument       doc      = rssVar.hamtaXML(URL);
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = ("    ");
            XmlWriter xmlOut = XmlWriter.Create(path, settings);

            switch (intervall)
            {
            case "Var 5e sekund":
                intervall = "5000";
                break;

            case "Var 10e sekund":
                intervall = "10000";
                break;

            case "Var 20e sekund":
                intervall = "20000";
                break;

            case "Var 30e sekund":
                intervall = "30000";
                break;
            }

            xmlOut.WriteStartDocument();
            xmlOut.WriteStartElement("channel");
            xmlOut.WriteElementString("interval", intervall);
            xmlOut.WriteElementString("url", URL);
            xmlOut.WriteElementString("lastSync", DateTime.Now.ToString());
            int i = 0;

            foreach (XmlNode item
                     in doc.DocumentElement.SelectNodes("channel/item"))
            {
                var title       = item.SelectSingleNode("title");
                var description = item.SelectSingleNode("description");
                var enclosure   = item.SelectSingleNode("enclosure/@url");

                xmlOut.WriteStartElement("item");

                xmlOut.WriteAttributeString("ID", "pod" + i);

                if (description.InnerText.Equals(""))
                {
                    xmlOut.WriteElementString("description", "Unfortunately, no description is available.");
                }
                else
                {
                    xmlOut.WriteElementString("description", description.InnerText);
                }

                xmlOut.WriteElementString("title", title.InnerText);
                xmlOut.WriteElementString("enclosure", enclosure.InnerText);
                xmlOut.WriteElementString("status", "Unlistened");

                xmlOut.WriteEndElement();
                i++;
            }
            xmlOut.WriteEndDocument();
            xmlOut.Close();
        }
Exemplo n.º 20
0
 public async Task <rss> PostAsJson([FromBody] rss snbrss)
 {
     return(await Task.FromResult(snbrss));
 }
Exemplo n.º 21
0
 public OnRssDownloadEventArgs(rss result)
 {
     Result = result;
 }
Exemplo n.º 22
0
        public ActionResult Index()
        {
            /* HashSet<string> hs = new HashSet<string>();
             * var query = from KeywordsTotal in db.keywordsTotal
             *           select KeywordsTotal;
             * for (int i = 0; i < query.Count(); i++)
             * {
             *   hs.Add(query.ElementAt(i).keyword);
             *
             * }*/

            //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦
            // int x = db.likes.Count(like => like.ItemId ==101);

            /******************************
            *  访问rss的地址,读取xml数据
            ******************************/
            rss newsItems = null;
            //  System.Net.WebClient client = new WebClient();
            //  byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            // string path = System.Text.Encoding.UTF8.GetString(page);
            //string path = "cars.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(rss));

            //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心
            // request.CookieContainer = new CookieContainer();
            // request.AllowAutoRedirect = false;
            //  WebResponse response = (WebResponse)request.GetResponse();
            //  Stream sm = response.GetResponseStream();
            //  System.IO.StreamReader streamReader = new System.IO.StreamReader(sm);
            //将流转换为字符串
            // string html = streamReader.ReadToEnd();
            // streamReader.Close();

            //  TextReader reader = new StreamReader(path);

            XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");

            newsItems = (rss)serializer.Deserialize(reader);

            /*var serializer = new XmlSerializer(typeof(rss));
             * using (TextReader reader = new StringReader(html))
             * {
             *    cars = (rss)serializer.Deserialize(reader);
             * }*/


            //  reader.Close();


            /******************************
            *  初始化最新时间newTime
            ******************************/
            DateTime newTime;

            if (db.sources.Find("NYTimes") == null)
            {
                string httpTime = newsItems.item[newsItems.item.Length - 1].pubDate;
                newTime = DateTime.Parse(httpTime);
                Models.source src = new Models.source("NYTimes", newTime);
                db.sources.Add(src);
            }
            else
            {
                Models.source src = db.sources.Find("NYTimes");
                newTime = src.newDate.Value;
            }


            /******************************
            *  循环添加每一条新闻条目,只添加新条目
            ******************************/
            for (var i = newsItems.item.Length - 1; i >= 0; i--)    //old item store into database first
            {
                string   httpTime = newsItems.item[i].pubDate;
                DateTime time     = DateTime.Parse(httpTime);


                // 每次添加新条目前,先与source里的最新时间对比
                if (time <= newTime)       //time值小于最新时间,舍弃
                {
                    continue;
                }
                else
                {
                    Models.source src = db.sources.Find("NYTimes");
                    src.newDate = time;    //更新时间
                }
                // description里面会带有<和> 之间的多余内容,例如广告,使用正则表达式可以消除掉
                newsItems.item[i].description = Regex.Replace(newsItems.item[i].description, "<.*?>", string.Empty);
                string text = newsItems.item[i].title + " " + newsItems.item[i].description;
                text = text.ToLower();

                text = non1.Replace(text, "");
                text = non2.Replace(text, "");
                text = non3.Replace(text, "");
                text = non4.Replace(text, "");
                text = non5.Replace(text, "");
                text = non6.Replace(text, "");
                text = non7.Replace(text, "");
                text = non8.Replace(text, "");
                text = non9.Replace(text, "");
                text = non10.Replace(text, "");
                text = non11.Replace(text, "");
                text = non12.Replace(text, "");
                text = non13.Replace(text, "");
                text = non14.Replace(text, "");
                text = non15.Replace(text, "");
                text = non16.Replace(text, "");
                text = non17.Replace(text, "");
                text = non18.Replace(text, "");
                text = non19.Replace(text, "");
                text = non20.Replace(text, "");
                char[]   sp    = new Char[] { ',', '.', ' ', '?', ':', '\'', '‘', '’', '|' };
                string[] words = text.Split(sp, StringSplitOptions.RemoveEmptyEntries);

                // string[] words = text.Split(' ');


                words[0] = Regex.Replace(words[0], "[\\s\\p{P}\n\r=<>$>+¥^]", "");
                words[1] = Regex.Replace(words[1], "[\\s\\p{P}\n\r=<>$>+¥^]", "");
                words[2] = Regex.Replace(words[2], "[\\s\\p{P}\n\r=<>$>+¥^]", "");


                Models.item item = new Models.item(newsItems.item[i], time, "NYTimes", 0, words[0], words[1], words[2]); // "");

                db.items.Add(item);                                                                                      //item include 4 elements
                db.SaveChanges();


                for (int j = 0; j < 3; j++)
                {
                    db.articleKeyword.Add(new ArticleKeyword(words[j], item.Id));

                    if (db.keywordsTotal.Find(words[j]) != null)
                    {
                        db.keywordsTotal.Find(words[j]).keywordSum++;
                    }
                    else
                    {
                        db.keywordsTotal.Add(new KeywordsTotal(words[j], 1));
                    }
                    //db.SaveChanges();
                }

                //db.channel.Add(cars.item[i]);
            }
            db.SaveChanges();

            /*var query = from item in db.items
             *           where item.imgId == ""
             *           select item;
             *
             * foreach (Models.item item in query)
             * {
             *  item.imgId = "i" + item.Id;
             * }
             * db.SaveChanges();*/
            return(View());
        }
Exemplo n.º 23
0
        //
        // GET: /News/

        public ActionResult Index()
        {
            //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦
            // int x = db.likes.Count(like => like.ItemId ==101);

            /******************************
            *  访问rss的地址,读取xml数据
            ******************************/
            rss cars = null;
            //  System.Net.WebClient client = new WebClient();
            //  byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            // string path = System.Text.Encoding.UTF8.GetString(page);
            //string path = "cars.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(rss));

            //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心
            // request.CookieContainer = new CookieContainer();
            // request.AllowAutoRedirect = false;
            //  WebResponse response = (WebResponse)request.GetResponse();
            //  Stream sm = response.GetResponseStream();
            //  System.IO.StreamReader streamReader = new System.IO.StreamReader(sm);
            //将流转换为字符串
            // string html = streamReader.ReadToEnd();
            // streamReader.Close();

            //  TextReader reader = new StreamReader(path);

            XmlReader reader = new XmlTextReader("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");

            cars = (rss)serializer.Deserialize(reader);

            /*var serializer = new XmlSerializer(typeof(rss));
             * using (TextReader reader = new StringReader(html))
             * {
             *    cars = (rss)serializer.Deserialize(reader);
             * }*/


            //  reader.Close();


            /******************************
            *  初始化最新时间newTime
            ******************************/
            DateTime newTime;

            if (db.sources.Find("NYTimes") == null)
            {
                //db.sources.Add(new Models.source("NYTimes", new DateTime(2000,1,1)));    //Initialize database
                db.sources.Add(new Models.source("NYTimes", DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT")));
            }
            //db.sources.Add(new source { srcName = "NYTimes", newDate = DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT") });
            //db.SaveChanges();

            if (db.sources.Find("NYTimes").newDate.Value < DateTime.Parse("Sat, 07 Feb 2015 00:57:00 GMT"))
            {
                string httpTime = cars.item[cars.item.Length - 1].pubDate;
                newTime = DateTime.Parse(httpTime);
                Models.source src = new Models.source("NYTimes", newTime);
                db.sources.Add(src);
            }
            else
            {
                Models.source src = db.sources.Find("NYTimes");
                newTime = src.newDate.Value;
            }


            /******************************
            *  循环添加每一条新闻条目,只添加新条目
            ******************************/

            for (var i = cars.item.Length - 1; i >= 0; i--)    //old item store into database first
            {
                string   httpTime = cars.item[i].pubDate;
                DateTime time     = DateTime.Parse(httpTime);


                // 每次添加新条目前,先与source里的最新时间对比
                if (time <= newTime)       //time值小于最新时间,舍弃
                {
                    continue;
                }
                else
                {
                    Models.source src = db.sources.Find("NYTimes");
                    src.newDate = time;    //更新时间
                }

                // description里面会带有<和> 之间的多余内容,例如广告,使用正则表达式可以消除掉
                cars.item[i].description = Regex.Replace(cars.item[i].description, "<.*?>", string.Empty);


                Models.item item = new Models.item(cars.item[i], time, "NYTimes", 0);

                db.items.Add(item);               //item include 4 elements

                db.SaveChanges();                 //save DB before calling other function !!


                /**********************************
                * 添加每篇文章同时对keyword表和artKey表进行统计
                * ********************************/
                KeywordAnalyzer ka = new KeywordAnalyzer();

                ka.analyze(item);                   //这里保存的数据库结果,不会传到view的ToList里?TFIDF

                ka.TFIDF(item.Id);                  //随着数据越多,TFIDF效果会越来越精确


                /*****************************
                * 把结果存进article表中。不能放在子函数,否则传不进View?
                *****************************/
                var query2 = db.artKeys
                             .Where(x => x.AId == item.Id)
                             .OrderByDescending(x => x.TFIDF)
                             .Take(3);                                  //获得排序最高的三个关键词
                string str = "";
                foreach (var line in query2)
                {
                    str = str + line.word + ",";
                }

                db.items.Find(item.Id).keyword = str;
                db.SaveChanges();
            }


            //db.SaveChanges();
            return(View(db.items.ToList()));
        }
Exemplo n.º 24
0
        //
        // GET: /Xml2Model/

        public ActionResult Index()
        {
            //Linq 语法 计算在likes 中ItemID文章的总like数目,也可用EF方法实现,比较麻烦
            // int x = db.likes.Count(like => like.ItemId ==101);

            /******************************
            *  访问rss的地址,读取xml数据
            ******************************/
            rss cars = null;
            //  System.Net.WebClient client = new WebClient();
            //  byte[] page = client.DownloadData("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            // string path = System.Text.Encoding.UTF8.GetString(page);
            //string path = "cars.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(rss));

            //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://rss.nytimes.com/services/xml/rss/nyt/US.xml");
            //使用Cookie设置AllowAutoRedirect属性为false,是解决“尝试自动重定向的次数太多。”的核心
            // request.CookieContainer = new CookieContainer();
            // request.AllowAutoRedirect = false;
            //  WebResponse response = (WebResponse)request.GetResponse();
            //  Stream sm = response.GetResponseStream();
            //  System.IO.StreamReader streamReader = new System.IO.StreamReader(sm);
            //将流转换为字符串
            // string html = streamReader.ReadToEnd();
            // streamReader.Close();

            //  TextReader reader = new StreamReader(path);

            XmlReader reader = new XmlTextReader("http://rss.cnn.com/rss/cnn_us.rss");

            cars = (rss)serializer.Deserialize(reader);

            /*var serializer = new XmlSerializer(typeof(rss));
             * using (TextReader reader = new StringReader(html))
             * {
             *    cars = (rss)serializer.Deserialize(reader);
             * }*/


            //  reader.Close();


            /******************************
            *  初始化最新时间newTime
            ******************************/
            DateTime newTime;

            if (db.sources.Find("CNN") == null)
            {
                string httpTime = cars.item[cars.item.Length - 1].pubDate;
                newTime = DateTime.ParseExact(httpTime, "ddd, dd MMM yyyy HH:mm:ss EST", new CultureInfo("en-US")).AddHours(-1);
                Models.source src = new Models.source("CNN", newTime);
                db.sources.Add(src);
            }
            else
            {
                Models.source src = db.sources.Find("CNN");
                newTime = src.newDate.Value;
            }


            /******************************
            *  循环添加每一条新闻条目,只添加新条目
            ******************************/
            for (var i = cars.item.Length - 1; i >= 0; i--)    //old item store into database first
            {
                string   httpTime = cars.item[i].pubDate;
                DateTime time     = DateTime.ParseExact(httpTime, "ddd, dd MMM yyyy HH:mm:ss EST", new CultureInfo("en-US")).AddHours(-1);


                // 每次添加新条目前,先与source里的最新时间对比
                if (time <= newTime)       //time值小于最新时间,舍弃
                {
                    continue;
                }
                else
                {
                    Models.source src = db.sources.Find("CNN");
                    src.newDate = time;    //更新时间
                }


                Models.item item = new Models.item(cars.item[i], time, "CNN", 0, "", "", ""); //, "");

                db.items.Add(item);                                                           //item include 4 elements
                //db.channel.Add(cars.item[i]);
            }
            db.SaveChanges();


            /*var query = from item in db.items
             *          where item.imgId == ""
             *          select item;
             *
             * foreach (Models.item item in query)
             * {
             *  item.imgId = "i" + item.Id;
             * }
             * db.SaveChanges();*/
            return(View());
        }
 public OnRssDownloadEventArgs(rss result)
 {
     Result = result;
 }
        private void Dto2TestCaseTest2()
        {
            const string stringID                        = "ID";
            const string stringTitle                     = "Title";
            const string stringSetup0                    = "&nbsp;- OLSS Workstation 2.2";
            const string stringSetup1                    = "";
            const int    indexVerification0              = 0;
            const string stringVerification0Data0        = "v1 data item 1";
            const string stringVerification0Data1        = "v1 data item 2";
            const string stringVerification0Data2        = "v1 data item 3";
            const string stringVerification0Step0Line0   = "v1 step 1 line 1";
            const string stringVerification0Step0Line1   = "v1 step 1 line 2";
            const string stringVerification0Step0Result0 = "result 1 for v1 step 1";
            const string stringVerification0Step0Result1 = "result 2 for v1 step 1";
            const string stringVerification0Step1        = "v1 step 2";
            const string stringVerification0Step1Result0 = "result 1 for v1 step 2";
            const string stringVerification0Step2        = "v1 step 3";
            const string stringVerification0Step2Result0 = "result 1 for v1 step 3";
            const string stringVerification0Step2Result1 = "result 2 for v1 step 3";
            const string stringVerification0Step2Result2 = "result 3 for v1 step 3";
            const string stringVerification0Step2Result3 = "result 4 for v1 step 3";

            var dto = new rss
            {
                channel = new rssChannel
                {
                    item = new rssChannelItem
                    {
                        title        = "[" + stringID + "] " + stringTitle,
                        customfields = new rssChannelItemCustomfield[2]
                        {
                            new rssChannelItemCustomfield
                            {
                                customfieldname   = "Setup",
                                customfieldvalues = new rssChannelItemCustomfieldCustomfieldvalues
                                {
                                    customfieldvalue = stringSetup0
                                                       + "<br/>" + stringSetup1
                                }
                            },
                            new rssChannelItemCustomfield
                            {
                                customfieldname   = "Manual Test Steps",
                                customfieldvalues = new rssChannelItemCustomfieldCustomfieldvalues
                                {
                                    steps = new rssChannelItemCustomfieldCustomfieldvaluesStep[1]
                                    {
                                        new rssChannelItemCustomfieldCustomfieldvaluesStep
                                        {
                                            index = indexVerification0,
                                            data  = new rssChannelItemCustomfieldCustomfieldvaluesStepData
                                            {
                                                Text = "<p>" + stringVerification0Data0 + " "
                                                       + "</p><ul type=\"square\" class=\"alternate\"><li>" + stringVerification0Data1
                                                       + "</li><li>" + stringVerification0Data2 + "</li></ul>"
                                            },
                                            step = new rssChannelItemCustomfieldCustomfieldvaluesStepStep
                                            {
                                                Text = "<p> 1. " + stringVerification0Step0Line0
                                                       + "<br/>" + stringVerification0Step0Line1
                                                       + "<br/> 2. " + stringVerification0Step1
                                                       + "</p><p>3." + stringVerification0Step2 + "</p>"
                                            },
                                            result = new rssChannelItemCustomfieldCustomfieldvaluesStepResult
                                            {
                                                Text = "<p>1."
                                                       + "</p><p>" + stringVerification0Step0Result0
                                                       + "</p><p>" + stringVerification0Step0Result1
                                                       + "</p><p>2 -" + stringVerification0Step1Result0
                                                       + "</p><ul><li> 3:" + stringVerification0Step2Result0
                                                       + "</li><li>" + stringVerification0Step2Result1
                                                       + "</li><br/>" + stringVerification0Step2Result2
                                                       + "<br/>" + stringVerification0Step2Result3
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestCase testCase = Dto2TestCaseConverter.ConvertDto2TestCase(dto);

            Assert.IsTrue(testCase.IdAndTitle == stringID + "-" + stringTitle);
            Assert.IsTrue(testCase.Setups.Count == 1);
            Assert.IsTrue(testCase.Setups[0].Text == stringSetup0);
            Assert.IsTrue(testCase.Verifications.Count == 1);
            Assert.IsTrue(testCase.Verifications[0].Number == indexVerification0);
            Assert.IsTrue(testCase.Verifications[0].Data.Count == 3);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Data[0], stringVerification0Data0));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Data[1], stringVerification0Data1));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Data[2], stringVerification0Data2));
            Assert.IsTrue(testCase.Verifications[0].Steps.Count == 3);
            Assert.IsTrue(testCase.Verifications[0].Steps[0].Text == stringVerification0Step0Line0 + "\n" + stringVerification0Step0Line1);
            Assert.IsTrue(testCase.Verifications[0].Steps[0].Results.Count == 2);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[0].Results[0], stringVerification0Step0Result0));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[0].Results[1], stringVerification0Step0Result1));
            Assert.IsTrue(testCase.Verifications[0].Steps[1].Text == stringVerification0Step1);
            Assert.IsTrue(testCase.Verifications[0].Steps[1].Results.Count == 1);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[1].Results[0], stringVerification0Step1Result0));
            Assert.IsTrue(testCase.Verifications[0].Steps[2].Text == stringVerification0Step2);
            Assert.IsTrue(testCase.Verifications[0].Steps[2].Results.Count == 4);
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[2].Results[0], stringVerification0Step2Result0));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[2].Results[1], stringVerification0Step2Result1));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[2].Results[2], stringVerification0Step2Result2));
            Assert.IsTrue(IsNewTestCaseItemCorrect(testCase.Verifications[0].Steps[2].Results[3], stringVerification0Step2Result3));
        }
Exemplo n.º 27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool blnPutInCache = false;

            string PodcastXMLString = Cache.Get("cache.RiverValley.PodcastXMLString") as string;

            if (null != PodcastXMLString)
            {//All Done we have a valid cache
                SendXmlString(PodcastXMLString);
                return;
            }

            //If That cache is dead chances are that document cache is dead also so force load
            //of the multimedia page so we know we have at least that cache
            string sThisFileName = System.IO.Path.GetFileName(Request.Url.AbsolutePath);
            string MultimediaPageURL = (Request.Url.AbsoluteUri).Replace(sThisFileName, "multimedia.aspx");
            string MultimediaPath = MultimediaPageURL.Replace(".aspx", "/");
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(MultimediaPageURL);

            try
            {
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            }
            catch
            {
                //Oh well we will try to continue
            }

            rss podCast = new rss();

            //Time to live (Optional)
            podCast.channel.ttl = 60;
            ///ttl stands for time to live.
            ///It's a number of minutes that indicates how long a channel can be cached before
            ///refreshingfrom the source. This makes it possible for RSS sources to be managed by
            ///a file-sharing network such as Gnutella.

            podCast.channel.title = "River Valley Community Church Sermons";
            podCast.channel.link = "http://www.rivervalleycommunity.org";
            podCast.channel.copyright = "River Valley Community Church " + DateTime.Now.Year;
            podCast.channel.description = "Sermon recordings form Andy Morgan, Pastor, River Valley Community Church, Aurora IL";
            podCast.channel.generator = "Jude's cool Podcast Generator";
            podCast.channel.lastBuildDate = DateTime.Now;

            List<Document> DocumentList = Cache.Get("cache.RiverValley.MultimediaFiles") as List<Document>;

            System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;

            if (DocumentList != null)
            {
                item i;
                foreach (MultimediaFile d in DocumentList)
                {
                    i = new item();
                    i.title = d.Title;
                    i.pubDate = d.Dated;
                    i.description = d.Description;
                    i.enclosure.url = MultimediaPath + d.Name;

                    foreach (Tag t in d.Tags)
                    {
                        i.cats.Add(new cat(textInfo.ToTitleCase(t.Name)));
                    }

                    podCast.channel.items.Add(i);

                    if (podCast.channel.items.Count >= MAX_ARTICLES)
                        break;

                    blnPutInCache = true;
                }
            }

            PodcastXMLString = Util.Serialize<rss>(podCast);

            if (true == blnPutInCache)
                Cache.Insert("cache.RiverValley.PodcastXMLString", PodcastXMLString);

            SendXmlString(PodcastXMLString);
        }
Exemplo n.º 28
0
        public static void Main()
        {
            var rss        = new rss();
            var rssChannel = new RssChannel();

            rss.channel = rssChannel;

            var feedImage = new Image
            {
                link   = weblogUri.AbsoluteUri,
                title  = weblogTitle,
                width  = weblogImageWidth.ToString(RssLocFormat),
                height = weblogImageHeight.ToString(RssLocFormat),
                url    = weblogImageUri.AbsoluteUri
            };

            var itemGuid = new Guid
            {
                isPermaLink = false,
                Value       = itemIdTag.AbsoluteUri
            };

            var itemCategory = new Category
            {
                Value = itemCategoryName
            };

            var rssItem = new RssItem
            {
                ItemsElementName = new []
                {
                    // Ordering must correspond to the contents of rssItem.Items
                    ItemsChoiceType1.link,
                    ItemsChoiceType1.pubDate,
                    ItemsChoiceType1.guid,
                    ItemsChoiceType1.title,
                    ItemsChoiceType1.description,
                    ItemsChoiceType1.category
                },
                Items = new object[]
                {
                    itemUri.AbsoluteUri,  // Must be a string value
                    itemPubDate.ToString( // Format data value
                        DateTimeFormatInfo.InvariantInfo.RFC1123Pattern,
                        RssLocFormat),
                    itemGuid,
                    itemTitle,
                    itemBody,
                    itemCategory
                }
            };

            rssChannel.ItemsElementName = new [] {
                // Ordering must correspond to the contents of rssChannel.Items
                ItemsChoiceType.title,
                ItemsChoiceType.link,
                ItemsChoiceType.language,
                ItemsChoiceType.image,
                ItemsChoiceType.rating
            };
            rssChannel.Items = new object[] {
                weblogTitle,
                weblogUri.AbsoluteUri,     // Must be a string value
                weblogLanguage.ToString(), // Must be a string value
                feedImage,
                weblogRating
            };
            // Add the blog post item(s)
            rssChannel.item = new [] {
                rssItem
            };

            var serializer = new XmlSerializer(typeof(rss));

            serializer.Serialize(Console.Out, rss);

            Console.WriteLine();
            Console.Write("Press any key to continue...");
            Console.ReadLine();
        }
Exemplo n.º 29
0
        public static string GetRss()
        {
            //using RssFeedGenerator;
            var myrss = new rss();

            //在这里声明rss
            myrss.version = 2.0m;

            myrss.channel = new rssChannel
            {
                title       = "开发者博客",
                description = "开发者博客最新发布",
                link        = "https://www.songshizhao.com/blog/RSS/RssHandler.ashx",
                language    = "zh-CN",
                copyright   = "Copyright 2017 - 2020, songshizhao.com",

                docs      = "https://www.songshizhao.com/blog/RSS/RssHandler.ashx",
                generator = "https://www.songshizhao.com/login.aspx",
                link1     = new link
                {
                    href = "https://www.songshizhao.com/blog/RSS/RssHandler.ashx",
                    rel  = "self",
                    type = "application/rss+xml",
                },
            };


            //DataSet MyBlogs = new DataSet();
            //string conStr = BlogHelpper.conStr;
            //using (OleDbConnection con = new OleDbConnection(conStr))
            //{
            //	string cmdStr = "select top 40 * from blog order by blogTime desc";
            //	con.Open();
            //	using (var cmd = new OleDbCommand(cmdStr, con))
            //	{
            //		using (OleDbDataAdapter s = new OleDbDataAdapter(cmdStr, conStr))
            //		{
            //			s.Fill(MyBlogs);
            //		}
            //	}
            //	con.Close();
            //}

            //var items = new List<rssChannelItem>();
            //myrss.channel.item = items;
            //for (int x = 0; x < MyBlogs.Tables[0].Rows.Count; x++)
            //{
            //	rssChannelItem blogItem = new rssChannelItem()
            //	{
            //		title = MyBlogs.Tables[0].Rows[x][2].ToString(),
            //		description = MyBlogs.Tables[0].Rows[x][4].ToString(),//, BlogHelpper.GetHtmlText(MyBlogs.Tables[0].Rows[x][4].ToString()),
            //		guid = new rssChannelItemGuid
            //		{
            //			isPermaLink = false,
            //			Value = MyBlogs.Tables[0].Rows[x][0].ToString(),
            //		},
            //		link = MyBlogs.Tables[0].Rows[x][5].ToString(),
            //		pubDate = MyBlogs.Tables[0].Rows[x][3].ToString(),

            //	};
            //	//if (blogItem.description.Length > 200)
            //	//{
            //	//	blogItem.description = blogItem.description.Substring(0, 200);
            //	//}
            //	blogItem.description = BlogHelpper.Decode(blogItem.description);
            //	items.Add(blogItem);
            //};

            //using RssFeedGenerator;
            var OutputXmlString = Generator.SerializeRSS(myrss);

            return(OutputXmlString);
        }
Exemplo n.º 30
0
        public static NewsResponseModel ParseRSS(this rss model)
        {
            var result = new NewsResponseModel();

            foreach (var item in model.channel.Any)
            {
                switch (item.Name)
                {
                case "title":
                {
                    result.Title = item.InnerText;
                    break;
                }

                case "link":
                {
                    result.Link = item.InnerText;
                    break;
                }

                case "description":
                {
                    result.SourceDescription = item.InnerText;
                    break;
                }

                case "lastBuildDate":
                {
                    result.LastBuildDate = item.InnerText;
                    break;
                }

                case "item":
                {
                    var pieceOfNews = new PieceOfNews();

                    for (int i = 0; i < item.ChildNodes.Count; i++)
                    {
                        string value = item.ChildNodes[i].InnerText;

                        switch (item.ChildNodes[i].Name)
                        {
                        case "title":
                        {
                            pieceOfNews.Title = value;
                            break;
                        }

                        case "description":
                        {
                            pieceOfNews.Description = value;
                            break;
                        }

                        case "pubDate":
                        {
                            pieceOfNews.PublishDate = value;
                            break;
                        }

                        case "link":
                        {
                            pieceOfNews.Link = value;
                            break;
                        }
                        }
                    }

                    result.News.Add(pieceOfNews);

                    break;
                }
                }
            }

            return(result);
        }