A very short description of the Team Model Role's goals
Friday, January 19, 2007
Basic MSF Models
A very short description of the Team Model Role's goals
Thursday, January 18, 2007
Why .Net apps consume so much memory
I was researching a little and I found very interesting information that I'm going to comment here.
I, like every body else had a .Net 2.0 Windows application consuming a lot of memory. Initially I eliminated the possibility to minimize the application so it only could be hidden and visible again. When I saw the Task Manager (which now I know is not a good indicator or the real memory a .Net application is using) I was worry because of the high amount of memory being used. Researching I discover Windows allocates private memory (referred later as Private Bytes) and shared memory (private memory plus shared memory is referred later as Working Set) for one single application , and the shared memory can be released if the application doesn’t need it. Surprisingly when an Application is minimized Windows releases the application's shared memory making the value shown in the Task Manager very low. I tested it using some counters with the perform monitor. I added two counters for my application: Private Bytes and Working Set then Running and minimizing my App I got this output:
It shows how the Working Set drops dramatically, but Private Bytes stays flat. When I look the size of my app minimized in the Task Manager I saw it uses two or 3 MB of RAM. Wow!! Then I did the same test with Messenger and GoogleTalk and I got the same result. Windows frees memory when apps are minimized which is logic and great!
Something else I notice: When you don’t want to show your application minimized to users but still want Windows to release memory then the application’s window must be visible at the moment it is minimized for Windows to recognize the visible change.
e.g. If you hide the application and later minimized it by code like this
this.Hide();
this.WindowState = FormWindowState.Minimized;
Windows won’t recognize that it is minimized then keeping the complete memory allocated for the application (the mem value in the Task Manager does not change). The code should be like this for Windows to be aware that the application is not been used
this.WindowState = FormWindowState.Minimized;
this.Hide();
I’m going to copy here some interesting conclusion from Tim Anderson's page. (http://www.itwriting.com/dotnetmem.php)
1. Windows generally does a good job of memory management. High figures in Task Manager needn’t concern the user if the system is running well.
2. .NET applications really do have a high memory footprint relative to most native code applications (Java has the same problem).
3. Don’t use the mem usage column in Task Manager for diagnostics or profiling.
4. There isn't much developers can do about the memory footprint of the .NET runtime. However, there is a lot that developers can do to make applications that use memory efficiently and avoid leaks. This mostly involves looking at the .NET counters rather than the system counters. Use of a profiler is near-essential; I like the SciTech ( http://memprofiler.com).
Wednesday, January 3, 2007
Best Practices for SQL (Evolving entry)
Books online/ Sample Data bases. Always huge source of best advises.
SQL Best Practices
------------------------
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/default.mspx
Best Practice Analyzer tool
-------------------------------
http://www.microsoft.com/downloads/details.aspx?FamilyID=B352EB1F-D3CA-44EE-893E-9E07339C1F22&displaylang=en
Storage Top 10 Best Practices
------------------------------------
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/storage-top-10.mspx
Data Patterns (high level)
--------------------------------
http://msdn.microsoft.com/practices/compcat/default.aspx?pull=/library/en-us/dnpatterns/html/dp.asp
Thursday, December 28, 2006
LAS VEGAS
Working with PDFs
Requirement of my App:
1. Can't download the PDF files to the client computer
2. Can't use Acrobat reader or any other plug in/reader (named Helper Applications) that push the user to download it .So everything should be embedded in my app, and the user can't have any plug-in or browser pre-installed to see and print the PDF files.
Because the PDF file cannot be downloaded to the user machine, it is needed to navigate or to load the document into the reader by passing to it an URL.
Alternatives:
1. Use the .Net WebBrowser Control in my Windows Form and embed the reader or any PDF plug-in (not acrobat! it means I cannot use the PDF Control that is include in VS when the acrobat reader is installed) into my Setup in order to install it unattended from the user. I never tried it!
2. Use a third party PDF browser-reader control (dll or ocx). I never found it!
Solution:
I found a control “WPViewPDF” (an ocx) able to load a PDF from a stream, and I implemented this method to get the stream from the URL:
--------------------------------------------------------------------------------
//Make a Request to the file and return it as Stream
WebRequest MyReq = WebRequest.Create(textBox1.Text);
WebResponse MyResp = MyReq.GetResponse();
Stream data = MyResp.GetResponseStream();
//Create the bytes array store the Stream
byte[] buff = new byte[MyResp.ContentLength];
//Read the Stream and Load the array
int len = 0;
int cnt;
do
{
cnt = data.Read(buff, len, buff.Length - len);
len += cnt;
} while (cnt > 0);
data.Close();
MyResp.Close();
//Recreate a Stream and pass it as a parameter
MemoryStream ms = new MemoryStream(buff);
pdfViewer1.LoadFromStream(ms);
I researched and I found this:
1. The easiest way to Download the file and save it to disk is using a WebClient
client.DownloadFile(varURL, localFileName);
using (BinaryWriter writer = new BinaryWriter(stream))
{writer.Write(ms.ToArray());}
-------------------------------------------------------------------------------
Conclusion so far:
It worked fine but the control does not render well the PDF file, so I’m looking foranother control that can download a document from a stream.
I tried before those components:
PDF-tools: It is an ocx and gave me to much exceptions.
PDFXpress: They don’t have a release for .NET 2.0
WPViewPDF: Does not render some PDF correctly.
PDFNEtDemo: Does not load PDF from URLs
There is also some exceptions that happen when PDF is used with .Net and the PDF document has not been done following the rfc2616 specification (www.ietf.org/rfc/rfc2616.txt) and it is loaded from the WEB (via URI):
System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine. A pain..!!
To help the community and avoid people from waste time reading and reading I’m going to give some links that show the story of this exception and the solutions.
Important to know:
Some .NET requirements for PDF documents (http://msdn2.microsoft.com/en-us/library/system.net.configuration.httpwebrequestelement.useunsafeheaderparsing(VS.80).aspx)
1. To help protect from "HTTP Response splitting" attacks, parsing is performed according to the document that is named Request for Comments (RFC) 2616. This means that all control characters are not permitted in names or in values. For example, the carriage return (CR) character and the linefeed (LF) character are not permitted. There are other characters that are not permitted in names. Additionally, every response header must have a colon.
2. Headers names should not have spaces in them.
3. If multiple status lines exist, all additional status lines are treated as malformed header name/value pairs.
4. The status line must have a status description, in addition to a status code.
5. Header names cannot have non-ASCII chars in them. This validation is performed whether this property is set to true or false.
Links to read about it:
http://blogs.msdn.com/mflasko/archive/2005/11/02/488370.aspx
http://support.microsoft.com/?kbid=888527
(search for "Undocumented bugs in the .NET Class Library (NCL)")
http://msdn2.microsoft.com/en-us/library/65ha8tzh.aspx
http://www.velocityreviews.com/forums/t302174-why-do-i-get-quotthe-server-committed-a-protocol-violationquot.html
Monday, November 20, 2006
Removing URL from the footer of a printed document
Well so far I have tried this:
I want to setup the header and footer when printing a page (notice that I’m not talking about the header and footer of the webpage, which can be solve using a PrintStyleSheet). I’m talking about the header and footer that appears in the Page Setup Dialog (you know the annoying URL)
I'm trying with the IE5. OCX control, via interop, that allows to pass a parameter to the header and footer of the pagesetup, but I don’t want to go back using unmanage code.
Also, I found this solution requires to change the keys entries in the registry. Of course it is necessary to have permission to write in the registry. The basic code is this and needs no explanation
--------------------------------------------------------------------------------------------
using Microsoft.Win32;
RegistryKey pageKey = Registry.CurrentUser.OpenSubKey("software\\microsoft\\internet explorer\\pagesetup", true);
string newFooter = "";
string newHeader = "";
object currentFooter = pageKey.GetValue("footer");
object currentHeader = pageKey.GetValue("header");
pageKey.SetValue("footerTemp", currentFooter );
pageKey.SetValue("headerTemp", currentHeader);
pageKey.SetValue("footer", newFooter);
pageKey.SetValue("header", newHeader);
pageKey.Close();
--------------------------------------------------------------------------------------------
Something to remember:
The header and footer entries in the registry are not created yet in the user machine. Windows create those entries the first time the user accesses the PageSetup windows. So if you receive an exception maybe because the code is trying to read entries that are not created yet. You should check first.
It was useful for me at the time I had a WebBrowser2.0 control running inside a windows form (VS2005 )so I could access the registry from my windows application. I have not use this code from a WebPage which require more code and some JavaScript to manipulate the registry but in this link is a sample showing it.
http://www.codeproject.com/useritems/Removing_url_in_print.asp?df=100&forumid=346298&select=1766196&msg=1766196
Test it!! and let me know.
Sunday, November 19, 2006
Microsoft and Novell Announce Broad Collaboration on Windows and Linux Interoperability and Support
REDMOND, Wash., and WALTHAM, Mass. — Nov. 2, 2006 — Microsoft Corp. and Novell Inc. today announced a set of broad business and technical collaboration agreements to build, market and support a series of new solutions to make Novell and Microsoft® products work better together. The two companies also announced an agreement to provide each other’s customers with patent coverage for their respective products. These agreements will be in place until at least 2012. Under this new model, customers will realize unprecedented choice and flexibility through improved interoperability and manageability between Windows® and Linux.“They said it couldn’t be done. This is a new model and a true evolution of our relationship that we think customers will immediately find compelling because it delivers practical value by bringing two of their most important platform investments closer together,” said Steve Ballmer, CEO of Microsoft. “We’re excited to work with Novell, whose strengths include its heritage as a mixed-source company. Resolving our patent issues enables a combined focus on virtualization and Web services management to create new opportunities for our companies and our customers.”
On-Demand Webcast
You can view an on-demand Webcast of the News Conference with Microsoft CEO Steve Ballmer and Ron Hovsepian, president and CEO of Novell, held Nov. 2.
View the Webcast (53 min. 34 sec.)
Under the agreement, Novell is establishing clear leadership among Linux platform and open source software providers on interoperability for mixed-source environments. As a result, Microsoft will officially recommend SUSE Linux Enterprise for customers who want Windows and Linux solutions. Additionally, Microsoft will distribute coupons for SUSE Linux Enterprise Server maintenance and support, so that customers can benefit from the use of an interoperable version of Linux with patent coverage as well as the collaborative work between the two companies.
Usign ORM
Solving the Data Access problem: to O/R map or not To O/R map
On the http://www.asp.net/forums (the architecture section), a person asked in the 'Your favorite O/R mapper' thread, why someone would use a 3rd party component for data-access and why would that be an O/R mapper and if so, which one?
Q: why would I go out and buy a 3rd party component / library?
A: With every task you have to perform during a software development project, you have to make a calculation: if I perform this task myself, how much time will that take, and given my hourly fee, how much money is involved in it, minus the knowledge I gain from doing it myself and the insight it gives me. The number resulting from that calculation is compared to what a 3rd party component costs + how much time it will take to get used to the 3rd party component + the time to figuring out which component is good + some risk calculation (because a 3rd party component can turn out to be a bad choice after all after a month or so). This sounds awkward, but it's common sense. It's not always more efficient to go out and buy a component to do things for you, like it's not always more efficient to do things yourself. However without making a simple calculation, it's hard to tell in which situation you're in. Software projects are hard to manage, and without tight cost control, or better: cost insight, it's hard to make a project be run efficient and profitable. So even if it's tempting to go out and buy a component or use an open source component, is it really more efficient to do so? Often it is, don't get me wrong on that, but don't forget the costs of using a 3rd party component, especially when it's a freebee without any documentation and just a raw example program without a lot of comments.
Q: why should I implement an O/R Mapper in my projects?
A: O/R mapping is in theory very simple: you have a table field and you have an entity field and you define a connection between them and use that connection in your logic to provide functionality like load a class' data, save it, etc. etc. However using solely the terms 'O/R mapping' and 'O/R mapper' is only making things more complicated. The problem description is:
"I have to make a connection between my business logic and my persistent storage, how do I do that?".
The answer: "use an O/R mapper" is not helpful, as it would require knowledge about what an O/R mapper is. If you don't know what it is, how can you judge if an O/R mapper is helpful and if that answer holds some truth? You can't. The right answer is a question: "how do I see my data?". It's the cornerstone of the answer leading to the solution of the dreaded Data-Access problem. There are a couple of different views on 'data' which result in different ways of how the DataAccess problem is solved. You have: 1) table approach 2) entity (Chen/Yourdon) approach 3) domain model (Fowler/Evans) approach(these are the top 3. There are others, most of them fall in either of these 3 categories though). 1) and 2) look the same, but aren't. Let's discuss these 3 views more in detail.1) Table approachThe table approach is the plain 'I use tables and query them' approach. No theory used, just a set of tables, not based on any abstract model, they're created right there in DDL. The developer uses tables and is expecting to work with tables in memory as well, so a plain dataset/datatable approach with stored procedures or VS.NET-generated SQL statements is an appealing approach. Typically, the developers using this approach use terms like 'rows' and 'customer record'. It might sound odd, but this is a very widely used approach on .NET. The reasons for that are that Microsoft preaches it through VS.NET designers and -examples and because in the pre-.NET period, ADO with recordset objects was the way to go. 2) Entity (Chen / Yourdon) approachThe entity approach is different. The relational model is build with an abstract model and is based on theory. This means people speak of entities (or if you want to go really deep into theory, relation) and attributes. An approach with solely DataTables / DataSets is often not appealing, as the relational model speaks of Customer Entity and not about Customer record. Developers using this approach want to use these type of elements also in their code. As they use a relational model as their base of their thinking, the entities by definition don't contain behavior/rules or just low level behavior/rules, like the checkconstraints/unique constraints and other constraints defined like 'shippingdate >=orderdate' or 'id >=0'. Also important is the way the developers want to utilize the relational model. They understand that the data in the database is just data, and an entity is just a relation based on attributes, which can be constructed dynamically as well, with a select statement. This is important for lists of combined attributes from different entities and reporting functionality. The entity approach uses a combination of O/R mapping for the entity data and generic data functionality like Datasets / DataTables for the dynamic data retrieval requests. The entity approach is also widely used, you see it more in the larger applications as these applications often require a system architect and data analyst. It's proven technology which exists since the late '70-ies of the past century. 3) Domain model (Fowler / Evans) approachThe Domain model is an approach which is the most used approach for solving the Data Access problem in the Java world, but interesting enough rather rare in the microsoft world. This is not that surprising, as in the Microsoft world it was simply unknown: Microsoft never talked about it, the techniques mostly used by the tools used by developers didn't support it very well, so running into it was not that common, only perhaps when you talked about Data Access with Java developers for example. Another reason it is not that widely used, is that it requires an OO approach which wasn't often possible with COM objects and/or VB5/6. The domain model focusses on domains, like the Customer domainor the Order domain. It starts with classes, like a Customer class, which contains the data for a customer but also all behavior for the customer, so all business rules for the customer are stored there. (This is somewhat simplistically said, there are a couple of variants of course, but for the sake of the argument, let's keep it with this description). Through inheritance you can create a compact model of classes and store the behavior you have to define in the class it belongs in, using polymorphism to override/modify behavior through the hierarchy. The classes / class hierarchy is then stored in a persistent storage, typically a database. This is a fundamental difference with 2) : with the Domain model, the relational model follows classes, classes don't follow the relational model. Typically, behavior in 2) (and also 1)) are stored in functionality objects like CustomerManager, which embeds the customer functionality, and which is applied to behaviorless entity objects. In 3) you have the behavior in the class, no manager classes. 3) requires an O/R mapper to work with the data in the persistent storage or better: the O/R mapper is required to (re-)instantiate entity objects from their persistent state in the persistent storage. Because the system focus on data is through objects, working with data like in 2) and 1) is not available, it's working with objects. What's the best approach?Hard to say. 25 years of 2) in millions of software systems around the world can't be wrong, however millions of software systems in Java using approach 3) can't be wrong either. I think it largely depends on what you think is more logical, how you want to work with data. I'm in camp 2), and our product LLBLGen Pro is a tool which tries to help with 2) by offering both O/R mapping and flexible relational model data access power. It's therefore not a pure O/R mapper as it doesn't fit that much in 3), it offers more functionality, to help with 2) than with 3). Also Paul Wilsons WilsonORMapper is more of a category 2) than category 3) application. More pure O/R mappers, like EntityBroker, DataObjects.NET, NHibernate and others focus on 3) (most of the time). Don't think lightly about this, the differences are fundamental and will influence how your system structure is designed for a great deal. So it's important to pick the approach which fits your way of thinking. To test how you think about data, ask yourself: "A customer gets the Gold status when the customer has bought at least 25,000$ worth of goods in one month. Where is that logic placed? in which class/classes?". Inside the Customer object, reading inside the customer object order data to test the rule? Or in a CustomerManager which executes rules and consumes customer and order objects? Also don't let your decision be influenced by "but this example proves x is better than y!": at the end of the day, data is data and not information. Information is data placed into context, and it requires interpretation to give it any value/meaning. How you do that is not important, as long as you meet requirements as: maintainability, scalability and efficiency in development, deployment and perhaps (but not necessarily) performance. So if your way of writing software is clearly in the Fowler/Evans camp, 3), don't use datasets, don't use a Data Access solution targeting 2) because it will be a struggle: the way of thinking doesn't fit the tool used: you want to drive in a nail with a screwdriver, you should either switch the nail with a screw or use a hammer instead of a screwdriver. So if you're in camp 3), use a pure O/R mapper, it will fit like a glove. If your way of thinking is clearly in the 2) camp, using a pure O/R mapper can give you headaches when you want to write a lot of reports, you want to use a lot of lists combined from attributes of multiple entities, you need functionality which allows you to perform scalar queries, and an approach which allows you to think from the relational model, so an application which has an approach tailored on starting with the relational model.