Esempio n. 1
0
        //add url to Collection:
        //POST api/Feed
        public void Post([FromBody] FeedUrl value)
        {
            //Db:
            //------------------------------------------------------
            string conStr =
                System.Configuration.ConfigurationManager.
                ConnectionStrings["Model1"].ConnectionString;

            using (SqlConnection con = new SqlConnection(conStr))
            {
                try
                {
                    //
                    // Open the SqlConnection.
                    //
                    con.Open();
                    //
                    // The following code uses an SqlCommand based on the SqlConnection.
                    //


                    using (SqlCommand command = new SqlCommand("INSERT INTO " + value.col + "(feedUrl) VALUES('" + value.urlValue + "');", con))
                        command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                }
            }
            //---------------------------------------------------------
            string a1 = value.col;

            string a2 = value.urlValue;
        }
Esempio n. 2
0
        /// <summary>
        /// Formats string and replaces placeholders with actual values
        /// </summary>
        /// <param name="Format"></param>
        /// <returns></returns>
        public string FormatLine(string Format)
        {
            Dictionary <string, string> replacementTable = new Dictionary <string, string>
            {
                { "i", (Index + 1).ToString() },
                { "l", FeedUrl?.ToString() },
                { "n", Configuration.Instance.GetReadState(UnreadItems > 0) },
                { "U", UnreadItems.ToString() },
                { "T", TotalItems.ToString() },
                { "u", (UnreadItems.ToString() + "/" + TotalItems.ToString()).PadLeft(8) },
                { "t", Title },
                { "V", Configuration.MAJOR_VERSION },
                { "v", Configuration.VERSION },
                { "g", (Tags != null ? string.Join(" ", Tags) : "") }
            };

            var line = Formatter.FormatLine(Format, replacementTable);

            if (this.IsProcessing)
            {
                return(Configuration.Instance.LoadingPrefix + line + Configuration.Instance.LoadingSuffix);
            }
            else
            {
                return(line);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> AddFeed(FeedUrl feedUrl)
        {
            if (ModelState.IsValid)
            {
                if (await _storageService.IsFeedAlreadyCreatedByMe(feedUrl.Url))
                {
                    return(Conflict());
                }

                try
                {
                    var response = await _feedService.GetFeedAsyc(feedUrl.Url, _userService.Id);

                    response.FeedCount = response.Items.Count;
                    response.UserId    = _userService.Id;
                    await _storageService.CreateFeed(response);
                }
                catch (Exception ex)
                {
                    _telemetryClient.TrackException(ex);
                    return(StatusCode(500));
                }
                return(Ok());
            }

            return(BadRequest(ModelState));
        }
Esempio n. 4
0
        protected override void Execute(CodeActivityContext context)
        {
            var feed = SyndicationFeed.Load(
                XmlReader.Create(FeedUrl.Get(context)));

            FeedResult.Set(context, feed);
        }
Esempio n. 5
0
        /// <summary>
        /// Formats string for display by replacing placeholder strings with actual values.
        /// </summary>
        /// <param name="Format">The <see cref="string"/></param>
        /// <returns>The <see cref="string"/></returns>
        public string FormatLine(string Format)
        {
            Dictionary <string, string> replacementTable = new
                                                           Dictionary <string, string>
            {
                { "i", (Index + 1).ToString() },
                { "n", Configuration.Instance.GetReadState(this.IsNew) },
                { "D", Configuration.Instance.GetDownloadState(this.IsDownloaded) },
                { "x", Configuration.Instance.GetDeletedState(this.Deleted) }, //only shown when article is marked as deleted, afterwards filtered out
                { "d", PublishDate.ToString(dateFormat) },
                { "u", LastUpdated.ToString(dateFormat) },
                { "t", Title },
                { "s", Summary },
                { "l", FeedUrl.ToString() },
                { "V", Configuration.MAJOR_VERSION },
                { "v", Configuration.VERSION }
            };
            var line = Formatter.FormatLine(Format, replacementTable);

            if (this.IsProcessing)
            {
                return(Configuration.Instance.LoadingPrefix + line +
                       Configuration.Instance.LoadingSuffix);
            }
            else
            {
                return(line);
            }
        }
Esempio n. 6
0
        //Add Rss :
        // POST: api/AddFeed
        public List <RSS> Post([FromBody] FeedUrl value)
        {
            //System.Threading.Thread.Sleep(1000);

            List <RSS> RSSList = RssReaderVS2017.Models.RssReader.GetRssFeed(value.urlValue);


            // return RSSList.Skip(Math.Max(0, RSSList.Count() - LastN)).ToList();
            //выбераем первые 5 постов:
            return(RSSList.Take(5).ToList());
        }
Esempio n. 7
0
        private void ButtonAddClick(object sender, RoutedEventArgs e)
        {
            if (FeedName == null)
            {
                FeedName = "";
            }
            if (FeedUrl == null)
            {
                FeedUrl = "";
            }
            FeedName = FeedName.Trim();
            FeedUrl  = FeedUrl.Trim();
            var feedName = FeedName;
            var feedUrl  = FeedUrl;
            var username = FeedUsername;
            var password = FeedPassword;

            this.StartWait();
            Program.Dispatcher = this.Dispatcher;
            var task = new Task(() =>
            {
                this.ValidateFields(feedName, feedUrl, username, password);
                Core.GameFeedManager.Get().AddFeed(feedName, feedUrl, username, password);
            });

            task.ContinueWith((continueTask) =>
            {
                var error = "";
                if (continueTask.IsFaulted)
                {
                    if (continueTask.Exception != null)
                    {
                        error = continueTask.Exception.InnerExceptions[0].Message;
                    }
                    else
                    {
                        error = "Unable to add feed. Try again later.";
                    }
                }
                this.Dispatcher.Invoke(new Action(() =>
                {
                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        this.SetError(error);
                    }
                    this.EndWait();
                    if (string.IsNullOrWhiteSpace(error))
                    {
                        this.Close(DialogResult.OK);
                    }
                }));
            });
            task.Start();
        }
Esempio n. 8
0
        public IEnumerable <BlogFeedContent> Read(string sourceFeedUrl, IDictionary filters, Pagination pagination)
        {
            var category = ExtractCategory(filters);
            var feedUrl  = new FeedUrl(sourceFeedUrl, category, pagination);

            var feedResult = _webClient.GetContent(feedUrl.Url);

            ValidateFeedResult(feedResult);
            var feedResultAsJson = _jsonParser.Parse <FeedResponseRoot>(feedResult);

            var blogFeedContent = _blogFeedContentParser.Parse(feedResultAsJson.posts);

            return(blogFeedContent);
        }
Esempio n. 9
0
        private string FormatFileName(string format)
        {
            var fullPath = format
                           .Replace("%i", Index.ToString().PadLeft(3))
                           .Replace("%n", Configuration.Instance.GetReadState(this.IsNew))
                           .Replace("%d", PublishDate.ToString(dateFormat))
                           .Replace("%t", Title)
                           .Replace("%l", FeedUrl.ToString());

            var    pathEndsAt = fullPath.LastIndexOf('\\');
            string result;

            if (pathEndsAt > 0)
            {
                var pathOnly     = fullPath.Substring(0, pathEndsAt).SanitizePath();
                var fileNameOnly = fullPath.Substring(pathEndsAt,
                                                      fullPath.Length - pathEndsAt).SanitizeFileName();

                //Limit full path length to 260 chars to avoid System.IO.PathTooLongException
                if (System.IO.Path.GetFullPath(pathOnly).Length + fileNameOnly.Length
                    > 260)
                {
                    int    dotPosition = fileNameOnly.LastIndexOf(".", StringComparison.InvariantCulture);
                    string fileName    = fileNameOnly.Substring(0, dotPosition);
                    string extension   = fileNameOnly.Substring(dotPosition,
                                                                fileNameOnly.Length - dotPosition);
                    fileNameOnly = fileName.Substring(0,
                                                      fileName.Length - System.IO.Path.GetFullPath(pathOnly).Length -
                                                      extension.Length) + extension;
                }
                result = pathOnly + "\\" + fileNameOnly;
            }
            else
            {
                result = fullPath.SanitizeFileName();
            }

            if (!Path.IsPathRooted(result))
            {
                result = System.IO.Path.GetFullPath(result);
            }

            return(result);
        }
Esempio n. 10
0
        public bool LoadUpdaterConfig()
        {
            string cfgfile = Assembly.GetExecutingAssembly().Location + ".config";

            if (File.Exists(cfgfile))
            {
                var doc = new XmlDocument
                {
                    XmlResolver = null
                };
                doc.Load(cfgfile);
                XmlNodeList elemList = doc.GetElementsByTagName("configuration");
                if (elemList?.Count > 0)
                {
                    var elem = elemList[0] as XmlElement;
                    if (elem != null)
                    {
                        elemList = elem.GetElementsByTagName("feed-url");
                        if (elemList?.Count > 0)
                        {
                            elem = elemList[0] as XmlElement;
                            if (elem != null)
                            {
                                FeedUrl = elem.InnerText;
                                if (!FeedUrl.EndsWith("/"))
                                {
                                    FeedUrl += "/";
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
 public void PostUrl([FromBody] FeedUrl value)
 {
     RssReaderVS2017.Models.RssReader.DeleteUrl(value);
 }