public async Task <IHttpActionResult> PutFeedConfig(int id, FeedConfig feedConfig) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != feedConfig.qno) { return(BadRequest()); } db.Entry(feedConfig).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FeedConfigExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void InitializeConfig(FeedConfig config) { config.BasePath = System.Configuration.ConfigurationManager.AppSettings["BasePath"]; config.Feeds.Add(new FeedDefinition { Name = "dotnetrocks", LatestDownload = DateTime.Today.AddDays(-7), Url = "http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master", }); }
public async Task <IHttpActionResult> GetFeedConfig(int id) { FeedConfig feedConfig = await db.FeedConfigs.FindAsync(id); if (feedConfig == null) { return(NotFound()); } return(Ok(feedConfig)); }
public async Task <IHttpActionResult> PostFeedConfig([FromUri] FeedConfig feedConfig) { string url2 = ConfigurationManager.AppSettings["Backup"]; WebRequest wrGETURL1; url2 = url2 + "a"; wrGETURL1 = WebRequest.Create(url2); Stream objStream1; objStream1 = wrGETURL1.GetResponse().GetResponseStream(); StreamReader objReader1 = new StreamReader(objStream1); String response = objReader1.ReadLine(); Console.Write(response); int count = 1; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var record in db.FeedConfigs) { count = record.qno; } feedConfig.qno = count + 1; try { db.FeedConfigs.Add(feedConfig); await db.SaveChangesAsync(); } catch (DbUpdateException) { } foreach (var pin in db1.Feeds) { db1.Feeds.Remove(pin); } try { await db1.SaveChangesAsync(); } catch (Exception e) { } return(CreatedAtRoute("DefaultApi", new { id = feedConfig.qno }, feedConfig)); }
public async Task <String> DeleteFeedConfig(int id) { int count = 0; FeedConfig feedConfig = await db.FeedConfigs.FindAsync(id); if (feedConfig == null) { return("0"); } else { db.FeedConfigs.Remove(feedConfig); await db.SaveChangesAsync(); } return("1"); }
/// <summary> /// User overridable callback. /// <p /> /// Is called when an Actor is started. /// Actors are automatically started asynchronously when created. /// Empty default implementation. /// </summary> protected override void PreStart() { // start reading the config file if (File.Exists(this.configFile)) { Logger.Log(LogSeverity.Information, LogCategory, "Loading existing config"); var json = File.ReadAllText(this.configFile); this.currentConfig = JsonConvert.DeserializeObject <FeedConfig>(json); } else { // create one! Logger.Log(LogSeverity.Information, LogCategory, "Creating fresh config"); this.currentConfig = new FeedConfig(); this.InitializeConfig(this.currentConfig); this.SaveCurrentConfig(); } this.Self.Tell(ConfigurationLoadedMessage); }
private Embed GetEmbed(FeedItem feedItem, FeedConfig feedConfig) { // TODO: Get UserAccount and link to appropriate pages, these bugs relate to that: // - Exits when null exception (no user with that username): // - Just catch it and pass a placeholder "user unknown" or something // - People with space in their name. Haven't tested this yet but I am pretty sure it won't work var description = new Converter().Convert(feedItem.Description) .Replace("<span class=\"printuser\">", "").Replace("</span>", ""); if (feedConfig.NewPageAnnouncement) { return(GetAnnouncementEmbed(feedItem, feedConfig, description)); } // There is a bug in the Html2Markdown library that inserts about 10 newlines instead of like 2 so this has to be in place // (not needed cuz I got rid of the whole section lol) // description = Regex.Replace(description, @"\n{4,}", "\n\n\n"); // Remove two redundant lines var split = description.Split("\n").ToList(); split.RemoveRange(2, 2); // And remove the preview split.RemoveRange(4, split.Count - 4); if (split.Last() == "\n") { split.RemoveAt(split.Count - 1); } description = string.Join("\n", split); return(new EmbedBuilder { Title = feedItem.Title, Description = string.IsNullOrEmpty(feedConfig.CustomDescription) ? description : feedConfig.CustomDescription, Color = feedConfig.EmbedColor == 0 ? Color.Blue : new Color(feedConfig.EmbedColor), // Adding one hour here cuz timezones Footer = new EmbedFooterBuilder().WithText(feedItem.PublishingDate?.AddHours(1).ToString(CultureInfo.InvariantCulture)) }.Build()); }
private Embed GetAnnouncementEmbed(FeedItem feedItem, FeedConfig feedConfig, string text) { var title = Regex.Match(feedItem.Title, "\"(.*)\" - .*").Groups[1].Value; var author = GetUsername(text); var description = new StringBuilder("Nový článek na wiki! Yay! \\o/\n"); if (!(author is null)) { var account = _accounts.GetAccountByWikidot(author); // TODO: fix this /* * if (!(account is null)) * { * var user = _client.GetUser(account.Id) as SocketGuildUser; * description.Append($"[{title}]({feedItem.Link}) od uživatele {user?.Mention}"); * } */ // else description.Append($"[{title}]({feedItem.Link}) od uživatele `{author}`"); }
private async Task <List <FeedItem> > GetNewItems(FeedConfig feedConfig) { Feed feed; if (!feedConfig.RequireAuth) { feed = await FeedReader.ReadAsync(feedConfig.Link); } else { // Basic HTTP auth _webClient.Credentials = new NetworkCredential(feedConfig.Username, feedConfig.Password); var response = _webClient.DownloadString(feedConfig.Link); feed = FeedReader.ReadFromString(response); } var lastUpdate = _lastUpdates[feedConfig]; if (lastUpdate is null) { _lastUpdates[feedConfig] = feed.LastUpdatedDate; return(null); } // If latest item is older than latest stored item, continue if (lastUpdate > feed.LastUpdatedDate) { return(null); } _lastUpdates[feedConfig] = feed.LastUpdatedDate; return(feedConfig.Filter is null ? feed.Items.Where(x => x.PublishingDate > lastUpdate).ToList() : feed.Items.Where(x => x.PublishingDate > lastUpdate && feedConfig.Filter.Any(x.Title.Contains)).ToList()); }
public List<FeedConfig> GetFeedConfig() { List<FeedConfig> ret = null; // Zentrale Konfigurationsdatei string url = "https://raw.github.com/00091701/ADFC-NewsApp-Mono/master/FeedConfig.json"; JsonValue jsonValue = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = true; request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.Method = "GET"; jsonValue = (JsonObject)JsonObject.Load(request.GetResponse().GetResponseStream()); } catch(WebException ex) { System.Diagnostics.Debug.WriteLine(string.Format("Fehler beim Abruf des Feeds: {0} - ex: ", url, ex.ToString())); } if (jsonValue != null && jsonValue.Count > 0) { ret = new List<FeedConfig>(); foreach (JsonValue feed in (jsonValue["Feeds"] as JsonArray)) { FeedConfig feedConfig = new FeedConfig(); feedConfig.Name = (string)feed["Name"]; feedConfig.Url = (string)feed["URL"]; if (feed.ContainsKey("CategoryFilter") && !string.IsNullOrEmpty((string)feed["CategoryFilter"])) feedConfig.CategoryFilter = (string)feed["CategoryFilter"]; switch((string)feed["FeedType"]) { case "News": feedConfig.FeedType = FeedTypes.News; break; case "Dates": feedConfig.FeedType = FeedTypes.Dates; break; default: feedConfig.FeedType = FeedTypes.UNSET; break; } switch((string)feed["URLType"]) { case "RSS": feedConfig.UrlType = UrlTypes.RSS; break; case "ICS": feedConfig.UrlType = UrlTypes.ICS; break; default: feedConfig.UrlType = UrlTypes.UNSET; break; } if (!string.IsNullOrEmpty(feedConfig.Name) && !string.IsNullOrEmpty(feedConfig.Url) && feedConfig.FeedType != FeedTypes.UNSET && feedConfig.UrlType != UrlTypes.UNSET) ret.Add(feedConfig); } } return ret; }
public List <FeedConfig> GetFeedConfig() { List <FeedConfig> ret = null; // Zentrale Konfigurationsdatei string url = "https://raw.github.com/00091701/ADFC-NewsApp-Mono/master/FeedConfig.json"; JsonValue jsonValue = null; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = true; request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.Method = "GET"; jsonValue = (JsonObject)JsonObject.Load(request.GetResponse().GetResponseStream()); } catch (WebException ex) { System.Diagnostics.Debug.WriteLine(string.Format("Fehler beim Abruf des Feeds: {0} - ex: ", url, ex.ToString())); } if (jsonValue != null && jsonValue.Count > 0) { ret = new List <FeedConfig>(); foreach (JsonValue feed in (jsonValue["Feeds"] as JsonArray)) { FeedConfig feedConfig = new FeedConfig(); feedConfig.Name = (string)feed["Name"]; feedConfig.Url = (string)feed["URL"]; if (feed.ContainsKey("CategoryFilter") && !string.IsNullOrEmpty((string)feed["CategoryFilter"])) { feedConfig.CategoryFilter = (string)feed["CategoryFilter"]; } switch ((string)feed["FeedType"]) { case "News": feedConfig.FeedType = FeedTypes.News; break; case "Dates": feedConfig.FeedType = FeedTypes.Dates; break; default: feedConfig.FeedType = FeedTypes.UNSET; break; } switch ((string)feed["URLType"]) { case "RSS": feedConfig.UrlType = UrlTypes.RSS; break; case "ICS": feedConfig.UrlType = UrlTypes.ICS; break; default: feedConfig.UrlType = UrlTypes.UNSET; break; } if (!string.IsNullOrEmpty(feedConfig.Name) && !string.IsNullOrEmpty(feedConfig.Url) && feedConfig.FeedType != FeedTypes.UNSET && feedConfig.UrlType != UrlTypes.UNSET) { ret.Add(feedConfig); } } } return(ret); }
public async Task <String> updatefeedback(int id, String feedback, String questionno) { int totalhappy = 0, totalsatisfied = 0, totalunhappy = 0; string url = ConfigurationManager.AppSettings["exportfeedback"]; string url1 = ConfigurationManager.AppSettings["getmatrix"]; int pos = 1; int count = 0; int temp; string [] questions = new string[id]; string url2 = ConfigurationManager.AppSettings["Backup"]; WebRequest wrGETURL1; url2 = url2 + "u"; wrGETURL1 = WebRequest.Create(url2); Stream objStream1; objStream1 = wrGETURL1.GetResponse().GetResponseStream(); StreamReader objReader1 = new StreamReader(objStream1); String response = objReader1.ReadLine(); Console.Write(response); for (int i = 0; i < feedback.Length - 1; i++) { if (feedback[i] != '$') { questions[count] = questions[count] + feedback[i]; } else { count++; } } string[] qno = questionno.Split('$'); for (int i = 0; i < id; i++) { temp = Int32.Parse(qno[i]); FeedConfig feedConfig = await db.FeedConfigs.FindAsync(temp); if (!(feedConfig.Question.Equals(questions[i]))) { feedConfig.Question = questions[i]; feedConfig.Dt = DateTime.Now; } db.Entry(feedConfig).State = EntityState.Modified; try { await db.SaveChangesAsync(); pos++; } catch (DbUpdateConcurrencyException) { return("error"); } } //count = 0; /*foreach (var record in db.FeedConfigs) * { * count++; * } * WebRequest wrGETURL; * * wrGETURL = WebRequest.Create(url1); * * Stream objStream; * objStream = wrGETURL.GetResponse().GetResponseStream(); * StreamReader objReader = new StreamReader(objStream); * String matrix = objReader.ReadLine(); * string[] temparray = matrix.Split(']'); * temparray[0] = temparray[0].Replace("[", ""); * string[] happyforeachquestion = temparray[0].Split(','); * * temparray[1] = temparray[1].Replace("[", ""); * temparray[1].Insert(0, ""); * string[] satisfiedforeachquestion = temparray[1].Split(','); * * temparray[2] = temparray[2].Replace("[", ""); * temparray[2].Insert(0, ""); * * string[] unhappyforeachquestion = temparray[2].Split(','); * * for (int i = 0; i < count; i++) * { * totalhappy = totalhappy + Int32.Parse(happyforeachquestion[i]); * } * for (int i = 1; i <= count; i++) * { * totalsatisfied = totalsatisfied + Int32.Parse(satisfiedforeachquestion[i]); * } * for (int i = 1; i <= count; i++) * { * totalunhappy = totalunhappy + Int32.Parse(unhappyforeachquestion[i]); * } * DataTable stat = new DataTable("Total"); * stat.Columns.Add("QUESTIONS"); * stat.Columns.Add("STATUS"); * stat.Columns.Add("COUNT"); * * //stat.Columns.Add("TOTAL SATISFIED"); * //stat.Columns.Add("TOTAL UNHAPPY"); * //stat.Rows.Add(totalhappy,totalsatisfied,totalunhappy); * int tcount = 0; * foreach (var record in db.FeedConfigs) * { * stat.Rows.Add(record.Question, "HAPPY", happyforeachquestion[tcount]); * tcount++; * } * tcount = 1; * foreach (var record in db.FeedConfigs) * { * stat.Rows.Add(record.Question, "SATISFIED", satisfiedforeachquestion[tcount]); * tcount++; * } * tcount = 1; * foreach (var record in db.FeedConfigs) * { * stat.Rows.Add(record.Question, "UNHAPPY", unhappyforeachquestion[tcount]); * tcount++; * } * FeedConfigsController p = new FeedConfigsController(); * //Patient patient = await db.Patients.FindAsync(id); * DataTable employeeTable = new DataTable("Patient feedbacks"); * employeeTable.Columns.Add("SNO"); * employeeTable.Columns.Add("MRNO"); * employeeTable.Columns.Add("PATIENT FEEDS"); * employeeTable.Columns.Add("REMARKS"); * employeeTable.Columns.Add("DATE"); * foreach (var pin in db1.Feeds) * { * employeeTable.Rows.Add(pin.sno, pin.MRNO, pin.Patient_feeds, pin.Remarks, pin.Dt); * } * * * //Create a DataSet with the existing DataTables * DataSet ds = new DataSet("Organization"); * ds.Tables.Add(employeeTable); * ds.Tables.Add(stat); * * p.ExportDataSetToExcel(ds);*/ foreach (var pin in db1.Feeds) { db1.Feeds.Remove(pin); } try { await db1.SaveChangesAsync(); } catch (Exception e) { } return("Feedback updated successfully"); }