public void TestWebPageBlock() { var page=new WebContent(); var result = page.GetParseBlock<MyPage>(@"<div><p id=1><span class=title>Test</span></p></div>", x => { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(x); var nodes = doc.DocumentNode.SelectNodes(@"//div"); var resultClass=new MyPage(); foreach (var node in nodes) { var id = node.SelectSingleNode(@"p").Attributes["id"].Value; var title = node.SelectSingleNode(@"//span").InnerText; resultClass.Id = Int32.Parse(id); resultClass.Title = title; } return resultClass; }); var originResult = new MyPage {Id = 1, Title = "Test"}; Assert.AreEqual(originResult, result); }
void CallCallback(object sender, EventArgs e) { WebContent.InjectJavascriptAsync("localCallback('Hello World');").ConfigureAwait(false); }
void AddCallback(object sender, EventArgs e) { WebContent.AddLocalCallback("localCallback", HandleCallback); }
void ForwardClicked(object sender, EventArgs e) { WebContent.GoForward(); }
void BackClicked(object sender, EventArgs e) { WebContent.GoBack(); }
private void AppBarButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { string Adress = string.Format("http://www.sakhiepi.ru/winphone.aspx?sp={0}&hd=1", HelperClass.PageId); WebContent.Navigate(new Uri(Adress)); }
protected void ButtonSupprimer_Click(object sender, EventArgs e) { if ((int)Cache["QuestionnaireID"] == 0) { ValidationMessage.Text += "<br/>Choisir un questionnaire à supprimer.<br/>"; ValidationMessage.CssClass = "LabelValidationMessageErrorStyle"; ValidationMessage.Visible = true; } else { int status = 0; int statusGlobal = 0; Questionnaire questionnaire = Questionnaire.GetQuestionnaire(( int )Cache["QuestionnaireID"]); Reporter.Trace("Questionnaire delete"); ValidationMessage.Text += "<br />-----------------------------------------------------<br />"; ValidationMessage.Text += " Début de la Suppression du Questionnaire <br />"; ValidationMessage.Text += "-----------------------------------------------------<br />"; foreach (PollQuestion question in ( PollQuestionCollection )Cache["Questions"]) { PollAnswerCollection reponses = PollAnswerCollection.GetByPollQuestionID(question.PollQuestionId); foreach (PollAnswer reponse in reponses) { PollVoteCollection votes = PollVoteCollection.GetVotes(reponse.PollAnswerId); int nbVotes = PollVoteCollection.NumberOfVotesByAnswer(reponse.PollAnswerId); ValidationMessage.Text += "----- Suppression des votes : " + nbVotes.ToString() + "<br />"; foreach (PollVote vote in votes) { status = PollVote.Delete(vote.VoteId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "---- Suppression de la Réponse : " + reponse.Answer + "<br />"; status = PollAnswer.Delete(reponse.PollAnswerId); statusGlobal = statusGlobal + status; ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "--- Suppression de la Question : " + question.Question + "<br />"; status = PollQuestion.Delete(question.PollQuestionId); statusGlobal = statusGlobal + status; SessionState.Limitations.SupprimerQuestion(); ValidationMessage.Text += " status : " + status.ToString() + "<br />"; } Reporter.Trace("Questionnaire delete fin"); //PersonneCollection personnes = PersonneCollection.GetQuestionnaire( ( int )Cache[ "QuestionnaireID" ] ); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contacts : " + (( PersonneCollection )Cache["Personnes"]).Count + "<br />"; foreach (Personne p in ( PersonneCollection )Cache["Personnes"]) { ValidationMessage.Text += p.Nom + " " + p.Prenom + " " + p.EmailBureau + " " + p.Societe + "<br />"; status = Personne.Delete(p.ID_Personne); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } SessionState.Limitations.SupprimerInterviewes((( PersonneCollection )Cache["Personnes"]).Count); MemberInfo membre = MemberInfo.GetMemberInfo(questionnaire.MembreGUID); //WebContentCollection webContents = WebContentCollection.GetWebContents( membre.NomUtilisateur, questionnaire.CodeAcces.ToString() ); ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des contenus web : " + (( WebContentCollection )Cache["WebContents"]).Count + "<br />"; foreach (WebContent wc in ( WebContentCollection )Cache["WebContents"]) { ValidationMessage.Text += wc.Section + " " + wc.Utilisateur + " " + wc.Visualisateur + "<br />"; status = WebContent.Delete(wc.WebContentID); statusGlobal = statusGlobal + status; ValidationMessage.Text += "status : " + status.ToString() + "<br />"; } ValidationMessage.Text += "</br>"; ValidationMessage.Text += "Suppression des scores : " + (( ScoreCollection )Cache["Scores"]).Count + "<br />"; foreach (Score s in ( ScoreCollection )Cache["Scores"]) { status = Score.Delete(s.ScoreID); statusGlobal = statusGlobal + status; } ValidationMessage.Text += "Suppression du Questionnaire : " + questionnaire.Description + "<br />"; status = Questionnaire.Delete(questionnaire.QuestionnaireID); statusGlobal = statusGlobal + status; SessionState.Limitations.SupprimerQuestionnaire(); ValidationMessage.Text += "status : " + status.ToString() + "<br />"; ValidationMessage.Text += "<br />status global : " + statusGlobal.ToString() + "<br />"; ValidationMessage.Visible = true; // Forcer les Questionnaires a se recharger depuis la Base de Donnees SessionState.Questionnaires = null; SessionState.Questionnaire = null; Cache["QuestionnaireID"] = 0; // fermer le formulaire // On ne supprime qu'une fois ! ButtonSupprimer.Visible = false; } }
public virtual void OnWebContentSelected(WebContentListScreenlet screenlet, WebContent content) { Console.WriteLine($"WebContent selected: {content.Attributes}"); }
private async void Search(object sender, RoutedEventArgs e) { if (_client == null) { WebContent.NavigateToString(string.Format(HtmlTemplate, "<h1 class='text-monospace mdl-typography--title'>Error</h1><p>You must be connected to a mongodb first!</p>\n")); return; } ButtonPreviousPage.IsEnabled = false; ButtonNextPage.IsEnabled = false; TextPage.IsEnabled = false; WebContent.NavigateToString(string.Format(HtmlTemplate, "<h1 class='text-monospace mdl-typography--title'>Please Wait</h1><p>Searching...</p>\n")); var toPageNumber = Convert.ToInt32(TextPage.Text); if (sender != null && ((Button)sender).Name == ButtonPreviousPage.Name) { toPageNumber--; } else if (sender != null && ((Button)sender).Name == ButtonNextPage.Name) { toPageNumber++; } else if (sender != null && ((Button)sender).Name == ButtonSearch.Name) { toPageNumber = 1; _query = new DatabaseQuery(_client, "zhihu", TextBoxFilter.Text, PageSize); await _query.Init(); } try { var contentBuilder = new StringBuilder(); var count = _query.PageSize * (toPageNumber - 1); var data = await _query.GetPage(toPageNumber); foreach (var one in data) { if (_query.CollectionName.Equals("answer")) { var content = one.GetValue("content").ToString(); var answerUrl = $"https://www.zhihu.com/question/{one.GetValue("questionId")}/answer/{one.GetValue("answerId")}"; var authorUrl = $"https://www.zhihu.com/people/{one.GetValue("authorId")}"; one.Set("content", "..."); contentBuilder.Append(string.Format(HtmlContentTemplate, JsonHelper.PrettyPrint(one.ToString()), StripHtml(content), count++, $"<a target='_blank' href='{answerUrl}'>{answerUrl}</a></p><p><a target='_blank' href='{authorUrl}'>{authorUrl}</a>")); } else if (_query.CollectionName.Equals("member")) { var url = $"https://www.zhihu.com/people/{one.GetValue("memberId")}"; contentBuilder.Append(String.Format(HtmlContentTemplate, JsonHelper.PrettyPrint(one.ToString()), "<p>" + $"Avatar: <img src='{one.GetValue("avatarUrl").ToString().Replace("https://", ImageServer)}'> " + $"<a target='_blank' href='{one.GetValue("avatarUrl").ToString().Replace("https://", ImageServer).Replace("_is", "")}'>(original size)</a>" + "</p>", count++, $"<a target='_blank' href='{url}'>{url}</a>")); } else { contentBuilder.Append(string.Format(HtmlContentTemplate, JsonHelper.PrettyPrint(one.ToString()), "", count++, "")); } } WebContent.NavigateToString(string.Format(HtmlTemplate, contentBuilder)); PanelPage.Visibility = Visibility.Visible; } catch (Exception exception) { WebContent.NavigateToString(string.Format(HtmlTemplate, "<h1 class='text-monospace mdl-typography--title'>Error</h1><p>Failed to search: <pre><code>" + exception + "</code></pre></p>\n")); PanelPage.Visibility = Visibility.Hidden; } TextBoxFilter.Text = _query.SearchString; ButtonPreviousPage.IsEnabled = true; ButtonNextPage.IsEnabled = true; TextPage.IsEnabled = true; TextPageCount.Text = $" / {_query.PageCount,3:D3}"; TextPage.Text = $"{_query.CurrentPageNumber, 3:D3}"; if (_query.CurrentPageNumber == 1) { ButtonPreviousPage.IsEnabled = false; } if (_query.CurrentPageNumber == _query.PageCount) { ButtonNextPage.IsEnabled = false; } }
private async void OnConnect(object sender, RoutedEventArgs e) { if (_client == null) { TextBoxConnect.IsEnabled = false; ButtonConnect.IsEnabled = false; ButtonConnect.Content = "connecting..."; var connStr = TextBoxConnect.Text; var result = await Task.Run(() => { MongoClient client = null; var names = new ArrayList(); try { client = new MongoClient(connStr); var collections = client.GetDatabase("zhihu").ListCollections().ToList(); foreach (var collection in collections) { names.Add(collection["name"]); } return(new { Names = names, Client = client, Error = false, Exception = new Exception() }); } catch (Exception exception) { return(new { Names = names, Client = client, Error = true, Exception = exception }); } }); if (result.Error) { _client = null; TextBlockInfo.Text = "connection error: " + result.Exception.GetType().FullName; WebContent.NavigateToString(string.Format(HtmlTemplate, "<h1 class='text-monospace mdl-typography--title'>Error</h1><p>Failed to connect: <pre><code>" + result.Exception + "</code></pre></p>\n")); TextBoxConnect.IsEnabled = true; ButtonConnect.IsEnabled = true; ButtonConnect.Content = "connect"; } else { _client = result.Client; TextBlockInfo.Text = "collections: " + string.Join(", ", result.Names.ToArray()); ButtonConnect.IsEnabled = true; ButtonConnect.Content = "disconnect"; WebContent.NavigateToString(string.Format(HtmlTemplate, HtmlIndex)); } } else { _client = null; TextBoxConnect.IsEnabled = true; TextBlockInfo.Text = ""; ButtonConnect.Content = "connect"; PanelPage.Visibility = Visibility.Hidden; WebContent.NavigateToString(string.Format(HtmlTemplate, HtmlIndex)); } }
protected void Page_Load(object sender, System.EventArgs e) { if (Section == null) { LabelContent.Text = "Il faut un nom de section pour le control WebContent."; } else { try { HiddenFieldSectionName.Value = _Section; string utilisateur = WebContent.GetUtilisateur(); string visualiseur = WebContent.GetVisualiseur(); WebContent web = WebContent.GetWebContent(_Section, utilisateur, visualiseur); if (web != null && WebContent.CanEdit()) { HyperlinkEdit.Visible = true; string url = "~\\WebContent\\Edit.aspx?id=" + web.WebContentID.ToString(); //~\\WebContent\\Edit.aspx?sectionname=" + HiddenFieldSectionName.Value; url += "&ReturnURL="; url += System.Web.HttpUtility.UrlEncode(Request.RawUrl); HyperlinkEdit.NavigateUrl = url; } // Il n'y a pas de WebContent pour cet Utilisateur et ce Visualiseur if (web == null) { // Y a t-il une page pour "Tout le monde" pour cet Utilisateur ? web = WebContent.GetWebContent(_Section, utilisateur, WebContent.ToutLeMonde); } // Il n'y a pas de WebContent "Tout le monde" pour cet Utilisateur if (web == null) { // Y a t-il une page "Admin" pour tout le monde ? web = WebContent.GetWebContent(_Section, WebContent.Admin, WebContent.ToutLeMonde); } // Section non créée, il faut la créer vide car sinon personne ne pourra le faire ! if (web == null) { web = new WebContent(); web.Section = _Section; web.SectionContent = "<p>" + _Section + "</p>"; web.Utilisateur = WebContent.Admin; web.Visualisateur = WebContent.ToutLeMonde; WebContent.Create(web); LabelContent.Text = _Section; } else { LabelContent.Text = web.SectionContent; } } catch (Exception ex) { // Uri string uri = HttpUtility.UrlEncode(ex.Message); Response.Redirect(Tools.PageErreurPath + uri); } } }
void OnRefreshClicked(object sender, EventArgs e) { WebContent.Refresh(); }
protected void ButtonCreer_Click(object sender, System.EventArgs e) { if (DropDownListWebContentSection.SelectedSection == "-1") { SessionState.ValidationMessage += "Sélectionnez une Section.<br/>"; } if (!WebContent.CanEdit()) { SessionState.ValidationMessage += "Vous n'avez pas les droits pour éditer cette section.<br/>"; } if (SessionState.ValidationMessage != null) { Response.Redirect(Request.RawUrl); } WebContent Contenu = new WebContent(); Contenu.Section = DropDownListWebContentSection.SelectedSection; Contenu.SectionContent = FCKeditor1.Value; if (User.IsInRole("Administrateur")) { // Admin cree la page pour lui meme if (DropDownListMembre.SelectedMembre == "-1") { Contenu.Utilisateur = WebContent.Admin; } else // Trouver l'utilisateur { Guid membreGuid = ( Guid )DropDownListMembre.MembreGUID[DropDownListMembre.SelectedIndex - 1]; MemberInfo membre = MemberInfo.Get(membreGuid); Contenu.Utilisateur = membre.NomUtilisateur; } } else { Contenu.Utilisateur = SessionState.MemberInfo.NomUtilisateur; } string codeAccess = ""; if (DropDownListQuestionnaire.SelectedQuestionnaire == "-1") // "-1" valeur mise par le composant { codeAccess = WebContent.ToutLeMonde; } else { codeAccess = DropDownListQuestionnaire.SelectedCodeAcces; } Contenu.Visualisateur = codeAccess; int status = WebContent.Create(Contenu); if (status == 2) { SessionState.ValidationMessage += "Erreur cette Page existe déjà.<br/>"; Response.Redirect(Request.RawUrl); } if (status != 1) { SessionState.ValidationMessage += "Erreur à la Creation de cette Page.<br/>"; Response.Redirect(Request.RawUrl); } Response.Redirect("~/WebContent/Manage.aspx"); }
private void Page_Load(object sender, System.EventArgs e) { if (Page.IsPostBack == false) { if (WebContent.CanEdit() == false) { string msg = "Vous n'avez pas les droits pour éditer ce contenu."; Response.Redirect(Tools.PageErreurPath + msg); } // Pourquoi il y a ce code ici ? SessionState.WebContent = null; // Depuis l'interface graphique, l'admin et le membres ne peuvent voir et // editer que les pages "Tout le monde" if (Request.QueryString["sectionname"] != null) { string section = Request.QueryString["sectionname"].ToString(); string utilisateur = WebContent.GetUtilisateur(); SessionState.WebContent = WebContent.GetWebContent(section, utilisateur, WebContent.ToutLeMonde); if (SessionState.WebContent == null) { FCKeditor1.Value = "<p></p>"; } else { FCKeditor1.Value = SessionState.WebContent.SectionContent; } } if (Request.QueryString["id"] != null) { // Edition d'une section int webContentID = int.Parse(Request.QueryString["id"]); SessionState.WebContent = WebContent.GetWebContent(webContentID); if (SessionState.WebContent == null) { FCKeditor1.Value = "<p></p>"; } else { FCKeditor1.Value = SessionState.WebContent.SectionContent; } } // Page Supprimee if (SessionState.WebContent == null && (Request.QueryString["sectionname"] != null || Request.QueryString["id"] != null)) { PanelCommande.Visible = false; PanelPageInexistante.Visible = true; LabelPageInexistante.Text = "Page supprimée"; DropDownListQuestionnaire.Visible = false; } // Page existante if (SessionState.WebContent != null) { // Selection de la Section DropDownListWebContentSection.SelectedSection = SessionState.WebContent.Section; // Selection du membre // BUG20100210 if (User.IsInRole("Administrateur")) { // Selection du membre si l'admin n'est pas en train de gerer ses pages if (SessionState.WebContent.Utilisateur != WebContent.Admin) { MemberInfo membre = MemberInfo.GetMemberInfo(SessionState.WebContent.Utilisateur); string selectedMembre = membre.Nom + "/" + membre.Prenom + "/" + membre.Societe; // Respecter le format de la DDL DropDownListMembre.SelectedMembre = selectedMembre; } } // Selection de la liste des questionnaires // BUG20100210 DropDownListQuestionnaire.SelectedMembreGUID = SessionState.MemberInfo.MembreGUID; if (User.IsInRole("Administrateur")) { // Selection du membre si l'admin n'est pas en train de gerer ses pages if (SessionState.WebContent.Utilisateur != WebContent.Admin) { MemberInfo membre = MemberInfo.GetMemberInfo(SessionState.WebContent.Utilisateur); DropDownListQuestionnaire.SelectedMembreGUID = membre.MembreGUID; } } // Selection du Visualiseur if (SessionState.WebContent.Visualisateur != WebContent.ToutLeMonde) { int code = int.Parse(SessionState.WebContent.Visualisateur); Questionnaire q = SessionState.Questionnaires.FindByCodeAcces(code); DropDownListQuestionnaire.SelectedQuestionnaire = q.Description + ":" + q.CodeAcces; } else { DropDownListQuestionnaire.SelectedQuestionnaire = WebContent.ToutLeMonde; } } // Panel if (User.IsInRole("Administrateur")) { PanelAdmin.Visible = true; } else { PanelAdmin.Visible = false; } } if (Request.QueryString["sectionname"] != null || Request.QueryString["id"] != null) { ButtonSupprimer.Visible = true; ButtonSauver.Text = "Sauver"; ButtonSauver.Click += new EventHandler(ButtonSauver_Click); } else { ButtonSupprimer.Visible = false; ButtonSauver.Text = "Créer"; ButtonSauver.Click += new EventHandler(ButtonCreer_Click); } MessageValider(); }
protected void ButtonSauver_Click(object sender, System.EventArgs e) { if (DropDownListWebContentSection.SelectedSection == "-1") { SessionState.ValidationMessage += "Sélectionnez une Section.<br/>"; } if (!WebContent.CanEdit()) { SessionState.ValidationMessage += "Vous n'avez pas les droits pour éditer cette section.<br/>"; } if (SessionState.ValidationMessage != null) { Response.Redirect(Request.RawUrl); } string newContenu = ""; string oldContenu = ""; if (FCKeditor1.Value == "") { newContenu = "<p></p>"; } else { newContenu = FCKeditor1.Value; } oldContenu = SessionState.WebContent.SectionContent; SessionState.WebContent.SectionContent = newContenu; SessionState.WebContent.Section = DropDownListWebContentSection.SelectedSection; if (DropDownListWebContentSection.SelectedSection == "CorpsEmail") { LogonInterviewe logon = new LogonInterviewe(newContenu); if (logon.Message != "") { ValidationMessage.Text = logon.Message; ValidationMessage.Visible = true; return; } } if (User.IsInRole("Administrateur")) { if (DropDownListMembre.SelectedMembre != "-1") { // Admin sauve la page pour lui meme if (DropDownListMembre.SelectedMembre == "-1") { SessionState.WebContent.Utilisateur = WebContent.Admin; } else // Trouver l'utilisateur { Guid membreGuid = ( Guid )DropDownListMembre.MembreGUID[DropDownListMembre.SelectedIndex - 1]; MemberInfo membre = MemberInfo.Get(membreGuid); SessionState.WebContent.Utilisateur = membre.NomUtilisateur; } } } string codeAccess = ""; if (DropDownListQuestionnaire.SelectedQuestionnaire == "-1") // "-1" valeur mise par le composant { codeAccess = WebContent.ToutLeMonde; } else { codeAccess = DropDownListQuestionnaire.SelectedCodeAcces; } SessionState.WebContent.Visualisateur = codeAccess; int status = WebContent.Update(SessionState.WebContent); if (status == 2) // n'existe pas { // l'utilisateur a changer le visualisateur d'une page existante SessionState.ValidationMessage += "La Page n'existait pas.<br/>"; int statusCreate = WebContent.Create(SessionState.WebContent); if (statusCreate != 1) { SessionState.ValidationMessage += "Erreur à la Creation de cette Page.<br/>"; } else { SessionState.ValidationMessage += "Elle est créée avec succès.<br />"; } // Create a le bon gout de mettre a jour l'id du nouvel objet cree Response.Redirect("~/WebContent/Edit.aspx?id=" + SessionState.WebContent.WebContentID); } if (status == 0) { SessionState.ValidationMessage += "Erreur serveur à la mise à jour de la Page.<br/>"; Response.Redirect(Request.RawUrl); } // Update string adrIP = Request.ServerVariables["REMOTE_ADDR"]; if (Global.SettingsXml.EnvoyerMiseAjour == true) { Courriel.EnvoyerMiseAJour(oldContenu, newContenu, "Mise à jour", SessionState.WebContent.Section, adrIP); } if (Request["ReturnURL"] != null) { Response.Redirect(Request["ReturnURL"].ToString()); } else { Response.Redirect("~/WebContent/Manage.aspx"); } }
void GlobalCallbackClicked(object sender, EventArgs e) { var text = GlobalText.Text; WebContent.InjectJavascriptAsync(text).ConfigureAwait(false); }
public MainWindow() { InitializeComponent(); WebContent.NavigateToString(string.Format(HtmlTemplate, HtmlIndex)); }
/* IWebContentDisplayListener */ public WebContent OnWebContentReceived(WebContent p0) { Toast.MakeText(this, $"WebContent received successfully: {p0}", ToastLength.Short).Show(); return(p0); }