|
BillWoodruff wrote: it is a type of Solution
It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.
|
|
|
|
|
+5 Absolutely correct: interestingly, I've never created a Class Library that way.
I have edited my response to incorporate your feedback, thanks.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
YOU'RE WEAK!
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
“Keep me away from the wisdom which does not cry, the philosophy which does not laugh and the greatness which does not bow before children.”
Kahlil Gibran
Happy Holidays, John !
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Hi,
I'm using iTextSharp to read text contents and coordinates of text from PDF. Able to read the text. For few pdfs, it is reading on letter by letter basis.
For eg, instead of reading the below text completely, its retuning F, R, O, M, S, E, R,...
"FROM SERVICER CASSA DI RISPARMIO DI CESENA SPA"
please guide me to solve this issue. Thanks in advance
Code:
private void button1_Click(object sender, EventArgs e)
{
PdfReader reader = new PdfReader(@"C:\Original.pdf");
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
int numberOfPages = reader.NumberOfPages;
for (int num = 1; num <= numberOfPages; num++)
{
TextWithFontExtractionStategy S = new TextWithFontExtractionStategy();
string F = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, num, S);
}
}
public class TextInfo
{
private double x;
private double y;
private double iwidth;
private double iheight;
private string strtext;
public double left
{
get
{
return x;
}
set
{
x = value;
}
}
public double top
{
get
{
return y;
}
set
{
y = value;
}
}
public double width
{
get
{
return iwidth;
}
set
{
iwidth = value;
}
}
public double height
{
get
{
return iheight;
}
set
{
iheight = value;
}
}
public string Text
{
get
{
return strtext;
}
set
{
strtext = value;
}
}
public StringBuilder strXML = new StringBuilder();
public string getTextInfo()
{
string strTextInfo = "";
strTextInfo = "top:" + y.ToString() + "left:" + x.ToString() + "width:" + iwidth.ToString() + "height:" + iheight.ToString() + "Text:" + strtext;
string xmlString = "<text top=\""+y.ToString()+" left=\""+x.ToString()+" width=\""+iwidth.ToString()+" height=\""+iheight.ToString()+" font=\"0\">" + strtext +"</text>";
return strTextInfo;
}
}
public class TextWithFontExtractionStategy : iTextSharp.text.pdf.parser.ITextExtractionStrategy
{
private List<TextInfo> lstTextInfo = new List<TextInfo>();
private StringBuilder result = new StringBuilder();
private enum TextRenderMode
{
FillText = 0,
StrokeText = 1,
FillThenStrokeText = 2,
Invisible = 3,
FillTextAndAddToPathForClipping = 4,
StrokeTextAndAddToPathForClipping = 5,
FillThenStrokeTextAndAddToPathForClipping = 6,
AddTextToPaddForClipping = 7
}
public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
{
TextInfo txtInfo = getTextInfo(renderInfo);
Console.WriteLine(txtInfo.getTextInfo());
lstTextInfo.Add(txtInfo);
}
private TextInfo getTextInfo(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
{
TextInfo txtInfo = new TextInfo();
Vector asStartpoint = renderInfo.GetAscentLine().GetStartPoint();
Vector asEndpoint = renderInfo.GetAscentLine().GetEndPoint();
Vector dsStartPoint = renderInfo.GetDescentLine().GetEndPoint();
txtInfo.left = Math.Round(asStartpoint[0]);
txtInfo.top = Math.Round(612-asStartpoint[1]);
txtInfo.height = Math.Round(asStartpoint[1] - dsStartPoint[1]);
txtInfo.width = Math.Round(asEndpoint[0] - asStartpoint[0]);
txtInfo.Text = renderInfo.GetText();
if (txtInfo.Text.Contains("closin")) { }
return txtInfo;
}
public string GetResultantText()
{
return result.ToString();
}
public List<TextInfo> GetTextInfo()
{
return lstTextInfo;
}
public void BeginTextBlock() { }
public void EndTextBlock() { }
public void RenderImage(ImageRenderInfo renderInfo) { }
}
modified 27-Dec-11 4:53am.
|
|
|
|
|
my data set contaions some colums containing bool values when i populate the dataset to DEV EXpress Grid view it shows these values as check boxes...i dont want to shw check boxes rathe the actual data....what should i do? .
|
|
|
|
|
What do you want to display the data as?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
can you show us your code of creating gridview ?
|
|
|
|
|
|
Use an icon file (.ico). Icon files support multiple image sizes within the same file.
|
|
|
|
|
Goal: I am wanting to write a C# program that will pull data from a website to help me exercise what I have learned and to further learn OOP and the .Net framework a little better.
Background: The website is a fantasy game that allows you to buy stocks of movies before they come out and the final stock price is the total amount the movie made in theaters.
What I Have: A class for each stock, a static class for the portfolio which holds a List<stock> containing each instance of stock, a static class called netConnection with a method for logging in and a method for pulling data from other pages, and a static class called dataProcessor that processes the data from netConnection.
Now I'm not brand new at programming but am having a little trouble figuring out how to setup my plan for my program with OOP in mind. I guess the easiest way to get advice would be to just post my code and let others give me ideas on ways to improve. I have seen other snippets that use their net connection in an OOP way but I'm not sure if I did it right since my connection doesn't need to be persistent.
modified 26-Dec-11 4:37am.
|
|
|
|
|
The first question you have to ask yourself is - "Does the code work as desired?" If you can answer *yes*, the code is done, and you can start a new version that refactors the code into something "better".
IMHO, you're over-using regular expressions (and it's generally considered ill-advised to use regular expressions to parse HTML).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
The code works as desired but it also worked as desired when it was less than beautiful. heh. What should I use to parse html?
|
|
|
|
|
No way am I reading through that code.
Natepizzle wrote: a static class for the portfolio ... a static class called netConnection
I recommend against that; those are not good candidates for static classes in my opinion.
|
|
|
|
|
I thought a static class would be the right choice as I have only 1 portfolio and 1 connection, therefore, not needing to create multiple instances of those classes. Do you have anything further to add to support your argument?
|
|
|
|
|
Natepizzle wrote: not needing to create multiple instances
You don't know what the future holds, don't limit flexibility.
There is also the argument that if the class holds state (as yours do) it should not be static.
Static is better suited to library routines.
|
|
|
|
|
Use static for things that are inherently unique, not for things that are currently unique.
|
|
|
|
|
First, it seems what you are modeling here now ... the "molecular object" ... is a single, static, instance of a "portfolio." And, the "atomic" elements of the portfolio are stocks/options owned now.
Certain attributes of those stocks/options are fixed (name, expiration date, purchase price); others need to be continually re-calculated based on changing current market prices (you don't state at what interval your application needs to poll the data source, the website, to refresh the calculated attributes).
At a higher level of abstraction: you are also updating the net worth of the portfolio at a current point in time, and, considering that options expire, I think you need to think about how you notify/present/warn the user of the application that an option is about to expire, or, when an option has expired, you remove it from the collection. Similarly, when you sell a stock: do the proceeds then feed back into some running total of net gain, or net loss, so that the portfolio reflects an entire "history" ?
It would seem "natural to me" that you would model a collection of portfolios, and the portfolio elements could be restricted in some ways to contain only bonds, or only puts, or calls, or whatever. Or, whatever: mix 'em all up: you're the artist here
This scenario suggests to me that your "macro object" that you model here is a container comprising a collection of Portfolio objects. The idea that there may be "types" of Portfolio objects, all of which share common functionality, suggests to me a class Portfolio (abstract ? virtual ?), with common fields, Properties, methods, etc., and, then, various Portofolio-Type classes/objects that inherit from the class Portfolio. Or "enforcing commonality" via use of Interfaces ?
If you choose to "mix 'em up:" what do you think about considering that what you are modeling ... at the atomic level ... is not a stock, bond, or option, but an "investment asset:" with one attribute of that investment asset being (fleshed-out as an Enum ?) its type: stock, bond, option-call, option-put, sell-short ?
The one "conspicuous" absence in your current design goal, to my eyes, is the lack of specification of the polling method to update current prices/values, and how it is controlled, or configured, by the end-user, or application. In the real world, the time-limited nature of options (puts, calls), the "tick" of each time-interval that moves you closer to expiration date may have a big influence on how frequently you monitor any given individual option.
There's also the possibility of having sell-at-price, and stop-loss sell-by, orders in place.
However, these are all just general ideas in reaction to the idea of modeling a portfolio, and I'm not saying there's anything wrong with your goals as stated here.
In terms of use of "static" classes: I certainly agree with Luc's very wise comment re: "inherently unique," and suggest you think of a static class as a place which is a repository of utility methods, in this scenario.
There are a lot resources here on CP related to web-scraping, and I'd definitely recommend you do a search for them, and take a look at your elaborate use of RegEx's to see if you could simplify that. RegEx's, however, can be compiled.
I'd also look around for a web service that may return stock/option information in a simpler format (JSON ? rather than XML ? or ?) that would be easier to parse ... assuming hsx.com is not just a name you created, a "placeholder" for accessing said information. Demand for stock/option information is so great, there are bound to be lots of ways to get that information on the web.
Assuming the user will want to create, use, change, their portfolio, and assuming your application does not run continuously: what about the issues of saving "state" when you close the application. Are you going to serialize, send a bunch of whatever off into a "Cloud:" and, if the application is closed, and then re-opened: should it automatically refresh ... warn the the user it is not currently refreshed ... or should the user, through the UI, control when refersh occurs.
My personal vote is for some dramatic visual indicator on the main UI when the current prices are not currently refreshed, or cannot be accessed to be refreshed.
If you do get involved in saving and restoring "state," do see Mehdi Gholam's remarkable work on a super-duper JSON writer/reader here on CP:[^].
Do you wish the user to be able to save "snapshots" of the Portfolio, or to introduce a "history mechanism" into the Portfolio: in which the Portfolio itself contains the entire data for each refresh that has occurred ?
Specific comments on the code:
1. in a static class ... or in a dynamic class ... there's absolutely no need to use private "backing field" variables as well as a public Property: ... unless you are using a very old version of .NET: just use the short-form like: "public static double CurrentPrice { get; set; }" : the private "backing field" will be created for you automatically.
2. by using slightly different casing in variable names in your parameter lists, you can eliminate a lot of the the use of syntax like: "this.optionType = optionType;" typical practice would be to name the variable, or Property, "OptionType," and the parameter name "optionType."
I think imagining what kind of UI a user would want to use your classes/objects is a good exercise ... even if, in this case, you don't choose to implement one ...
good luck, best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
modified 26-Dec-11 6:55am.
|
|
|
|
|
Thank you for the advice and the detail in your reply. Honestly, I haven't been able to plan out where I want this application to go but with your reply I will look into the things you talked about that I haven't ran into yet. Thank you.
|
|
|
|
|
This post is somewhat inspired by Blubbo's recent post, here, on creating a set of methods with similar signatures and return values.
I think I can describe what I want to ask more clearly in the context of some "real code:"
Assume you have a WinForm with three NumericUpDown controls, and one ComboBox presenting a list of three choices: "Multiply, Divide, Power:"
private Func<decimal, decimal, decimal> PE;
private decimal x, y;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
x = numericUpDown1.Value;
y = numericUpDown2.Value;
switch (comboBox1.SelectedIndex)
{
case 0:
PE = (d1, d2) => d1*d2;
break;
case 1:
PE = (d1, d2) => d1/ d2;
break;
case 2:
PE = (d1, d2) => (decimal) Math.Pow((double) d1, (double) d2);
break;
default:
break;
}
try { numericUpDown3.Value = PE(x, y); }
catch (DivideByZeroException dZero) { }
catch (OverflowException oFlow) {}
} What I would appreciate your opinions on are:
1. is there any real performance value inherent in making use of Func and lambdas here ... assuming we "scale" this simple example up to include a very large number of "case" conditions in the "switch" block ?
2. for those of you with understanding of what happens in IL "under the hood:" does anything about assigning those lambdas to the Func "PE" in the "case" statements make the "switch" statement any more complex, or less performant ... once again assuming this example is really scaled up ?
3. since 'throw' is a valid command for exiting a case statement in a switch block, would you ever throw an error in a case statement when possible ?
4. what's your opinion on using something like this compared with the use of Interfaces, as suggested in responses to Blubbo's question ?
thanks ! ... and Merry Xmas ... Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
1. I don't know, but I would prefer to eliminate the switch somehow
2. Ditto
3. I would never throw simply to exit a control structure (I don't even like break and continue)
4. Interface
What comes to mind (in my usual over-engineered way) is a class that holds a delegate to some method. You populate your ComboBox with them, the ToString is used as the text. When selected, you execute the method.
|
|
|
|
|
- The readability, and hence, maintenance would suffer. Lambda's and delegate's are fast.
- It's an extra assignment. Assignments don't take much time though.
- We don't use exceptions to influence the flow of the program. Ever.
- Your switch reminds me of the
Strategy pattern.
BillWoodruff wrote: thanks ! ... and Merry Xmas ... Bill
Enjoy your holidays
Bastard Programmer from Hell
|
|
|
|
|
1. I don't know, I have to do some benchmarks to find out myself.
2. It normally should not make the switch statement less performant, but again, it depends.
3. It's a very bad programming practise to control flow using exceptions.
4. A better solution would be to use Strategy pattern, it would make the code more readable and easy to follow by all programmers, not just the .NET ones.
|
|
|
|
|
I Using C# and DirectX.Capture I Can capture Webcame, but I can't figure out how to mix it with rotating text, should I create a filter?
|
|
|
|
|
Hello,
I am not sure if this is allowed or not – if this post is against any Rules i apologize in advance and this post can be removed.
I am in the process of creating a open-source project to track the Psychological Mood of a person, this application will be used by people visiting psychologists.
Target Audience
People that are currently in therapy or want to keep track of mood changes. The program is based on CBT.
Aims
To provide to the end-user the tools for him to be able to monitor his mood.
To provide to the therapist additional information for the client through the automatic generation of graphs.
To reduce the international suicide rate.
To make this application available for everyone to use.
We are looking for some volunteers to help with Coding of the Project.
The Project has been seperated into three parts for easier management.
The Desktop Application is coded in VB.NET and using an ORM called nHibernate.
Project URL: http://moodtracker.codeplex.com
The Web-Based Application will be coded in C# and use MSSQL as the Database.
Project URL: http://webmoodtracker.codeplex.com/
The iPhone Application.
Project URL: http://iphonemoodtracker.codeplex.com/
We're aiming to develop a feature-rich Psychological Mood Tracker to help the end-users as much as we can.
If anyone is interested please feel to apply to the CodePlex Project Page.
Thank you in advance.
Constantinos
|
|
|
|
|