is there a way of randomizing the user agent using Gecko Browser ? i tried doing it on a separated thread but i couldn't since Gecko must be ran on the same Thread.
try this
Create new class Global.cs
public class Globals
{
public static ArrayList Useragent = new ArrayList();
}
next in your form1 code
private string GetUserAgent()
{
Random Rnd = new Random();
return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
}
load your file with user agent lines
private void button2_Click(object sender, EventArgs e)
{
var OpenFile = new OpenFileDialog();
OpenFile.Filter = "*.txt | *.txt";
OpenFile.ShowDialog();
if (OpenFile.FileName != "")
{
Globals.Useragent.AddRange(File.ReadAllLines(OpenFile.FileName));
}
else
{
MessageBox.Show("Chooee Your User agent file");
}
}
======================
private string GetUserAgent()
{
Random Rnd = new Random();
return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
}
Ok its finish!
Now you can do this - input your new code GetUserAgent();
private void button1_Click(object sender, EventArgs e)
{
CookieManager.RemoveAll();
Gecko.GeckoPreferences.User["general.useragent.override"] = GetUserAgent();
}
Related
Starting with this...
https://github.com/jeremytammik/RevitLookup/blob/master/CS/EventTrack/Events/ApplicationEvents.cs
I'm trying to add an event listener for a synchronization event. the code below throws an error stating that the m_app is null. Can i not subscribe to this event while Revit is starting up?
I was able to do this before with application.ViewActivated += ..... Im wondering if this has something to do with DB vs UI driven events and when they are allowed to be subscribed to? I just don't know.
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app = null;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
return Result.Succeeded;
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("asd","asd");
}
}
}
Here is updated code reflecting my response to the first answer. The message box opens when the document is loaded. No errors are thrown when I try to initialize the synchronization event handlers, however, neither of the message boxes open before or after a synchronization event.
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentOpened += new EventHandler<DocumentOpenedEventArgs>(app_DocOpened);
return Result.Succeeded;
}
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("sync", "sync");
}
void m_app_DocumentSavedToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
{
MessageBox.Show("Doone", "Done");
}
}
this worked.... Thanks largely in part to the SDK sample project EventsMonitor
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(app_syncStart);
application.ControlledApplication.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(app_syncOver);
return Result.Succeeded;
}
public void app_syncStart(object o ,DocumentSynchronizingWithCentralEventArgs args)
{
MessageBox.Show("","Stasrting");
}
public void app_syncOver(object o,DocumentSynchronizedWithCentralEventArgs args)
{
MessageBox.Show("", "Over");
}
}
}
Try
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral)
in your OnStartup() method.
The call is failing because instance member m_app is initialized to null.
The UIApplication.ControlledApplication object that raises the DocumentSynchronizingWithCentralEventArgs is being accessible from the parameter to OnStartup.
You can try this:
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
Autodesk.Revit.ApplicationServices.Application m_app = args.Document.Application;
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}
I created a WCF service using Visual Studio 2017 Community version (employing TAP). I used the AsyncAutoResetEvent from the Microsoft.VisualStudio.Threading reference but it seems that this waithandle is not getting signalled after calling the Set function. The service is hosted in a console application. The traces generated by the NonBlockingConsole.WriteLine display properly however.
server:
AsyncAutoResetEvent aare = new AsyncAutoResetEvent(false);
public async Task<string> TestfuncAsync()
{
string strRet = "finished";
NonBlockingConsole.WriteLine("before autoresetevent");
await aare.WaitAsync();
NonBlockingConsole.WriteLine("after autoresetevent"); //is not traced even if asyncautoresetevent is set
return strRet;
}
void SetEvent()
{
aare.Set();
NonBlockingConsole.WriteLine("auto reset event set");
}
client UI:
private async void button1_Click(object sender, EventArgs e)
{
string value = await client.TestfuncAsync();
...
}
private void button2_Click(object sender, EventArgs e)
{
client.SetEvent();
}
NonBlockingConsole class: (reused from Does Console.WriteLine block?)
public static class NonBlockingConsole
{
private static BlockingCollection<string> m_Queue = new BlockingCollection<string>();
static NonBlockingConsole()
{
var thread = new Thread(
() =>
{
while (true) Console.WriteLine(m_Queue.Take());
}
);
thread.IsBackground = true;
thread.Start();
}
public static void WriteLine(string value)
{
value = DateTime.Now.ToString("<HH:mm:ss.fff>") + " " + value + " <ThreadID>: " + Thread.CurrentThread.ManagedThreadId.ToString();
m_Queue.Add(value);
}
}
I am creating an application on Windows Form and collided with a trouble.
I am getting each second a value from a website by Selenium Webdriver, using XPath and recording it to my local string. I am getting value of a timer. It doesn't matter, it's comfortable to me to get it like a string.
So. I have a loop, which reading data from website and this string I put to TextBox each second too.
But I am not able to see an output of the textBox until my loop is run. I don't want to stop it.
I want to see values from a website online in my application.
Do you have ideas how to refresh the form each second?
I can provide my code if you need.
Thank you in advance, my guru!
public static ChromeDriver GetDriver() {
return new ChromeDriver();
}
public static void CheckGame(string URLevent) {
while (GameIsRun) {
GetInformation(GetDriver(), URLevent);
GameIsRun = false;
}
}
static void GetInformation(ChromeDriver driver, string URLevent) {
driver.Navigate().GoToUrl(URLevent);
do {
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/" +
"div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
Print print = new Print()
print.Info(TimeOfGame);
System.Threading.Thread.Sleep(1000);
}
while (TimeOfGame != "90:00");
}
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
Form form = new Form();
}
private static Form1 _form = null;
public static Form1 Form {
get {
if (_form == null) {
_form = new Form1();
}
return _form;
}
}
private void button1_Click(object sender, EventArgs e) {
string eventId = tbEventID.Text; //this works vice versa. It's not my issue.
string URLevent = "url..." + tbEventID.Text + "/";
Program.CheckGame(URLevent);
}
}
public class Print {
public void Info(string TimeOfGame) {
Form1.Form.tbTeam1.Text = TimeOfGame;
//my issue is here. I want to check result at TextBox each second!
}
}
This statement in your code
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
is very brittle. You should use getText() method for extracting the inner text of HTML methods. Also, in order to locate webElement precisely, it is preferred to use focused relative Xpath over absolute Xpath.
I'm using Ignite 2.1.0 and I create a simple program to try DataStreamer, but I offen got error like this:
"[diagnostic]Failed to wait for partition map exchange" or "Attempted to release write lock while not holding it".
I started two local nodes, one was started in windows CMD using example xml configuration and another was started in Eclipse. My code in Eclipse like this :
public class TestDataStreamer {
public static void main(String[] args) {
// TODO Auto-generated method stub
long bgn,end;
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
Ignite ignite = Ignition.start(cfg);
CacheConfiguration<Long, Map> cacheConf = new CacheConfiguration();
cacheConf.setName("TestDataStreamer").setCacheMode(CacheMode.REPLICATED);
cacheConf.setBackups(0);
IgniteCache cache = ignite.getOrCreateCache(cacheConf);
cache.clear();
File dataFile = new File("D:/data/1503307171374.data"); //10,000,000 rows text data
bgn = System.currentTimeMillis();
try {
loadByStreamer(dataFile,ignite,"TestDataStreamer");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
end = System.currentTimeMillis();
System.out.println("---------------");
System.out.println((end-bgn)/1000.0+" s");
}
cache.destroy();
System.out.println("cache destroy...");
ignite.close();
System.out.println("finish");
}
private static void loadByStreamer(File dataFile, Ignite ignite, String cacheName) throws Exception {
IgniteDataStreamer<Long,TestObj> ds = ignite.dataStreamer(cacheName);
//ds.allowOverwrite(true);
ds.autoFlushFrequency(10000);
ds.perNodeBufferSize(4096);
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(dataFile),"UTF-8"));
String line = null;
long count = 0;
while((line=br.readLine())!=null){
ds.addData(System.currentTimeMillis(), parseData(line, Constants.DEFAULT_SEPARATOR,
"id,sn,type_code,trade_ts,bill_ts,company_code,company_name,biz_type,charge_amt,pay_mode".split(",")));
if(++count%10000==0){
System.out.println(count+" loaded...");
}
//System.out.println(count+":"+line);
}
System.out.println("flushing...");
ds.flush();
System.out.println("flushed");
br.close();
ds.close();
System.out.println("file handled...");
}
private static TestObj parseData(String data, String saperator, String[] fields){
TestObj obj = new TestObj();
if(data!=null && saperator.trim().length()>0){
String[] values = data.split(saperator);
obj.setId(values[0]);
obj.setSn(values[1]);
obj.setType_code(values[2]);
obj.setTrade_ts(values[3]);
obj.setBill_ts(values[4]);
obj.setCompany_code(values[5]);
obj.setCompany_name(values[6]);
obj.setBiz_type(values[7]);
obj.setCharge_amt(values[8]);
obj.setPay_mode(values[9]);
}
return obj;
}
}
class TestObj {
private String id;
private String sn;
private String type_code;
private String trade_ts;
private String bill_ts;
private String company_code;
private String company_name;
private String biz_type;
private String charge_amt;
private String pay_mode;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getType_code() {
return type_code;
}
public void setType_code(String type_code) {
this.type_code = type_code;
}
public String getTrade_ts() {
return trade_ts;
}
public void setTrade_ts(String trade_ts) {
this.trade_ts = trade_ts;
}
public String getBill_ts() {
return bill_ts;
}
public void setBill_ts(String bill_ts) {
this.bill_ts = bill_ts;
}
public String getCompany_code() {
return company_code;
}
public void setCompany_code(String company_code) {
this.company_code = company_code;
}
public String getCompany_name() {
return company_name;
}
public void setCompany_name(String company_name) {
this.company_name = company_name;
}
public String getBiz_type() {
return biz_type;
}
public void setBiz_type(String biz_type) {
this.biz_type = biz_type;
}
public String getCharge_amt() {
return charge_amt;
}
public void setCharge_amt(String charge_amt) {
this.charge_amt = charge_amt;
}
public String getPay_mode() {
return pay_mode;
}
public void setPay_mode(String pay_mode) {
this.pay_mode = pay_mode;
}
}
If stop the node started in CMD and run the program in only one node, it works well.
Is there anyone can help me?
Update jdk for both nodes to the same version, for example for 1.8.0_144(as you already have it in installed), or at least, try to update idk in eclipse to the latest of 1.7 versions, it should help.
There is a thread on Ignite user list, when guys faced pretty the same exception and updating of java version helped them to fix it.
I can't seem to figure out how to display Account ID and Account Balance into a textbox after the selected index is changed in the listbox. I have a Customer class and a Checking account class(which is a subclass of a Bank Account class). The part of the code that is messing up is at the bottom.
This is the part of my code that I'm having trouble with:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
This is the rest of the code:
public partial class frmStart : Form
{
private static List<Customer_Account> customers;
private Customer_Account aCustomer;
private Saving_Account aSaver;
private static List<Saving_Account> savers;
private Checking_Account aChecker;
private static List<Checking_Account> checkers;
public frmStart()
{
InitializeComponent();
customers = new List<Customer_Account>();
checkers = new List<Checking_Account>();
savers = new List<Saving_Account>();
}
#region New form for Savings and Checking
private void lstFrmStartChecking_DoubleClick(object sender, EventArgs e)
{
//Shows Checking form
frmChecking showCheckingForm = new frmChecking();
this.Hide();
showCheckingForm.ShowDialog();
this.Close();
}
private void lstFrmStartSavings_SelectedIndexChanged(object sender, EventArgs e)
{
//Show Savings form
frmSavings showSavingForm = new frmSavings();
this.Hide();
showSavingForm.ShowDialog();
this.Close();
}
#endregion
#region Everything needed for TabPage1
//Sets CheckChanged event handler for either New customer or Existing Customer
private void rdoNewCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Visible = true;
groupBox3.Visible = false;
}
private void rdoExistingCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox3.Visible = true;
groupBox2.Visible = false;
}//End of CheckChanged event handler
//Button controls for Adding customer to our bank and Clearing the textboxes
//in the 1st group panel
private void btnAddCustomer_Click(object sender, EventArgs e)
{
AddCustomerAccountToList();
PopulateListBox(customers);
}
private void AddCustomerAccountToList()
{
double socialSecurity;
double phoneNumber;
double zipCode;
if (double.TryParse(txtTab1SocialSecurity.Text, out socialSecurity) && double.TryParse(txtTab1PhoneNumber.Text, out phoneNumber)
&& double.TryParse(txtTab1Zip.Text, out zipCode))
{
aCustomer = new Customer_Account(txtTab1SocialSecurity.Text, txtTab1Name.Text, txtTab1Address.Text, txtTab1City.Text,
txtTab1State.Text, txtTab1Zip.Text, txtTab1PhoneNumber.Text, txtTab1Email.Text);
customers.Add(aCustomer);
}
else
{
MessageBox.Show("Please be sure to use only numeric entries for: \nSocial Security \nPhone Number \nZip Code", "Non-numeric Entry");
}
}//End of AddCustomerAccount
private void btnTab1Clear_Click(object sender, EventArgs e)
{
foreach (Control ctrl in groupBox2.Controls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Clear();
}
txtTab1SocialSecurity.Focus();
}
}//end of button controls for 1st group panel
//Add CheckingAccount to List()
//Populate ListBox for List<>
private void PopulateListBox(List<Customer_Account> aListCustomerAccount)
{
lstTabPage1.Items.Clear();
lstTabPage2Checking.Items.Clear();
foreach (Customer_Account customer in aListCustomerAccount)
{
lstTabPage1.Items.Add(customer.GetCustomerName().ToUpper());
lstTabPage2Checking.Items.Add(customer.GetCustomerName().ToUpper());
}
}//End of Populate listbox
//Search for an existing member with name
private void txtTabPage1Search_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage1.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage1Search.Text))
{
lstTabPage1.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage1.Items[i]).StartsWith(txtTabPage1Search.Text.ToUpper()))
{
lstTabPage1.SetSelected(i, true);
}
else
{
lstTabPage1.SetSelected(i, false);
}
}
}//End of search
//This button will open a checking account for the customer
private void btnOpenCheckingAccount_Click(object sender, EventArgs e)
{
string acctID;
acctID = txtAccountID.Text;
aChecker = new Checking_Account(acctID, DateTime.Today, 0,
200, frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
//This button will open a saving account for the customer
private void btnOpenSavingsAccount_Click(object sender, EventArgs e)
{
aSaver = new Saving_Account(txtAccountID.Text, DateTime.Today, 0, 0.05,
frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
private static List<Customer_Account> GetCustomer()
{
return customers;
}
#endregion
#region Everything Needed for TabPage2
//Search TabPage 2 Checkers
private void txtTabPage2SearchChecking_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage2Checking.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage2SearchChecking.Text))
{
lstTabPage2Checking.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage2Checking.Items[i]).StartsWith(txtTabPage2SearchChecking.Text.ToUpper()))
{
lstTabPage2Checking.SetSelected(i, true);
}
else
{
lstTabPage2Checking.SetSelected(i, false);
}
}
}//End Search TabPage2 Checkers
//Display values in textboxes depending on user selection in listbox
private void lstTabPage2Checking_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
txtTab2SocialSecurity.Text = customers[lstTabPage2Checking.SelectedIndex].GetSocialSecurity().ToString();
txtTab2Name.Text = customers[lstTabPage2Checking.SelectedIndex].GetCustomerName().ToString();
txtTab2City.Text = customers[lstTabPage2Checking.SelectedIndex].GetCity().ToString();
txtTab2State.Text = customers[lstTabPage2Checking.SelectedIndex].GetState().ToString();
txtTab2Zip.Text = customers[lstTabPage2Checking.SelectedIndex].GetZip().ToString();
txtTab2PhoneNumber.Text = customers[lstTabPage2Checking.SelectedIndex].GetPhoneNumber().ToString();
txtTab2Email.Text = customers[lstTabPage2Checking.SelectedIndex].GetEmail().ToString();
txtTab2Address.Text = customers[lstTabPage2Checking.SelectedIndex].GetAddress().ToString();
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
}
(This is what the error message says)
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Welcome to SO, Guy!
It looks to me that you are appending the .ToString() method to all of your controls except for this one:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
Change your code to:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber().ToString();
And you should be fine!