I would like to add search functionality to my page, with search_next, search_previous, search_close(clear selections) functionality along with this i would like to know the information about search_result_count, current_search_result_index. But there are only two methods exposed in CEF API:
public void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);
public void StopFinding(bool clearSelection);
It seems like first we can do search_next and search_previous.
I tried following for doing this and able to search backward and forward as expected but when i try to search other word then its not working:
private void previousMouseUp(object sender, MouseButtonEventArgs e)
{
ChromeView.Find(searchIdentifier, searchText, false, isCaseSensitive, true);
}
private void nextMouseUp(object sender, MouseButtonEventArgs e)
{
ChromeView.Find(searchIdentifier, searchText, true, isCaseSensitive, true);
}
And there is no method exposed to get search results count and current search index. I am using 41.0.1.0 version. Please guide me in right direction to achieve my requirements?
Kindly don't mind my English;
The CefSharp.WinForms.Example has a basic working implementation of Find.
https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.WinForms.Example/BrowserTabUserControl.cs#L253
The CEF API documentation is http://magpcss.org/ceforum/apidocs3/projects/%28default%29/CefBrowserHost.html#Find%28int,constCefString&,bool,bool,bool%29
Related
I want a process to be called each time I navigated to my view to refresh a list.
I am using Xamarin Forms and prism framework.
I made my ViewModel derivate from ContentPage but the following method is never called :
protected override void OnAppearing()
{
//Do things
}
How am I supposed to do to get the event? Is it better to use OnNavigateTo?
Through the document:
There are times in your application where you may want to invoke code
in your ViewModel based on when the Page Appears or Disappears without
Navigation specific consideration. For these times you can utilize the
IPageLifecycleAware interface to properly respond to the Appearing and
Disappearing events from the Page.
public class ViewAViewModel : IPageLifecycleAware
{
public void OnAppearing()
{
Console.WriteLine("We are appearing");
}
public void OnDisappearing()
{
Console.WriteLine("We are disappearing");
}
}
I found a solution to make my code work, I add to do this in my code behind from the page:
protected override void OnAppearing()
{
(BindingContext as IPageLifecycleAware)?.OnAppearing();
}
Still a mystery why I need to add this and it is not in the sample.
at the time of this post, the sample does it differently. It uses Behaviors to achieve expectation
It has a PageLifeCycleAwareBehavior class
private void OnAppearing(object sender, EventArgs e)
{
MvvmHelpers.InvokeViewAndViewModelAction<IPageLifecycleAware>(AssociatedObject, aware => aware.OnAppearing());
}
private void OnDisappearing(object sender, EventArgs e)
{
MvvmHelpers.InvokeViewAndViewModelAction<IPageLifecycleAware>(AssociatedObject, aware => aware.OnDisappearing());
}
You can see the full implementation here
You can also call Initialize is a good alternative
Add ini to your class
public class HelloViewModel : BindableBase, IInitialize
then add the following method
public void Initialize(INavigationParameters parameters)
{
// Do stuff
}
Hi to all i'm beginner in ASP.net ,i'd try using routing to introduce
some solutions by following code in global.asax:
protected void RoutingHandler(string routeName, string repUrl, string Url)
{
RouteTable.Routes.MapPageRoute(routeName,repUrl,Url);
}
protected void Application_Start(object sender, EventArgs e)
{
RoutingHandler("SolutionsRoute", "Solutions/{name}", "~/Pages/Solutions.aspx");
RoutingHandler("SolutionsPageRoute", "Solutions", "~/Pages/Solutions.aspx");
}
and it work good ,I'd use to link the page
in my menu but when i'm in the url if click again on the other link
the url cheng like this /Solutions/Solutions/VDI
how can I solve this problems
your problem is likely due to having two routing declarations for the same page. While this is valid it is not a recommended method. You should change your deceleration to instead specify a default null value like this
protected void RoutingHandlerWDefault(string routeName, string repUrl,
string Url, bool chkURL, string varOne)
{
RouteTable.Routes.MapPageRoute(routeName,repUrl,Url, chkURL,
chkUrl, new RouteValueDictionary { { varOne, string.Empty } });
}
protected void Application_Start(object sender, EventArgs e)
{
RoutingHandlerWDefault("SolutionsRoute", "Solutions/{name}", "~/Pages/Solutions.aspx",
false, "name");
}
SO Reference: asp.net webforms routing: optional parameters
Also note that you may want to change how you link to your urls. you can find references on how to link to routed urls in these links.
http://msdn.microsoft.com/en-us/library/cc668176.aspx
https://web.archive.org/web/20211020111718/https://www.4guysfromrolla.com/articles/012710-1.aspx
My problems was at the href's link that was like this solutions/security i'd placed a forwad slash behind of the url like this /solutions/security
we are using HttpModule for switching aspx pages..
But if large number of client try to hit same time then people get wrong page on screen... I am not sure if something wrong in my code due to Server.TransferRequest.
Can any one give any suggestion?
public class SwitchMasterModule : IHttpModule, IRequiresSessionState
{
public void Init(HttpApplication context)
{
context.BeginRequest += Context_BeginRequest;
}
void Context_BeginRequest(object sender, EventArgs e)
{
var AppId = SiteSettings.ApplicationId().ToString();
if (HttpContext.Current.Request.CurrentExecutionFilePath.Equals("/default.aspx", StringComparison.InvariantCultureIgnoreCase))
{
HttpContext.Current.Server.TransferRequest(string.Format("~/Templates/{0}/default.aspx", AppId), true);
}
}
}
Moved from comment to answer.
It might be that SiteSettings.ApplicationId() returns incorrect value.
I don't know what the origin of the SiteSettings class is, but if it's not absolutely thread-safe, you could easily wind up with one user accessing the ApplicationId value appropriate for another user.
I am looking at a legacy enterprise application, which written using ASP.NET. No controls or web forms. This is how it works:
EmployeeList.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="EmployeeList.aspx.cs" Inherits="EmployeeList" %>
EmployeeList.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
// Security Check
// Load Template, get version 1.4 of active employee list
StringBuilder template = GetTemplate("Employee", "ActiveList", "1.4", true);
// Get list from database
using(SqlDataReader objReader = GetListFromDB())
{
while(objReader.Read())
{
//fills data
TUtils.Replace(template, ROW, "%name%", objReader[0]);
}
}
// return response
Response.Write(template.ToString());
}
private StringBuilder GetTemplate(string x, string y, string v, bool z);
{
// returns template
}
private SqlDataReader GetListFromDB() {
// returns data reader
}
My question is, since we are not using web forms, is there a way to introduce NUnit in this event driven model (as shown above)?
Also, please avoid suggestions to move to ASP.NET MVC or other patterns, which we are considering, but wondering is there any way to convert this enterprise application testable.
This is absolutely possible. You should have a look on implementing MVP pattern with ASP.NET Webforms. There are several open source implementations but you can do a smaller specialized on your your own.
The basics are to move your code behind logic to a presenterclass. The presenter class has a reference to the page implementing an interface. The trick in your case will be to Mock the Page.Response object for your test. Thats why it´s hard to unit test it right way. The PageResponse Property contains a object deriving from HttpResponseBase and that´s the baseclass you should Mock in your tests and do your asserts on with your example. You could start with that and then extend your presenter with functionalty like Session, Request etc.
If you don´t have any markup at all probably you can just create the presenter in the view constructor and don´t bother of having and reference to the view.
To clarify: The big trick is to get the code out of the aspx.cs file. That beast is not testable.
Sample base class for Presenters:
public class Presenter<T> where T : class, IView
{
protected readonly T View;
protected Presenter(T view, ILogger logger)
{
View = view;
}
public virtual void page_PreRender(object sender, EventArgs e)
{
}
public virtual void page_Init(object sender, EventArgs e)
{
}
public virtual void page_Load(object sender, EventArgs eventArgs)
{
}
public HttpContextBase HttpContext { protected get; set; }
protected HttpRequestBase Request
{
get { return HttpContext.Request; }
}
}
Since most of your code is in the code-behind, I dont think that the usual testing approach with NUnit / Visual Studio testing framework will work well.
However, I think one possible approach is to use UI Testing frameworks like WATIN / Selenium. This will enable you to still write tests for the various functionality.
I have done something similar in the past by basically writing a test case for every UI action that results in a server postback. May not be ideal but it does allow you to automate your testing.
Can someone provide me with a simple example of Asynchronous page processing in ASP.NET Webforms 2.0 (I'm using VS 2010, so new syntax like lambdas are ok)?
I have some long running requests that I don't want tying up IIS threads.
For simplicity's sake, let's say my current code looks like this:
protected void Page_Load(object sender, EventArgs e)
{
string param1 = _txtParam1.Text;
string param2 = _txtParam2.Text;
//This takes a long time (relative to a web request)
List<MyEntity> entities = _myRepository.GetEntities(param1, param2);
//Conceptually, I would like IIS to bring up a new thread here so that I can
//display the data after it has come back.
DoStuffWithEntities(entities);
}
How can I modify this code so that it is asynchronous? Let's assume that I already set async="true" in the aspx page.
EDIT
I think I figured out how to get what I'm looking for. I've put the example code in an answer here. Feel free to point out any flaws or changes that can be made.
I asked some folks on the ASP.NET team. Here's their emailed response to me, and now, to you.
All that code ends up doing is spinning up a new thread and performing delegate invocation on that thread. So now there are two threads running: the request thread and the new thread. Hence this sample actually has worse performance than the original synchronous code would have had.
See http://www.asp.net/web-forms/tutorials/aspnet-45/using-asynchronous-methods-in-aspnet-45 for a sample on how to write and consume async methods in ASP.NET.
Here is a simple example of asynchronous processing.
protected void Page_Load(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
ThreadPool.QueueUserWorkItem(state => Dokimes_Programming_multithread_QueryWorkThead.ThreadProc2());
Debug.Write("Main thread does some work, then sleeps.");
// If you comment out the Sleep, the main thread exits before
// the thread pool task runs. The thread pool uses background
// threads, which do not keep the application running. (This
// is a simple example of a race condition.)
// Thread.Sleep(4000);
txtDebug.Text += "ended";
Debug.Write("end.");
}
// This thread procedure performs the task.
static void ThreadProc(Object stateInfo)
{
// No state object was passed to QueueUserWorkItem, so stateInfo is null.
Debug.Write(" Hello from the thread pool 1.");
}
static void ThreadProc2()
{
// No state object was passed to QueueUserWorkItem, so stateInfo is null.
Debug.Write("Hello from the thread pool 2.");
}
Other way
You can use the PageAsyncTask, see here a full example:
http://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask.aspx
Something like
clAsynCustomObject oAsynRun = new clAsynCustomObject();
PageAsyncTask asyncTask = new PageAsyncTask(oAsynRun.OnBegin, oAsynRun.OnEnd, oAsynRun.OnTimeout, null, true);
Page.RegisterAsyncTask(asyncTask);
Page.ExecuteRegisteredAsyncTasks();
I think I discovered how to do what I wanted to accomplish... though it may not be the best way, feel free to chime in.
At the time of writing there was only one answer in this thread, by Aristos. While he gave an example of executing an asynchronous request, what I wanted was a way to tell ASP.NET to execute some long running method, release the IIS thread so it can be available to service other requests, and then come back when the method finished.
Here's what I came up with, using the same (or similar) example in the question:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Web.UI;
namespace WebApplication2
{
public class MyEntity
{
public string Name { get; set; }
}
public class MyRepository
{
public List<MyEntity> GetEntities(string param1, string param2)
{
Thread.Sleep(10000);
return new List<MyEntity> {new MyEntity {Name = "John Smith"}};
}
}
public partial class Default : Page
{
private readonly MyRepository _myRepository = new MyRepository();
private List<MyEntity> _myEntities;
protected void Page_Load(object sender, EventArgs e)
{
}
private void DoStuffWithEntities()
{
Response.Write("<br/><br/><b>" + _myEntities[0].Name + "</b><br/><br/>");
}
protected void _btnProcess_Click(object sender, EventArgs e)
{
AddOnPreRenderCompleteAsync(BeginExecution, EndExecution, null);
}
private void GetEntities()
{
string param1 = _txtParam1.Text;
string param2 = _txtParam2.Text;
//This takes a long time (relative to a web request)
_myEntities = _myRepository.GetEntities(param1, param2);
}
private IAsyncResult BeginExecution(object sender, EventArgs e, AsyncCallback callback, object state)
{
var t = new ThreadStart(GetEntities);
return t.BeginInvoke(callback, null);
}
private void EndExecution(IAsyncResult result)
{
//Conceptually, I would like IIS to bring up a new thread here so that I can
//display the data after it has come back.
DoStuffWithEntities();
}
}
}