|
If I understand this right, you want to take a page source and execute JS within it to extract data?
Website scraping is a specific thing for each site, whatever you do, so I recommend that you instead parse the JS (it's almost certainly automatically generated and therefore easy to automatically decompose) to get the data. A regex ought to be able to do that for you. Executing arbitrary JavaScript could produce surprising or even malicious results.
Also, you should check that automated scraping doesn't violate the terms of use of the website, particularly if the content you are scraping is not visible without an account.
|
|
|
|
|
I have 3 separate lists of objects, all containing the same properties:
List<SalesTeamNorth> teamNorth;
List<SalesTeamSouth> teamSouth;
List<SalesTeamEast> teamEast;
Is there a way to merge these 3 lists into a single list (i.e. "List<AllSalesReps> allReps")? I was able to figure out how to merge 3 lists of the same object but not 3 lists of different objects.
For most of my application, it's beneficial to keep these 3 objects separate, however there's one part in which having them merged into a single list object will save me from using lots of repetitive code.
Thanks.
|
|
|
|
|
Do they all share something like a base class, or even better, an interface? If they do, just use that as your type - the horrible alternative is to maintain it as a List of objects which, quite frankly, is no better than maintaining an ArrayList.
|
|
|
|
|
Even when your SalesTeamXyz classes would inherit from a common SalesTeam class, you wouldn't be able to simply cast a List<SalesTeamNorth> to a List<SalesTeam>, so the three lists have no common ancestor. [fixed angular brackets here].
Now do you really want those three classes? and even if you do, do you need the highly specialized lists? it would probably make more sense to have compatible lists, like so:
List<SalesTeam> teamNorth;
List<SalesTeam> teamSouth;
List<SalesTeam> teamEast;
while you still can store more specialized teams in them (with a risk of making some mistakes).
Here is a complete example:
class SalesTeam {
public string name;
}
class SalesTeamNorth : SalesTeam {
public SalesTeamNorth(int v) { name="N"+v; }
}
class SalesTeamSouth : SalesTeam {
public SalesTeamSouth(int v) { name="S"+v; }
}
public override void Test(int arg) {
List<SalesTeam> teamsNorth=new List<SalesTeam>();
for(int i=0; i<3; i++) teamsNorth.Add(new SalesTeamNorth(i));
List<SalesTeam> teamsSouth=new List<SalesTeam>();
for (int i=0; i<3; i++) teamsSouth.Add(new SalesTeamSouth(i));
foreach (List<SalesTeam> teams in new List<List<SalesTeam>>(){ teamsNorth, teamsSouth }) {
foreach (SalesTeam team in teams) {
log(team.name);
}
}
}
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Thursday, May 26, 2011 12:43 PM
|
|
|
|
|
Why do you have SalesTeamNorth, SalesTeamSouth and SalesTeamEast objects? Why wouldn't you just have a single SalesTeamMember or whatever object?
|
|
|
|
|
Assuming that SalesTeamNorth, SalesTeamSouth, and SalesTeamEast are all classes inheriting from AllSalesReps, you could do it with LINQ:
IList<AllSalesReps> allReps = teamNorth
.Cast<AllSalesReps>()
.Concat(teamSouth)
.Concat(teamEast)
.ToList();
|
|
|
|
|
Agreed.
|
|
|
|
|
You could put everything in one class and add a property "category" eg. With LINQ you could then easily split the one list into the three you want.
Just a quick idea.
V.
|
|
|
|
|
As others have said, there is no obvious reason why you should need a separate class for different groups of sales personnel. If they all have the same properties, and they are all semantically representing the same concept (a salesman), they are actually the same class.
You can't merge lists of different classes. That's an additional incentive for you to rationalise this into being all one class.
|
|
|
|
|
Hello All gurus in C#
Currently I'm developing add-ins for MS Outlook 2007
the idea is, I want to protect my file with some kind of encryption
before attach it into my email.
I have created Outlook form region that applies for Inspector in composing mode and reading mode,
so the add-ins will only appears in composing new mail and appears in reading mail.
I faced some problems, like
1) I cannot attach file programmaticaly to the current Composing Mail Windows
2) I cannot extract file programmatically from the current Reading Mail Windows
I've tried to modify some code from MSDN, but I stuck in the middle
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
private void button1_Click(object sender, EventArgs e)
{
Outlook.MailItem MyMail = Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
OpenFileDialog attachment = new OpenFileDialog();
OpenFileDialog.show();
if (attachment.FileName.Length > 0)
{
MyMail.Attachments.Add(attachment.FileName, Outlook.OlAttachmentType.olByValue, 1, attachment.FileName);
}
}
Thanks
|
|
|
|
|
Hi,
as the title suggests, I get the following error:
Failed to open XML parser COM object. C:\Program Files (x86)\Microsoft XDE\1.0\WM7_skin.xml
Error while processing skin file C:\Program Files (x86)\Microsoft XDE\1.0\WM7_Skin.xml
View element is either missing or invalid.
System is Windows 7 64 bit with Visual Studio 2010.
Didn't find any useful advice in the Net. Any idea here maybe?
Thanks...
|
|
|
|
|
Do you have the SDK installed? Perhaps reinstalling it will help.
Also, this question would have been better posted in the Mobile forum as it deals with Mobile development rather than C# in general
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I', soory about that, I didn't know there was an extra forum devoted to Mobile development...
As far as the SDK concerns, well I installed the Windows Phone Developer Tools, to be more precise the machine did it, as I had to use the online installer, which I hate, but I didn't find a "normal" installation file to download. Shouldn't the SDK be included?
|
|
|
|
|
|
That is the web installer and I' ve already done it.
My only hope is to try the Windows Phone Developer Tools 7.1 Beta, although something keeps telling me that it will not help and maybe I 'll get problems into running VS afterwards (it happened already once during my previous efforts). Thanks anyway...
|
|
|
|
|
Have you installed all of these? (I copied this from a reply I posted elsewhere)...
Download and install the Windows Phone SDK (Windows Phone Developer Tools), the Windows Phone Developer Tools January 2011 Update, and the Windows Phone Developer Tools Fix. They can be found here[^] (look under "Windows Phone Developer Tools 7.0" and follow instructions).
I wouldn't try the beta unless you're willing to be a tester
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I tried everything, even uninstalling and reinstalling all the stuff.
Did not work!
Unhandled exception in XDE.exe... whoever knows why...
I'm thinking of switching into Android, maybe I'll have better luck there
modified on Friday, May 27, 2011 10:19 AM
|
|
|
|
|
You're running Visual Studio as an administrator, yes?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, of course. Meanwhile I succesfully installed it on another machine. I think I'messed it up having installed some of the german and/or the english versions of Visual Studio. But I do not know what to fix or deinstall.
Isn't there any advice in which direction that problem could be resolved? I mean other than just reinstalling everything, which apparently doesn't work...
The machine says the following:
Failed to open XML parser COM object. C:\Program Files (x86)\Microsoft XDE\1.0\WM7_skin.xml
Error while processing skin file C:\Program Files (x86)\Microsoft XDE\1.0\WM7_Skin.xml
View element is either missing or invalid.
What could (or should) be the work around to such a problem?
|
|
|
|
|
nstk wrote: I think I'messed it up having installed some of the german and/or the english versions of Visual Studio.
I thought I remember hearing something about at least one of the WP7 tools only working on EN versions...you may be on to something there.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I wouldn't know. My last hope was installing Blend 4, when I found out that it was not the english version. Alas... it was again only lost time...
It seems however, I am not the only one with that problem, at least it has occured to others before.
http://blog.robgarrett.com/2006/08/15/failed-to-open-xml-parser-com-object/
http://social.msdn.microsoft.com/Forums/en/microsoftdeviceemu/thread/7dff48af-2d25-4a52-a849-2b357b283386
None of those tricks helped me though... still searching, it must have been a long time since I haven't gone beyond the 3rd page on a google search...
|
|
|
|
|
SqlConnection conn = new SqlConnection("");
conn = DataHandler.conn;
String username = txtUsername.Text;
String password = txtPassword.Text;
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM [TBLUsers]", conn);
cmd.Connection = conn;
DataTable table = new DataTable();
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (txtUsername.Text == (reader["UserName"].ToString()) && txtPassword.Text = reader["Password"].ToString()))
{
reader.Dispose();
table.Load(reader);
POS2 p = new POS2();
MainPage page = (MainPage)this.MdiParent;
p.MdiParent = page;
p.WindowState = FormWindowState.Maximized;
p.Show();
page.WelcomeUser = reader["UserName"].ToString();
//throw new CustomException("Enter Correct Username and Password");
}
}
I'm getting this error-->Invalid attempt to call MetaData when reader is closed.
What can i do??
thanks in advance
Sandra
|
|
|
|
|
You have to add all your code inside try{}catch{}finally{} and in finally scope dispose datareader and close connection string.
e.g
try
{
}
catch(Exception exp){MessageBox.Show(exp.Message);}
finally
{
if (rdr != null)
rdr.Close();
if (con.State == ConnectionState.Open)
con.Close();
}
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
oh my. Lots of comments:
1.
please use PRE tags to improve code readability.
2.
the problem is you dispose of your reader on the first match, and then you continue the while loop which depends on the reader. The dispose should be outside the while loop!
3.
the easier way to get the dispose stuff right is by using a using statement, like so (note the result of PRE tags):
using (SqlDataReader reader = cmd.ExecuteReader()) {
while (reader.Read()) {
if (txtUsername.Text == (reader["UserName"].ToString()) && txtPassword.Text = reader["Password"].ToString())) {
break;
}
}
}
4.
So you are storing usernames and passwords in a table. Do you consider that a good practice?
Normally one would:
- [rephrased] concatenate the username, the password, and a little constant string ("salt"); [/rephrased]
- then call a hashing function;
- and lookup the table, which does not contain the password, all it holds is the hash value.
The reason is this: if your database gets compromised, all users loose the privacy of their password (and most of them would have been foolish enough to use the same username and password on other applications and/or web sites).
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Thursday, May 26, 2011 8:09 AM
|
|
|
|
|
Yeah, what Luc said. Plus:
SqlCommand cmd = new SqlCommand("SELECT * FROM [TBLUsers]", conn);
cmd.Connection = conn;
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
txtPassword.Text == reader
And you don't break the loop.
Of course, you should probably use a parameterized query rather than querying the whole table.
|
|
|
|