|
It has quite a few unexpected articles, yes
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
so here I'm trying to use proxies from a listView in my project. But I have no clue and have had no experiences in using proxies in C# before nore in any other form of anything haha.
So what I've got so far is a button to import a .txt file of "proxies" and it adds the items to a listView.
From there I'm wanting a loop in my proxy state so it runs through the listView of proxies.
I have no clue on what I'm doing here so would need some extended support here. In need of this for a college project.
Here is my post data.
CookieContainer cookieCon = new CookieContainer();
public string postRequest(string url, String postData, String Username, String Password)
{
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.CookieContainer = cookieCon;
request.ContentType = "application/json; charset=utf-8";
request.Headers.Add("Cookie", "devicecookie=146.200.41.147.1446567416483.346;");
request.UserAgent = "FireFox User Agent";
request.Headers.Add("Accept-Language", "en-GB,en-US;q=0.8");
request.Host = "www.collegename.co.uk";
request.Headers.Add("Accept-Encoding", "gzip");
request.KeepAlive = true;
byte[] byteArr = Encoding.Default.GetBytes(postData);
request.ContentLength = byteArr.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArr, 0, byteArr.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string source = reader.ReadToEnd();
return source;
}
catch (Exception ex)
{
if (ex.Message.Contains("401"))
{
}
}
return null;
}
Would appreciate it if you could give me some help here, thanks guys. I'm not looking to change a mass amount of my code but would appreciate some help.
|
|
|
|
|
Member 11367553 wrote: I have no clue on what I'm doing here Exactly what are you trying to do with these proxies? And more importantly, are you sure this is a good choice of college project?
|
|
|
|
|
It's to login and yes it's a good choice of college project because it's what we have been asked to do.
|
|
|
|
|
Member 11367553 wrote: It's to login What exactly is that supposed to mean?
|
|
|
|
|
It's posting to the student login page, our project is to utilize proxies in a project so this is what I'm doing.
|
|
|
|
|
Can you show us the code where you load data into the listview? That is assuming you already have that code
What kind of listview are we talking about? The one from WinForms? If yes, then you can "foreach" the Items property.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
yeah i have this already coded where the proxies from the .txt file are listed in the listView.
Here is the code for that.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "TXT files|*.txt";
ofd.Title = "Load Proxies";
var dialogResult = ofd.ShowDialog();
if (dialogResult == DialogResult.OK)
{
foreach (var line in System.IO.File.ReadLines(ofd.FileName))
{
if (line.Contains(":"))
proxies.Add(line);
proxyView.Items.Add(line);
}
}
|
|
|
|
|
You already 'run' through the items right there
Add a button to your form, and create a similar loop for the items in the listview;
foreach (var item in proxyView.Items)
{
System.Diagnostics.Debug.WriteLine(Convert.ToString(item));
} You can then reference any item in the listview and access its properties. Looks like each item is a single item, a text-string. I assume you want to call the other method and pass that then?
Where do the other arguments come from, like the name and password? Does the user have to enter those?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What I'm trying to do with the proxies that have been imported into the proxyView is use them in the request to login.
So for instance 3 proxies are imported for example
1.1.1.1:1738
2.2.2.2:1982
3.3.3.3:1234
I'm wanting each request to pull a proxy from the proxyView list and use it in the request that's being made.
The String Username and String Password are user defined they enter there username & password.
|
|
|
|
|
Member 11367553 wrote: So for instance 3 proxies are imported for example If those are the exact lines in the text-file, I'd expect them to be strings in the listview.
Member 11367553 wrote: I'm wanting each request to pull a proxy from the proxyView list and use it in
the request that's being made. Once you have your loop set up, have it call the method you showed in the first post. You'd still need to modify that to actually set a proxy. The example-code on MSDN[^] shows how to set a proxy for a request.
Member 11367553 wrote: The String Username and String Password are user defined they enter there
username & password. You'll need to get those into variables before you start the loop.
private Button1_Click(object sender, EventArgs e)
{
string userName = textBox12.Text;
string passWord = textBox34.Text;
foreach (var item in proxyView.Items)
{
postRequest(userName, passWord, item);
}
} What do you intend to "post"? If the answer is "dunno", then I'd suggest a "GET", not a post.
I don't know what level college is, or whether pointing to the documentation is sufficient. If it isn't, just say so.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Member 11367553 wrote:
if (line.Contains(":"))
proxies.Add(line);
proxyView.Items.Add(line);
I believe there's a bug here? Missing {} brackets, that is.
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Is there a way to prevent a method from execution if it is in design time or the method can only be executed at runtime.
I got this problem while creating a custom control because there is a method call in the constructor that will only work at runtime.
now at design time while designing the form and use that control, then the form will generate the error. now i tried this at the constructor of the user control
public ctrl_information()
{
InitializeComponent();
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)) return;
SomeMethod();
}
what i want to achieve is something like this
[ExecuteOnlyAtRuntime]
public void SomeMethod()
{
}
then call it like this
public ctrl_information()
{
InitializeComponent();
SomeMethod();
}
Is it possible?
Please shed some light on this.
Thank you
|
|
|
|
|
As far as I know there is no such attribute predefined. I could be wrong, though.
You could always design your own attribute, Writing Custom Attributes[^], but I don't really see the point in this case.
What you want is for Visual Studio to recognize your method as executable only at runtime, without any extra code necessary.
However, if you write your own attribute you also need to write the code to access it, Accessing Custom Atributes[^].
That would be a lot more work than doing it like this
public void RunTimeOnlyMethod()
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return;
}
This way you move the logic into the method that knows if it should be executed or not, instead of having logic in the calling method.
|
|
|
|
|
Gilbert Consellado wrote: Is there a way to prevent a method from execution if it is in design time The code does not run in the designer, it gets compiled. If the designer raises an error then you need to show us what it is.
|
|
|
|
|
I have a process inside the constructor of the usercontrol, then i get this error "The given key was not present in the dictinoary" on the designer from the form that uses the usercontrol.
It happen because at the design time the form will try to connect to the database but the connectionstring can be generated at runtime.
|
|
|
|
|
You don't need an attribute, there is a Control property which does this for you: DesignMode[^]
So all you have to do in your constructor is:
public ctrl_information()
{
InitializeComponent();
if (!DesignMode)
{
SomeMethod();
}
} Because a Form is derived from Control, this works there as well.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
unfortunately, it doesn't work on me
|
|
|
|
|
So show us exactly what code you are using (relevant bits, only, please!)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
here is the constructor of the usercontrol
public ctrl_patient_information()
{
InitializeComponent();
InitializeControl();
}
public void InitializeControl()
{
Patient = Patient ?? new Patient();
PatientContact = Patient.GetPatientContact();
PatientImage = new Patient.PatientImage(Patient);
pictureedit_patient.Image = PatientImage.GetPatientImage();
PopulateCombos();
InitValidation();
Patient.PropertyChanged += Patient_PropertyChanged;
InitControlBinding();
}
private void PopulateCombos()
{
combo_titles.Properties.Items.AddRange(new PatientTitle[] { PatientTitle.MR, PatientTitle.MS });
combo_titles.SelectedIndex = -1;
combo_titles.Select();
combo_gender.Properties.Items.AddRange(new Gender[] { Gender.Male, Gender.Female });
combo_gender.SelectedIndex = -1;
combo_religion.Properties.Items.AddRange(Religion.GetReligions(false));
combo_religion.Leave += Religion.ValidateControlReligionItem;
combo_marital_status.Properties.Items.AddRange(
new MaritalStatus[]
{
MaritalStatus.Single,
MaritalStatus.Married,
MaritalStatus.Widow,
MaritalStatus.Seperated
}
);
}
when the
Religion.GetReligions(false) been called it will try to connect to DB but the problem is the application is still in designmode, and the connectionstring for the DB is generated at runtime, so VS cant connect to db. then the Form that use the usercontrol will get an error at designtime.
public static BindingList<Religion> GetReligions(bool reset)
{
if (!reset && _bindingListItem.Count > 0) return _bindingListItem;
DisableRaiseChangedEvent();
_bindingListItem.Clear();
_bindingListItemPointer.Clear();
var ms = new MySQLSelect("SELECT * FROM `tbl_religion` WHERE `tracked_id` = @tid");
ms.AddParamWithValue("tid", HIMSHelper.TrackedID);
foreach (var item in ms.DataReader())
{
var r = new Religion()
{
ID = item[0].ToInt(),
ReligionName = item[2].ToString()
};
_bindingListItem.Add(r);
_bindingListItemPointer.Add(r.ID, r);
}
EnableRaiseChangedEvent();
return _bindingListItem;
}
for now i have a temporary workaround, just to make it work but still looking for the best solution, the only solution i can think is to create an attribute but as for now i dont have experience creating attribute and i am running out of time.
|
|
|
|
|
for now my workaround, instead having a condition
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)) return;
I just make
InitializeControl() public then call it separately on the Form that will use the control.
|
|
|
|
|
That's not a good idea - since your control relies on it in order to work at all, it kinda breaks OOPs to make the container remember to call it.
I'd probably just change it to this:
public void InitializeControl()
{
if (!DesignMode)
{
Patient = Patient ?? new Patient();
PatientContact = Patient.GetPatientContact();
PatientImage = new Patient.PatientImage(Patient);
pictureedit_patient.Image = PatientImage.GetPatientImage();
PopulateCombos();
InitValidation();
Patient.PropertyChanged += Patient_PropertyChanged;
InitControlBinding();
}
}
So that the actual content didn't get filled in except in run mode.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I dont know why but DesignMode is not working, its still execute the whole block inside the "if" statment.
and it give me this messages when opening the form.
Exception has been thrown by the target of an invocation.
The variable 'ctrl_patient_information' is either undeclared or was never assigned.
I think i am gonna use LicenseManager.UsageMode for now.
BTW thank you for your help
|
|
|
|
|
Assuming that you mean Debug and Release, you can use pre-processor directives to do what you want:
public ctrl_information()
{
InitializeComponent();
#if(!DEBUG)
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)) return;
#endif
SomeMethod();
}
|
|
|
|
|
Rectangle a=new Rectangle(); Arraylist b=new Arraylist; b.add(a); a.X=1;
When i debug these codes, i found b[0] is not a 's reference, they are not same, b[0].x is 0, not 1.
I am fuzzy to gdi+, i need put all shapes in a Arraylist, when they are update(move or change shapes),i can re-draw all of it in a canvas.
So how can i do it?
|
|
|
|