private void BtnStart_Click(object sender, EventArgs e) { btnStart.Enabled = false; txtLog.Text += "STARTING\r\n"; txtLog.Update(); BBL bbl = new BBL(); bbl.load(txtBBL.Text); string[] files = Directory.GetFiles(txtDir.Text, "*.bbc"); foreach (string file in files) { BBC bbc = new BBC(); txtLog.Text += file + "\r\n"; txtLog.Update(); string error = bbc.load(file); if (error != null) { txtLog.Text = "[ERROR][" + file + "] " + error + "\r\n"; txtLog.Update(); } bbl.removeBlocks(bbc); } bbl.save(txtOutput.Text); txtLog.Text += "DONE\r\n"; btnStart.Enabled = true; }
// GET: /Web/PlayBBC public ContentResult PlayBBC( string pid) { if (String.IsNullOrEmpty(Running.RunningProgram)) { DesktopClient.SendSpecialkey("ClearDesktop"); } Running.LaunchProgram("Web", "-k -nomerge " + BBC.GetTvPlayerUrl(pid)); return(Content("OK")); }
// GET: /Music/PlayListenAgain public ContentResult PlayListenAgain( string pid) { string name; string station; DateTime startTime; string streamUrl = BBC.GetStreamUrl(pid, out name, out station, out startTime); JRMC.SetStreaming(name, station, startTime); JRMC.GetXml(JRMC.Url + "Control/CommandLine?Arguments=/Play " + HttpUtility.UrlEncode(streamUrl)); return(this.Content("")); }
private void BtnStart_Click(object sender, EventArgs e) { btnStart.Enabled = false; txtLog.Text += "STARTED\r\n"; List <string> results = new List <string>(); Dictionary <string, BBC> coverages = new Dictionary <string, BBC>(); string[] files = Directory.GetFiles(txtCoverage.Text, "*"); string bestName = ""; uint bestCount = 0; foreach (string file in files) { BBC tmp = new BBC(); tmp.load(file); coverages[Path.GetFileName(file)] = tmp; if (tmp.getCount() > bestCount) { bestCount = tmp.getCount(); bestName = Path.GetFileName(file); } } while (results.Count < Convert.ToUInt32(txtCount.Text)) { txtLog.Text += "[" + bestCount + "] " + bestName + "\r\n"; txtLog.Update(); BBC tmp = coverages[bestName]; coverages.Remove(bestName); results.Add(bestName); bestCount = 0; foreach (KeyValuePair <string, BBC> entry in coverages) { entry.Value.removeBlocks(tmp); if (entry.Value.getCount() > bestCount) { bestCount = entry.Value.getCount(); bestName = Path.GetFileName(entry.Key); } } } foreach (string file in results) { string fileReal = file.Substring(0, file.LastIndexOf(".")); File.Copy(txtInput.Text + "\\" + fileReal, txtOutput.Text + "\\" + fileReal); } txtLog.Text += "DONE\r\n"; btnStart.Enabled = true; }
public static void Main(string[] args) { Wheels w = new Yamaha(5); Wheels w2 = new BBC(7); Engine e = new Engine(500); Body b = new Body("Blue"); Car_Agregation carAgregation = new Car_Agregation(w, e, b); carAgregation.Info(); Car_Composition carComposition = new Car_Composition(); carComposition.Info(); }
private async void BtnStart_Click(object sender, EventArgs e) { btnStart.Enabled = false; log("STARTING \r\n"); string[] files = Directory.GetFiles(txtDir.Text, "*.bbc"); string error; if (files.Length == 0) { MessageBox.Show("No .bbc files"); return; } log("[INFO]['" + files[0] + "'] loading\r\n"); BBC baseObj = new BBC(); error = baseObj.load(files[0]); if (error != null) { log("[ERROR]['" + files[0] + "'] " + error); btnStart.Enabled = true; return; } for (int x = 1; x < files.Length; x++) { log("[INFO]['" + files[x] + "'] loading\r\n"); BBC tmpObj = new BBC(); error = tmpObj.load(files[x]); if (error != null) { log("[ERROR]['" + files[x] + "'] " + error); btnStart.Enabled = true; return; } baseObj.commons(tmpObj); } baseObj.save(txtOutput.Text); log("ALL DONE \r\n"); btnStart.Enabled = true; }
/// <summary> /// Delete a link /// </summary> /// <param name="readerCreator">DataReader Creator</param> /// <param name="linkId">Link to delete</param> /// <param name="identifier">User ID or id username involved</param> /// <param name="siteID">Site ID involved</param> /// <param name="byDnaUserId"></param> public static void DeleteLink(IDnaDataReaderCreator readerCreator, BBC.Dna.Users.CallingUser viewingUser, string identifier, int siteID, int linkId, bool byDnaUserId) { int dnaUserId = 0; if (!byDnaUserId) { // fetch all the lovely intellectual property from the database using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("getdnauseridfromidentityusername")) { reader.AddParameter("identityusername", identifier); reader.Execute(); if (reader.HasRows && reader.Read()) { dnaUserId = reader.GetInt32NullAsZero("userid"); } else { throw ApiException.GetError(ErrorType.UserNotFound); } } } else { try { dnaUserId = Convert.ToInt32(identifier); } catch (Exception) { throw ApiException.GetError(ErrorType.UserNotFound); } } //You can't delete someone else's links (unless you're an editor or superuser) if (viewingUser.UserID == dnaUserId || viewingUser.IsUserA(BBC.Dna.Users.UserTypes.Editor) || viewingUser.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)) { using (IDnaDataReader dataReader = readerCreator.CreateDnaDataReader("deletelink")) { dataReader.AddParameter("linkid", linkId); dataReader.AddParameter("userID", dnaUserId); dataReader.AddParameter("siteID", siteID); dataReader.Execute(); } } else { throw ApiException.GetError(ErrorType.NotAuthorized); } }
private static void NotifyAuthorOnPersonalSpace(IDnaDataReaderCreator readerCreator, int submitterId, string submitterUsername, int editorId, string editorUsername, int articleId, BBC.Dna.Sites.ISite site, int reviewForumId, int newThreadForumId, int newThreadThreadId, int newThreadPostId, string subject, string comments) { int personalSpaceForumID = FetchPersonalSpaceForum(readerCreator, editorId, site.SiteID); ReviewForum reviewForum = ReviewForum.CreateFromDatabase(readerCreator, reviewForumId, true); string generatedSubject = "Your entry has been submitted to '" + reviewForum.ForumName + "'"; string generatedBody = "Entry: " + subject + " - A" + articleId + " \n"; generatedBody += "Author: " + editorUsername + " - U" + editorId + " \n"; generatedBody += "Submitter: " + submitterUsername + " - U" + submitterId + "\n\n"; generatedBody += "This is an automated message.\n\n"; generatedBody += "Your entry above has been submitted to the Review Forum '" + reviewForum.ForumName + "'" + " by the Researcher named above. For more information about what happens next check out <./>ReviewForums-Next</.>.\n\n"; generatedBody += "You can see the discussion about your entry at " + "F" + newThreadForumId.ToString() + "?thread=" + newThreadThreadId.ToString() + "\n\n"; generatedBody += "If you'd rather your entry wasn't in this Review Forum then you can remove it by visiting " + "<./>" + reviewForum.UrlFriendlyName + "</.> and clicking on the relevant 'Remove' link." + " To prevent it being put into a Review Forum in the future, please click on the 'Edit Entry' button and tick the 'Not for Review' box.\n\n"; bool forceModeration; CheckForProfanities(site, generatedBody, out forceModeration); //TODO URL and Email filter // save the Post in the database ThreadPost post = new ThreadPost(); post.InReplyTo = 0; post.ThreadId = 0; post.Subject = generatedSubject; post.Text = generatedBody; post.Style = PostStyle.Style.plaintext; post.CreateForumPost(readerCreator, submitterId, personalSpaceForumID, false, false, "", System.Guid.Empty, false, false, false, forceModeration, string.Empty, string.Empty); }
/// <summary> /// /// </summary> /// <param name="postid"></param> /// <param name="forumid"></param> /// <param name="status"></param> /// <param name="edittedText"></param> private void ModerateComment(int postid, int forumid, BBC.Dna.Component.ModeratePosts.Status status, string edittedText) { using (FullInputContext _context = new FullInputContext(true)) { int threadId = 0, modId = 0, threadModStatus = 0; using (IDnaDataReader dataReader = _context.CreateDnaDataReader("")) { dataReader.ExecuteDEBUGONLY("select modid, threadid, forumid, status from threadmod where postid=" + postid.ToString()); if (dataReader.Read()) { threadId = dataReader.GetInt32NullAsZero("threadid"); modId = dataReader.GetInt32NullAsZero("modid"); threadModStatus = dataReader.GetInt32NullAsZero("status"); forumid = dataReader.GetInt32NullAsZero("forumid"); } } using (IDnaDataReader dataReader = _context.CreateDnaDataReader("moderatepost")) { dataReader.AddParameter("forumid", forumid); dataReader.AddParameter("threadid", threadId); dataReader.AddParameter("postid", postid); dataReader.AddParameter("modid", modId); dataReader.AddParameter("status", (int)status); dataReader.AddParameter("notes", ""); dataReader.AddParameter("referto", 0); dataReader.AddParameter("referredby", 0); dataReader.AddParameter("moderationstatus", threadModStatus); dataReader.Execute(); } if(status == BBC.Dna.Component.ModeratePosts.Status.PassedWithEdit) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatepostdetails")) { dataReader.AddParameter("userid", TestUserAccounts.GetNormalUserAccount.UserID); dataReader.AddParameter("postid", postid); dataReader.AddParameter("subject", ""); dataReader.AddParameter("text", edittedText); dataReader.AddParameter("setlastupdated", true); dataReader.AddParameter("forcemoderateandhide", 0); dataReader.AddParameter("ignoremoderation", 1); dataReader.Execute(); } } } }
/// <summary> /// Clips the given page to the Users user page /// </summary> /// <param name="cache"></param> /// <param name="readerCreator"></param> /// <param name="user">User who's clipping</param> /// <param name="siteId">Site Id we're clipping in</param> /// <param name="pageType"> textual type of page we're clipping</param> /// <param name="objectID">ID of page we're clipping</param> /// <param name="linkDescription">Textual description (link text)</param> /// <param name="linkGroup">textual (optional) group containing link (user defined)</param> /// <param name="isPrivate">Whether the link is private</param> public static void ClipPageToUserPage(ICacheManager cache, IDnaDataReaderCreator readerCreator, BBC.Dna.Users.User user, int siteId, string pageType, int objectID, string linkDescription, string linkGroup, bool isPrivate) { using (IDnaDataReader dataReader = readerCreator.CreateDnaDataReader("addlinks")) { dataReader.AddParameter("sourcetype", "userpage"); dataReader.AddParameter("sourceid", user.UserID); dataReader.AddParameter("desttype", pageType); dataReader.AddParameter("destid", objectID); dataReader.AddParameter("submitterid", user.UserID); dataReader.AddParameter("description", linkDescription); dataReader.AddParameter("group", linkGroup); dataReader.AddParameter("ishidden", isPrivate); dataReader.AddParameter("teamid", user.TeamID); dataReader.AddParameter("url", String.Empty); dataReader.AddParameter("title", DBNull.Value); dataReader.AddParameter("relationship", "Bookmark"); dataReader.AddParameter("destsiteid", siteId); try { dataReader.Execute(); if (dataReader.HasRows) { if (dataReader.Read()) { string result = dataReader.GetStringNullAsEmpty("result"); if (result != "success") { throw ApiException.GetError(ErrorType.AlreadyLinked); } } } } catch (SqlException ex) { if (ex.Message.Contains("Violation of UNIQUE")) { //Don't need to flag this error up now //They're just trying to bookmark the same thing just carry on return; //throw ApiException.GetError(ErrorType.AlreadyLinked); } else { throw ex; } } } }
/// <summary> /// Hides a thread with a CallingUser IsSuperUser check /// </summary> /// <param name="forumId"></param> /// <param name="threadId"></param> /// <param name="user">Calling User</param> public void HideThreadWithCallingUser(int forumId, int threadId, BBC.Dna.Users.ICallingUser user) { if (user.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)) {//do work using (IDnaDataReader reader = _creator.CreateDnaDataReader("SetThreadVisibletoUsers")) { reader.AddParameter("threadid", threadId); reader.AddParameter("forumid", forumId); reader.AddParameter("Visible", false); reader.Execute(); if (reader.Read()) { if (reader.GetInt32NullAsZero("ThreadBelongsToForum") != 1) { throw new BBC.Dna.Api.ApiException("Unable to hide thread, doesn't belong to the Forum.", BBC.Dna.Api.ErrorType.UnableToHideUnHideThread); } } else { throw new BBC.Dna.Api.ApiException("Unable to hide thread", BBC.Dna.Api.ErrorType.UnableToHideUnHideThread); } } } else { throw new BBC.Dna.Api.ApiException("Unable to hide thread", BBC.Dna.Api.ErrorType.NotAuthorized); } }
static public PageUi GetPageUi(IDnaDataReaderCreator creator, Article guide, BBC.Dna.Objects.User viewingUser) { PageUi pageUi = new PageUi(viewingUser.UserId); // Update the edit link if the user is allowed bool editable = false; string editableLink = "/UserEdit"; if (!guide.IsDeleted && guide.HasEditPermission(viewingUser)) { editable = true; editableLink += guide.H2g2Id.ToString(); } // Now set the recommended link string recommendLink = "RecommendEntry?h2g2ID=" + guide.H2g2Id.ToString() + "&mode=POPUP"; bool recommendable = guide.ArticleInfo.Status.Type == 3 && viewingUser.UserId > 0 && (viewingUser.IsEditor || viewingUser.IsScout); // If this is a sub editors copy of a recommended entry, and the viewer is // the sub editor, then give them a button to say they have finished subbing // it and want to return the entry to the editors string subbedLink = "SubmitSubbedEntry?h2g2ID=" + guide.ArticleInfo.H2g2Id.ToString() + "&mode=POPUP"; bool subeditor = viewingUser.UserId > 0 && (viewingUser.IsEditor || viewingUser.IsSubEditor) && guide.CheckIsSubEditor(viewingUser, creator); // Setup the discuss UI string discussLink = "AddThread?forum=" + guide.ArticleInfo.ForumId.ToString() + "&article=" + guide.ArticleInfo.H2g2Id.ToString(); bool discussable = !guide.IsDeleted && guide.ArticleInfo.ForumId > 0 && viewingUser.UserId > 0; pageUi.EditPage = new PageUiElement(editableLink, editable); pageUi.RecommendEntry = new PageUiElement(recommendLink, recommendable); pageUi.EntrySubbed = new PageUiElement(subbedLink, subeditor); pageUi.Discuss = new PageUiElement(discussLink, discussable); pageUi.SiteHome = new PageUiElement("/", true); pageUi.DontPanic = new PageUiElement("/DONTPANIC", true); pageUi.Search = new PageUiElement("/Search", true); return pageUi; }
public static ReviewSubmission SubmitArticle(IDnaDataReaderCreator readerCreator, int submitterId, string submitterUsername, BBC.Dna.Sites.ISite site, int articleId, string subject, int editorId, string editorUsername, int reviewForumId, string comments) { ReviewSubmission reviewSubmissionResponse = new ReviewSubmission(); string subjectDB = "A" + articleId.ToString() + " - " + subject; string editedComments = "Entry: " + subject + " - A" + articleId.ToString() + "\n"; editedComments += "Author: " + editorUsername + " - U" + editorId.ToString() + "\n\n"; editedComments += comments; string hash = String.Empty; string hashString = subject + "<:>" + editedComments + "<:>" + submitterId.ToString() + "<:>0<:>0<:>0<:>ToReviewForum"; using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("addarticletoreviewforummembers")) { reader.AddParameter("h2g2id", articleId); reader.AddParameter("reviewforumid", reviewForumId); reader.AddParameter("submitterid", submitterId); reader.AddParameter("subject", subjectDB); reader.AddParameter("content", editedComments); reader.AddParameter("Hash", DnaHasher.GenerateHash(hashString)); reader.Execute(); // Check to see if we found anything if (reader.HasRows && reader.Read()) { reviewSubmissionResponse.ArticleH2G2Id = articleId; reviewSubmissionResponse.NewThreadPostId = reader.GetInt32NullAsZero("postid"); reviewSubmissionResponse.NewThreadThreadId = reader.GetInt32NullAsZero("threadid"); reviewSubmissionResponse.NewThreadForumId = reader.GetInt32NullAsZero("forumid"); } else { throw ApiException.GetError(ErrorType.AddIntoReviewForumFailed); } } //set the lastupdatefield on the guideentry //this is done by a trigger so update a field to be the same as it already is using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("ForceUpdateEntry")) { reader.AddParameter("h2g2id", articleId); reader.Execute(); } if (submitterId != editorId) { NotifyAuthorOnPersonalSpace(readerCreator, submitterId, submitterUsername, editorId, editorUsername, articleId, site, reviewForumId, reviewSubmissionResponse.NewThreadForumId, reviewSubmissionResponse.NewThreadThreadId, reviewSubmissionResponse.NewThreadPostId, subject, comments); } return reviewSubmissionResponse; }
/// <summary> /// Closes a thread with a CallingUser IsSuperUser check /// </summary> /// <param name="currentSiteId"></param> /// <param name="forumId"></param> /// <param name="threadId"></param> public void CloseThreadWithCallingUser(int currentSiteId, int forumId, int threadId, BBC.Dna.Users.ICallingUser user, ISiteList siteList) { bool authorised = (user.IsUserA(BBC.Dna.Users.UserTypes.Editor) || user.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)); if (!authorised && siteList.GetSiteOptionValueBool(currentSiteId, "Forum", "ArticleAuthorCanCloseThreads")) {//check if author can modify forum thread. authorised = IsUserAuthorForArticle(forumId); } if (authorised) {//do work CallCloseThreadSP(threadId); } else { throw new BBC.Dna.Api.ApiException("Unable to close thread", BBC.Dna.Api.ErrorType.NotAuthorized); } }
private static void CheckForProfanities(BBC.Dna.Sites.ISite site, string textToCheck, out bool forceModeration) { string matchingProfanity; List<Term> terms = null; forceModeration = false; ProfanityFilter.FilterState state = ProfanityFilter.CheckForProfanities(site.ModClassID, textToCheck, out matchingProfanity, out terms, 0); if (ProfanityFilter.FilterState.FailBlock == state) { throw ApiException.GetError(ErrorType.ProfanityFoundInText); } if (ProfanityFilter.FilterState.FailRefer == state) { forceModeration = true; } }
/// <summary> /// Hides a Thread Post /// </summary> /// <param name="readerCreator"></param> /// <param name="postId"></param> /// <param name="hiddenStatus"></param> /// <returns></returns> static public void HideThreadPost(IDnaDataReaderCreator readerCreator, int postId, BBC.Dna.Moderation.Utils.CommentStatus.Hidden hiddenStatus) { using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("HidePost")) { reader.AddParameter("PostID", postId); reader.AddParameter("HiddenID", hiddenStatus); reader.Execute(); } }
private void AddLatestPreModPostingToParamList(DnaTestURLRequest.ParamList paramList, ModerationItemStatus status, BBC.Dna.Api.PostStyle.Style postStyle) { paramList.Add("postid", 0); paramList.Add("alerts", 0); var pmp = GetLatestPreModPosting(); paramList.Add("threadid", pmp.threadId.HasValue ? pmp.threadId.Value : 0); paramList.Add("modid", pmp.modId); paramList.Add("forumid", pmp.forumId); paramList.Add("siteid", _siteid); paramList.Add("decision", (int)status); paramList.Add("postStyle", (int)postStyle); paramList.Add("skin", "purexml"); }
private void PreviewPost(string previewText, string expectedText, BBC.Dna.Objects.QuoteEnum quote) { try { var url = String.Format("PostToForum?skin=purexml&forumid=" + _forumId.ToString()); switch(quote) { case BBC.Dna.Objects.QuoteEnum.QuoteId: url += "&AddQuoteID=1"; break; case BBC.Dna.Objects.QuoteEnum.QuoteUser: url += "&AddQuoteUser=1"; break; } url += "&d_identityuserid=dotnetnormaluser"; var request = new DnaTestURLRequest(_siteName); var postParams = new Queue<KeyValuePair<string, string>>(); postParams = new Queue<KeyValuePair<string, string>>(); postParams.Enqueue(new KeyValuePair<string, string>("threadid", _threadId.ToString())); postParams.Enqueue(new KeyValuePair<string, string>("inreplyto", _inReplyTo.ToString())); postParams.Enqueue(new KeyValuePair<string, string>("dnapoststyle", "1")); postParams.Enqueue(new KeyValuePair<string, string>("forum", _forumId.ToString())); postParams.Enqueue(new KeyValuePair<string, string>("subject", "test post")); postParams.Enqueue(new KeyValuePair<string, string>("body", previewText)); postParams.Enqueue(new KeyValuePair<string, string>("preview", "preview message")); request.RequestPage(url, postParams); var xml = request.GetLastResponseAsXML(); DnaXmlValidator validator = new DnaXmlValidator(xml.SelectSingleNode("/H2G2/POSTTHREADFORM").OuterXml, "PostThreadForm.xsd"); validator.Validate(); var returnedPreview = xml.SelectSingleNode("/H2G2/POSTTHREADFORM/PREVIEWBODY").InnerXml; Assert.AreEqual(expectedText, returnedPreview); } finally { } }
public static SubmitSubbedEntry ReturnArticle(IDnaDataReaderCreator readerCreator, BBC.Dna.Sites.ISite site, int userId, bool isEditor, int articleId, string comments) { SubmitSubbedEntry submitSubbedEntryResponse = new SubmitSubbedEntry(); CreateFromh2g2ID(readerCreator, userId, isEditor, articleId, comments); int entryId = articleId / 10; bool invalidEntry = false; bool userNotSub = false; bool okay = false; int recommendationStatus = 0; DateTime dateReturned = DateTime.MinValue; //Submit the article using (IDnaDataReader reader = readerCreator.CreateDnaDataReader("SubmitReturnedSubbedEntry")) { reader.AddParameter("UserID", userId); reader.AddParameter("EntryID", entryId); if (comments != String.Empty) { reader.AddParameter("Comments", comments); } reader.Execute(); // Check to see if we found anything if (reader.HasRows && reader.Read()) { invalidEntry = reader.GetBoolean("InvalidEntry"); userNotSub = reader.GetBoolean("UserNotSub"); okay = reader.GetBoolean("Success"); recommendationStatus = reader.GetInt32NullAsZero("RecommendationStatus"); if (reader.DoesFieldExist("DateReturned") && !reader.IsDBNull("DateReturned")) { dateReturned = reader.GetDateTime("DateReturned"); } } } if (invalidEntry) { throw new ApiException("Entry is not in the list of accepted scout recommendations", ErrorType.NotAuthorized); } else if (userNotSub) { throw new ApiException("You are not the Sub Editor for this Entry", ErrorType.NotAuthorized); } else if (recommendationStatus != 2) { string message = String.Empty; switch (recommendationStatus) { case 0 : { throw new ApiException("Recommendation has no status", ErrorType.WrongStatus); } case 1 : { throw new ApiException("Recommendation has not yet been allocated to a Sub Editor", ErrorType.WrongStatus); } case 3 : { throw new ApiException("Recommendation has already been submitted on " + dateReturned.ToShortDateString(), ErrorType.WrongStatus); } default: { throw new ApiException("Recommendation has wrong status", ErrorType.WrongStatus); } } } // something unspecified went wrong else if (!okay) { throw new ApiException("An unspecified error occurred whilst processing the request.", ErrorType.Unknown); } return submitSubbedEntryResponse; }